Expected number of heads when flipping until both heads and tails are encountered

102 Views Asked by At

Consider a coin that lands heads with probability $p$. If I flip the coin until both heads and tails are encountered, let $X$ be a random variable representing the number of heads flipped. What is $\mathbb E[X]$?

My friends and I went about solving this problem in two different ways, and arrived at two different answers. I want to know which is wrong (or if both are), and where the mistake occurs.

My approach was to simply use the definition of expectation:

$$\mathbb E[X]=1\cdot(p(1-p)+(1-p)p+(1-p)^2p+...)+2\cdot(p^2(1-p))+...$$

$$=p(1-p)+\sum_{k=1}^\infty(1-p)^kp+\sum_{k=2}^\infty kp^k(1-p)$$

$$=p(1-p)+p\frac 1{1-(1-p)}+(1-p)\left(\sum_{k=1}^\infty kp^k-p\right)$$

$$=p(1-p)+1+(1-p)\frac p{(1-p)^2}-(1-p)p=1+\frac p{1-p}\text.$$

Theirs was to condition on the outcome of the first flip. Here let $X_k$ be the outcome of the $k$th flip:

$$\mathbb E[X]=\text{Pr}(X_1=H)\cdot\mathbb E[X|X_1=H]+\text{Pr}(X_1=T)\cdot\mathbb E[X|X_1=T]\text.$$

If the first flip is tails, the only heads will occur on the last flip, implying that $\mathbb E[X|X_1=T]=1$. If the first flip is heads, then the game ends at the first tails encountered. At that point, the number of heads follows a negative binomial distribution. Thus $\mathbb E[X|X_1=H]=p/(1-p)$, and

$$\mathbb E[X]=p\frac p{1-p}+(1-p)\cdot 1=\frac{p^2}{1-p}+1-p\text.$$

My intuition tells me that my friends' solution is wrong, because if $p=1/2$ then their solution implies that we can generally expect one head to occur. That doesn't make sense to me because we can always expect at least one head, and can often expect more. So my intuition agrees more with my solution, which implies an expectation of two heads.

2

There are 2 best solutions below

3
On

Let's first look at the case of Tails coming first. In this case, there will always only be one head.

So, we can simply sum the probabilities: $$(1-p)p+(1-p)^2p+... = \frac{p(1-p)}p = 1-p$$

In the case of Heads coming first, we have to be a bit more careful. The infinite summation becomes $$p(1-p)+2p^2(1-p)+3p^3(1-p)...=p(1-p)+p^2(1-p)+p^3(1-p)...+p^2(1-p)+p^3(1-p)... ... = \frac{p(1-p)}{1-p}+\frac{p^2(1-p)}{1-p}+...=p+p^2+...=\frac p{1-p}$$

So, our answer is $$\color{red}{1-p+\frac p{1-p}}$$

1
On

You're friend was almost right. However $\mathbb E[X \mid X_1 = H]$ is not quite a negative binomial distribution since you're already guaranteed one head (the first one). $\mathbb E[X \mid X_1 = H]$ has the distribution of $1 + Y$ where $Y$ has a negative binomial distribution $\text{NB}(1, p)$. Therefore $$ \mathbb E[X \mid X_1 = H] = 1 + \frac{p}{1 - p} = \frac{1}{1 - p}$$ Plugging this in will give you the correct answer.