Selection Sort
SortingavgO(n²)worstO(n²)spaceO(1)
53
55
62
61
85
56
12
55
62
47
50
85
44
68
69
20
21
31
42
40
Start with 20 unsorted values
1 / 291
Size20
Distribution
Custom values2 to 150 whole numbers, each 1 to 999
seed 11
How it works
Scans the unsorted suffix for its smallest element and swaps it to the front. After pass i the first i + 1 elements are final, so it makes at most n − 1 swaps but always about n²/2 comparisons.
Complexity
- Best
- O(n²)
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stable
- No
- In place
- Yes