Discrete MathematicsProbability, Conditioning and Expectation7 of 9
Probability, Conditioning and Expectation · 7

Linearity of Expectation and Indicator Variables

Finding an expected value directly from the definition, E[X]=∑xx⋅P(X=x)\ev{E[\rv{X}]} = \sum_x \val{x} \cdot \prob{P(\rv{X} = x)}, means finding the probability of every possible total x\val{x} first, which gets painful when the parts of a problem depend on each other.

1

Linearity of Expectation

Suppose 100100 people check their hats at a restaurant and get them handed back completely at random. To find the expected number of people who get their own hat back, we can line up the outcomes in a table and add down each person's column instead of across each outcome row.

Linearity of Expectation
100 hats, handed back at random\text{100 hats, handed back at random}
X=number of people who=get their own hat back\begin{aligned}\htmlClass{lc-violet}{X} &= \text{number of people who}\\ &\phantom{{}={}}\text{get their own hat back}\end{aligned}
E[X]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{X}\htmlClass{lc-pink}{]} = {?}

In the 66-row table for Alice, Bob, and Charlie, rearranging which rows share 1\one{1}s changes the row totals X\rv{X} and their distribution on the right, while each column's average and the overall expected value E[X]\ev{E[\rv{X}]} at the bottom stay the same.

Changing which rows share 1s changes the row totals, while each column average and the expected value stay the same.

Whether the outcomes are equally likely or not, and no matter how dependent the random variables are, the expected value of a sum is always the sum of the expected values:

E[X+Y+Z]\displaystyle \ev{E[}\rv{X} + \rv{Y} + \rv{Z}\ev{]} =E[X]+E[Y]+E[Z]\displaystyle = \ev{E[\rv{X}]} + \ev{E[\rv{Y}]} + \ev{E[\rv{Z}]}
2

Indicator Variables and the Hat Problem

In the hat table, each person's column holds only 1\one{1} (if they got their own hat) or 00 (if they did not). A 00-or-1\one{1} random variable like this is an indicator variable, and its expected value is just the probability that it equals 1\one{1}:

E[IA⏟indicator:1 if A happens,0 if not]\displaystyle \ev{E[}\underbrace{\rv{I_A}}_{\substack{\text{indicator:} \\ \one{1} \text{ if } A \text{ happens,} \\ 0 \text{ if not}}}\ev{]} =1⋅P(IA=1)+0⋅P(IA=0)\displaystyle = \one{1} \cdot \prob{P(\rv{I_A} = 1)} + 0 \cdot P(\rv{I_A} = 0) =P(IA=1)\displaystyle = \prob{P(\rv{I_A} = 1)}

With indicator variables, we can find the expected number of people who get their own hat back out of 100100 people without counting derangements or writing out 100!100! rows.

Indicator Variables and the Hat Problem
IA\htmlClass{lc-violet}{I_A}
A  B  C\mathrm{A}\,\,\mathrm{B}\,\,\mathrm{C}
Alice\htmlClass{lc-violet}{\text{Alice}}
Bob\htmlClass{lc-violet}{\text{Bob}}
Charlie\htmlClass{lc-violet}{\text{Charlie}}
X\htmlClass{lc-violet}{X}
p1\htmlClass{lc-green}{p_{1}}
A  B  C\htmlClass{lc-green}{\mathrm{A}}\,\,\htmlClass{lc-green}{\mathrm{B}}\,\,\htmlClass{lc-green}{\mathrm{C}}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
1\htmlClass{lc-green}{1}
3\htmlClass{lc-blue}{3}
p2\htmlClass{lc-green}{p_{2}}
A  C  B\htmlClass{lc-green}{\mathrm{A}}\,\,\mathrm{C}\,\,\mathrm{B}
1\htmlClass{lc-green}{1}
00
00
1\htmlClass{lc-blue}{1}
p3\htmlClass{lc-green}{p_{3}}
C  B  A\mathrm{C}\,\,\htmlClass{lc-green}{\mathrm{B}}\,\,\mathrm{A}
00
1\htmlClass{lc-green}{1}
00
1\htmlClass{lc-blue}{1}
p4\htmlClass{lc-green}{p_{4}}
B  A  C\mathrm{B}\,\,\mathrm{A}\,\,\htmlClass{lc-green}{\mathrm{C}}
00
00
1\htmlClass{lc-green}{1}
1\htmlClass{lc-blue}{1}
p5\htmlClass{lc-green}{p_{5}}
B  C  A\mathrm{B}\,\,\mathrm{C}\,\,\mathrm{A}
00
00
00
0\htmlClass{lc-blue}{0}
p6\htmlClass{lc-green}{p_{6}}
C  A  B\mathrm{C}\,\,\mathrm{A}\,\,\mathrm{B}
00
00
00
0\htmlClass{lc-blue}{0}
E[IA]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{I_A}\htmlClass{lc-pink}{]} = {?}
Text solution
One indicator per personGive each of the 100\nind{100} people an indicator variable Ik\rv{I_k} that equals 1\one{1} if Person kk gets their own hat and 00 otherwise, so the total number of matches is their sum.
X\displaystyle \rv{X} =I1+I2+⋯+I100\displaystyle = \rv{I_1} + \rv{I_2} + \dots + \rv{I_{100}}
Probability for one personLooking at Person kk on their own, all 100100 hats are equally likely to be handed to them, so they get their own hat with probability 1100\prob{\frac{1}{100}}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =P(Ik=1)\displaystyle = \prob{P(\rv{I_k} = 1)} =1100\displaystyle = \prob{\frac{1}{100}}
Add the column averagesBy linearity of expectation, we add the 100\nind{100} individual column averages together.
E[X]=E[I1]+E[I2]+⋯+E[I100]=100×1100=1\displaystyle \begin{aligned} \ev{E[\rv{X}]} &= \ev{E[\rv{I_1}]} + \ev{E[\rv{I_2}]} \\ &\quad + \dots + \ev{E[\rv{I_{100}}]} \\ &= \nind{100} \times \prob{\frac{1}{100}} \\ &= 1 \end{aligned}

So on average, 11 person gets their own hat back, whether there are 33 people or 100100 people.

3

Scaling and Shifting Random Variables

Columns in the outcome table do not have to be 00s and 1\one{1}s. When a random variable is multiplied by a constant or shifted by a fixed amount, we can pull the multiplier out in front and add the constant at the end.

Suppose you roll two standard 66-sided dice, a red die R\reddie{R} and a blue die B\bluedie{B}. You win $4\reddie{\$4} for every dot on R\reddie{R}, lose $2\bluedie{\$2} for every dot on B\bluedie{B}, and receive a fixed $10\$10 bonus for playing, so your payout is W=4R−2B+10\rv{W} = \reddie{4R} - \bluedie{2B} + 10. What is your expected payout E[W]E[\rv{W}]?

Scaling and Shifting Random Variables
R\htmlClass{lc-pink}{R}
B\htmlClass{lc-blue}{B}
+ $4 per dot{+}\,\htmlClass{lc-pink}{\$4}\text{ per dot}
− $2 per dot{-}\,\htmlClass{lc-blue}{\$2}\text{ per dot}
+ $10 bonus for playing{+}\,\$10\text{ bonus for playing}
W=4R−2B+10\htmlClass{lc-violet}{W} = \htmlClass{lc-pink}{4R} - \htmlClass{lc-blue}{2B} + 10
E[W]=?E[\htmlClass{lc-violet}{W}] = {?}

For any random variables X\rv{X} and Y\rv{Y} and any constants aa, bb, and cc:

E[aX+bY+c]\displaystyle \ev{E[}a\rv{X} + b\rv{Y} + c\ev{]} =aE[X]+bE[Y]+c\displaystyle = a\ev{E[\rv{X}]} + b\ev{E[\rv{Y}]} + c
Text solution
Average of one dieA standard 66-sided die lands on 11 through 66 equally often, so each die has an average roll of 3.53.5.
E[R]\displaystyle E[\reddie{R}] =1+2+3+4+5+66\displaystyle = \frac{1 + 2 + 3 + 4 + 5 + 6}{6} =3.5,E[B]\displaystyle = \reddie{3.5}, \qquad E[\bluedie{B}] =3.5\displaystyle = \bluedie{3.5}
Split the sum and pull out constantsApply linearity to scale each die's expected value and add the $10\$10 bonus.
E[4R−2B+10]=4E[R]−2E[B]+10=4(3.5)−2(3.5)+10=14−7+10=17\displaystyle \begin{aligned} &E[\reddie{4R} - \bluedie{2B} + 10] \\ &= \reddie{4}E[\reddie{R}] - \bluedie{2}E[\bluedie{B}] + 10 \\ &= \reddie{4(3.5)} - \bluedie{2(3.5)} + 10 \\ &= \reddie{14} - \bluedie{7} + 10 \\ &= 17 \end{aligned}

So your expected payout is $17\$17.

4

Expected Value of a Binomial Distribution

We can now find the expected value of a binomial distribution without evaluating the factorial sum ∑k=0nk(nk)pk(1−p)n−k\sum_{k=0}^n \val{k} \prob{\binom{n}{k} p^k (1 - p)^{n - k}}. In n\nind{n} trials where each trial succeeds with probability p\prob{p}, what is the expected total number of successes E[X]\ev{E[\rv{X}]}?

Expected Value of a Binomial Distribution
n independent trialsn\text{ independent trials}
⋯\cdots
Trial 1\htmlClass{lc-mute}{\text{Trial }1}
Trial 2\htmlClass{lc-mute}{\text{Trial }2}
Trial 3\htmlClass{lc-mute}{\text{Trial }3}
Trial n\htmlClass{lc-mute}{\text{Trial }n}
p\htmlClass{lc-green}{p}
1−p\htmlClass{lc-orange}{1 - p}
X=number of successes\htmlClass{lc-violet}{X} = \text{number of successes}
E[X]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{X}\htmlClass{lc-pink}{]} = {?}
Text solution
One indicator per trialLet Ik\rv{I_k} equal 1\one{1} if Trial kk succeeds and 00 if it fails, so the total number of successes is the sum of the n\nind{n} indicators.
X\displaystyle \rv{X} =I1+I2+⋯+In\displaystyle = \rv{I_1} + \rv{I_2} + \dots + \rv{I_n}
Probability of one trialEach single trial succeeds with probability p\prob{p}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =p\displaystyle = \prob{p}
Add the n\nind{n} trialsSumming the n\nind{n} column averages gives the expected number of successes.
E[X]=E[I1]+E[I2]+⋯+E[In]=p+p+⋯+p⏟n times=np\displaystyle \begin{aligned} \ev{E[\rv{X}]} &= \ev{E[\rv{I_1}]} + \ev{E[\rv{I_2}]} \\ &\quad + \dots + \ev{E[\rv{I_n}]} \\ &= \underbrace{\prob{p} + \prob{p} + \dots + \prob{p}}_{\nind{n} \text{ times}} \\ &= \nind{n}\prob{p} \end{aligned}
5

Overlapping Events: Coin Flip Pairs

In the hat and binomial problems, there were n\nind{n} people or n\nind{n} trials, so it was clear where to put the n\nind{n} indicators. What if the events we are counting take more than one coin flip and overlap with each other?

In 1010 flips of a fair coin, what is the expected number of times two Heads appear in a row (HHHH), including overlaps?

1\htmlClass{lc-mute}{1}
22
3\htmlClass{lc-mute}{3}
4\htmlClass{lc-mute}{4}
5\htmlClass{lc-mute}{5}
6\htmlClass{lc-mute}{6}
7\htmlClass{lc-mute}{7}
8\htmlClass{lc-mute}{8}
9\htmlClass{lc-mute}{9}
10\htmlClass{lc-mute}{10}
I1\htmlClass{lc-violet}{I_{1}}
I2\htmlClass{lc-violet}{I_{2}}
I3\htmlClass{lc-violet}{I_{3}}
I4\htmlClass{lc-violet}{I_{4}}
I5\htmlClass{lc-violet}{I_{5}}
I6\htmlClass{lc-violet}{I_{6}}
I7\htmlClass{lc-violet}{I_{7}}
I8\htmlClass{lc-violet}{I_{8}}
I9\htmlClass{lc-violet}{I_{9}}
Overlapping Events: Coin Flip Pairs
1\htmlClass{lc-green}{1}
2\htmlClass{lc-green}{2}
X=number of HH pairs=in 10 flips, overlaps counted\begin{aligned}\htmlClass{lc-violet}{X} &= \text{number of HH pairs}\\ &\phantom{{}={}}\text{in 10 flips, overlaps counted}\end{aligned}
E[X]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{X}\htmlClass{lc-pink}{]} = {?}
Text solution
One indicator per adjacent pair of slotsA single HHHH requires two adjacent flips, so we put an indicator on each of the 9\nind{9} adjacent slot pairs (1,2)(1, 2), (2,3)(2, 3), …\dots, (9,10)(9, 10).
X\displaystyle \rv{X} =I1+I2+⋯+I9\displaystyle = \rv{I_1} + \rv{I_2} + \dots + \rv{I_9}
Probability of one pairLooking at just two adjacent slots on their own, both flips land Heads with probability 12×12\frac{1}{2} \times \frac{1}{2}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =12×12\displaystyle = \frac{1}{2} \times \frac{1}{2} =14\displaystyle = \prob{\frac{1}{4}}
Add the 9\nind{9} pairsEven though adjacent pairs share a coin slot, linearity lets us add the 9\nind{9} column averages directly.
E[X]\displaystyle \ev{E[\rv{X}]} =9×14\displaystyle = \nind{9} \times \prob{\frac{1}{4}} =2.25\displaystyle = 2.25

So on average, HHHH appears 2.252.25 times in 1010 fair flips.

6

Counting Pairs: Shared Birthdays

Adjacent coin flips only paired neighbors next to each other in line. Now suppose any two people in a room can form a matching pair.

In a room of 3030 people (with all 365365 birthdays equally likely), what is the expected number of pairs of people who share the same birthday?

Counting Pairs: Shared Birthdays
30 people\text{30 people}
365 days, all equally likely365\text{ days, all equally likely}
X=number of pairs of people=with the same birthday\begin{aligned}\htmlClass{lc-violet}{X} &= \text{number of pairs of people}\\ &\phantom{{}={}}\text{with the same birthday}\end{aligned}
E[X]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{X}\htmlClass{lc-pink}{]} = {?}
Text solution
One indicator per pair of peopleBecause each matching pair of people adds +1\one{+1} to the count, we put an indicator on every possible pair of 22 people chosen from the 3030 people.
(302)\displaystyle \nind{\binom{30}{2}} =30×292\displaystyle = \frac{30 \times 29}{2} =435 pairs\displaystyle = \nind{435} \text{ pairs}
Probability of one pair matchingFor any single pair of people, whatever day the first person was born on, the second person has a 1365\prob{\frac{1}{365}} chance of having that same birthday.
E[Ipair]\displaystyle \ev{E[\rv{I_{\text{pair}}}]} =1365\displaystyle = \prob{\frac{1}{365}}
Add all 435\nind{435} pairsSumming the 435\nind{435} column averages gives the expected number of matching pairs.
E[X]\displaystyle \ev{E[\rv{X}]} =435×1365\displaystyle = \nind{435} \times \prob{\frac{1}{365}}
7

Counting Empty Bins

Sometimes whether a single indicator equals 1\one{1} depends on every random action from start to finish.

Suppose we toss 1010 balls independently and equally likely into any of 55 bins. After all 1010 balls are thrown, what is the expected number of empty bins?

Counting Empty Bins
10 balls tossed into 5 bins at random\text{10 balls tossed into 5 bins at random}
Bin 1\htmlClass{lc-mute}{\text{Bin }1}
Bin 2\htmlClass{lc-mute}{\text{Bin }2}
Bin 3\htmlClass{lc-mute}{\text{Bin }3}
Bin 4\htmlClass{lc-mute}{\text{Bin }4}
Bin 5\htmlClass{lc-mute}{\text{Bin }5}
X=number of empty bins\htmlClass{lc-violet}{X} = \text{number of empty bins}
E[X]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{X}\htmlClass{lc-pink}{]} = {?}
Text solution
One indicator per binSince we are counting empty bins, we put 5\nind{5} indicators I1,…,I5\rv{I_1}, \dots, \rv{I_5} on the 5\nind{5} bins rather than on the 1010 balls.
X\displaystyle \rv{X} =I1+I2+I3+I4+I5\displaystyle = \rv{I_1} + \rv{I_2} + \rv{I_3} + \rv{I_4} + \rv{I_5}
Probability that one bin stays emptyA single bin stays empty only if all 1010 independent balls miss it, and each ball misses that bin with probability 45\miss{\frac{4}{5}}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =(45)10\displaystyle = \prob{\left(\frac{4}{5}\right)^{10}}
Add the 5\nind{5} binsSumming across all 5\nind{5} bins gives the expected number of empty bins.
E[X]\displaystyle \ev{E[\rv{X}]} =5×(45)10\displaystyle = \nind{5} \times \prob{\left(\frac{4}{5}\right)^{10}}
8

