Math Core

Module 2.4 · Counting and Probability

Linearity of expectation

"Find the expected number of..." questions can look impossible: the full probability distribution may be a nightmare. Linearity of expectation lets you skip the distribution entirely. You break the count into tiny yes-or-no pieces, find the probability of each piece, and add.

The key fact

The expected value of a random quantity XX is its long-run average, E[X]=∑x⋅P(X=x)E[X] = \sum x \cdot P(X = x). The most useful property of expectation is that it adds.

Linearity of expectation

For any random quantities X1,X2,…,XnX_1, X_2, \dots, X_n,

E[X1+X2+⋯+Xn]=E[X1]+E[X2]+⋯+E[Xn].E[X_1 + X_2 + \dots + X_n] = E[X_1] + E[X_2] + \dots + E[X_n].

This is true even when the XiX_i depend on each other. No independence is needed.

Indicator variables

To find the expected number of times something happens, write the count as a sum of indicators. An indicator II is 11 if some event happens and 00 if not, so E[I]=P(event)E[I] = P(\text{event}).

Definition

Indicator method

If XX counts how many of the events B1,…,BnB_1, \dots, B_n occur, write X=I1+⋯+InX = I_1 + \dots + I_n, where Ij=1I_j = 1 exactly when BjB_j occurs. Then

E[X]=P(B1)+P(B2)+⋯+P(Bn).E[X] = P(B_1) + P(B_2) + \dots + P(B_n).

For example, in a random permutation of 1,2,…,n1, 2, \dots, n, let Ij=1I_j = 1 if jj is in position jj. Each P(Ij=1)=1nP(I_j = 1) = \dfrac{1}{n}, so the expected number of fixed points is n⋅1n=1n \cdot \dfrac{1}{n} = 1, for every nn. The events "11 is fixed" and "22 is fixed" are not independent, and it doesn't matter.

Common choices of indicator:

  • one per position (is position jj special?),
  • one per pair of positions or objects (is this pair adjacent, matching, inverted?),
  • one per object (does this object appear, get picked, come before something?).

Waiting times

The expected number of trials until an event of probability pp first happens is 1p\dfrac{1}{p}. Combine this with linearity to handle multi-stage waiting. To collect all nn faces of a fair nn-sided die, split the wait into stages: after you have seen kk faces, a new face appears with probability n−kn\dfrac{n - k}{n}, so that stage lasts nn−k\dfrac{n}{n - k} rolls on average. Adding,

E=n(1n+1n−1+⋯+11).E = n\left(\frac{1}{n} + \frac{1}{n - 1} + \dots + \frac{1}{1}\right).

Common mistake

Linearity works for sums, not products or maxima. E[XY]E[XY] is not E[X]E[Y]E[X]E[Y] unless XX and YY are independent, and E[max⁡(X,Y)]E[\max(X, Y)] is not max⁡(E[X],E[Y])\max(E[X], E[Y]). If the question asks for the expected value of a maximum or minimum, look for a way to write it as a sum of indicators first.

Worked example: Mixed neighbors

Five men and five women sit at random around a round table. Find the expected number of pairs of neighbors consisting of one man and one woman, written as mn\dfrac{m}{n} in lowest terms; give m+nm + n.

There are 1010 neighboring pairs of seats. For a given pair, the probability that the two seats hold one man and one woman is 2⋅510⋅59=592 \cdot \dfrac{5}{10} \cdot \dfrac{5}{9} = \dfrac{5}{9}. So the expectation is 10⋅59=50910 \cdot \dfrac{5}{9} = \dfrac{50}{9}, and m+n=59m + n = 59.

Worked example: The smallest element

A 44-element subset of {1,2,…,20}\{1, 2, \dots, 20\} is chosen at random. Find the expected value of its smallest element.

Write the minimum as a sum of indicators: min⁡=∑j≥1Ij\min = \sum_{j \ge 1} I_j, where Ij=1I_j = 1 if min⁡≥j\min \ge j. Then

E[min⁡]=∑j=117P(min⁡≥j)=∑j=117(21−j4)(204)=(215)(204)=215E[\min] = \sum_{j=1}^{17} P(\min \ge j) = \sum_{j=1}^{17} \frac{\binom{21 - j}{4}}{\binom{20}{4}} = \frac{\binom{21}{5}}{\binom{20}{4}} = \frac{21}{5}

by the hockey stick identity. In general the expected minimum of a random kk-subset of {1,…,n}\{1, \dots, n\} is n+1k+1\dfrac{n + 1}{k + 1}.

Worked example: Distinct faces

Six fair dice are rolled. What is the expected number of different values that appear?

Let Iv=1I_v = 1 if value vv appears at least once. P(Iv=1)=1−(56)6P(I_v = 1) = 1 - \left(\dfrac{5}{6}\right)^6. So the expectation is 6(1−1562546656)=310317776≈3.996\left(1 - \dfrac{15625}{46656}\right) = \dfrac{31031}{7776} \approx 3.99.

Tip

When you're stuck, ask "what is the smallest yes-or-no event whose count is my answer?" If each event has an easy probability, you're done.

Practice

Practice 1

A random permutation a1,a2,…,a10a_1, a_2, \dots, a_{10} of 1,2,…,101, 2, \dots, 10 is chosen. The expected number of indices ii with 1≤i≤91 \le i \le 9 and ai>ai+1a_i > a_{i+1} is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

Three fair six-sided dice are rolled. The expected number of distinct values showing is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

A standard 5252-card deck is shuffled and laid out in a row. The expected number of pairs of adjacent cards that are both aces is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 4

A fair 44-sided die with faces 1,2,3,41, 2, 3, 4 is rolled repeatedly until every face has appeared at least once. The expected number of rolls is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

Each cell of a 4×44 \times 4 grid is colored black or white independently with probability 12\dfrac{1}{2} each. The expected number of 2×22 \times 2 blocks of cells (out of the 99 such blocks) whose four cells all have the same color is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

Ten people stand in a room. Each person points at one of the other nine people, chosen uniformly at random and independently. A pair of people is mutual if each points at the other. The expected number of mutual pairs is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

A bag holds 66 red marbles and 44 blue marbles. Marbles are drawn one at a time without replacement. The expected number of red marbles drawn before the first blue marble is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

The letters A,A,A,A,A,A,B,B,B,BA, A, A, A, A, A, B, B, B, B are arranged in a random order. A run is a maximal block of consecutive identical letters; for example, AABBBAAAABAABBBAAAAB has 44 runs. The expected number of runs is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Real contest practice

  • 1996 AIME, Problem 12: the average of a sum of absolute differences over all permutations, one pair at a time.
  • 2022 AIME I, Problem 12: a sum over pairs of subsets, handled by counting each element's contribution separately.