LOGBOOK

HELP

Quiz Entry - updated: 2026.12.01

Radix-sorting $n$ 32-bit integers: how does the choice of digit width trade passes against buckets?

With digits of $r$ bits there are $d = 32/r$ passes and $N = 2^r$ buckets, so the cost is $\frac{32}{r}(n + 2^r)$. Wider digits mean fewer passes over the data but more buckets per pass; a good width cuts the number of passes while keeping $2^r$ well below $n$.

For a million numbers ($n = 10^6$):

Digit width $r$ Passes $d$ Buckets $N$ $d(n + N)$
1 bit 32 2 about 32 million
4 bits 8 16 about 8 million
8 bits (one byte) 4 256 about 4 million
16 bits 2 65 536 about 2.1 million
32 bits (the whole key) 1 about 4.3 billion about 4.3 billion

The extremes show the trade-off. One bit per digit is cheap per pass but needs 32 passes. The whole key as one digit is a single bucket-sort with $2^{32}$ buckets, hopeless for a million numbers. In between the count favours wide digits, but every pass also has to touch all $N$ buckets, and bucket arrays that no longer fit in fast memory cost more than the formula shows; one byte per pass is a common compromise.

The last row is what skipping the digits altogether would cost: one bucket-sort pass on whole keys needs $N^d$ buckets ($10^3 = 1000$ for three decimal digits, $2^{32}$ for a 32-bit key), while $d$ passes get by with $N$ buckets each. Every pass reuses the same $N$ buckets, so the extra memory stays $O(n + N)$, however many digits the keys have.

Go deeper:

From Quiz: ADS / Sorting Lower Bound, Bucket-Sort and Radix-Sort | Updated: Dec 01, 2026