Counting Sort
SortingavgO(n + k)worstO(n + k)spaceO(n + k)
mainoutcount
95
95
35
75
55
95
95
95
35
75
35
95
95
35
95
75
75
35
75
55
95
35
55
75
Values range from 35 to 95
1 / 56
Size24
Distribution
Custom values2 to 150 whole numbers, each 1 to 999
seed 9
How it works
Never compares elements: it tallies how often each value occurs, turns the tally into prefix sums (each value's end position), then places every element straight into the output. It runs in linear time when the value range k is small.
Complexity
- Best
- O(n + k)
- Average
- O(n + k)
- Worst
- O(n + k)
- Space
- O(n + k)
- Stable
- Yes
- In place
- No