IntermediateAbout 25 min

    Radix Sort

    Read the full article on Substack

    8 min read.

    Sort integers digit by digit using a stable sort (like Counting Sort) as a subroutine. Achieves O(d×(n+b)) time where d is the number of digits and b is the base.

    Think of it this way: Think of sorting a library by call numbers. First sort by the last digit, then the second-to-last, and so on. After processing all digits, the books are perfectly ordered!

    ÷11700451752903802424526667
    0123456789

    Sort by the ones digit, then tens, then hundreds — each pass is stable.

    1/32

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Least significant digit first

    Sequence

    Order the passes of an LSD radix sort on three-digit numbers.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    Why must the per-digit sort in Radix Sort be stable?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going