Why my expression for coupon collector is giving wrong output

88 Views Asked by At
   y=n*log(n)+0.50*n+0.50;

This is my expression but it is giving 36.32 for n=12 while it has to give 37.24/

edit:This is the problem https://en.wikipedia.org/wiki/Coupon_collector's_problem

2

There are 2 best solutions below

3
On

Hint: The formula is $E(T)=n\cdot log(n)+\gamma\cdot n+0.50+o(1)$, when $n \to \infty$

$\gamma\approx 0.577215664$ is the Euler–Mascheroni constant.

If you use the constant for your calculations, then you will get your desired result.

0
On

From Wikipedia, the exact expectation value for the coupon collector's problem is $$ n \cdot H_n, $$ where $$ H_n = \left( 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \dots + \frac{1}{n} \right) $$ is the $n$-th harmonic number.

For your problem, you have $n = 12$. So simply compute $$ 12 \cdot \left( 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \dots + \frac{1}{12} \right). $$ This gives the answer you're looking for.

When $n$ is large, the harmonic number $H_n$ (the big sum) can be approximated as $$ H_n \approx \log(n) + \gamma + \frac{1}{2n} + (\text{additional terms that are too small to matter}), $$ where $\gamma \approx 0.577215664$ is the Euler-Mascheroni constant. Plugging in this approximation, the expected value for the coupon collector's problem is $$ n \log(n) + \gamma n + \frac{1}{2}. $$ This is the equation you had (but with the correct $\gamma$). It also gives the answer you're looking for.