⚡ AlgoZen_
~/home/sorting_algorithms/counting_sort7 / 7

Counting Sort

Beginner

Sort integers by counting occurrences of each value, then reconstructing the sorted array. Makes zero comparisons — beats the O(n log n) lower bound when the value range k is small.

time:O(n + k)
space:O(k)
⚡ +150_XP
step[1/23]
> Start
4
2
2
8
3
3
1
7
4
Input: [4, 2, 2, 8, 3, 3, 1, 7, 4]. Counting Sort counts occurrences of each value — no comparisons!

// tap NEXT STEP to walk through one step at a time