All d digits are scanned, with n elements and b buckets per digit: Θ(d(n+b)).
Sorting algorithms · 6/7
Radix sort (LSD)
Sorts from the least significant digit using stable passes.
How it works
Group by units, then tens, hundreds and so on; stability preserves earlier digit ordering.
Step-by-step visualization
Each bar represents one element. Colors identify compared elements, the pivot or key, the final region and the active range.
Use 2 to 16 values. This visualizer accepts values from 0 to 999.
- Comparisons
- 0
- Writes
- 0
- Swaps
- 0
- Pass / level
- 0
Pseudocode linked to the visualization
exp ← 1while max(A) / exp > 0stably sort by digit (value / exp) mod 10distribute values into queues 0 … 9concatenate queues in orderexp ← exp · 10
The highlighted line corresponds to the operation described by the visualizer. Index-management details are intentionally simplified.
Complexity analysis
Initial order does not change the number of passes.
For at most d digits the same Θ(d(n+b)) bound applies.
A stable pass uses Θ(n+b) memory and stability is required for LSD correctness.
Properties at a glance
Stability concerns the relative order of elements with equal keys.
This classification refers to the version shown on this page.
When to use it and what to avoid
A good choice when…
Good for nonnegative integers, identifiers and bounded-length strings.
Common mistake
An unstable digit sort erases previous work; signs need explicit handling.