Selection Sort
Scan for the smallest value left, then swap it home. At most n-1 swaps.
Selection Sort: Seven values
Swap 1 into index 0. The sorted prefix grows.
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
- Yes: Comparison based
- No: Stable
- Yes: In place
- No: Adaptive
- No: Online