30
$\begingroup$

Suppose we flip a coin until we see a head. What is the expected value of the number of flips we will take?


I am pretty new to expected value, so I tried to evaluate it by multiplying the probability of each scenario with the number of flips it took to get there (like taking the arithmetic mean). This didn't work though, because of the infinite possibilities. I'm really confused, and if someone were to provide an answer, I would really appreciate it if they could go into detail.

$\endgroup$
3
  • $\begingroup$ Thanks for responding so fast, @angryavian! I am pretty new to expected value, so I tried to evaluate it by multiplying the probability of each scenario with the number of flips it took to get there (like taking the arithmetic mean). This didn't work though, because of the infinite possibilities. I'm really confused, and if someone were to provide an answer, I would really appreciate it if they could go into detail. $\endgroup$
    – hyperdo
    Mar 19, 2015 at 3:09
  • 1
    $\begingroup$ It should be mentioned, the name of this distribution is "the geometric distribution." See here for a table of common distributions. $\endgroup$
    – JMoravitz
    Mar 19, 2015 at 3:46
  • $\begingroup$ You may also want to take a look at my answer, which some people call "first-step analysis". It is widely and easily applied, for example see math.stackexchange.com/a/364135. $\endgroup$
    – user21820
    Mar 19, 2015 at 5:44

4 Answers 4

33
$\begingroup$

Let $X$ be a discrete random variable with possible outcomes: $x_1, x_2, x_3,\dots, x_i,\dots$ with associated probabilities $p_1,p_2,p_3,\dots,p_i,\dots$

The expected value of $f(X)$ is given as:

$E[f(X)] = \sum\limits_{i\in\Delta} f(x_i)p_i$

In your specific example, $X$ could be one of the values: $1,2,3,\dots ,i,\dots$ with corresponding probabilities $\frac{1}{2},\frac{1}{4},\frac{1}{8},\dots,\frac{1}{2^i},\dots$ (seen easily from the beginnings of a tree diagram)

So, the expected value of $X$ is:

$\sum\limits_{i=1}^\infty i(\frac{1}{2})^i$

This is a well-known infinite sum of the form $\sum\limits_{i=1}^\infty i p (1-p)^{i-1}$, in this case with $p=1-p=\frac{1}{2}$. You will likely be expected to simply memorize the result, and it is included in most formula lists. $\sum\limits_{i=1}^\infty i p (1-p)^{i-1}=\frac{1}{p}~~~~~~~(\dagger)$

Using this result without proof, we get our expected number of flips is $\frac{1}{0.5}=2$

The proof of $(\dagger)$:

$$\sum\limits_{i=1}^\infty i p (1-p)^{i-1} = p\sum\limits_{i=1}^\infty i (1-p)^{i-1}\\ = p\left(\sum\limits_{i=1}^\infty (1-p)^{i-1} + \sum\limits_{i=2}^\infty (1-p)^{i-1} + \sum\limits_{i=3}^\infty (1-p)^{i-1} + \dots\right)\\ = p\left[(1/p)+(1-p)/p+(1-p)^2/p+\dots\right]\\ = 1 + (1-p)+(1-p)^2+\dots\\ =\frac{1}{p}$$

$\endgroup$
1
  • $\begingroup$ The correct "thank you" for your contribute to my peaches, apricots and.."nespole" :-) $\endgroup$
    – Sebastiano
    Aug 28, 2020 at 14:59
12
$\begingroup$

Let $X$ be the number of flips we make before seeing heads. Let $p$ be the probability of getting heads on any one flip. And note three things that, individually, aren't too hard to see:

  1. Coin flipping is a memoryless process.
  2. We must flip the coin at least once in order to get heads (or tails, or anything).
  3. The probability of not getting heads on that first flip is $1-p$.

Using these three ideas, we can model $E[X]$, the expected number of flips we perform before seeing heads, as:

$E[X] = 1 + (1-p)E[X]$

That is, we flip the coin once (hence the $1$), and there is a ($1-p$) chance that we get tails and have to continue flipping the coin (hence the $+ (1-p)E[X]$). Because coin flipping is memoryless, the expected value of $X$ after flipping a tails is the same as before flipping that tails (that's why the $E[X]$ on the RHS of the equation is not conditioned).

Now it turns out that modeling $E[X]$ in this way is useful because we can easily solve for $E[X]$ and answer our question:

$E[X] = 1 + (1-p)E[X]$

$E[X] - (1-p)E[X] = 1$

$E[X] + (-1+p)E[X] = 1$

$E[X] - E[X] + pE[X] = 1$

$pE[X] = 1$

$E[X] = 1 / p$

Since $p = 1/2$, we get $E[X] = 2$.

I learned of this clever approach here: http://online.stanford.edu/course/algorithms-design-and-analysis-part-1

$\endgroup$
3
  • $\begingroup$ wrong, true only if p = 1/2 $\endgroup$
    – frhack
    Mar 3, 2020 at 21:39
  • 1
    $\begingroup$ as @frhack mentioned, this only works if p is 1/2. i submitted an edit so that the answer is generalizable to any value of p $\endgroup$ Mar 16, 2021 at 17:02
  • $\begingroup$ the URL in the answer is dead, perhaps this is the updated one? online.stanford.edu/courses/… $\endgroup$
    – McSuperbX1
    17 hours ago
7
$\begingroup$

Let $x$ be the expected number of flips. Then after the first flip half the time we stop and the other half the time we continue. That gives $x = 1 + \frac{1}{2}(0) + \frac{1}{2}(x)$ and so $x = 2$ or $x$ is infinite. The latter is impossible (see note below) and hence $x = 2$.

Note

Given any such iterative process where each iteration is identical and independent of the previous ones and has nonzero probability of stopping, and the desired quantity being the cumulative sum of values of each iteration, where there are upper and lower bounds on the value of all iterations, the desired quantity has finite expectation, for the reason that a series similar to the infinite sum in the other answers converges. The point is that we just have to prove this fact once, and subsequently we can just use the above analysis to handle far more complicated processes without any infinite summation at all.

$\endgroup$
1
  • $\begingroup$ For another example see here, which also gives a proof of a general fact about absorbing finite-state Markov chains, related to the above note. $\endgroup$
    – user21820
    Oct 8, 2019 at 9:08
3
$\begingroup$

Note that the probability of flipping $n$ times is $\frac{1}{2^{n}}$, since that's the probability of flipping exactly $n-1$ tails followed by $1$ heads. (Thinking another way: there's a 1/2 chance you flip heads the first time, then a 1/2 of 1/2 = 1/4 chance you don't flip heads until the second time, etc.)

The expected value of the number of flips is the sum of each possible number multiplied by the probability that number occurs. So, $E(\text{# of flips})= \sum_{n=1}^\infty n\frac{1}{2^n}$.

You could plug that series into Wolfram Alpha to get 2 as your solution.

If you're skeptical, then note that $\sum_{n=1}^m n\frac{1}{2^n}=\frac{2^{m+1}-2-m}{2^m}$. Proof: this is true when $m=1$. Then by induction, $$\sum_{n=1}^{m+1} n\frac{1}{2^n}=\frac{2^{m+1}-2-m}{2^m}+\frac{m+1}{2^{m+1}}$$ $$=\frac{2^{m+2}-4-2m+m+1}{2^{m+1}}$$ $$=\frac{2^{m+2}-2-(m+1)}{2^{m+1}}$$ As a result, $\sum_{n=1}^\infty n\frac{1}{2^n}=\lim_{m\to\infty}\frac{2^{m+1}-2-m}{2^m}=\frac{2}{1}=2$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .