Coupon collector's problem

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 Θ ( n log ( n ) ) {\displaystyle \Theta (n\log(n))} .[a] For example, when n = 50 it takes about 225[b] 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

S ( T 1 , n 1 ) n ! n T {\displaystyle {\frac {S(T-1,n-1)n!}{n^{T}}}}
By manipulating the generating function of the Stirling numbers, we can explicitly calculate all moments of T:
f k ( x ) := T S ( T , k ) x T = r = 1 k x 1 r x {\displaystyle f_{k}(x):=\sum _{T}S(T,k)x^{T}=\prod _{r=1}^{k}{\frac {x}{1-rx}}}
In general, the k-th moment is ( n 1 ) ! ( ( D x x ) k f n 1 ( x ) ) | x = 1 / n {\displaystyle (n-1)!((D_{x}x)^{k}f_{n-1}(x)){\Big |}_{x=1/n}} , where D x {\displaystyle D_{x}} is the derivative operator d / d x {\displaystyle d/dx} . For example, the 0th moment is
T S ( T 1 , n 1 ) n ! n T = ( n 1 ) ! f n 1 ( 1 / n ) = ( n 1 ) ! × r = 1 n 1 1 / n 1 r / n = 1 {\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}
and the 1st moment is ( n 1 ) ! ( D x x f n 1 ( x ) ) | x = 1 / n {\displaystyle (n-1)!(D_{x}xf_{n-1}(x)){\Big |}_{x=1/n}} , which can be explicitly evaluated to n H n {\displaystyle nH_{n}} , 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 T = t 1 + + t n {\displaystyle T=t_{1}+\cdots +t_{n}} . Think of T and ti as random variables. Observe that the probability of collecting a new coupon is p i = n ( i 1 ) n = n i + 1 n {\displaystyle p_{i}={\frac {n-(i-1)}{n}}={\frac {n-i+1}{n}}} . Therefore, t i {\displaystyle t_{i}} has geometric distribution with expectation 1 p i = n n i + 1 {\displaystyle {\frac {1}{p_{i}}}={\frac {n}{n-i+1}}} . By the linearity of expectations we have:

E ( T ) = E ( t 1 + t 2 + + t n ) = E ( t 1 ) + E ( t 2 ) + + E ( t n ) = 1 p 1 + 1 p 2 + + 1 p n = n n + n n 1 + + n 1 = n ( 1 1 + 1 2 + + 1 n ) = n H n . {\displaystyle {\begin{aligned}\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{aligned}}}

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

E ( T ) = n H n = n log n + γ n + 1 2 + O ( 1 / n ) , {\displaystyle \operatorname {E} (T)=n\cdot H_{n}=n\log n+\gamma n+{\frac {1}{2}}+O(1/n),}

where γ 0.5772156649 {\displaystyle \gamma \approx 0.5772156649} is the Euler–Mascheroni constant.

Using the Markov inequality to bound the desired probability:

P ( T c n H n ) 1 c . {\displaystyle \operatorname {P} (T\geq cnH_{n})\leq {\frac {1}{c}}.}

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:

E ( T k ) = E ( t k + 1 + t k + 2 + + t n ) = n ( 1 1 + 1 2 + + 1 n k ) = n H n k {\displaystyle {\begin{aligned}\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{aligned}}}

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

Calculating the variance

Using the independence of random variables ti, we obtain:

Var ( T ) = Var ( t 1 + + t n ) = Var ( t 1 ) + Var ( t 2 ) + + Var ( t n ) = 1 p 1 p 1 2 + 1 p 2 p 2 2 + + 1 p n p n 2 < ( n 2 n 2 + n 2 ( n 1 ) 2 + + n 2 1 2 ) = n 2 ( 1 1 2 + 1 2 2 + + 1 n 2 ) < π 2 6 n 2 {\displaystyle {\begin{aligned}\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}}}\\&{}<\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)\\&{}<{\frac {\pi ^{2}}{6}}n^{2}\end{aligned}}}

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

Bound the desired probability using the Chebyshev inequality:

