Radix Sort Visualizer
Watch how Radix Sort organizes numbers by processing each digit position, from least to most significant, using stable bucket sorting.
SlowFast
515
(10)Ready to start sorting
Array Elements
161
[0]
65
[1]
23
[2]
26
[3]
179
[4]
151
[5]
101
[6]
105
[7]
65
[8]
72
[9]
Processing
Sorted
Waiting
Operation Logs
No operations yet
Algorithm Info
Time Complexity: O(d × n) — d = number of digits
Space Complexity: O(k + n) — k = number of buckets
Stable: Yes - maintains relative order of equal elements
How it works: Radix sort processes numbers digit by digit, starting from the least significant digit. It uses counting sort to maintain stability while distributing elements into buckets.
Implementation
function radixSort(arr) {
let maxNum = Math.max(...arr);
let exp = 1;
while (Math.floor(maxNum / exp) > 0) {
// Create 10 buckets (0-9)
let buckets = Array.from({ length: 10 }, () => []);
// Distribute elements into buckets by current digit
for (let i = 0; i < arr.length; i++) {
let digit = Math.floor(arr[i] / exp) % 10;
buckets[digit].push(arr[i]);
}
// Collect elements back from buckets in order
arr = [].concat(...buckets);
exp *= 10; // Move to next digit
}
return arr;
}