Skip to content
StackDecode
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

  1. Sort by one digit at a time, starting with the least significant (ones).
  2. 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.
  3. Repeat for tens, then hundreds.
  4. After the last digit the list is fully sorted, without comparing numbers to each other.

Watch it run

Loading animation…