SortingAnimated
Selection Sort
Repeatedly select the minimum and put it first.
Time
O(n²)
Extra space
O(1)
Use it for
When writes are expensive (at most n swaps).
How it works
- Scan the unsorted part to find the smallest value.
- Swap it into the first unsorted position.
- The sorted part grows by one; repeat.
- Always about n²/2 comparisons, but at most n swaps.
Watch it run
Loading animation…