SortingAnimated
Radix Sort
Sort digit by digit with a stable sort.
Time
O(d · (n + k))
Extra space
O(n + k)
Use it for
Fixed-width integers or strings.
How it works
- Sort by one digit at a time, starting with the least significant (ones).
- For each digit, put every number into one of ten buckets (0 to 9) and read the buckets back in order. Each pass must be stable.
- Repeat for tens, then hundreds.
- After the last digit the list is fully sorted, without comparing numbers to each other.
Watch it run
Loading animation…