Why does bucket-sort take $O(n + N)$ time, and when is that a good deal?
Phase 1 handles each of the $n$ entries once: $O(n)$. Phase 2 has to visit all $N$ buckets, empty or not, and moves each entry once more: $O(N + n)$. Together that is $O(n + N)$, linear when the key range $N$ is at most proportional to $n$, and wasteful when $N$ is far larger than $n$.
Phase 2 looks expensive at first sight: a loop over the buckets with a loop over each bucket's entries inside. But nobody knows how full each bucket is, and nobody needs to: the bucket sizes add up to $n$, so the inner loop runs $n$ times in total. Phase 2 costs $N + n$ steps, the whole sort $N + 2n$, which is $O(n + N)$.
The $N$ is easy to overlook: every bucket has to be created and checked, even if nothing ever lands in it. How much it matters depends on how $N$ compares with $n$:
| Input | Steps, about | Verdict |
|---|---|---|
| 9 million Swiss residents by postal code (keys below 10 000) | 9 000 000 + 10 000 | excellent: $n$ dominates, no comparisons |
| 1 000 orders by postal code | 1 000 + 10 000 | no gain: $n\log_2 n$ is also about 10 000 |
| 10 customer numbers with keys up to $10^9$ | a billion buckets for 10 entries | absurd: any comparison sort is faster |
The buckets also cost memory, $O(n + N)$ extra space, and every bucket is an object of its own: in CPython an empty deque takes 760 bytes, so a billion of them would need about 760 GB. Buckets can also be created lazily: leave $B[k]$ empty (null or None) until its first entry arrives. That saves the memory and allocation time of buckets that stay empty, at the price of one extra check per insertion, and changes nothing in the $O$-bound. Bucket-sort is the right tool when there are many entries and few possible keys, which is exactly the situation radix-sort creates by cutting large keys into small digits.
Go deeper:
USFCA visualization: counting sort — the close relative that counts keys instead of collecting lists, animated on small random keys.