DSA
    intermediate

    Radix Sort

    Radix Sort

    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.

    ⏱ O(d(n+b))
    💾 O(n+k)
    Ready
    Current Array
    170
    45
    75
    90
    802
    24
    2
    66
    Buckets (0-9)
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9

    Starting Radix Sort. Max value: 802, needs 3 passes

    50%
    Live Variables
    maxNum802
    maxDigits3

    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

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

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

    The short version

    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!

    In more depth

    LSD Radix Sort (Least Significant Digit)

    Process digits from right to left:

    1.Sort all numbers by ones digit
    2.Sort by tens digit (stable sort preserves ones order)
    3.Sort by hundreds digit...
    4.Continue until all digits processed

    Why LSD Works

    Later passes override earlier ones, but stable sorting ensures ties are broken by earlier digit order.

    When to Use

    Fixed-length integers or strings
    Range is large but digit count is small
    Alternative to O(n log n) sorts

    When to reach for this

    • Sorting large integers or fixed-length strings
    • Need O(n) time for integer sorting
    • Values have a fixed number of digits
    • Sorting by multiple keys (like dates: year, month, day)

    Interview Questions

    Google
    Microsoft
    Amazon
    Airbnb
    Facebook
    Bloomberg
    Apple
    Uber

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required