The Patient Coin Flipper

A fair coin is tossed repeatedly until 5 consecutive heads occur. What is the expected number of coin tosses?


The answer is 62.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

8 solutions

Calvin Lin Staff
May 13, 2014

Let X n X_n be the random variable for the number of coin tosses needed to obtain n n consecutive heads. Let E n E_n be the expected value of X n X_n . In order to obtain n n consecutive heads, we need to first obtain n 1 n-1 consecutive heads, and get heads on the next coin flip. If we get tails on the next coin flip, we are back at the start.

Hence, by Law of Iterated Expectation , E [ X n ] = 1 2 ( E [ X n 1 ] + 1 ) + 1 2 ( E [ X n 1 ] + 1 + E [ X n ] ) E[X_n] = \frac {1}{2} (E[X_{n-1}] + 1) + \frac {1}{2} ( E[X_{n-1}] + 1 + E[X_n]) , or that E n = 1 2 ( E n 1 + 1 ) + 1 2 ( E n 1 + 1 + E n ) E n = 2 E n 1 + 2 E_n = \frac {1}{2} ( E_{n-1} +1) + \frac {1}{2} ( E_{n-1} + 1 + E_n) \Rightarrow E_n = 2 E_{n-1} +2 .

Clearly, E 0 = 0 E_0 = 0 , since we are guaranteed to get 0 consecutive heads after 0 coin flips. This allows us to calculate E 1 = 2 , E 2 = 6 , E 3 = 14 , E 5 = 62 E_1 = 2, E_2 = 6, E_3 = 14, \ldots E_{5} = 62 .

Note: The closed form for E n E_n is 2 n + 1 2 2^{n+1}-2 . This can be shown by solving the recurrence relation.

I'm confused what how the linearity of expectation implies the formula E [ X n ] = 1 2 ( E [ X n 1 ] + 1 ) + 1 2 ( E [ X n 1 ] + 1 + E [ X n ] ) . E[X_n] = \frac{1}{2}(E[X_{n-1}]+1) + \frac{1}{2}(E[X_{n-1}] + 1 + E[X_n]).

As I understand it, the linearity of expectation implies that E ( a X + b ) = a E ( X ) + b . E(aX+b) = aE(X) + b .

Please can someone enlighten me :)

Roberto Nicolaides - 6 years ago

Log in to reply

A I understand, two steps are combined here, first total expectation E [ X n ] = E [ X n n-th filp is H ] 1 2 + E [ X n n-th flip is T ] 1 2 E[X_n] = E[X_n|\text{n-th filp is H}] \frac {1}{2} + E[Xn|\text{n-th flip is T}] \frac {1}{2}

Then, at the second step, the linearity of expectation is applied E [ X n n-th filp is H ] = E [ X n 1 + 1 ] = E [ X n 1 ] + 1 E[X_n|\text{n-th filp is H}] = E[X_{n-1}+1] = E[X_{n-1}]+1 and E [ X n n-th filp is T ] = E [ X n 1 + 1 + X n ] = E [ X n 1 ] + 1 + E [ X n ] E[X_n|\text{n-th filp is T}] = E[X_{n-1}+1+X_{n}] = E[X_{n-1}]+1+E[X_{n}]

Ilya Prokin - 3 years, 10 months ago

Hello sir,

If we toss a fair coin repeatedly for N N times, can we say the number of expected n n -consecutive heads is N E n \dfrac{N}{E_n} ?

Kazem Sepehrinia - 5 years, 8 months ago

Log in to reply

Nope. the expected number of n-consecutive heads will just be N n + 1 2 n \frac{ N-n + 1 } { 2 ^n } , and follows immediately from Discrete Random Variables - Indicator Variables

Calvin Lin Staff - 5 years, 8 months ago

Hii Calvin lin!! Can you please explain in detail how did you get the first two expressions? I am not able to understand. I understood the fact that you have applied the linearity of expectation but haven't understood how did you get those expressions.

Chirag Sharma - 3 years, 1 month ago

Hi Calvin,

