- RECURSION
- Call Stack
- Iterative Approach
- Memoization
- Head Tail
- DATA STRUCTURES
- Arrays, Sets
- Time Complexity
- Hash Tables
- Stacks
- Queues
- Linked Lists
- Trees
- Binary Search Trees
- Tries
- Graphs
- COMPARISION BASED
- Bubble Sort
-
Selection Sort
- Merge Sort
- DIVIDE CONQUER
- Binary Search
- Quicksort
- Karatsuba Multiplication
- GRAPH TRAVERSAL
- Flood Fill
- Depth First Search
- Breadth First Search
- Dijkstra's Algorithm
- DECISION MAKING
- Minimax
- GREEDY
- Coin Change
- Fractional Knapsack
Selection Sort
The algorithm works by repeatedly finding the minimum element from the unsorted part of the array and putting it at the beginning.
def selection_sort(X):
for i in range(len(X)):
min_index = i
for j in range(i+1, len(X)):
if X[j] < X[min_index]: # Look Here
min_index = j
X[i], X[min_index] = X[min_index], X[i]
# Example usage:
A = [1, 3, 9, 5, 4, 0]
selection_sort(A)
print("Sorted list =", A)
"""
[0, 1, 3, 4, 5, 9]
"""
Last update: 486 days ago