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), means finding the probability of every possible total x first, which gets painful when the parts of a problem depend on each other.
1
Linearity of Expectation
Suppose 100 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
In the 6-row table for Alice, Bob, and Charlie, rearranging which rows share 1s changes the row totals X and their distribution on the right, while each column's average and the overall expected value E[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]=E[X]+E[Y]+E[Z]
2
Indicator Variables and the Hat Problem
In the hat table, each person's column holds only 1 (if they got their own hat) or 0 (if they did not). A 0-or-1 random variable like this is an indicator variable, and its expected value is just the probability that it equals 1:
E[indicator:1 if A happens,0 if notIA]=1⋅P(IA=1)+0⋅P(IA=0)=P(IA=1)
With indicator variables, we can find the expected number of people who get their own hat back out of 100 people without counting derangements or writing out 100! rows.
Indicator Variables and the Hat Problem
Text solution
One indicator per personGive each of the 100 people an indicator variable Ik that equals 1 if Person k gets their own hat and 0 otherwise, so the total number of matches is their sum.
X=I1+I2+⋯+I100
Probability for one personLooking at Person k on their own, all 100 hats are equally likely to be handed to them, so they get their own hat with probability 1001.
E[Ik]=P(Ik=1)=1001
Add the column averagesBy linearity of expectation, we add the 100 individual column averages together.
E[X]=E[I1]+E[I2]+⋯+E[I100]=100×1001=1
So on average, 1 person gets their own hat back, whether there are 3 people or 100 people.
3
Scaling and Shifting Random Variables
Columns in the outcome table do not have to be 0s and 1s. 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 6-sided dice, a red die R and a blue die B. You win $4 for every dot on R, lose $2 for every dot on B, and receive a fixed $10 bonus for playing, so your payout is W=4R−2B+10. What is your expected payout E[W]?
Scaling and Shifting Random Variables
For any random variables X and Y and any constants a,b, and c:
E[aX+bY+c]=aE[X]+bE[Y]+c
Text solution
Average of one dieA standard 6-sided die lands on 1 through 6 equally often, so each die has an average roll of 3.5.
E[R]=61+2+3+4+5+6=3.5,E[B]=3.5
Split the sum and pull out constantsApply linearity to scale each die's expected value and add the $10 bonus.
We can now find the expected value of a binomial distribution without evaluating the factorial sum ∑k=0nk(kn)pk(1−p)n−k. In n trials where each trial succeeds with probability p, what is the expected total number of successes E[X]?
Expected Value of a Binomial Distribution
Text solution
One indicator per trialLet Ik equal 1 if Trial k succeeds and 0 if it fails, so the total number of successes is the sum of the n indicators.
X=I1+I2+⋯+In
Probability of one trialEach single trial succeeds with probability p.
E[Ik]=p
Add the n trialsSumming the n column averages gives the expected number of successes.
E[X]=E[I1]+E[I2]+⋯+E[In]=n timesp+p+⋯+p=np
5
Overlapping Events: Coin Flip Pairs
In the hat and binomial problems, there were n people or n trials, so it was clear where to put the n indicators. What if the events we are counting take more than one coin flip and overlap with each other?
In 10 flips of a fair coin, what is the expected number of times two Heads appear in a row (HH), including overlaps?
Overlapping Events: Coin Flip Pairs
Text solution
One indicator per adjacent pair of slotsA single HH requires two adjacent flips, so we put an indicator on each of the 9 adjacent slot pairs (1,2),(2,3),…,(9,10).
X=I1+I2+⋯+I9
Probability of one pairLooking at just two adjacent slots on their own, both flips land Heads with probability 21×21.
E[Ik]=21×21=41
Add the 9 pairsEven though adjacent pairs share a coin slot, linearity lets us add the 9 column averages directly.
E[X]=9×41=2.25
So on average, HH appears 2.25 times in 10 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 30 people (with all 365 birthdays equally likely), what is the expected number of pairs of people who share the same birthday?
Counting Pairs: Shared Birthdays
Text solution
One indicator per pair of peopleBecause each matching pair of people adds +1 to the count, we put an indicator on every possible pair of 2 people chosen from the 30 people.
(230)=230×29=435 pairs
Probability of one pair matchingFor any single pair of people, whatever day the first person was born on, the second person has a 3651 chance of having that same birthday.
E[Ipair]=3651
Add all 435 pairsSumming the 435 column averages gives the expected number of matching pairs.
E[X]=435×3651
7
Counting Empty Bins
Sometimes whether a single indicator equals 1 depends on every random action from start to finish.
Suppose we toss 10 balls independently and equally likely into any of 5 bins. After all 10 balls are thrown, what is the expected number of empty bins?
Counting Empty Bins
Text solution
One indicator per binSince we are counting empty bins, we put 5 indicators I1,…,I5 on the 5 bins rather than on the 10 balls.
X=I1+I2+I3+I4+I5
Probability that one bin stays emptyA single bin stays empty only if all 10 independent balls miss it, and each ball misses that bin with probability 54.
E[Ik]=(54)10
Add the 5 binsSumming across all 5 bins gives the expected number of empty bins.
E[X]=5×(54)10
8
Counting Runs Using Boundaries
In every problem so far, each piece we checked had a fixed size: 1 person, 2 flips, 2 people, or 1 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 has 5 runs). In 10 fair coin flips, what is the expected number of runs?
Counting Runs Using Boundaries
Text solution
One indicator on the first flip and one on each boundaryFlip 1 always starts the first run (I1=1), and each of the 9 boundaries between adjacent flips starts a +1 new run whenever the two flips on either side differ.
Runs=1+I2+I3+⋯+I10
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 21.
E[Ik]=21for k=2,…,10
Add the first run and the 9 boundariesSumming the initial run and the 9 boundary averages gives the expected number of runs.
E[Runs]=1+9×21=5.5
As blocks of identical flips merge or split across the 10 coins, the total number of runs is always 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 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 10 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
Text solution
One indicator per spot in linePut an indicator Ik on each spot k from 1 to 10, where Ik=1 if the k-th person is taller than the first k−1 people.
Records=I1+I2+⋯+I10
Probability that spot k sets a recordLooking only at the first k people to enter, the tallest person among those k people is equally likely to stand in any of the first k spots, so they stand last in spot k with probability k1.
E[Ik]=k1
Add the 10 different probabilitiesBecause each column has a different average, we add the fractions from k=1 to k=10.
Even with 100 people, the expected number of records is 1+21+31+⋯+1001≈5.19.
For any chosen spot k in line, the record indicator Ik equals 1 whenever the tallest person among the first k spots stands in spot k, regardless of how the first k−1 people are ordered or who stands after spot k.
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] always holds even when A and B are dependent, it is tempting to assume that E[A×B]=E[A]×E[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
On one flip of a fair coin, let A=1 on Heads (0 on Tails) and B=1 on Tails (0 on Heads). Multiplying their individual averages gives 41, but in every outcome one of the variables is 0, so their product A×B is always 0:
E[A]×E[B]E[A×B]=21×21=41=E[0]=0=41
Multiplying expected values works when the variables are independent:
E[A×B]=E[A]×E[B]when A and B are independent
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]=aE[X]+bE[Y]+c
For two dice with E[R]=E[B]=3.5, a payout of 4R−2B+10 has expected value 4(3.5)−2(3.5)+10=17.
The 3-step indicator method
finds the expected number of times something happens without finding the distribution of the total X:
Put a 0-or-1 indicator on every place where a single +1 can happen:
Individual items being counted: 100 people for hats (X=I1+⋯+I100), n trials for binomial (X=I1+⋯+In), or 5 bins for empty bins (I1,…,I5 on the bins, not the balls).
Multi-item windows or pairs: 9 overlapping slot pairs (1,2),…,(9,10) for HH in 10 flips; (230)=435 pairs of people for shared birthdays.
Runs of any length: 1 for the first flip plus 9 boundary indicators I2,…,I10 where adjacent flips differ.
Find one indicator's probability on its own: Ignore all other indicators and use E[Ik]=P(Ik=1), such as 1001 for one hat match, (54)10 for one bin missed by 10 balls, or k1 for the k-th person being the tallest among the first k people.
Add the column averages: E[X]=E[I1]+E[I2]+⋯+E[Im].
When not to use this method
If a question asks for the probability of a specific total, such as P(X=0) (no one gets their own hat), finding E[X]=1 will not give you P(X=0). You have to count derangements directly.
If you need the expected value of a product E[X⋅Y] and X and Y are dependent, do not multiply E[X]⋅E[Y]; find X⋅Y in each outcome row first and then take the average.
11
Practice
1
You roll a fair 8-sided die R (numbered 1 to 8) and a fair 12-sided die B (numbered 1 to 12). You win $6 for every dot on R, lose $4 for every dot on B, and pay a fixed $5 fee to play. What is your expected net payout?
Watch out: dividing the highest number by 2 gives 4 and 6, which misses the +0.5 on each die and leads to the wrong answer −$5.
Write the net payout as a linear combination of R and B, and find the average roll of each die from its first and last numbers.
Average of each dieThe average of 1 through 8 is 21+8=4.5, and the average of 1 through 12 is 21+12=6.5. (Watch out: dividing the highest number by 2 gives 4 and 6, which misses the +0.5 on each die and leads to the wrong answer −$5.)
E[R]=4.5,E[B]=6.5
Expected net payoutPull out the multipliers and subtract the $5 fee.
E[6R−4B−5]=6(4.5)−4(6.5)−5=27−26−5=−$4
2
Fifteen passengers have assigned seats 1 through 15 in a 20-seat train car (numbered 1 through 20), but they ignore their tickets and choose 15 of the 20 seats completely at random. What is the expected number of passengers who sit in their own assigned seat?
Watch out: there are 15 passengers but 20 seats, so a single passenger's probability is 201, not 151, which would give the hat-problem answer 1.
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 on each of the 15 passengers.
X=I1+I2+⋯+I15
Probability for one passengerLooking at Passenger k alone, all 20 seats in the car are equally likely, so they land in their assigned seat with probability 201. (Watch out: there are 15 passengers but 20 seats, so a single passenger's probability is 201, not 151, which would give the hat-problem answer 1.)
E[Ik]=201
Add the 15 passengers
E[X]=15×201=43
3
A biased coin lands Heads with probability 32 and Tails with probability 31. In 12 independent flips of this coin, what is the expected number of times the 3-flip pattern HTH appears, including overlaps?
Watch out: a 3-flip window cannot start at slot 11 or 12; using 12 windows gives the wrong answer 916.
Count how many 3-flip windows in a row fit inside 12 flip slots, then find the probability that a single window lands HTH.
One indicator per 3-flip windowA 3-flip window can start at slot 1,2,…,10, giving 10 indicators I1,…,I10. (Watch out: a 3-flip window cannot start at slot 11 or 12; using 12 windows gives the wrong answer 916.)
X=I1+I2+⋯+I10
Probability of one windowA single 3-flip window lands HTH with probability 32×31×32.
E[Ik]=32×31×32=274
Add the 10 windows
E[X]=10×274=2740
4
Ten people each independently choose a random month of the year (all 12 months equally likely). What is the expected number of triples of 3 people who all choose the exact same month?
Watch out: multiplying three factors of 121 gives 17281, which is the probability that all three pick January specifically, leading to the wrong answer 725.
Put an indicator on each possible group of 3 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 3 people out of 10 is (310).
(310)=3×2×110×9×8=120 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×121×121. (Watch out: multiplying three factors of 121 gives 17281, which is the probability that all three pick January specifically, leading to the wrong answer 725.)
E[Itriple]=1×121×121=1441
Add all 120 triples
E[X]=120×1441=65
5
Eight balls are tossed independently and equally likely into any of 4 bins. What is the expected number of bins that end up with exactly 1 ball?
Watch out: forgetting the 8 choices for which ball lands in the bin gives 41(43)7 for one bin and the wrong total 163842187.
Put an indicator on each of the 4 bins, and find the binomial probability that 1 of the 8 balls lands in that bin while the other 7 balls miss it.
One indicator per binPut 4 indicators I1,I2,I3,I4 on the 4 bins.
X=I1+I2+I3+I4
Probability that one bin gets 1 ballAny of the 8 balls can be the one that lands in Bin k (probability 41) while the other 7 balls miss it (probability (43)7). (Watch out: forgetting the 8 choices for which ball lands in the bin gives 41(43)7 for one bin and the wrong total 163842187.)
E[Ik]=8×41×(43)7=2×(43)7
Add the 4 bins
E[X]=4×2×(43)7=8×(43)7=20482187
6
You roll a fair 6-sided die 15 times in a row. A run is a block of identical numbers in a row. What is the expected number of runs in the 15 rolls?
Watch out: forgetting the +1 for the first roll gives 335.Watch out: using 21 from the coin-flip run problem instead of 65 gives the wrong answer 8.
Roll 1 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 boundariesRoll 1 always starts Run 1, and there are 14 boundaries between adjacent rolls where a change starts a +1 new run. (Watch out: forgetting the +1 for the first roll gives 335.)
Runs=1+I2+I3+⋯+I15
Probability of a change at one boundaryWhatever number the roll before a boundary showed, the next roll shows one of the 5 different numbers with probability 65. (Watch out: using 21 from the coin-flip run problem instead of 65 gives the wrong answer 8.)
E[Ik]=65
Add the first run and 14 boundaries
E[Runs]=1+14×65=338
7
Six people of all different heights walk through a door one by one in a completely random order. If the k-th person to enter is taller than everyone before them (setting a new height record), they win k dollars; otherwise they win $0. What is the expected total amount of money won by all 6 people?
Watch out: adding the unweighted probabilities 1+21+⋯+61=2049 counts the expected number of records rather than the dollar payout.
Write the total money won using the record indicators I1,…,I6, multiplying each indicator Ik by its k-dollar prize.
Weighted sum of record indicatorsLet Ik equal 1 if the k-th person sets a height record and 0 otherwise, so the k-th person wins k⋅Ik dollars. (Watch out: adding the unweighted probabilities 1+21+⋯+61=2049 counts the expected number of records rather than the dollar payout.)
W=1⋅I1+2⋅I2+3⋅I3+4⋅I4+5⋅I5+6⋅I6
Probability of a record at spot kAmong the first k people, the tallest stands in spot k with probability k1.
E[Ik]=k1
Add the expected payouts
E[W]=1(1)+2(21)+3(31)+4(41)+5(51)+6(61)=$6
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 2 people at the ends have 1 neighbor; the 6 people in the middle have 2 neighbors). What is the expected number of local peaks?
Watch out: giving all 8 spots probability 31 ignores the ends and gives 38, while multiplying 21×21=41 for a middle spot treats its two comparisons as independent and gives 25.Watch out: giving all 8 spots probability 31 ignores the ends and gives 38, while multiplying 21×21=41 for a middle spot treats its two comparisons as independent and gives 25.
Find the probability for an end spot (1 neighbor) and a middle spot (2 neighbors) separately by asking how many adjacent people are being compared at each spot.
One indicator per spot in linePut indicators I1,…,I8 on the 8 spots.
X=I1+I2+⋯+I8
End spots versus middle spotsEach of the 2 end spots is compared against 1 neighbor (a group of 2 people), so the taller person stands at the end with probability 21. Each of the 6 middle spots is compared against 2 neighbors (a group of 3 people), so the tallest of those 3 stands in the middle with probability 31. (Watch out: giving all 8 spots probability 31 ignores the ends and gives 38, while multiplying 21×21=41 for a middle spot treats its two comparisons as independent and gives 25.)
E[Iend]=21,E[Imiddle]=31
Add the 2 end spots and 6 middle spots
E[X]=2(21)+6(31)=3
9
You flip a fair coin 2 times. Let X be the total number of Heads, and let Y be the indicator variable that equals 1 if both flips are Tails and 0 otherwise. Find E[X]⋅E[Y] and E[X⋅Y].
Compute E[X] and E[Y] separately for the first product, then check what value the product X⋅Y takes in each of the 4 coin-flip outcomes for the second.
Product of expected valuesIn 2 fair flips, E[X]=2×21=1, and E[Y]=P(TT)=41.
E[X]⋅E[Y]=1×41=41
Expected value of the productWhenever both flips are Tails (Y=1), there are 0 Heads (X=0), and whenever X>0,Y=0. So X⋅Y=0 in every single outcome. (Watch out: assuming E[X⋅Y]=E[X]⋅E[Y]=41 fails because X and Y are dependent.)