Radix sort
A sorting algorithm that doesn't compare: it sorts by digits, from last to first, using a stable sort on each pass.
Example
1 million 6-digit numbers are sorted in 6 passes: about 6 million steps.
Test yourself: Radix sort
Radix sort
Radix sort with 8-digit numbers makes ___ passes.
1 pass per digit. With plain counting sort, 100 million counters would be needed; this way, 10 per pass.
Radix sort
With [23, 21], after sorting by units you get [21, 23]. By tens they tie at 2, and since the pass is stable, the first is still ___.
Stability keeps the previous pass's order among ties: 21 before 23. Without it they could end up reversed.
Radix sort
The units digit of 4,735 is ___.
4,735 % 10 = 5. It's digit 1: dividing by 10⁰ = 1 changes nothing and the remainder of dividing by 10 is 5.
0/3
▶ Play