Loading algorithms…
Loading visualizer…
Sort integers digit by digit using a stable counting sort. Each pass processes one digit place (ones, tens, hundreds, …) — achieving linear time O(d·(n+k)) without ever comparing values.
Each pass: count the digits → prefix-sum → place by digit → copy back. Repeat for the next digit place.
Radix sort is a non-comparison sorting algorithm for integers (and other keys with discrete structure). It processes the input digit by digit, from the least-significant digit to the most-significant. Each pass is a stable counting sort on one digit — and because counting sort is stable, the work done in earlier passes is preserved when later passes reorder the array.
d = ⌊log₁₀ max⌋ + 1).count[d] where d = (arr[i] / exp) % 10.count[i] += count[i - 1]).output[count[d] - 1], decrementing count[d]. Walking right-to-left is what preserves stability.arr with output.💡 Why LSD? MSD (most significant digit first) seems intuitive but requires recursion: once you bucket by the leading digit, you must recursively sort each bucket. LSD avoids this entirely — one full pass per digit place, no recursion, identical per-pass structure.
Radix sort is a non-comparison sort: it never compares two values directly. Instead, it exploits digit structure to bucket and stitch the array back together in O(d·(n + k)) time.