Radix sort sorts numbers digit by digit without comparing them. The least significant digit (LSD) version shown here first sorts all values by their ones digit, then by their tens digit, then by their hundreds digit. Each pass is a stable counting sort with ten buckets, so values that tie on the current digit keep the order from the previous pass. After the last digit, the whole array is sorted.
The visualizer shows the ten digit counts, their running totals and the output array for each pass, and the message names the digit being used. Watch how the bars look jumbled after the first pass but are fully sorted after the hundreds pass.
How to use the Radix Sort Visualizer tool
- Pick an array size and an input: random, nearly sorted, reversed or few unique values. You can also type your own numbers.
- Press Play to watch the sort, or Step to move one comparison or swap at a time. Back goes one step back.
- Follow the colours: orange bars are being compared, red bars are being swapped or written, green bars are in their final place.
- Read the message under the controls and the highlighted pseudocode line to see exactly what the algorithm is doing.
- Change the speed, switch the code tab to C++, Java, Python or JavaScript, and compare the counters with other inputs.
Why use ToolOrca Radix Sort Visualizer
- Animated bars with play, pause, step and step back
- Speed slider and a position slider to jump to any step
- Digit counts and output array for every pass
- Random, nearly sorted, reversed and few-unique inputs, or your own numbers
- Highlighted pseudocode line for every step
- Code in C++, Java, Python and JavaScript
- Works on phones and tablets, keyboard accessible
How LSD radix sort works
Find the maximum value to know how many digits d to process. For exp = 1, 10, 100 and so on: take each value’s digit (x / exp) mod 10, count how many values have each digit, turn the counts into running totals, and place the values into an output array from right to left. Copy the output back and move to the next digit.
The trick is stability. When sorting by the tens digit, 31 and 37 tie, but the previous pass already put 31 before 37, and a stable pass keeps it that way. So after processing the tens, the values are sorted by their last two digits, and so on up to the most significant digit.
Time and space complexity of radix sort
Each pass is a counting sort with base b = 10, costing O(n + b). With d digits the total is O(d × (n + b)). For fixed-width keys such as 32-bit integers, d is a constant, so radix sort runs in linear time. It needs O(n + b) extra memory for the output and count arrays. Real implementations often use base 256 and sort one byte per pass.
When to use radix sort
Radix sort shines on large arrays of integers, fixed-length strings, dates, IP addresses or other keys made of digits or characters. GPUs and database engines use it for this. It is not a general-purpose sort: it needs keys that split into digits, and for small arrays the passes cost more than a simple comparison sort.
Every visualizer on this site runs in your browser with the same controls: Play, Pause, Step forward, Step back and a speed slider. You can also drag the position slider to jump to any step, or focus the drawing and use the Space bar and arrow keys.
Frequently asked questions
What is the time complexity of radix sort?
O(d × (n + b)), where d is the number of digits, n the number of values and b the base (10 here).
Why does LSD radix sort start with the last digit?
Because each later pass is stable, it keeps the order produced by the less significant digits for values that tie. After the most significant digit the order is fully correct.
What is the difference between LSD and MSD radix sort?
LSD processes digits from the rightmost to the leftmost and needs every key to have the same number of digits (padding with zeros). MSD starts at the leftmost digit and recursively sorts each bucket, which suits strings of different lengths.
Is radix sort faster than quick sort?
For many fixed-width integer keys it can be, because it is linear. For small arrays, mixed data or complex keys, quick sort or the built-in sort is usually faster and simpler.