Selection Sort
Interactive lab
Try it: Selection Sort
How selection sort repeatedly finds the smallest (or largest) remaining value and swaps it into the next position.
How it works
- Scan the unsorted part and remember the position of the smallest value.
- Swap it into the first unsorted position.
- That position is now final; repeat on the rest.
- Always n(n−1)/2 comparisons, at most n−1 swaps; not stable.
Default run (27 steps): Selection sort, ascending: [8, 3, 5, 1, 9, 2]. … Sorted ascending: [1, 2, 3, 5, 8, 9] — 15 comparisons, 5 swaps.
Simplified: Up to 12 numbers from 0 to 99. The comparison table runs all five algorithms on the same input. Python's own sort() uses Timsort.
Educational simulation
Loading the simulation…