I undertand the concept of linearity of expectation, but I am disturb by how the expectancy of Xn has been decomposed. I would appreciate if you could explain further.

KR

Rubén Pérez Sanz - 2 years, 5 months ago

Log in to reply

Check out Law of Iterated Expectation , which is a "deeper" use of linearity. I've updated the solution accordingly.

This law gives us
E [ X n ] = E [ X n 1 next filp is H ] × P ( next filp is H ) + E [ X n 1 next flip is T ] × P ( next filp is T ) . E[X_n] = E[X_{n-1}|\text{next filp is H}] \times P(\text{next filp is H}) + E[X_{n-1}|\text{next flip is T}] \times P(\text{next filp is T}).

After that, we apply linearity to conclude that

E [ X n ] = ( E [ X n 1 ] + 1 ) × 1 2 + ( E [ X n 1 + 1 + E [ X n ] ) × 1 2 . E[X_n] = ( E[X_{n-1}] + 1 ) \times \frac{1}{2} + ( E[X_{n-1} + 1 + E[X_n] ) \times \frac{1}{2}.

Calvin Lin Staff - 2 years, 5 months ago

It's not about the linearity of expectation!! What he has written as an equation is basically what he described in English. You have n - 1 heads, then you either get a head or not (each with the probability of 1/2). Then, if you get a head on your n-th flip, you have the first term. If you get a tail, you have the second term.

Peyman Ayoubi - 7 months, 3 weeks ago
Jianzhi Wang
May 20, 2014

Let E E be the Expectation we want to calculate. Let H H stand for heads and T T stand for tails in the following. Note that if we ever get a T T , then since the coin tosses are independent, we would have to start over again.

If the first toss result in a T T , the probability is 1 2 \frac {1}{2} and the game restarts.

If the first and second tosses result in a H H , then a T T , the probability is 1 4 \frac {1}{4} ) and the game restarts.

If the first, second and third tosses result in a H , H H, H , then a T T , the probability is 1 8 \frac {1}{8} and the game restarts.

If the first, second, third and fourth tosses result in a H , H , H H, H, H then a T T , the probability is 1 16 \frac {1}{16} and the game restarts.

If the first, second, third, fourth and fifth tosses result in a H , H , H , H H, H, H, H then a T T , the probability is 1 32 \frac {1}{32} and the game restarts.

If the first, second, third, fourth and fifth tosses result in a H , H , H , H H, H, H, H and H H , the probability is 1 32 \frac {1}{32} , and the game ends.

Hence, by the linearity of expectation, we get E = 1 2 × ( E + 1 ) + 1 4 × ( E + 2 ) + 1 8 × ( E + 3 ) + 1 16 ( E + 4 ) + 1 4 × ( E + 5 ) + 1 32 × 5 E= \frac {1}{2} \times (E+1) + \frac {1}{4}\times (E+2) + \frac {1}{8} \times (E+3) + \frac {1}{16} (E+4) + \frac {1}{4} \times (E+5) + \frac {1}{32} \times 5 . Solving the equation, we get E = 62 E=62 .

What is the expected number of coin tosses needed to get n n heads? Hint: How would you apply the technique used to solve this problem?

Calvin Lin Staff - 7 years ago

Log in to reply

My Approach

Lets calculate it for n consecutive tosses the expected number of tosses needed Lets say that for En-1 for n-1 consecutive heads and En for n consecutive heads Now if we get one more head after En-1 then we have n consecutive heads or if it is a tail then again we have to repeat the procedure So for the two scenarios 1.En-1 +1 2.En +1 1 for a tail

So En=1/2 (En-1 +1)+1/2(En-1+ En+ 1) So En= 2En-1+2 So we have the general recurrence relation as f(x)=2 f(x-1)+2 where for x>=2 and for n=2 we can easily derive that f(2)=6; So f(x)=2 f(x-1)+2=f(x)=2 (2 f(x-2)+2)+2=2 (2 (2 f(x-3)+2)+2)+2 which can be generalized as f(x)=2^x+2^1 +2^2+2^3+....... 2^(n-1) =2^x+2 (2^(n-1)-1) So for x=5 it will be 32+2 (2^4-1)=62

Parth Lohomi - 6 years, 6 months ago

I don't get where the E+1 and E+2 comes from.

Baby Googa - 6 years, 3 months ago

is that supposed to be 1/32(E+5)?

Ashish Sacheti - 4 years, 11 months ago
Karlo Jeremias
May 20, 2014

First of all, the expected number of coin tosses for getting a single head is 2 since on a coin toss, there are two possibilities but on the case of having consecutive number of heads, it is different . For example, as in the question, 5 consecutive heads. Before this would occur, we should first have to have a case where 4 consecutive heads to occur. And after that, depending on the next toss, we would either stop since a head is achieved otherwise continue if its a tail. Putting all this into equation: T = 1/2 (P+1) + 1/2(P+1+T) or T = 2P +2 where T is the expected number of coin tosses and P is the last expected coin tosses for the last consecutive number of heads.

So to get T for 2 consecutive heads: T = 2P + 2 T = 2(2) + 2 T = 6

For 3 consecutive heads: T = 2P + 2 T = 2(6) +2 T = 14

For 4 consecutive heads: T = 2P + 2 T = 2(14) + 2 T = 30

And lastly, for 5 consecutive heads: T = 2P + 2 T = 2(30) + 2 T = 62

Arjen Vreugdenhil
Sep 12, 2016

At any stage, the situation can be described by a state variable n = n = number of consecutive heads in the previous tosses. Whenever we toss another head, n n is increased by one; whenever we toss tail, we are back at state 0.

Let E n E_n be the expected number of tosses from state n n . The answer to the problem will be E 0 E_0 .

Based on the process described above and the probabilities of 1 2 \tfrac12 , we get the recurrence relations E n = 1 + 1 2 E 0 + 1 2 E n + 1 , E_n = 1 + \tfrac12 E_0 + \tfrac12 E_{n+1}, and we set E 5 = 0 E_5 = 0 because it is the final state. In matrix form, ( 1 2 1 2 0 0 0 1 2 1 1 2 0 0 1 2 0 1 1 2 0 1 2 0 0 1 1 2 1 2 0 0 0 1 ) ( E 0 E 1 E 2 E 3 E 4 ) = ( 1 1 1 1 1 ) . \left(\begin{array}{ccccc} \tfrac12 & -\tfrac12 & 0 & 0 & 0 \\ -\tfrac12 & 1 & -\tfrac12 & 0 & 0 \\ -\tfrac12 & 0 & 1 & -\tfrac12 & 0 \\ -\tfrac12 & 0 & 0 & 1 & -\tfrac12 \\ -\tfrac12 & 0 & 0 & 0 & 1 \end{array}\right) \left(\begin{array}{c} E_0 \\ E_1 \\ E_2 \\ E_3 \\ E_4\end{array}\right) = \left(\begin{array}{c} 1 \\ 1 \\ 1 \\ 1 \\ 1 \end{array}\right). Solve this by (a) doubling the values of each row, (b) then adding each row to all rows underneath, ( 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 ) ( E 0 E 1 E 2 E 3 E 4 ) = ( 2 4 8 16 32 ) , \left(\begin{array}{ccccc} 1 & -1 & 0 & 0 & 0 \\ 0 & 1 & -1 & 0 & 0 \\ 0 & 0 & 1 & -1 & 0 \\ 0 & 0 & 0 & 1 & -1 \\ 0 & 0 & 0 & 0 & 1 \end{array}\right) \left(\begin{array}{c} E_0 \\ E_1 \\ E_2 \\ E_3 \\ E_4\end{array}\right) = \left(\begin{array}{c} 2 \\ 4 \\ 8 \\ 16 \\ 32 \end{array}\right), and finally (c) (starting at the bottom) adding each row to the one above it, ( 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 ) ( E 0 E 1 E 2 E 3 E 4 ) = ( 62 60 56 48 32 ) . \left(\begin{array}{ccccc} 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 \end{array}\right) \left(\begin{array}{c} E_0 \\ E_1 \\ E_2 \\ E_3 \\ E_4\end{array}\right) = \left(\begin{array}{c} 62 \\ 60 \\ 56 \\ 48 \\ 32 \end{array}\right). These are the values of E n E_n ; we read off immediately that E 0 = 62 E_0 = \boxed{62} .

General case

The expected number of rolls to obtain N N consecutive heads is 2 N + 1 2 2^{N+1} - 2 .

Proof : with the definitions above, E n = 2 N + 1 2 n + 1 . E_n = 2^{N+1}-2^{n+1}. It is easy to check that E N = 2 N + 1 2 N + 1 = 0 E_N = 2^{N+1}-2^{N+1} = 0 to make state N N the proper endpoint; and E n = 2 N + 1 2 n + 1 = 1 2 ( 2 N + 1 + 2 N + 1 + 2 2 2 n + 2 ) = 1 + 1 2 ( 2 N + 1 2 ) + 1 2 ( 2 N + 1 2 n + 2 ) = 1 + 1 2 E 0 + 1 2 E n + 1 . E_n = 2^{N+1} - 2^{n+1} = \tfrac12(2^{N+1}+2^{N+1} + 2 - 2 - 2^{n+2}) \\ = 1 + \tfrac12(2^{N+1} - 2) + \tfrac12(2^{N+1} - 2^{n+2}) = 1 + \tfrac12 E_0 + \tfrac12 E_{n+1}.

Manoj Pandey
May 20, 2014

Let x x be the expected number of tosses. It is clear that x x is finite.

Now, start tossing. If we get a tail immediately (probability 1 2 \frac{1}{2} ) then the expected number is x x +1.

If we get a head then a tail (probability 1 4 \frac{1}{4} ), then the expected number is x x +2.

Continue …. If we get 4 heads then a tail, the expected number is x x +5.

Finally, if our first 5 tosses are heads, then the expected number is 5.

Thus x x = 1 2 \frac{1}{2} ( x x +1)+ 1 4 \frac{1}{4} ( x x +2)+ 1 8 \frac{1}{8} ( x x +3)+ 1 16 \frac{1}{16} ( x x +4)+ 1 32 \frac{1}{32} ( x x +5)+ 1 32 \frac{1}{32} (5).

Solve this linear equation for x x . We get x x =62.

Scottie Pippen
May 20, 2014

Let e be the expected number of tosses. It is clear that e is finite.

Start tossing. If we get a tail immediately (probability 1/2) then the expected number is e+1. If we get a head then a tail (probability 1/4), then the expected number is e+2. Continue ….

If we get 4 heads then a tail, the expected number is e+5. Finally, if our first 5 tosses are heads, then the expected number is 5. Thus,

e = 1/2 (e+1) + 1/4 (e+2) + 1/8 (e+3) + 1/16 (e+4) + 1/32 (e+5) + 1/32 (5).

Solve this linear equation for e. We get e = 62.

David Vaccaro
Jul 11, 2016

Imagine a gambler in a casino who bets against a fair coin. If he guesses correctly he doubles his stake, if he guesses incorrectly he loses his stake. Each time a coin is tossed he bets a new $1 that it lands heads. If he wins then he bets his winnings that the next coin will also be heads. He keeps going until the first time that five heads occur in a row.

When five heads occur in a row he leaves the casino with 32 + 16 + 8 + 4 + 2 = 62 32+16+8+4+2=62 dollars i.e. 32 dollars from the stake that had accumulated 5 winning, 16 dollars from the stake with four winnings and so on.

As the casino is fair he would expect to leave the casino with the same amount of money that he had put in as bets. He gambles one dollar per round so the expected number of tosses is 62.

Tootie Frootie
Jun 15, 2015

125-1=124/2=62

If your solution is (n * n * n - 1) / 2 it only works when n = 3 and n = 5. I don't what is your approach for this solution though.

vahid sanei - 4 years, 7 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...