Selection Sort
Scan for the smallest value left, then swap it home. At most n-1 swaps.
Decision · step 3 of 35Selection Sort: Seven values
1 is smaller than 5: new minimum.
What you will see
A scan finds the minimum (marked candidate), then one swap plants it at the boundary.
Cost
| Best | O(n^2) |
|---|---|
| Average | O(n^2) |
| Worst | O(n^2) |
| Space | O(1) |
Always n(n-1)/2 comparisons; at most n-1 swaps.
Properties
- ✓ comparison based
- × stable
- ✓ in place
- × adaptive
- × online
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, compare two runs.
Screen readers: Cells announce index, value and state (comparing, swapped, sorted); each step announces the comparison outcome and any move.
Reduced motion: Swaps become value crossfades with outline flashes; sorted-region growth is a static span change.