Counting Sort vs Radix Sort
Counting Sort vs Radix Sort compares two non-comparison sorts that both achieve near-linear time. They are closely related — Radix Sort actually uses Counting Sort internally — but they handle the range of values in fundamentally different ways.
The relationship
Counting Sort tallies every distinct value, needing O(k) memory for value range k. Radix Sort sidesteps the memory blow-up by sorting digit by digit, applying a stable Counting Sort on each digit so k stays tiny (just 10 for decimal digits).
When to use each
Use Counting Sort when the value range k is small (scores 0-100, ages). Use Radix Sort when values are large integers but have a fixed number of digits — it keeps memory low while still beating O(n log n). Both are stable and non-comparison.
Frequently asked questions
What is the difference between Counting Sort and Radix Sort? +
Does Radix Sort use Counting Sort? +
See it in motion
Watch this algorithm and 9 others run step by step in our free interactive visualizer.
▶ Launch Visualiser