Solved – Expected number of times a coin is flipped until it lands on “heads”

expected valueprobability

I found a solution to this problem somewhere but I'm unsure about the solution.

It uses a first time head case and a first time tail case to create a recursive equation and solves for $E(x)$.

$E(x) = p + (1-p)[1+E(x)]$ where $p$ is probability of getting heads, and $E(x)$ is the expected number of coin tosses until landing on heads.

But what if I add the third case too?

$E(x) = p + (1-p)[1+E(x)] + (1-p)^2[2+E(x)]$

That would give me a different answer. Can someone please clarify this to me?

Best Answer

The first answer is correct. Let's say we flip a coin with bias $p$ (probability of heads) until it lands on heads, and the number of tosses is $X$. I'll demonstrate a more direct calculation and then you'll see why the recursive calculation works.

$$ \mathbb{E}[X] = 1p + 2p(1-p) + 3p(1-p)^2 + 4p(1-p)^3 + \dots $$

This is because if $X = n$, there have been $(n-1)$ tails and then $1$ heads. Now let's try to relate this to your expression. We are going to add $1$ to both sides but on the right hands side it will be in a tricky form.

$$ 1 = p + p(1-p) + p(1-p)^2 + \dots = P(1) + P(2) + + P(3) \dots $$

So then we have,

$$ \mathbb{E}[X] + 1 = 2p + 3p(1-p) + 4p(1-p)^2 + 5p(1-p)^3 + \dots $$

So if we multiply both sides by $(1-p)$ and add $p$ we have,

$$ p + (1-p)(\mathbb{E}[X] + 1) = p + 2p(1-p) + 3p(1-p)^3 + \dots = \mathbb{E}[X]. $$


That concludes the proof, but how about the intuition. The intuition is that when you start flipping, with probability $p$ you finish on one flip, so let's add $$ 1 \cdot p $$ to the expectation. With probability $(1-p)$ you get a tails and pretty much start all over again, but of course you have wasted a flip. So we add $$ (1-p)(1 + \mathbb{E}[X]) $$ to the expectation. Hope that helps. If you have any questions, please comment.