Counting Runs Using Boundaries

In every problem so far, each piece we checked had a fixed size: 11 person, 22 flips, 22 people, or 11 bin. What if the things we are counting can have any length?

A run is a block of identical flips in a row (for instance, HH∣TTT∣H∣T∣HHH\text{HH}|\text{TTT}|\text{H}|\text{T}|\text{HHH} has 5\val{5} runs). In 1010 fair coin flips, what is the expected number of runs?

Counting Runs Using Boundaries
1\htmlClass{lc-green}{1}
2\htmlClass{lc-green}{2}
3\htmlClass{lc-green}{3}
4\htmlClass{lc-green}{4}
5\htmlClass{lc-green}{5}
Runs=number of runs=in 10 fair flips\begin{aligned}\htmlClass{lc-violet}{\text{Runs}} &= \text{number of runs}\\ &\phantom{{}={}}\text{in 10 fair flips}\end{aligned}
E[Runs]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{\text{Runs}}\htmlClass{lc-pink}{]} = {?}
Text solution
One indicator on the first flip and one on each boundaryFlip 11 always starts the first run (I1=1\rv{I_1} = \one{1}), and each of the 9\nind{9} boundaries between adjacent flips starts a +1\one{+1} new run whenever the two flips on either side differ.
Runs\displaystyle \rv{\text{Runs}} =1+I2+I3+⋯+I10\displaystyle = \one{1} + \rv{I_2} + \rv{I_3} + \dots + \rv{I_{10}}
Probability of a change at one boundaryAt any single boundary between two adjacent flips, whatever the left coin landed on, the right coin lands on the opposite side with probability 12\prob{\frac{1}{2}}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =12for k\displaystyle = \prob{\frac{1}{2}} \quad \text{for } k =2,…,10\displaystyle = 2, \dots, 10
Add the first run and the 9\nind{9} boundariesSumming the initial run and the 9\nind{9} boundary averages gives the expected number of runs.
E[Runs]\displaystyle \ev{E[\rv{\text{Runs}}]} =1+9×12\displaystyle = \one{1} + \nind{9} \times \prob{\frac{1}{2}} =5.5\displaystyle = 5.5

As blocks of identical flips merge or split across the 1010 coins, the total number of runs is always 1\one{1} (for the first coin) plus the number of boundaries where adjacent coins differ.

No matter how runs stretch, shrink, merge, or split across the 10 flips, the number of runs is always 1 for the first coin plus the number of boundaries where neighboring coins differ.
9

Indicators with Different Probabilities: Height Records

In the previous examples, all the indicators (or all 9\nind{9} boundary indicators) shared the same probability, so the final sum simplified to multiplying by the number of indicators. Now let's see what happens when every indicator has a different probability.

Suppose 1010 people of all different heights walk through a door one by one in a completely random order. A person sets a new height record if they are taller than everyone who walked in before them. What is the expected number of height records set?

Indicators with Different Probabilities: Height Records
10 people walk in, in random order\text{10 people walk in, in random order}
1\htmlClass{lc-mute}{1}
2\htmlClass{lc-mute}{2}
3\htmlClass{lc-mute}{3}
4\htmlClass{lc-mute}{4}
5\htmlClass{lc-mute}{5}
6\htmlClass{lc-mute}{6}
7\htmlClass{lc-mute}{7}
8\htmlClass{lc-mute}{8}
9\htmlClass{lc-mute}{9}
10\htmlClass{lc-mute}{10}
record: taller than everyone before\text{record: taller than everyone before}
E[Records]=?\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{\text{Records}}\htmlClass{lc-pink}{]} = {?}
Text solution
One indicator per spot in linePut an indicator Ik\rv{I_k} on each spot kk from 11 to 1010, where Ik=1\rv{I_k} = \one{1} if the kk-th person is taller than the first k−1k - 1 people.
Records\displaystyle \rv{\text{Records}} =I1+I2+⋯+I10\displaystyle = \rv{I_1} + \rv{I_2} + \dots + \rv{I_{10}}
Probability that spot kk sets a recordLooking only at the first kk people to enter, the tallest person among those kk people is equally likely to stand in any of the first kk spots, so they stand last in spot kk with probability 1k\prob{\frac{1}{k}}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =1k\displaystyle = \prob{\frac{1}{k}}
Add the 10\nind{10} different probabilitiesBecause each column has a different average, we add the fractions from k=1k = 1 to k=10k = 10.
E[Records]=E[I1]+E[I2]+⋯+E[I10]=1+12+13+⋯+110\displaystyle \begin{aligned} &\ev{E[\rv{\text{Records}}]} \\ &= \ev{E[\rv{I_1}]} + \ev{E[\rv{I_2}]} + \dots + \ev{E[\rv{I_{10}}]} \\ &= \prob{1} + \prob{\frac{1}{2}} + \prob{\frac{1}{3}} + \dots + \prob{\frac{1}{10}} \end{aligned}

