A fair coin is tossed repeatedly until 5 consecutive heads occur. What is the expected number of coin tosses?
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.
I'm confused what how the linearity of expectation implies the formula E [ X n ] = 2 1 ( E [ X n − 1 ] + 1 ) + 2 1 ( 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 .
Please can someone enlighten me :)
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 ] 2 1 + E [ X n ∣ n-th flip is T ] 2 1
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 and E [ X n ∣ n-th filp is T ] = E [ X n − 1 + 1 + X n ] = E [ X n − 1 ] + 1 + E [ X n ]
Hello sir,
If we toss a fair coin repeatedly for N times, can we say the number of expected n -consecutive heads is E n N ?
Log in to reply
Nope. the expected number of n-consecutive heads will just be 2 n N − n + 1 , and follows immediately from Discrete Random Variables - Indicator Variables
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.
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
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
)
.
After that, we apply linearity to conclude that
E [ X n ] = ( E [ X n − 1 ] + 1 ) × 2 1 + ( E [ X n − 1 + 1 + E [ X n ] ) × 2 1 .
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.
Let E be the Expectation we want to calculate. Let H stand for heads and T stand for tails in the following. Note that if we ever get a T , then since the coin tosses are independent, we would have to start over again.
If the first toss result in a T , the probability is 2 1 and the game restarts.
If the first and second tosses result in a H , then a T , the probability is 4 1 ) and the game restarts.
If the first, second and third tosses result in a H , H , then a T , the probability is 8 1 and the game restarts.
If the first, second, third and fourth tosses result in a H , H , H then a T , the probability is 1 6 1 and the game restarts.
If the first, second, third, fourth and fifth tosses result in a H , H , H , H then a T , the probability is 3 2 1 and the game restarts.
If the first, second, third, fourth and fifth tosses result in a H , H , H , H and H , the probability is 3 2 1 , and the game ends.
Hence, by the linearity of expectation, we get E = 2 1 × ( E + 1 ) + 4 1 × ( E + 2 ) + 8 1 × ( E + 3 ) + 1 6 1 ( E + 4 ) + 4 1 × ( E + 5 ) + 3 2 1 × 5 . Solving the equation, we get E = 6 2 .
What is the expected number of coin tosses needed to get n heads? Hint: How would you apply the technique used to solve this problem?
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
I don't get where the E+1 and E+2 comes from.
is that supposed to be 1/32(E+5)?
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
At any stage, the situation can be described by a state variable n = number of consecutive heads in the previous tosses. Whenever we toss another head, n is increased by one; whenever we toss tail, we are back at state 0.
Let E n be the expected number of tosses from state n . The answer to the problem will be E 0 .
Based on the process described above and the probabilities of 2 1 , we get the recurrence relations E n = 1 + 2 1 E 0 + 2 1 E n + 1 , and we set E 5 = 0 because it is the final state. In matrix form, ⎝ ⎜ ⎜ ⎜ ⎜ ⎛ 2 1 − 2 1 − 2 1 − 2 1 − 2 1 − 2 1 1 0 0 0 0 − 2 1 1 0 0 0 0 − 2 1 1 0 0 0 0 − 2 1 1 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ ⎝ ⎜ ⎜ ⎜ ⎜ ⎛ E 0 E 1 E 2 E 3 E 4 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ = ⎝ ⎜ ⎜ ⎜ ⎜ ⎛ 1 1 1 1 1 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ . Solve this by (a) doubling the values of each row, (b) then adding each row to all rows underneath, ⎝ ⎜ ⎜ ⎜ ⎜ ⎛ 1 0 0 0 0 − 1 1 0 0 0 0 − 1 1 0 0 0 0 − 1 1 0 0 0 0 − 1 1 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ ⎝ ⎜ ⎜ ⎜ ⎜ ⎛ E 0 E 1 E 2 E 3 E 4 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ = ⎝ ⎜ ⎜ ⎜ ⎜ ⎛ 2 4 8 1 6 3 2 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ , 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 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ = ⎝ ⎜ ⎜ ⎜ ⎜ ⎛ 6 2 6 0 5 6 4 8 3 2 ⎠ ⎟ ⎟ ⎟ ⎟ ⎞ . These are the values of E n ; we read off immediately that E 0 = 6 2 .
General case
The expected number of rolls to obtain N consecutive heads is 2 N + 1 − 2 .
Proof : with the definitions above, E n = 2 N + 1 − 2 n + 1 . It is easy to check that E N = 2 N + 1 − 2 N + 1 = 0 to make state N the proper endpoint; and E n = 2 N + 1 − 2 n + 1 = 2 1 ( 2 N + 1 + 2 N + 1 + 2 − 2 − 2 n + 2 ) = 1 + 2 1 ( 2 N + 1 − 2 ) + 2 1 ( 2 N + 1 − 2 n + 2 ) = 1 + 2 1 E 0 + 2 1 E n + 1 .
Let x be the expected number of tosses. It is clear that x is finite.
Now, start tossing. If we get a tail immediately (probability 2 1 ) then the expected number is x +1.
If we get a head then a tail (probability 4 1 ), then the expected number is x +2.
Continue …. If we get 4 heads then a tail, the expected number is x +5.
Finally, if our first 5 tosses are heads, then the expected number is 5.
Thus x = 2 1 ( x +1)+ 4 1 ( x +2)+ 8 1 ( x +3)+ 1 6 1 ( x +4)+ 3 2 1 ( x +5)+ 3 2 1 (5).
Solve this linear equation for x . We get x =62.
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.
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 3 2 + 1 6 + 8 + 4 + 2 = 6 2 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.
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.
Problem Loading...
Note Loading...
Set Loading...
Let X n be the random variable for the number of coin tosses needed to obtain n consecutive heads. Let E n be the expected value of X n . In order to obtain n consecutive heads, we need to first obtain 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 ] = 2 1 ( E [ X n − 1 ] + 1 ) + 2 1 ( E [ X n − 1 ] + 1 + E [ X n ] ) , or that E n = 2 1 ( E n − 1 + 1 ) + 2 1 ( E n − 1 + 1 + E n ) ⇒ E n = 2 E n − 1 + 2 .
Clearly, 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 = 1 4 , … E 5 = 6 2 .
Note: The closed form for E n is 2 n + 1 − 2 . This can be shown by solving the recurrence relation.