Sorting By
1s (Ones)
170
45
75
90
802
24
2
66
0
1
2
3
4
5
6
7
8
9

Radix Sort

A non-comparison algorithm that sorts numbers digit-by-digit, starting from the least significant digit (LSD).

Sorting Ones (1s)

We look at the last digit of each number and drop it into the matching bucket 0-9.

Buckets Filled (1s)

170->0, 90->0, 802->2, 2->2, 24->4, 45->5, 75->5, 66->6.

Collect (1s)

We gather them back from Bucket 0 to 9. The order is preserved (Stable Sort).

Sorting Tens (10s)

Now we sort by the second digit. 170->7, 02->0, 24->2...

Buckets Filled (10s)

Note: 802 has '0' in tens place. 2 is '02', so '0' tens.

Collect (10s)

Gathering back... Notice the list is getting more ordered.

Sorting Hundreds (100s)

Final pass. Most numbers have '0' hundreds (e.g. 45 -> 045).

Buckets Filled (100s)

Almost everyone goes to Bucket 0. 170 goes to 1. 802 goes to 8.

Final Collection

Gathering from 0 to 9 one last time.

Sorted!

The array is perfectly sorted! We did this without ever comparing two numbers directly (like 802 > 170).

Linear Time*

O(n·k) where k is the number of digits. For fixed-size integers, this is effectively O(n) linear time!

No Comparisons.

Radix Sort breaks the O(n log n) barrier by using the structure of numbers themselves.

AlgoAnimator: Interactive Data Structures