Even with 100100 people, the expected number of records is 1+12+13+⋯+1100≈5.19\prob{1} + \prob{\frac{1}{2}} + \prob{\frac{1}{3}} + \dots + \prob{\frac{1}{100}} \approx 5.19.

For any chosen spot kk in line, the record indicator Ik\rv{I_k} equals 1\one{1} whenever the tallest person among the first kk spots stands in spot kk, regardless of how the first k−1k - 1 people are ordered or who stands after spot kk.

A spot in line sets a height record only when the tallest person so far stands in that spot, no matter how the earlier or later people are ordered.
10

Why Multiplication Needs Independence

Because E[A+B]=E[A]+E[B]\ev{E[}\rv{A} + \rv{B}\ev{]} = \ev{E[\rv{A}]} + \ev{E[\rv{B}]} always holds even when A\rv{A} and B\rv{B} are dependent, it is tempting to assume that E[A×B]=E[A]×E[B]\ev{E[}\rv{A} \times \rv{B}\ev{]} = \ev{E[\rv{A}]} \times \ev{E[\rv{B}]} always holds too. A single coin flip shows that multiplying expected values can give the wrong answer when the variables are dependent.

Why Multiplication Needs Independence
E[A+B]=E[A]+E[B]E[A×B]=?E[A]×E[B]\begin{aligned}\htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{A} + \htmlClass{lc-violet}{B}\htmlClass{lc-pink}{]} &= \htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{A}\htmlClass{lc-pink}{]} + \htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{B}\htmlClass{lc-pink}{]}\\ \htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{A} \times \htmlClass{lc-violet}{B}\htmlClass{lc-pink}{]} &\overset{?}{=} \htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{A}\htmlClass{lc-pink}{]} \times \htmlClass{lc-pink}{E[}\htmlClass{lc-violet}{B}\htmlClass{lc-pink}{]}\end{aligned}
A\htmlClass{lc-violet}{A}
B\htmlClass{lc-violet}{B}
12\htmlClass{lc-green}{\dfrac{1}{2}}
Heads\text{Heads}
1\htmlClass{lc-green}{1}
00
12\htmlClass{lc-green}{\dfrac{1}{2}}
Tails\text{Tails}
00
1\htmlClass{lc-green}{1}

On one flip of a fair coin, let A=1\rv{A} = \one{1} on Heads (00 on Tails) and B=1\rv{B} = \one{1} on Tails (00 on Heads). Multiplying their individual averages gives 14\frac{1}{4}, but in every outcome one of the variables is 00, so their product A×B\rv{A} \times \rv{B} is always 00:

E[A]×E[B]=12×12=14E[A×B]=E[0]=0≠14\displaystyle \begin{aligned} \ev{E[\rv{A}]} \times \ev{E[\rv{B}]} &= \frac{1}{2} \times \frac{1}{2} = \frac{1}{4} \\ \ev{E[}\rv{A} \times \rv{B}\ev{]} &= \ev{E[}0\ev{]} = 0 \wrong{\neq} \frac{1}{4} \end{aligned}

Multiplying expected values works when the variables are independent:

E[A×B]=E[A]×E[B]when A and B are independent\displaystyle \begin{gathered} \ev{E[}\rv{A} \times \rv{B}\ev{]} = \ev{E[\rv{A}]} \times \ev{E[\rv{B}]} \\ \text{when } \rv{A} \text{ and } \rv{B} \text{ are independent} \end{gathered}

Key concepts

Linearity of expectation

applies to any sum or linear combination of random variables, whether they are independent or dependent:

E[aX+bY+c]\displaystyle \ev{E[}a\rv{X} + b\rv{Y} + c\ev{]} =aE[X]+bE[Y]+c\displaystyle = a\ev{E[\rv{X}]} + b\ev{E[\rv{Y}]} + c
For two dice with E[R]=E[B]=3.5E[\reddie{R}] = E[\bluedie{B}] = 3.5, a payout of 4R−2B+10\reddie{4R} - \bluedie{2B} + 10 has expected value 4(3.5)−2(3.5)+10=17\reddie{4(3.5)} - \bluedie{2(3.5)} + 10 = 17.

The 33-step indicator method

finds the expected number of times something happens without finding the distribution of the total X\rv{X}:

  • Put a 00-or-1\one{1} indicator on every place where a single +1\one{+1} can happen:
    • Individual items being counted: 100\nind{100} people for hats (X=I1+⋯+I100\rv{X} = \rv{I_1} + \dots + \rv{I_{100}}), n\nind{n} trials for binomial (X=I1+⋯+In\rv{X} = \rv{I_1} + \dots + \rv{I_n}), or 5\nind{5} bins for empty bins (I1,…,I5\rv{I_1}, \dots, \rv{I_5} on the bins, not the balls).
    • Multi-item windows or pairs: 9\nind{9} overlapping slot pairs (1,2),…,(9,10)(1,2), \dots, (9,10) for HHHH in 1010 flips; (302)=435\nind{\binom{30}{2}} = \nind{435} pairs of people for shared birthdays.
    • Runs of any length: 1\one{1} for the first flip plus 9\nind{9} boundary indicators I2,…,I10\rv{I_2}, \dots, \rv{I_{10}} where adjacent flips differ.
  • Find one indicator's probability on its own: Ignore all other indicators and use E[Ik]=P(Ik=1)\ev{E[\rv{I_k}]} = \prob{P(\rv{I_k} = 1)}, such as 1100\prob{\frac{1}{100}} for one hat match, (45)10\prob{\left(\frac{4}{5}\right)^{10}} for one bin missed by 1010 balls, or 1k\prob{\frac{1}{k}} for the kk-th person being the tallest among the first kk people.
  • Add the column averages: E[X]=E[I1]+E[I2]+⋯+E[Im]\ev{E[\rv{X}]} = \ev{E[\rv{I_1}]} + \ev{E[\rv{I_2}]} \\ \quad + \dots + \ev{E[\rv{I_m}]}.
