Probability & Statistics

Heads in a Row

Flip a fair coin until you see n heads in a row. How many flips should you expect to need?

solvedmedium1 min

You flip a fair coin until you see nn heads in a row. What is the expected number of flips?

Reveal solutionHide solution

#Build the streak one rung at a time

Let EnE_n be the expected number of flips to reach a run of nn heads. To get there, first reach a run of n1n-1, which takes En1E_{n-1} flips, then flip once more. With probability 12\tfrac{1}{2} it is heads and the run is complete; with probability 12\tfrac{1}{2} it is tails, which wipes the streak back to zero and leaves you needing a fresh EnE_n flips. So

En=En1+1+120+12En.(1)E_n = E_{n-1} + 1 + \tfrac{1}{2}\cdot 0 + \tfrac{1}{2}\,E_n. \tag{1}

#Solve the recursion

Rearranging gives 12En=En1+1\tfrac{1}{2}E_n = E_{n-1} + 1, that is En=2En1+2E_n = 2E_{n-1} + 2. Starting from E0=0E_0 = 0 this unrolls to

En=2n+12.(2)E_n = 2^{\,n+1} - 2. \tag{2}
HHHT resets to 00123
The state is the current run of heads. A head climbs one rung, a tail drops all the way back to 0, and the run is complete at n. Because every tail erases the whole streak, the expected wait doubles at each new rung.

#Read it off

Each extra head roughly doubles the wait, because one tail at the wrong moment costs the entire run and sends you back to the start. For three heads in a row, E3=242=14E_3 = 2^4 - 2 = 14 flips, and for ten in a row it is already 20462046.