puzzle #2
In this lesson

Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.

Coupon collector’s problem

You will learn: Compute the changing chance of a new type and the time needed to collect them all.

Start with: Geometric distribution

A cereal brand hides one of n distinct prizes in each box. You buy boxes one at a time, each containing an independent uniformly random prize. How many boxes do you need to collect all n prizes?

The expected number is nHnn H_n, where HnH_n is the nn-th harmonic number:

E[T]=nHn=n ⁣(1+12+13+⋯+1n)E[T] = n H_n = n\!\left(1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{n}\right)

Collect a set

Each box is an independent draw with replacement. Coupon 1 has probability 10.00%; each other coupon has probability 10.00%. Changing the model replays the same random draws.

#1
0 copies
#2
0 copies
#3
0 copies
#4
0 copies
#5
0 copies
#6
0 copies
#7
0 copies
#8
0 copies
#9
0 copies
#10
0 copies

0 boxes opened; 0 of 10 types collected; 0 duplicates.

Latest draws, including repeats: No boxes yet.

Repeat the whole experiment

count by draws to complete set050100150200250020406080100draws to complete setcount
expected nHnn H_n = 29.3 simulated mean = 29.0

Chance of completing all 10 types within 30 draws: 62.91% (exact state-probability calculation). Simulated: 63.95%.

Histogram of 2000 completed runs for 10 coupon types; every run counts in the mean and completion probability. No runs are censored and the axis includes every result. Dashed: exact expectation for the selected probabilities. The play history is a separate run.

What to notice

  • The tail is long. Most runs cluster near the expected value, but some runs are much longer. The distribution is right-skewed because completing the last few coupons requires many “wasted” draws on already-collected prizes.
  • Expected grows faster than n. At n = 10, you need about 29 draws. At n = 50, about 225. The asymptotic rate is nln⁡nn \ln n — not linear, and not quite quadratic.
  • The last coupon is the killer. When you have n−1 of n coupons, each draw has only a 1/n chance of being the missing one, so you wait n more draws on average for just the final piece.

The math

When you have already collected k distinct coupons, the probability of the next box giving a new one is (n−k)/n. The waiting time until the next new coupon is geometric with success probability (n−k)/n, and has expected value n/(n−k). Summing over k from 0 to n−1:

E[T]=∑k=0n−1nn−k=n∑j=1n1j=nHnE[T] = \sum_{k=0}^{n-1} \frac{n}{n-k} = n\sum_{j=1}^{n}\frac{1}{j} = n H_n

Expected duration is not a deadline

The draw-budget control calculates P(T≤m), the chance of completion by a chosen number of boxes. An expected duration of about 29.29 for n=10 does not mean completion is guaranteed by box 30. Move the budget to see how much extra room is needed for high completion probability.

The exact calculation tracks the number of distinct types seen: from k types, stay at k with probability k/n or advance to k+1 with probability (n−k)/n. This works because all types are equally likely. With unequal coupon probabilities, the identity of the missing types matters, so this small state model and the nHₙ formula no longer apply.

A rare coupon changes the bottleneck

Switch to Coupon 1 is ten times rarer. Its probability is 0.1/n; the other n−1 types share the remaining probability equally. At n=10, coupon 1 appears in 1% of boxes, and each other type in 11%. Waiting for coupon 1 alone takes 100 draws on average, so the expected time to finish the whole set must be at least 100. The uniform answer, 29.29, no longer describes this experiment.

The nonuniform calculation tracks two things: how many common types you have and whether coupon 1 has appeared. If k common types are collected, the probability of a new common type is (n−1−k) times its individual probability. A missing rare type adds another 0.1/n chance of progress. Otherwise the draw is a duplicate. The exact completion probability advances these state probabilities once per box; the expected duration sums geometric waits between discoveries. The histogram samples those same waiting stages without discarding long runs.

For two equally likely types, the first box always adds a type and the remaining wait has mean 2, giving E[T]=3. Completion by draw m≥1 has probability 1−2·(1/2)^m. This provides a small case you can verify by listing every sequence.

Make a prediction

You have four of five types. Is the chance of finishing on the next draw always 1/5?

Explore the answer

Only in the uniform model. In the rare-coupon model, it is 0.02 if coupon 1 is missing and 0.245 if a common coupon is missing. The number collected alone is no longer enough information.

Reference

Random Services: the coupon collector problem develops the uniform waiting-stage model and completion distribution. The two-state-group recurrence above derives the specific nonuniform variant used here.

Reset all settings