When not to use this method

  • If a question asks for the probability of a specific total, such as P(X=0)\prob{P(\rv{X} = 0)} (no one gets their own hat), finding E[X]=1\ev{E[\rv{X}]} = 1 will not give you P(X=0)\prob{P(\rv{X} = 0)}. You have to count derangements directly.
  • If you need the expected value of a product E[X⋅Y]\ev{E[}\rv{X} \cdot \rv{Y}\ev{]} and X\rv{X} and Y\rv{Y} are dependent, do not multiply E[X]⋅E[Y]\ev{E[\rv{X}]} \cdot \ev{E[\rv{Y}]}; find X⋅Y\rv{X} \cdot \rv{Y} in each outcome row first and then take the average.
11

Practice

1

You roll a fair 88-sided die R\reddie{R} (numbered 11 to 88) and a fair 1212-sided die B\bluedie{B} (numbered 11 to 1212). You win $6\$6 for every dot on R\reddie{R}, lose $4\$4 for every dot on B\bluedie{B}, and pay a fixed $5\$5 fee to play. What is your expected net payout?

Write the net payout as a linear combination of R\reddie{R} and B\bluedie{B}, and find the average roll of each die from its first and last numbers.

Average of each dieThe average of 11 through 88 is 1+82=4.5\frac{1 + 8}{2} = \reddie{4.5}, and the average of 11 through 1212 is 1+122=6.5\frac{1 + 12}{2} = \bluedie{6.5}. (Watch out: dividing the highest number by 22 gives 4\wrong{4} and 6\wrong{6}, which misses the +0.5+0.5 on each die and leads to the wrong answer −$5\wrong{-\$5}.)
E[R]\displaystyle E[\reddie{R}] =4.5,E[B]\displaystyle = \reddie{4.5}, \qquad E[\bluedie{B}] =6.5\displaystyle = \bluedie{6.5}
Expected net payoutPull out the multipliers and subtract the $5\fee{\$5} fee.
E[6R−4B−5]=6(4.5)−4(6.5)−5=27−26−5=−$4\displaystyle \begin{aligned} &E[\reddie{6R} - \bluedie{4B} - \fee{5}] \\ &= \reddie{6(4.5)} - \bluedie{4(6.5)} - \fee{5} \\ &= \reddie{27} - \bluedie{26} - \fee{5} \\ &= -\$4 \end{aligned}
2

Fifteen passengers have assigned seats 11 through 1515 in a 2020-seat train car (numbered 11 through 2020), but they ignore their tickets and choose 1515 of the 2020 seats completely at random. What is the expected number of passengers who sit in their own assigned seat?

Put an indicator on each passenger who could sit in their own seat, and ask how many seats a single passenger is equally likely to land in.

