[Math] Expected number of flips needed that at least two heads and one tail have been flipped

expected valueprobability

The original question is shown below (References from the book of Introduction to Probability Models Tenth Edition):

A coin, having probability $p$ of landing heads, is continually flipped until at least one head and one tail have been flipped.

(a) Find the expected number of flips needed.

(d) Repeat part (a) in the case where flipping is continued until a total of at least two heads and one tail have been flipped.

I solve the question (a), but I am not sure my answer for question (d).

My answer is shown:

Let $N$ is the number of flips at least two head and one tail.

$$
\begin{align*}
E[N] &= E[E[N|Y]]\\ &= E[N|HH]P(H)P(H) + E[N|HT]P(H)P(T) + E[N|TH]P(T)P(H)
\end{align*}
$$

$E[N|HH]$ means the first two are heads until a tail appeared;

$E[N|HT]$ means the first two are head and tail until a head appeared;

$E[N|TH]$ means the first two are head and tail a head appeared;

Let $E[T] = 1/q = 1/1-p$, $E[H] = 1/p$

Then, $E[N] = (2+1/q)pp + (2+1/p)p(1-p) + (2+1/p)p(1-p)$ ←Ans.

I am not sure whether I am right? Thanks a lot.

Best Answer

Let $q=1-p$, $P=1/p$, and $Q=1/q$ for convenience. Some brief scratch paper work will verify that $pP=qQ=1$, $pQ=Q-1$, and $qP=P-1$.

Let's solve part (a) first, since it will be useful. Your first flip is either heads or tails. If it is heads, then we expect it will take $Q$ flips for the first tails to come up. If it is tails, then we expect it will take $P$ flips for the first heads to come up. Therefore, if $A$ is the expected number of flips before we see both heads and tails, then $$E[A]=p(1+Q)+q(1+P)\\=p+pQ+q+qP\\=1+(Q-1)+(P-1)=P+Q-1\\=(P-p)+(Q-q)$$

The same effort applies to the second part. Your first flip is either heads or tails. If it is heads, then we expect it will take $A$ flips to get another head and a tail. If it is tails, then we expect it will take $2P$ flips for two heads to come up. Therefore, $$E[B]=p(1+E[A])+q(1+2P)\\=p(P+Q)+q(1+2P)\\=pP+pQ+q+2qP \\=1+(Q-1)+q+2(P-1)\\=Q+q+2P-2\\=Q+q+2P-(2p+2q)\\=2P-2p+Q-q=2(P-p)+(Q-q)$$

Thanks to bof for recognizing that this collapses into an elegant form.