logo
SEE ALGORITHMS
    Bubble Sort
    Insertion Sort
    Selection Sort
    Heap Sort
    Merge Sort
    Quick Sort
    Radix Sort

Radix Sort

Radix Sort organizes numbers by sorting them digit by digit. It starts with the least significant digit (rightmost) and works to the most significant digit (leftmost). Numbers are placed into buckets based on each digit's value, then collected back together in order. This process is repeated for each digit, leading to arr sorted list.

Things to Observe

  • Digit by Digit: Notice how the sorting happens in passes, one for each digit place (ones, tens, hundreds, etc.), starting from the rightmost digit. The currently sorted digit is highlighted in pink.
  • Bucketing: In each pass, watch how the numbers are distributed into "buckets" (0-9) based on the value of the current digit. They are then collected back from the buckets in order, preserving the relative order from the previous pass.
max = largest(arr)
exp = 1
while (max / exp) > 0:
    buckets[0..9] = empty stacks
    for i = 0 to (n - 1):
        d = (arr[i] / exp) % 10
        push arr[i] to buckets[d]
    k = n - 1
    for j = 9 to 0:
        b = buckets[j]
        while b is not empty:
            arr[k] = b.pop()
            k = k - 1
    exp = exp * 10
Select number of elements:  

Curious to Learn More?

Hand-picked resources to deepen your understanding

Beginner Friendly
Grokking Algorithms

A friendly, fully illustrated guide. The best starting point for visual learners.

Practical Guide
A Common-Sense Guide to Data Structures and Algorithms

A practical guide with clear explanations and real-world examples.

Deep Dive
Introduction to Algorithms

The definitive guide (CLRS). Comprehensive and rigorous, perfect for deep diving into theory.

As an Amazon Associate, I earn from qualifying purchases. This helps support the site at no extra cost to you.

© 2025 SEE Algorithms. Code licensed under MIT, content under CC BY-NC 4.0.