One indicator per passengerPut an indicator Ik\rv{I_k} on each of the 15\nind{15} passengers.
X\displaystyle \rv{X} =I1+I2+⋯+I15\displaystyle = \rv{I_1} + \rv{I_2} + \dots + \rv{I_{15}}
Probability for one passengerLooking at Passenger kk alone, all 2020 seats in the car are equally likely, so they land in their assigned seat with probability 120\prob{\frac{1}{20}}. (Watch out: there are 15\nind{15} passengers but 2020 seats, so a single passenger's probability is 120\prob{\frac{1}{20}}, not 115\wrong{\frac{1}{15}}, which would give the hat-problem answer 1\wrong{1}.)
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =120\displaystyle = \prob{\frac{1}{20}}
Add the 15\nind{15} passengers
E[X]\displaystyle \ev{E[\rv{X}]} =15×120\displaystyle = \nind{15} \times \prob{\frac{1}{20}} =34\displaystyle = \frac{3}{4}
3

A biased coin lands Heads with probability 23\frac{2}{3} and Tails with probability 13\frac{1}{3}. In 1212 independent flips of this coin, what is the expected number of times the 33-flip pattern HTHHTH appears, including overlaps?

Count how many 33-flip windows in a row fit inside 1212 flip slots, then find the probability that a single window lands HTHHTH.

One indicator per 33-flip windowA 33-flip window can start at slot 1,2,…,101, 2, \dots, 10, giving 10\nind{10} indicators I1,…,I10\rv{I_1}, \dots, \rv{I_{10}}. (Watch out: a 33-flip window cannot start at slot 1111 or 1212; using 12\wrong{12} windows gives the wrong answer 169\wrong{\frac{16}{9}}.)
X\displaystyle \rv{X} =I1+I2+⋯+I10\displaystyle = \rv{I_1} + \rv{I_2} + \dots + \rv{I_{10}}
Probability of one windowA single 33-flip window lands HTHHTH with probability 23×13×23\frac{2}{3} \times \frac{1}{3} \times \frac{2}{3}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =23×13×23\displaystyle = \frac{2}{3} \times \frac{1}{3} \times \frac{2}{3} =427\displaystyle = \prob{\frac{4}{27}}
Add the 10\nind{10} windows
E[X]\displaystyle \ev{E[\rv{X}]} =10×427\displaystyle = \nind{10} \times \prob{\frac{4}{27}} =4027\displaystyle = \frac{40}{27}
4

Ten people each independently choose a random month of the year (all 1212 months equally likely). What is the expected number of triples of 33 people who all choose the exact same month?

Put an indicator on each possible group of 33 people, and find the probability that the second and third people in a triple match whatever month the first person chose.

One indicator per triple of peopleThe number of ways to choose 33 people out of 1010 is (103)\nind{\binom{10}{3}}.
(103)\displaystyle \nind{\binom{10}{3}} =10×9×83×2×1\displaystyle = \frac{10 \times 9 \times 8}{3 \times 2 \times 1} =120 triples\displaystyle = \nind{120} \text{ triples}
Probability of one triple matchingWhatever month the first person in the triple picks, the second and third people both match that month with probability 1×112×1121 \times \frac{1}{12} \times \frac{1}{12}. (Watch out: multiplying three factors of 112\frac{1}{12} gives 11728\wrong{\frac{1}{1728}}, which is the probability that all three pick January specifically, leading to the wrong answer 572\wrong{\frac{5}{72}}.)
E[Itriple]\displaystyle \ev{E[\rv{I_{\text{triple}}}]} =1×112×112\displaystyle = 1 \times \frac{1}{12} \times \frac{1}{12} =1144\displaystyle = \prob{\frac{1}{144}}
Add all 120\nind{120} triples
E[X]\displaystyle \ev{E[\rv{X}]} =120×1144\displaystyle = \nind{120} \times \prob{\frac{1}{144}} =56\displaystyle = \frac{5}{6}
5

Eight balls are tossed independently and equally likely into any of 44 bins. What is the expected number of bins that end up with exactly 11 ball?

Put an indicator on each of the 44 bins, and find the binomial probability that 11 of the 88 balls lands in that bin while the other 77 balls miss it.

One indicator per binPut 4\nind{4} indicators I1,I2,I3,I4\rv{I_1}, \rv{I_2}, \rv{I_3}, \rv{I_4} on the 4\nind{4} bins.
X\displaystyle \rv{X} =I1+I2+I3+I4\displaystyle = \rv{I_1} + \rv{I_2} + \rv{I_3} + \rv{I_4}
Probability that one bin gets 11 ballAny of the 88 balls can be the one that lands in Bin kk (probability 14\prob{\frac{1}{4}}) while the other 77 balls miss it (probability (34)7\miss{\left(\frac{3}{4}\right)^7}). (Watch out: forgetting the 88 choices for which ball lands in the bin gives 14(34)7\wrong{\frac{1}{4}\left(\frac{3}{4}\right)^7} for one bin and the wrong total 218716384\wrong{\frac{2187}{16384}}.)
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =8×14×(34)7\displaystyle = 8 \times \prob{\frac{1}{4}} \times \miss{\left(\frac{3}{4}\right)^7} =2×(34)7\displaystyle = 2 \times \miss{\left(\frac{3}{4}\right)^7}
Add the 4\nind{4} bins
E[X]=4×2×(34)7=8×(34)7=21872048\displaystyle \begin{aligned} \ev{E[\rv{X}]} &= \nind{4} \times 2 \times \miss{\left(\frac{3}{4}\right)^7} \\ &= 8 \times \miss{\left(\frac{3}{4}\right)^7} \\ &= \frac{2187}{2048} \end{aligned}
6

You roll a fair 66-sided die 1515 times in a row. A run is a block of identical numbers in a row. What is the expected number of runs in the 1515 rolls?

Roll 11 starts the first run; what is the probability that the two rolls on either side of a boundary show different numbers?

First roll plus 14\nind{14} boundariesRoll 11 always starts Run 11, and there are 14\nind{14} boundaries between adjacent rolls where a change starts a +1\one{+1} new run. (Watch out: forgetting the +1\one{+1} for the first roll gives 353\wrong{\frac{35}{3}}.)
Runs\displaystyle \rv{\text{Runs}} =1+I2+I3+⋯+I15\displaystyle = \one{1} + \rv{I_2} + \rv{I_3} + \dots + \rv{I_{15}}
Probability of a change at one boundaryWhatever number the roll before a boundary showed, the next roll shows one of the 55 different numbers with probability 56\prob{\frac{5}{6}}. (Watch out: using 12\wrong{\frac{1}{2}} from the coin-flip run problem instead of 56\prob{\frac{5}{6}} gives the wrong answer 8\wrong{8}.)
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =56\displaystyle = \prob{\frac{5}{6}}
Add the first run and 14\nind{14} boundaries
E[Runs]\displaystyle \ev{E[\rv{\text{Runs}}]} =1+14×56\displaystyle = \one{1} + \nind{14} \times \prob{\frac{5}{6}} =383\displaystyle = \frac{38}{3}
7

Six people of all different heights walk through a door one by one in a completely random order. If the kk-th person to enter is taller than everyone before them (setting a new height record), they win kk dollars; otherwise they win $0\$0. What is the expected total amount of money won by all 66 people?

Write the total money won using the record indicators I1,…,I6\rv{I_1}, \dots, \rv{I_6}, multiplying each indicator Ik\rv{I_k} by its kk-dollar prize.

Weighted sum of record indicatorsLet Ik\rv{I_k} equal 1\one{1} if the kk-th person sets a height record and 00 otherwise, so the kk-th person wins k⋅Ik\val{k} \cdot \rv{I_k} dollars. (Watch out: adding the unweighted probabilities 1+12+⋯+16=4920\prob{1} + \prob{\frac{1}{2}} + \dots + \prob{\frac{1}{6}} = \wrong{\frac{49}{20}} counts the expected number of records rather than the dollar payout.)
W=1⋅I1+2⋅I2+3⋅I3+4⋅I4+5⋅I5+6⋅I6\displaystyle \begin{aligned} \rv{W} &= \val{1} \cdot \rv{I_1} + \val{2} \cdot \rv{I_2} + \val{3} \cdot \rv{I_3} \\ &\quad + \val{4} \cdot \rv{I_4} + \val{5} \cdot \rv{I_5} + \val{6} \cdot \rv{I_6} \end{aligned}
Probability of a record at spot kkAmong the first kk people, the tallest stands in spot kk with probability 1k\prob{\frac{1}{k}}.
E[Ik]\displaystyle \ev{E[\rv{I_k}]} =1k\displaystyle = \prob{\frac{1}{k}}
Add the expected payouts
E[W]=1(1)+2(12)+3(13)+4(14)+5(15)+6(16)=$6\displaystyle \begin{aligned} \ev{E[\rv{W}]} &= \val{1}(\prob{1}) + \val{2}\left(\prob{\frac{1}{2}}\right) + \val{3}\left(\prob{\frac{1}{3}}\right) \\ &\quad + \val{4}\left(\prob{\frac{1}{4}}\right) + \val{5}\left(\prob{\frac{1}{5}}\right) + \val{6}\left(\prob{\frac{1}{6}}\right) \\ &= \$6 \end{aligned}
8

Eight people of all different heights stand in a single line in a random order. A person is a "local peak" if they are taller than every immediate neighbor standing right next to them (the 22 people at the ends have 11 neighbor; the 66 people in the middle have 22 neighbors). What is the expected number of local peaks?

Find the probability for an end spot (11 neighbor) and a middle spot (22 neighbors) separately by asking how many adjacent people are being compared at each spot.

One indicator per spot in linePut indicators I1,…,I8\rv{I_1}, \dots, \rv{I_8} on the 8\nind{8} spots.
X\displaystyle \rv{X} =I1+I2+⋯+I8\displaystyle = \rv{I_1} + \rv{I_2} + \dots + \rv{I_8}
End spots versus middle spotsEach of the 2\nind{2} end spots is compared against 11 neighbor (a group of 22 people), so the taller person stands at the end with probability 12\prob{\frac{1}{2}}. Each of the 6\nind{6} middle spots is compared against 22 neighbors (a group of 33 people), so the tallest of those 33 stands in the middle with probability 13\prob{\frac{1}{3}}. (Watch out: giving all 88 spots probability 13\frac{1}{3} ignores the ends and gives 83\wrong{\frac{8}{3}}, while multiplying 12×12=14\frac{1}{2} \times \frac{1}{2} = \wrong{\frac{1}{4}} for a middle spot treats its two comparisons as independent and gives 52\wrong{\frac{5}{2}}.)
E[Iend]\displaystyle \ev{E[\rv{I_{\text{end}}}]} =12,E[Imiddle]\displaystyle = \prob{\frac{1}{2}}, \qquad \ev{E[\rv{I_{\text{middle}}}]} =13\displaystyle = \prob{\frac{1}{3}}
Add the 2\nind{2} end spots and 6\nind{6} middle spots
E[X]\displaystyle \ev{E[\rv{X}]} =2(12)+6(13)\displaystyle = \nind{2}\left(\prob{\frac{1}{2}}\right) + \nind{6}\left(\prob{\frac{1}{3}}\right) =3\displaystyle = 3
9

You flip a fair coin 22 times. Let X\rv{X} be the total number of Heads, and let Y\rv{Y} be the indicator variable that equals 11 if both flips are Tails and 00 otherwise. Find E[X]⋅E[Y]\ev{E[\rv{X}]} \cdot \ev{E[\rv{Y}]} and E[X⋅Y]\ev{E[}\rv{X} \cdot \rv{Y}\ev{]}.

Compute E[X]\ev{E[\rv{X}]} and E[Y]\ev{E[\rv{Y}]} separately for the first product, then check what value the product X⋅Y\rv{X} \cdot \rv{Y} takes in each of the 44 coin-flip outcomes for the second.

Product of expected valuesIn 22 fair flips, E[X]=2×12=1\ev{E[\rv{X}]} = \nind{2} \times \prob{\frac{1}{2}} = 1, and E[Y]=P(TT)=14\ev{E[\rv{Y}]} = \prob{P(TT)} = \prob{\frac{1}{4}}.
E[X]⋅E[Y]\displaystyle \ev{E[\rv{X}]} \cdot \ev{E[\rv{Y}]} =1×14\displaystyle = 1 \times \frac{1}{4} =14\displaystyle = \frac{1}{4}
Expected value of the productWhenever both flips are Tails (Y=1\rv{Y} = \one{1}), there are 0\val{0} Heads (X=0\rv{X} = \val{0}), and whenever X>0\rv{X} > \val{0}, Y=0\rv{Y} = 0. So X⋅Y=0\rv{X} \cdot \rv{Y} = 0 in every single outcome. (Watch out: assuming E[X⋅Y]=E[X]⋅E[Y]=14\ev{E[}\rv{X} \cdot \rv{Y}\ev{]} = \ev{E[\rv{X}]} \cdot \ev{E[\rv{Y}]} = \wrong{\frac{1}{4}} fails because X\rv{X} and Y\rv{Y} are dependent.)
E[X⋅Y]\displaystyle \ev{E[}\rv{X} \cdot \rv{Y}\ev{]} =0\displaystyle = 0