Definition · LSD radix sortLeast-significant-digit radix sort sorts n keys, each of d digits in base b, by performing d passes. Pass i is a stable counting sort of the whole array on digit i, counting digits from the least significant, which is digit zero. After the last pass the array is sorted.
Each pass is counting sort with k = b, so a pass costs n + b and the whole sort costs d(n + b). Nothing is compared, so the comparison lower bound is as silent here as it was there: on seven keys it says 13 comparisons are necessary for any comparison sort, and this algorithm makes none.
Example · Seven three-digit keys, base tenThe keys are 329 457 657 839 436 720 355. Three passes, 17 units of work each, 51 in all. Pass one reads the units digit, pass two the tens, pass three the hundreds, and the array after each pass is in the worked example below. Only after the third pass is it sorted, and after the first two it is sorted on a suffix of the key.
Theorem · The passes composeIf every pass is a stable sort on its digit, then after the pass on digit i the array is in increasing order of the number formed by digits 0 through i of each key.
By induction on i. Before any pass, the claim is about no digits at all and holds vacuously.
Suppose it holds after the pass on digit i−1, and run a stable pass on digit i. Take two keys x and y with x before y in the output. If their digits i differ, the pass placed them in increasing order of that digit, and digit i outranks all the digits below it, so the numbers formed by digits 0 … i are in increasing order.
If their digits i agree, the pass left them in the order it found them, which by the inductive hypothesis was increasing order of digits 0 … i−1. Since their digits i are equal, that is increasing order of digits 0 … i as well. The claim holds after pass i, and after pass d−1 it is the whole key.
□
Read the second paragraph of that proof again: the only fact used about the pass was stability, and it was used in the case where the current digit decides nothing. That is why an unstable pass does not merely degrade the result — it removes the argument entirely, and the lab shows the array that comes out.
Choosing the base
The base is free and it moves both terms. Larger b means fewer digits d = ⌈log_b U⌉ for keys below U, and a bigger bucket array per pass. The same seven keys cost 3 × (7 + 10) = 51 in base ten, 10 × (7 + 2) = 90 in base two, and 3 × (7 + 16) = 69 in base sixteen. There is no rule that one base always wins; there is a product to evaluate, and the lab evaluates it as you move the control.
The honest form of the cost is therefore Θ(d(n + b)) with d depending on the key width and the base, which is why radix sort is not Θ(n) in any useful sense. For n keys drawn from 0 … n^c − 1 and base b = n, it is Θ(cn), and that statement carries its hypotheses in it.
Example · The two broken variants, side by sideUnstable passes, least significant first: 355 329 457 436 657 720 839 — not sorted. Most significant first with no recursion: 720 355 436 457 657 329 839 — not sorted, and sorted on the units digit alone, because the pass that ran last read the units. The lab checks both against the sorted array rather than asserting failure.
Neither variant is a strawman. The first is what happens when the per-digit sort is replaced by something convenient that happens not to be stable. The second is what happens when a reader reasons from significance: the most important digit should be settled first. Most-significant-digit radix sort is a real and useful algorithm — it recurses into each bucket, which is precisely the step whose absence the lab is demonstrating.