Radix Sort Visualization
Radix Sort sorts numbers digit by digit, from the least significant digit up, without comparing values.
How it works
Radix Sort never compares two values. It distributes the numbers into buckets by their last digit, collects them in bucket order, then repeats with the next digit. Because each pass is stable, after the last digit the list is fully sorted. This version uses base 4, so each pass looks at two bits.
The work is n × the number of digits, which beats n log n when the keys are short. It needs extra memory for the buckets, works on integers or fixed-length keys, and is stable.
What to watch for
Watch the colours regroup into a few repeating bands on each pass; on the last pass, the bands line up into one rainbow.
Complexity
- Best
- n·k
- Average
- n·k
- Worst
- n·k
- Extra space
- n + b
- Stable
- Yes
Race it
Same shuffle, same speed, one winner: Radix vs Quick. Or open the studio to try other layouts, sizes and speeds, and make a video of it.
FAQ
Is Radix Sort faster than Quick Sort?
For fixed-size integer keys it can be, because its work grows linearly with n. For general data Quick Sort is more flexible.
Is Radix Sort stable?
Yes, and it relies on that: each digit pass must keep the order from the previous pass.