sort.cny.shStart a race
Back to library
10 / 18Algorithm

Radix Sort (LSD)

Stable-bucket by digit, least significant first.

StableIn-place
BestO(nk)
AverageO(nk)
WorstO(nk)
01How it works

Sort by the least-significant digit using a stable bucket pass, then by the next digit, and so on up to the most significant. No comparisons happen — values move based entirely on their own representation.

02Best for

Large arrays of fixed-width integers, strings of known length, IP addresses, or anything with a small digit alphabet. Runs in O(nk) where k is the number of digits, which is effectively linear for realistic key sizes.

03Avoid when

Keys are floats, variable-length strings without a tight bound, or comparison is cheap and n is small — the k factor plus bucket overhead wipes out the win.