42
0
17
1
88
2
33
3
71
4
9
5
56
6
25
7
64
8
12
9
AlgoPlus//sorting / counting sort
Read the theory

Counting Sort · Tally & Place

Count each value, then write them back in order — no comparisons.

Stability
Stable
In-Place
No
Space Complexity
O(n+k)
Avg Time
O(n+k)
Size10
Legend
Comparing
Swapping / moving
Tracked (min / key)
Pivot
Sorted / found
Out of focus
AI Tutor Workspace
In a nutshell
Counting sort never compares values. It tallies how many times each possible value appears, adds the tallies up into running totals that say where each value belongs, then places every item directly into its final position. It's blazingly fast when the values come from a small range, but the extra memory grows with that range, not the number of items.
Ready
Press play to begin the cinematic walkthrough.
Don't compare items — count them. Tally how many times each value appears, turn those tallies into running positions, then drop every value straight into its final slot.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Counting Sort · Tally & Place.