Coupon collector's problem

From HandWiki
Short description: Problem in probability theory
Graph of number of coupons, n vs the expected number of trials (i.e., time) needed to collect them all, E (T )

In probability theory, the coupon collector's problem refers to mathematical analysis of "collect all coupons and win" contests. It asks the following question: If each box of a brand of cereals contains a coupon, and there are n different types of coupons, what is the probability that more than t boxes need to be bought to collect all n coupons? An alternative statement is: Given n coupons, how many coupons do you expect you need to draw with replacement before having drawn each coupon at least once? The mathematical analysis of the problem reveals that the expected number of trials needed grows as [math]\displaystyle{ \Theta(n\log(n)) }[/math].[lower-alpha 1] For example, when n = 50 it takes about 225[lower-alpha 2] trials on average to collect all 50 coupons.

Solution

Via generating functions

By definition of Stirling numbers of the second kind, the probability that exactly T draws are needed is[math]\displaystyle{ \frac{S(T-1, n-1)n!}{n^T} }[/math]By manipulating the generating function of the Stirling numbers, we can explicitly calculate all moments of T:[math]\displaystyle{ f_k(x) := \sum_T S(T, k) x^T = \prod_{r=1}^k \frac{x}{1-rx} }[/math]In general, the k-th moment is [math]\displaystyle{ (n-1)! ((D_x x)^kf_{n-1}(x)) \Big|_{x=1/n} }[/math], where [math]\displaystyle{ D_x }[/math] is the derivative operator [math]\displaystyle{ d/dx }[/math]. For example, the 0th moment is[math]\displaystyle{ \sum_T \frac{S(T-1, n-1)n!}{n^T} = (n-1)! f_{n-1}(1/n) = (n-1)! \times \prod_{r=1}^{n-1} \frac{1/n}{1-r/n} = 1 }[/math]and the 1st moment is [math]\displaystyle{ (n-1)! (D_x xf_{n-1}(x)) \Big|_{x=1/n} }[/math], which can be explicitly evaluated to [math]\displaystyle{ nH_n }[/math], etc.

Calculating the expectation

Let time T be the number of draws needed to collect all n coupons, and let ti be the time to collect the i-th coupon after i − 1 coupons have been collected. Then [math]\displaystyle{ T=t_1 + \cdots + t_n }[/math]. Think of T and ti as random variables. Observe that the probability of collecting a new coupon is [math]\displaystyle{ p_i = \frac{n - (i - 1)}{n} = \frac{n - i + 1}{n} }[/math]. Therefore, [math]\displaystyle{ t_i }[/math] has geometric distribution with expectation [math]\displaystyle{ \frac{1}{p_i} = \frac{n}{n - i + 1} }[/math]. By the linearity of expectations we have:

[math]\displaystyle{ \begin{align} \operatorname{E}(T) & {}= \operatorname{E}(t_1 + t_2 + \cdots + t_n) \\ & {}= \operatorname{E}(t_1) + \operatorname{E}(t_2) + \cdots + \operatorname{E}(t_n) \\ & {}= \frac{1}{p_1} + \frac{1}{p_2} + \cdots + \frac{1}{p_n} \\ & {}= \frac{n}{n} + \frac{n}{n-1} + \cdots + \frac{n}{1} \\ & {}= n \cdot \left(\frac{1}{1} + \frac{1}{2} + \cdots + \frac{1}{n}\right) \\ & {}= n \cdot H_n. \end{align} }[/math]

Here Hn is the n-th harmonic number. Using the asymptotics of the harmonic numbers, we obtain:

[math]\displaystyle{ \operatorname{E}(T) = n \cdot H_n = n \log n + \gamma n + \frac{1}{2} + O(1/n), }[/math]

where [math]\displaystyle{ \gamma \approx 0.5772156649 }[/math] is the Euler–Mascheroni constant.

Using the Markov inequality to bound the desired probability:

[math]\displaystyle{ \operatorname{P}(T \geq cn H_n) \le \frac{1}{c}. }[/math]

The above can be modified slightly to handle the case when we've already collected some of the coupons. Let k be the number of coupons already collected, then:

[math]\displaystyle{ \begin{align} \operatorname{E}(T_k) & {}= \operatorname{E}(t_{k+1} + t_{k+2} + \cdots + t_n) \\ & {}= n \cdot \left(\frac{1}{1} + \frac{1}{2} + \cdots + \frac{1}{n-k}\right) \\ & {}= n \cdot H_{n-k} \end{align} }[/math]

And when [math]\displaystyle{ k=0 }[/math] then we get the original result.

Calculating the variance