P ( | T n H n | c n ) π 2 6 c 2 . {\displaystyle \operatorname {P} \left(|T-nH_{n}|\geq cn\right)\leq {\frac {\pi ^{2}}{6c^{2}}}.}

Tail estimates

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

P [ Z i r ] = ( 1 1 n ) r e r / n . {\displaystyle {\begin{aligned}P\left[{Z}_{i}^{r}\right]=\left(1-{\frac {1}{n}}\right)^{r}\leq e^{-r/n}.\end{aligned}}}

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

P [ T > β n log n ] = P [ i Z i β n log n ] n P [ Z 1 β n log n ] n β + 1 . {\displaystyle {\begin{aligned}P\left[T>\beta n\log n\right]=P\left[\bigcup _{i}{Z}_{i}^{\beta n\log n}\right]\leq n\cdot P[{Z}_{1}^{\beta n\log n}]\leq n^{-\beta +1}.\end{aligned}}}

Extensions and generalizations

  • Pierre-Simon Laplace, but also Paul Erdős and Alfréd Rényi, proved the limit theorem for the distribution of T. This result is a further extension of previous bounds. A proof is found in.[1]
P ( T < n log n + c n ) e e c ,  as  n . {\displaystyle \operatorname {P} (T<n\log n+cn)\to e^{-e^{-c}},{\text{ as }}n\to \infty .} 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:
E ( T m ) = n log n + ( m 1 ) n log log n + O ( n ) ,  as  n . {\displaystyle \operatorname {E} (T_{m})=n\log n+(m-1)n\log \log n+O(n),{\text{ as }}n\to \infty .}
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:
P ( T m < n log n + ( m 1 ) n log log n + c n ) e e c / ( m 1 ) ! ,  as  n . {\displaystyle \operatorname {P} \left(T_{m}<n\log n+(m-1)n\log \log n+cn\right)\to e^{-e^{-c}/(m-1)!},{\text{ as }}n\to \infty .}
  • In the general case of a nonuniform probability distribution, according to Philippe Flajolet et al.[2]
E ( T ) = 0 ( 1 i = 1 m ( 1 e p i t ) ) d t . {\displaystyle \operatorname {E} (T)=\int _{0}^{\infty }\left(1-\prod _{i=1}^{m}\left(1-e^{-p_{i}t}\right)\right)dt.}
This is equal to
E ( T ) = q = 0 m 1 ( 1 ) m 1 q | J | = q 1 1 P J , {\displaystyle \operatorname {E} (T)=\sum _{q=0}^{m-1}(-1)^{m-1-q}\sum _{|J|=q}{\frac {1}{1-P_{J}}},}
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 N ( 0 ) , N ( 1 ) , {\displaystyle N(0),N(1),\dots } by letting N ( t ) {\displaystyle N(t)} be the number of coupons not yet seen after t {\displaystyle t} draws. The random process is just a sequence generated by a Markov chain with states n , n 1 , , 1 , 0 {\displaystyle n,n-1,\dots ,1,0} , and transition probabilities

p i i 1 = i / n , p i i = 1 i / n {\displaystyle p_{i\to i-1}=i/n,\quad p_{i\to i}=1-i/n}
Now define
M ( t ) := N ( t ) ( n n 1 ) t {\displaystyle M(t):=N(t)\left({\frac {n}{n-1}}\right)^{t}}
then it is a martingale, since
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 ) {\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)}
Consequently, we have E [ N ( t ) ] = n ( 1 1 / n ) t {\displaystyle E[N(t)]=n(1-1/n)^{t}} . In particular, we have a limit law lim n E [ N ( n ln n + c n ) ] = e c {\displaystyle \lim _{n\to \infty }E[N(n\ln n+cn)]=e^{-c}} for any c > 0 {\displaystyle c>0} . This suggests to us a limit law for T {\displaystyle T} .

More generally, each ( n n k ) t N ( t ) ( N ( t ) k + 1 ) {\displaystyle \left({\frac {n}{n-k}}\right)^{t}N(t)\cdots (N(t)-k+1)} is a martingale process, which allows us to calculate all moments of N ( t ) {\displaystyle N(t)} . For example,

