[Math] Expected Number of coin flips for 2 consecutive heads for first time.

expectation

I was working on problems on expectation and found this one as a question from a well-known exam

Assume that you are flipping a fair coin, i.e. probability of heads or tails is equal. Then the expected number of coin flips required to obtain two consecutive heads for the first time is.

(A)4

(B)3

(C)6

(D)10

(E)5

I worked up like Let N be the number of tosses required untill 2 consecutive heads are obtained for the first time.

Let the probability of obtaining heads be p and tails be q and for a coin p=q=1-p=1-q.

For N=2, the probability will be $p^2$

For N=3, the probability will be $p^2.q$

For N=4, the probability will be $q^2.p^2$

For N=5, the probability will be $q^3.p^2$

and so on…

Now, $E[N]=2(p^2)+3(p^2.q)+4(q^2.p^2)+5(q^3.p^2)+……$

and this comes out to be $\frac{3}{2}$ but it matches with none of the options.

Please tell me where I am wrong and what should I do to reach the correct solution?

Best Answer

Here is a generating function approach.


$T$ is represented by $(1-p)x$
$HT$ is represented by $p(1-p)x^2$
$HH$ is represented by $p^2x^2$


The generating function for the probability that it will take $n$ flips to get two heads in a row is $$ \begin{align} g(x) &=p^2x^2\sum_{k=0}^\infty\left((1-p)x+p(1-p)x^2\right)^k\\ &=\frac{p^2x^2}{1-(1-p)x(1+px)}\tag1 \end{align} $$ As a check, $$ g(1)=1\tag2 $$ that is, the probability of eventually getting two heads is $1$.


Taking the derivative of $(1)$: $$ g'(x)=\frac{p^2x\,(2-(1-p)x)}{\left(1-(1-p)x(1+px)\right)^2}\tag3 $$ Thus, the expected number of flips to get two heads in a row is $$ g'(1)=\frac{1+p}{p^2}\tag4 $$ For a fair coin, we get the expected number of flips to get two heads in a row is $$ \begin{align} \frac{1+p}{p^2} &=\frac{\ \frac32\ }{\frac14}\\[6pt] &=6\tag5 \end{align} $$


Taking two derivatives of $(1)$: $$ g''(x)=\frac{2p^2\left(1+p(1-p)x^2(3-(1-p)x)\right)}{\left(1-(1-p)x(1+px)\right)^3}\tag6 $$ Thus, the variance of the number of flips to get two heads in a row is $$ g''(1)+g'(1)-g'(1)^2=\frac{(1-p)(1+p(3+p))}{p^4}\tag7 $$ For a fair coin, we get the variance of the number of flips to get two heads in a row is $$ \begin{align} \frac{(1-p)(1+p(3+p))}{p^4} &=\frac{\ \frac{11}8\ }{\frac1{16}}\\[6pt] &=22\tag8 \end{align} $$

Related Question