Probability
The Coupon Collector's Problem: Why the Last Coupon Takes Forever
You buy random packets, each holding one of n equally likely coupons, and you keep buying until you own all n. How many packets should you expect to buy? The answer is not n, and it is not close to n: it is n·Hₙ ≈ n ln n + γn, because the last missing coupon alone costs an expected n packets. This page derives the mean, the variance, and a one-line tail bound from the single trick that makes the whole problem collapse — splitting the wait into independent geometric pieces.
- Expected drawsE[T] = n·Hₙ
- Asymptoticsn ln n + γn + 1/2 + o(1)
- γ≈ 0.5772 (Euler–Mascheroni)
- Variance≈ π²n²/6
- Std. deviation≈ πn/√6 ≈ 1.28n
- Tail boundP(T > n ln n + cn) ≤ e^(−c)
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
The last coupon is the slow one
Start with the asymmetry, because it is the whole story. Suppose there are n coupon types and you already hold n − 1 of them. Every new draw is a fresh uniform pick, so the chance it is the one type you are missing is 1/n. A trial that succeeds with probability 1/n takes an expected n trials. So the final coupon, by itself, costs an expected n draws.
Compare that with the beginning. Your first draw is always new, and the second is new with probability (n − 1)/n, so it costs about one draw. Early coupons are nearly free; the last one is expensive all by itself.
For a six-sided die, the last face costs an expected 6 rolls out of a total expected 14.7 — about 41% of the whole collection time spent on one specific face, and the last two faces together cost 6 + 3 = 9 rolls, or 61%. Any intuition that says "n types, so roughly n draws" measures the easy part and ignores the expensive tail.
Setup and the geometric decomposition
Formally: there are n distinct coupon types, and each draw is independent and uniform over them, with replacement, so types can repeat forever. Let T be the number of draws until you first hold all n types. Writing down the distribution of T directly is awkward, so instead cut T into pieces at the moments your collection grows:
- T₁ = draws needed to get your 1st distinct type (starting from nothing),
- T₂ = further draws needed to get your 2nd distinct type,
- …
- Tᵢ = further draws needed to get the i-th new type, given that you already hold i − 1 types.
Every draw belongs to exactly one of these blocks, so T = T₁ + T₂ + … + Tₙ exactly — no approximation.
Now fix i and suppose you hold i − 1 types. There are n − (i − 1) = n − i + 1 types you still need, each equally likely, so a single draw is new with probability
pᵢ = (n − i + 1)/n.
That probability does not change while you wait, and the draws are independent, so Tᵢ is a geometric random variable counting trials until the first success: Tᵢ ~ Geometric(pᵢ), and E[Tᵢ] = 1/pᵢ = n/(n − i + 1).
Two details earn their keep. First, pᵢ depends only on how many types you hold, not which ones — that symmetry is why the problem has a closed form at all. Second, each Tᵢ is fixed by its own disjoint block of draws with a success probability known in advance, so the Tᵢ are mutually independent. The sum gives the mean; the independence gives the variance.
The expectation: E[T] = n·Hₙ
Expectation is linear, so no independence is needed for the mean:
E[T] = ∑ᵢ₌₁ⁿ n/(n − i + 1).
As i runs 1, 2, …, n the denominator n − i + 1 runs n, n − 1, …, 1 — the same terms in reverse. Substituting k = n − i + 1 gives
E[T] = n ∑ₖ₌₁ⁿ 1/k = n(1 + 1/2 + 1/3 + … + 1/n) = n·Hₙ,
where Hₙ is the n-th harmonic number. That is the complete, exact answer for uniform coupons.
Harmonic numbers grow logarithmically. The standard expansion Hₙ = ln n + γ + 1/(2n) − 1/(12n²) + … , with γ ≈ 0.5772 the Euler–Mascheroni constant, gives
E[T] = n ln n + γn + 1/2 + o(1).
So the cost is slightly superlinear: n ln n, plus a surprisingly large linear correction γn, plus half a draw.
Worked numbers. For a die, n = 6 and H₆ = 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6. Over the common denominator 60 that is (60 + 30 + 20 + 15 + 12 + 10)/60 = 147/60 = 49/20 = 2.45 exactly, so E[T] = 6 · 2.45 = 14.7 rolls to see all six faces. For n = 50, H₅₀ ≈ ln 50 + γ + 1/100 ≈ 3.9120 + 0.5772 + 0.0100 ≈ 4.4992, so E[T] ≈ 50 · 4.4992 ≈ 225 draws — four and a half full sets' worth of buying for one complete set. The table above collects these values; its E[T]/n column is just Hₙ, which creeps up only from 2.45 to 5.19 as n goes from 6 to 100. Logarithms grow slowly, which is why the answer stays manageable in practice.
Variance: how concentrated is T?
Because the Tᵢ are independent, variances add: Var(T) = ∑ᵢ Var(Tᵢ), and for a geometric count of trials until the first success Var = (1 − p)/p². Reindex as before with k = n − i + 1, so p = k/n. Then
(1 − p)/p² = (1 − k/n)/(k²/n²) = n(n − k)/k²,
and summing over k = 1, …, n gives
Var(T) = ∑ₖ₌₁ⁿ n(n − k)/k² = n² ∑ₖ₌₁ⁿ 1/k² − n ∑ₖ₌₁ⁿ 1/k = n² ∑ₖ₌₁ⁿ 1/k² − n·Hₙ.
This is exact. Now take n large. The Basel sum gives ∑ₖ₌₁^∞ 1/k² = π²/6, and the tail ∑ₖ₌ₙ₊₁^∞ 1/k² is about 1/n, so n²∑ₖ₌₁ⁿ 1/k² = π²n²/6 − O(n). The subtracted n·Hₙ term is only of order n ln n. Both corrections are negligible against n², so
Var(T) ≈ π²n²/6, sd(T) ≈ πn/√6 ≈ 1.2825 n.
Read that carefully, because it is the interesting part. The mean grows like n ln n, but the standard deviation grows like 1.28n — linear. The relative spread is therefore
sd(T)/E[T] ≈ 1.28/ln n,
which shrinks to 0 as n grows: about 0.28 at n = 100 and 0.14 at n = 10 000. So T is relatively concentrated for large n, with T/(n ln n) → 1 in probability. In absolute terms 1.28n is still a lot of draws — about 128 against a mean of 519 at n = 100 — so individual outcomes differ widely even as the ratio tightens.
At small n the asymptotic formula is a poor guide. For n = 6 the exact expression gives Var(T) = 36 · (1 + 1/4 + 1/9 + 1/16 + 1/25 + 1/36) − 14.7 = 36 · 1.49139 − 14.7 ≈ 38.99, so sd ≈ 6.24, well below the asymptotic 7.70.
A tail bound you can quote
The mean and variance could be combined through Chebyshev's inequality, but a much cleaner bound comes from a union bound over coupons rather than from moments. Fix a time t and a specific coupon type i. The event Aᵢ = "type i has not appeared in the first t draws" happens exactly when every one of the t independent draws avoided type i, so
P(Aᵢ) = (1 − 1/n)^t.
Now T > t means at least one type is still missing, i.e. the union A₁ ∪ … ∪ Aₙ. The union bound gives P(T > t) ≤ ∑ᵢ P(Aᵢ) = n(1 − 1/n)^t.
Choose t = n ln n + cn for a constant c ≥ 0 and apply the inequality 1 − x ≤ e^(−x) with x = 1/n:
(1 − 1/n)^t ≤ e^(−t/n) = e^(−ln n − c) = e^(−c)/n.
Multiplying by the n coupon types, the n cancels and we get the quotable result
P(T > n ln n + cn) ≤ e^(−c).
One formula, no asymptotics, valid for every n and every c ≥ 0. Set c = 3: the chance of needing more than n ln n + 3n draws is at most e^(−3) ≈ 0.0498, under 5%. For n = 50 that reads 50 · ln 50 + 150 ≈ 196 + 150 ≈ 346, so fewer than one collector in twenty needs more than about 346 draws.
The shape is also right, not an artifact of a lossy union bound: as n → ∞ the exact limit is P(T ≤ n ln n + cn) → e^(−e^(−c)), a Gumbel distribution whose complement is ≈ e^(−c) for large c.
Unequal probabilities, and where this shows up
Everything above assumed uniform draws, and real packets rarely are. The honest statement is short: non-uniform probabilities always make it worse. The rarest type becomes the bottleneck, and the expected wait for it alone is 1/pₘᵢₙ, which exceeds n whenever that probability is below 1/n. Uniform is the best case; any skew increases E[T].
There is no simple closed form in general. The expectation can be written as an inclusion–exclusion sum over subsets of types, or equivalently as the integral E[T] = ∫₀^∞ (1 − ∏ᵢ (1 − e^(−pᵢ s))) ds, but neither collapses to anything as tidy as n·Hₙ. If you need a number for a skewed distribution, compute it numerically or simulate; do not reach for n ln n + γn and hope.
Where the problem actually appears:
- Test coverage and fuzzing. If random inputs hit n code paths roughly uniformly, expect about n ln n inputs before every path is exercised — not n.
- Network coding and erasure codes. "How many random packets until every one of n blocks has arrived?" is exactly this problem, and the n ln n answer is the standard argument for coded packets, where any n of them suffice.
- Random sampling with replacement. How long until a sampler has touched every record, cache line, or shard — the same question for caches and deduplication coverage.
- Sticker albums and trading cards. The original motivation, and the reason trading is so valuable: swapping duplicates with other collectors is precisely an attack on the expensive last-coupon phase.
Common mistakes
Thinking it takes about n draws. The dominant error. With n = 50 the answer is 225, not 50, and the inflation factor Hₙ ≈ ln n + γ grows without bound: at n = 1000 you need about 7.5 full sets' worth of draws. The mistake is forgetting that the final type costs n draws on its own.
Confusing the mean with the median. T is right-skewed, so the mean sits above the typical value. From the Gumbel limit the median is at n ln n + cn with e^(−e^(−c)) = 1/2, i.e. c = −ln(ln 2) ≈ 0.3665, while the mean is at c = γ ≈ 0.5772 — a gap of about 0.21n draws. So somewhat more than half of collectors finish before E[T].
Applying the uniform formula to unequal probabilities. n·Hₙ is a lower bound in that setting, not an estimate. A single rare coupon can dominate everything.
Forgetting that draws are with replacement. Sample without replacement — shuffle all n coupons and deal them — and T = n with probability 1. The whole difficulty comes from duplicates.
Treating the asymptotics as exact. Both n ln n + γn + 1/2 and sd ≈ 1.28n are large-n statements. For small n use n·Hₙ and the exact variance n²∑ₖ₌₁ⁿ 1/k² − n·Hₙ; they are no harder to evaluate and they are right.
| n | Hₙ | E[T] = n·Hₙ | E[T] / n | Asymptotic sd ≈ 1.28n |
|---|---|---|---|---|
| 6 (a die) | 2.45 | 14.7 | 2.45 | 7.7 |
| 10 | 2.9290 | 29.3 | 2.93 | 12.8 |
| 20 | 3.5977 | 72.0 | 3.60 | 25.7 |
| 50 | 4.4992 | 225.0 | 4.50 | 64.1 |
| 100 | 5.1874 | 518.7 | 5.19 | 128.3 |
Frequently asked questions
How many rolls does it take to see all six faces of a die?
An expected 14.7 rolls. The formula is n·Hₙ with n = 6, and H₆ = 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 = 147/60 = 49/20 = 2.45 exactly, so E[T] = 6 · 2.45 = 14.7. Of that, an expected 6 rolls are spent waiting for the single final face.
Why does n ln n appear instead of n?
Because collecting the i-th new type takes an expected n/(n − i + 1) draws, and summing those terms gives n(1 + 1/2 + … + 1/n) = n·Hₙ. The harmonic sum Hₙ is approximately ln n + γ, so the total is n ln n + γn + 1/2 + o(1). The logarithm is the accumulated cost of the increasingly rare new types.
What is the variance of the collection time?
Exactly n²∑ₖ₌₁ⁿ 1/k² − n·Hₙ, since the waiting times are independent geometrics with Var = (1 − p)/p². For large n this tends to π²n²/6 because ∑ₖ₌₁^∞ 1/k² = π²/6, giving a standard deviation of about πn/√6 ≈ 1.28n.
Is the collection time concentrated around its mean?
In relative terms, yes, and increasingly so: the ratio sd/mean is about 1.28/ln n, which goes to 0, so T/(n ln n) → 1 in probability. In absolute terms the spread is large — 1.28n draws is not small — so individual outcomes still vary a lot. The clean tail statement is P(T > n ln n + cn) ≤ e^(−c).
What changes if some coupons are rarer than others?
The expected number of draws goes up, always. The uniform distribution is the best case; any skew lengthens the wait, roughly because the rarest type with probability pₘᵢₙ alone costs about 1/pₘᵢₙ draws. There is no simple closed form — only an inclusion–exclusion sum over subsets or an equivalent integral — so compute numerically rather than reusing n·Hₙ.
Does trading duplicates with other collectors help?
Substantially, because it attacks exactly the expensive phase. The uniform analysis says the final type costs an expected n draws and the last few types dominate the total; a trade converts a worthless duplicate into a missing type directly, bypassing that geometric wait. This is why organised swapping shortens album completion so dramatically in practice.