E [ N ( t ) 2 ] = n ( n 1 ) ( n 2 n ) t + n ( n 1 n ) t , n 2 {\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}
giving another limit law lim n V a r [ N ( n ln n + c n ) ] = e c {\displaystyle \lim _{n\to \infty }Var[N(n\ln n+cn)]=e^{-c}} . More generally,
lim n E [ N ( n ln n + c n ) ( N ( n ln n + c n ) k + 1 ) ] = e k c {\displaystyle \lim _{n\to \infty }E[N(n\ln n+cn)\cdots (N(n\ln n+cn)-k+1)]=e^{-kc}}
meaning that N ( n ln n + c n ) {\displaystyle N(n\ln n+cn)} has all moments converging to constants, so it converges to some probability distribution on 0 , 1 , 2 , {\displaystyle 0,1,2,\dots } .

Let N {\displaystyle N} be the random variable with the limit distribution. We have

E [ 1 ] = 1 E [ N ] = e c E [ N ( N 1 ) ] = e 2 c E [ N ( N 1 ) ( N 2 ) ] = e 3 c {\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}}}
By introducing a new variable t {\displaystyle t} , we can sum up both sides explicitly:
E [ 1 + N t / 1 ! + N ( N 1 ) t 2 / 2 ! + ] = 1 + e c t / 1 ! + e 2 c t 2 / 2 ! + {\displaystyle E[1+Nt/1!+N(N-1)t^{2}/2!+\cdots ]=1+e^{-c}t/1!+e^{-2c}t^{2}/2!+\cdots }
giving E [ ( 1 + t ) N ] = e e c t {\displaystyle E[(1+t)^{N}]=e^{e^{-c}t}} .

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

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

See also

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 n log n + γ n + 1 / 2 {\displaystyle n\log n+\gamma n+1/2} for this expected number gives in this case 50 log 50 + 50 γ + 1 / 2 195.6011 + 28.8608 + 0.5 224.9619 {\displaystyle 50\log 50+50\gamma +1/2\approx 195.6011+28.8608+0.5\approx 224.9619} .

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.{{cite book}}: CS1 maint: location missing publisher (link)
  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, CiteSeerX 10.1.1.217.5965, doi:10.1016/0166-218x(92)90177-c
  3. ^ Kan, N. D. (2005-05-01). "Martingale approach to the coupon collection problem". Journal of Mathematical Sciences. 127 (1): 1737–1744. doi:10.1007/s10958-005-0134-y. ISSN 1573-8795.
  • Blom, Gunnar; Holst, Lars; Sandell, Dennis (1994), "7.5 Coupon collecting I, 7.6 Coupon collecting II, and 15.4 Coupon collecting III", Problems and Snapshots from the World of Probability, New York: Springer-Verlag, pp. 85–87, 191, ISBN 0-387-94161-4, MR 1265713.
  • Dawkins, Brian (1991), "Siobhan's problem: the coupon collector revisited", The American Statistician, 45 (1): 76–82, doi:10.2307/2685247, JSTOR 2685247.
  • Erdős, Paul; Rényi, Alfréd (1961), "On a classical problem of probability theory" (PDF), Magyar Tudományos Akadémia Matematikai Kutató Intézetének Közleményei, 6: 215–220, MR 0150807.
  • Laplace, Pierre-Simon (1812), Théorie analytique des probabilités, pp. 194–195.
  • Newman, Donald J.; Shepp, Lawrence (1960), "The double dixie cup problem", American Mathematical Monthly, 67 (1): 58–61, doi:10.2307/2308930, JSTOR 2308930, MR 0120672
  • 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, MR 1189469.
  • Isaac, Richard (1995), "8.4 The coupon collector's problem solved", The Pleasures of Probability, Undergraduate Texts in Mathematics, New York: Springer-Verlag, pp. 80–82, ISBN 0-387-94415-X, MR 1329545.
  • Motwani, Rajeev; Raghavan, Prabhakar (1995), "3.6. The Coupon Collector's Problem", Randomized algorithms, Cambridge: Cambridge University Press, pp. 57–63, ISBN 9780521474658, MR 1344451.

External links