Expected Runs in a Card Deck

Expectation · Medium · Free problem

A standard 52-card deck has 26 red cards and 26 black cards. You shuffle the deck thoroughly and lay the cards out in a row. A "run" is a maximal consecutive sequence of cards of the same color -- for example, if the first four cards are Red, Red, Red, Black, that is two runs (one of length 3 and one of length 1 so far).

What is the expected number of runs in the full 52-card sequence?

Hints

  1. Instead of thinking about entire runs, think about where each new run begins.
  2. Define an indicator variable $X_i$ for whether the color changes at position $i$. How does the number of runs relate to $\sum X_i$?
  3. By symmetry, $P(X_i = 1) = 26/51$ for every adjacent pair. Now use linearity of expectation.

Worked Solution

How to Think About It: Don't try to enumerate the possible run-length patterns -- that is a combinatorial nightmare. Instead, think about it locally: a new run starts at position 1 (always) and at every subsequent position where the color changes. So the number of runs equals 1 plus the number of color changes. That immediately converts a global counting problem into a sum of local indicators, and linearity of expectation does the rest.

Quick Estimate: There are 51 adjacent pairs. At each pair, roughly half the time the colors differ (since the deck is evenly split). So you expect about $51 \times 0.5 \approx 25$-$26$ color changes, giving roughly 26-27 runs. That is our target.

Approach: Define indicator variables for color changes at each position and use linearity of expectation.

Formal Solution:

Define $X_i = 1$ if card $i$ differs in color from card $i-1$, for $i = 2, 3, \ldots, 52$. Then:

$$\text{Runs} = 1 + \sum_{i=2}^{52} X_i$$

By linearity of expectation:

$$E[\text{Runs}] = 1 + \sum_{i=2}^{52} P(X_i = 1)$$

Now compute $P(X_i = 1)$. By symmetry, every card is equally likely to be any of the 52 cards, and the pair at positions $(i-1, i)$ is a uniformly random ordered pair drawn without replacement. If card $i-1$ is red (which happens with probability $26/52$), then card $i$ is drawn from the remaining 51 cards, of which 26 are black. If card $i-1$ is black, the same argument gives $P(\text{card } i \text{ is red}) = 26/51$. Either way:

$$P(X_i = 1) = \frac{26}{51}$$

Since this probability is the same for every $i$:

$$E[\text{Runs}] = 1 + 51 \cdot \frac{26}{51} = 1 + 26 = 27$$

Generalization: With $r$ red and $b$ black cards in a deck of $n = r + b$, the probability that any adjacent pair differs is $\frac{2rb}{n(n-1)}$, so:

$$E[\text{Runs}] = 1 + \frac{2rb}{n}$$

For $r = b = 26$: $1 + \frac{2 \cdot 26 \cdot 26}{52} = 1 + 26 = 27$.

Answer: The expected number of runs is $\boxed{27}$.

Intuition

This is a textbook example of the indicator variable technique: when you need the expectation of a count, decompose it into a sum of 0-1 random variables and use linearity of expectation. You never need to compute the full distribution of runs, and the indicators do not need to be independent -- linearity of expectation works regardless. This trick appears constantly in interview problems involving counts of matches, inversions, fixed points, and other "how many X" questions.

The practical lesson is about reframing. A "global" question (how many runs in the whole deck?) becomes a "local" question (does a color change happen at this one position?). The local question is easy because each adjacent pair is just a hypergeometric draw from 26 red and 26 black cards. This decomposition strategy is one of the most powerful tools in discrete probability -- whenever you see "expected number of something," your first instinct should be to look for indicators.

Open the full interactive solver →