Using the independence of random variables ti, we obtain:

[math]\displaystyle{ \begin{align} \operatorname{Var}(T)& {}= \operatorname{Var}(t_1 + \cdots + t_n) \\ & {} = \operatorname{Var}(t_1) + \operatorname{Var}(t_2) + \cdots + \operatorname{Var}(t_n) \\ & {} = \frac{1-p_1}{p_1^2} + \frac{1-p_2}{p_2^2} + \cdots + \frac{1-p_n}{p_n^2} \\ & {} \lt \left(\frac{n^2}{n^2} + \frac{n^2}{(n-1)^2} + \cdots + \frac{n^2}{1^2}\right) \\ & {} = n^2 \cdot \left(\frac{1}{1^2} + \frac{1}{2^2} + \cdots + \frac{1}{n^2} \right) \\ & {} \lt \frac{\pi^2}{6} n^2 \end{align} }[/math]

since [math]\displaystyle{ \frac{\pi^2}6=\frac{1}{1^2}+\frac{1}{2^2}+\cdots+\frac{1}{n^2}+\cdots }[/math] (see Basel problem).

Bound the desired probability using the Chebyshev inequality:

[math]\displaystyle{ \operatorname{P}\left(|T- n H_n| \geq cn\right) \le \frac{\pi^2}{6c^2}. }[/math]

Tail estimates

A stronger tail estimate for the upper tail be obtained as follows. Let [math]\displaystyle{ {Z}_i^r }[/math] denote the event that the [math]\displaystyle{ i }[/math]-th coupon was not picked in the first [math]\displaystyle{ r }[/math] trials. Then

[math]\displaystyle{ \begin{align} P\left [ {Z}_i^r \right ] = \left(1-\frac{1}{n}\right)^r \le e^{-r / n}. \end{align} }[/math]

Thus, for [math]\displaystyle{ r = \beta n \log n }[/math], we have [math]\displaystyle{ P\left [ {Z}_i^r \right ] \le e^{(-\beta n \log n ) / n} = n^{-\beta} }[/math]. Via a union bound over the [math]\displaystyle{ n }[/math] coupons, we obtain

[math]\displaystyle{ \begin{align} P\left [ T \gt \beta n \log n \right ] = P \left [ \bigcup_i {Z}_i^{\beta n \log n} \right ] \le n \cdot P [ {Z}_1^{\beta n \log n} ] \le n^{-\beta + 1}. \end{align} }[/math]

Extensions and generalizations

[math]\displaystyle{ \operatorname{P}(T \lt n\log n + cn) \to e^{-e^{-c}}, \text{ as } n \to \infty. }[/math] which is a Gumbel distribution. A simple proof by martingales is in the next section.
  • Donald J. Newman and Lawrence Shepp gave a generalization of the coupon collector's problem when m copies of each coupon need to be collected. Let Tm be the first time m copies of each coupon are collected. They showed that the expectation in this case satisfies:
[math]\displaystyle{ \operatorname{E}(T_m) = n \log n + (m-1) n \log\log n + O(n), \text{ as } n \to \infty. }[/math]
Here m is fixed. When m = 1 we get the earlier formula for the expectation.
  • Common generalization, also due to Erdős and Rényi:
[math]\displaystyle{ \operatorname{P}\left(T_m \lt n\log n + (m-1) n \log\log n + cn\right) \to e^{-e^{-c}/(m-1)!}, \text{ as } n \to \infty. }[/math]
  • In the general case of a nonuniform probability distribution, according to Philippe Flajolet et al.[2]
[math]\displaystyle{ \operatorname{E}(T)=\int_0^\infty \left(1 - \prod_{i=1}^m \left(1-e^{-p_it}\right)\right)dt. }[/math]
This is equal to
[math]\displaystyle{ \operatorname{E}(T)=\sum_{q=0}^{m-1} (-1)^{m-1-q} \sum_{|J|=q} \frac{1}{1-P_J}, }[/math]
where m denotes the number of coupons to be collected and PJ denotes the probability of getting any coupon in the set of coupons J.

Martingales

This section is based on [3].

