42
0
17
1
88
2
33
3
71
4
9
5
56
6
25
7
64
8
12
9
AlgoPlus//sorting / selection sort
Read the theory

Selection Sort · Minimum Hunt

Scan, lock onto the smallest, exchange — repeat.

Stability
Unstable
In-Place
Yes
Space Complexity
O(1)
Avg Time
O(n²)
Size10
Legend
Comparing
Swapping / moving
Tracked (min / key)
Pivot
Sorted / found
Out of focus
AI Tutor Workspace
In a nutshell
Selection sort repeatedly scans the unsorted part of the list to find the smallest value, then swaps it to the front of that part. The sorted region grows one item at a time from the left. It always does the same amount of looking regardless of the data, but it makes very few swaps — only one per pass.
Ready
Press play to begin the cinematic walkthrough.
Each pass scans the unsorted region and selects the smallest element to place at the boundary.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Selection Sort · Minimum Hunt.
Code Simulator
1
def selection_sort(arr):
2
    n = len(arr)
3
    for i in range(n):
4
        min_idx = i
5
        for j in range(i + 1, n):
6
            if arr[j] < arr[min_idx]:
7
                min_idx = j
8
        arr[i], arr[min_idx] = arr[min_idx], arr[i]
Why Python? · Readable first, fast second

Dynamically typed and interpreted — every comparison and swap is dispatched by the interpreter at run time, so tight loops run roughly 10–100× slower than compiled C/C++. Unbeatable for learning the idea with the least code; not what you reach for when the inner loop is the bottleneck.