🧮 Brain Teaser
Probability
Expected Runs of Heads
2026-06-24
✏︎

The Ballot Problem's Cousin: Runs of Heads

You flip a fair coin nn times. A run of heads is a maximal consecutive sequence of heads. For example, in the sequence HHTHHH, there are two runs of heads (of lengths 2 and 3).

Question: What is the expected number of runs of heads in nn fair coin flips?

(Give a clean closed-form answer and explain the key idea.)

indicator variableslinearity of expectationcoin flipsruns

Answer: Expected Runs of Heads

Key Idea / Intuition

Rather than trying to count runs directly — which requires tracking complex consecutive structure — we use indicator random variables. A run of heads starts at position ii if and only if position ii is heads AND either i=1i=1 or position i1i-1 is tails. This decouples the problem beautifully: we just count the expected number of "run starts."


Formal Proof / Solution

Setup: Let X1,X2,,XnX_1, X_2, \ldots, X_n be i.i.d. fair coin flips (HH or TT, each with probability 12\frac{1}{2}).

Define indicator variables: Let IiI_i be the indicator that a run of heads begins at position ii. Then:

(number of runs of heads)=i=1nIi\text{(number of runs of heads)} = \sum_{i=1}^{n} I_i

When does a run of heads begin at position ii?

  • Case i=1i = 1: A run starts at position 1 iff X1=HX_1 = H. So: P(I1=1)=12P(I_1 = 1) = \frac{1}{2}

  • Case i2i \geq 2: A run starts at position ii iff Xi1=TX_{i-1} = T and Xi=HX_i = H (tails followed by heads, meaning a new run begins). Since flips are independent: P(Ii=1)=P(Xi1=T)P(Xi=H)=1212=14P(I_i = 1) = P(X_{i-1} = T) \cdot P(X_i = H) = \frac{1}{2} \cdot \frac{1}{2} = \frac{1}{4}

Expected number of runs of heads:

E[i=1nIi]=E[I1]+i=2nE[Ii]=12+(n1)14E\left[\sum_{i=1}^{n} I_i\right] = E[I_1] + \sum_{i=2}^{n} E[I_i] = \frac{1}{2} + (n-1) \cdot \frac{1}{4}

E[runs of heads]=n+14\boxed{E[\text{runs of heads}] = \frac{n+1}{4}}

Sanity check: For n=1n=1: the formula gives 24=12\frac{2}{4} = \frac{1}{2}, which is correct (one run of heads with probability 12\frac{1}{2}). For n=2n=2: formula gives 34\frac{3}{4}. Direct check: sequences HH,HT,TH,TTHH, HT, TH, TT have 1,1,1,01, 1, 1, 0 runs of heads respectively, giving expected value 34\frac{3}{4}. ✓

Why this is beautiful: The linearity of expectation transforms a problem about complex consecutive structure into a simple sum over independent pairs of coin flips. No need to track run lengths or use generating functions — just ask "where does a new run begin?"

Note: By symmetry, the expected number of runs of tails is also n+14\frac{n+1}{4}, and the expected total number of runs (heads or tails) is n+12\frac{n+1}{2}, a clean result.

Source: Mathematical folklore / Mosteller-style probability puzzle

Type: ProbabilitySource: Mathematical folklore / Mosteller-style probability puzzleEdit on GitHub ↗