Define a discrete random process [math]\displaystyle{ N(0), N(1), \dots }[/math] by letting [math]\displaystyle{ N(t) }[/math] be the number of coupons not yet seen after [math]\displaystyle{ t }[/math] draws. The random process is just a sequence generated by a Markov chain with states [math]\displaystyle{ n, n-1, \dots, 1, 0 }[/math], and transition probabilities[math]\displaystyle{ p_{i \to i-1} = i/n, \quad p_{i \to i} = 1-i/n }[/math]Now define [math]\displaystyle{ M(t) := N(t) \left(\frac{n}{n-1}\right)^t }[/math]then it is a martingale, since[math]\displaystyle{ E[M(t+1)|M(t)] = (n/(n-1))^{t+1} E[N(t+1)|N(t)] = (n/(n-1))^{t+1} (N(t) - N(t)/n)= M(t) }[/math]Consequently, we have [math]\displaystyle{ E[N(t)] = n(1-1/n)^t }[/math]. In particular, we have a limit law [math]\displaystyle{ \lim_{n \to \infty} E[N(n\ln n + cn)] = e^{-c} }[/math] for any [math]\displaystyle{ c \gt 0 }[/math]. This suggests to us a limit law for [math]\displaystyle{ T }[/math].

More generally, each [math]\displaystyle{ \left(\frac{n}{n-k}\right)^t N(t) \cdots (N(t) - k+1) }[/math] is a martingale process, which allows us to calculate all moments of [math]\displaystyle{ N(t) }[/math]. For example, [math]\displaystyle{ E [N(t)^2] = n(n-1)\left(\frac{n-2}{n}\right)^t + n\left(\frac{n-1}{n}\right)^t, \quad n \geq 2 }[/math]giving another limit law [math]\displaystyle{ \lim_{n \to \infty} Var[N(n\ln n + cn)] = e^{-c} }[/math]. More generally, [math]\displaystyle{ \lim_{n \to \infty} E[N(n\ln n + cn) \cdots (N(n\ln n + cn) - k+1 )] = e^{-kc} }[/math]meaning that [math]\displaystyle{ N(n \ln n + cn) }[/math] has all moments converging to constants, so it converges to some probability distribution on [math]\displaystyle{ 0, 1, 2, \dots }[/math].

Let [math]\displaystyle{ N }[/math] be the random variable with the limit distribution. We have[math]\displaystyle{ \begin{aligned} E[1] &= 1 \\ E[N] &= e^{-c} \\ E[N(N-1)] &= e^{-2c} \\ E[N(N-1)(N-2)] &= e^{-3c} \\ & \vdots \end{aligned} }[/math]By introducing a new variable [math]\displaystyle{ t }[/math], we can sum up both sides explicitly:[math]\displaystyle{ E[1 + Nt/1! + N(N-1)t^2/2! + \cdots ] = 1 + e^{-c}t/1! + e^{-2c}t^2/2! + \cdots }[/math]giving [math]\displaystyle{ E[(1+t)^N] = e^{e^{-c}t} }[/math].

At the [math]\displaystyle{ t \to 0 }[/math] limit, we have [math]\displaystyle{ Pr(N = 0) = e^{-e^{-c}} }[/math], which is precisely what the limit law states.

By taking the derivative [math]\displaystyle{ d/dt }[/math] multiple times, we find that [math]\displaystyle{ Pr(N=k) = \frac{e^{-kc}}{k!} e^{-e^{-c}} }[/math], which is a Poisson distribution.

See also

  • McDonald's Monopoly – an example of the coupon collector's problem that further increases the challenge by making some coupons of the set rarer
  • Watterson estimator
  • Birthday problem

Notes

  1. Here and throughout this article, "log" refers to the natural logarithm rather than a logarithm to some other base. The use of Θ here invokes big O notation.
  2. E(50) = 50(1 + 1/2 + 1/3 + ... + 1/50) = 224.9603, the expected number of trials to collect all 50 coupons. The approximation [math]\displaystyle{ n\log n+\gamma n+1/2 }[/math] for this expected number gives in this case [math]\displaystyle{ 50\log 50+50\gamma+1/2 \approx 195.6011+28.8608+0.5\approx 224.9619 }[/math].

References

  1. Mitzenmacher, Michael (2017). Probability and computing : randomization and probabilistic techniques in algorithms and data analysis. Eli Upfal (2nd ed.). Cambridge, United Kingdom. Theorem 5.13. ISBN 978-1-107-15488-9. OCLC 960841613. 
  2. Flajolet, Philippe; Gardy, Danièle; Thimonier, Loÿs (1992), "Birthday paradox, coupon collectors, caching algorithms and self-organizing search", Discrete Applied Mathematics 39 (3): 207–229, doi:10.1016/0166-218x(92)90177-c 
  3. Kan, N. D. (2005-05-01). "Martingale approach to the coupon collection problem" (in en). Journal of Mathematical Sciences 127 (1): 1737–1744. doi:10.1007/s10958-005-0134-y. ISSN 1573-8795. https://doi.org/10.1007/s10958-005-0134-y. 

External links