Some expected values look hopeless to compute directly. How many people, on average, get their own hat back when hats are handed out at random? How many different faces appear in ten rolls of a die? Working out the full probability distribution in such cases is painful. Linearity of expectation avoids the distribution entirely, using one simple and remarkably powerful fact: the expected value of a sum is the sum of the expected values, always, whether or not the pieces are independent.
- The rule E[X + Y] = E[X] + E[Y] and why independence is not needed
- The indicator-variable technique for counting problems
- Four worked examples, including one checked by listing every outcome
- Where linearity stops working
The Rule
For any random variables X and Y, and constants a and b:
This holds even when X and Y are strongly dependent, and it extends to any number of terms. Compare this with the variance of a sum, which does depend on how the variables relate, as covered in covariance. Expectation is friendlier: no independence check is ever required. The basic definition of expected value is in expected value; this article is about a trick built on it.
The Indicator-Variable Method
To find the expected number of times something happens, write the count as a sum of indicator variables: variables equal to 1 if a particular event occurs and 0 otherwise. The expected value of an indicator is just the probability of its event, since E[I] = 1 × P(event) + 0 × P(no event) = P(event). Linearity then says the expected count is the sum of the individual probabilities. The recipe has three steps: define an indicator for each possible occurrence, find each one's probability, and add them up.
Worked Examples
Example 1: The sum of two dice
Let X and Y be two dice rolls. Each has expected value (1 + 2 + 3 + 4 + 5 + 6) ÷ 6 = 3.5, so E[X + Y] = 3.5 + 3.5 = 7, with no need to list the 36 outcomes. Averaging all 36 sums directly also gives 7, confirming it.
Example 2: The mean of a binomial
A binomial count is the number of successes in n trials. Write it as I₁ + I₂ + … + Iₙ, where Iₖ is 1 if trial k succeeds. Each indicator has expectation p, so the total has expectation np. This one-line argument replaces the summation of binomial probabilities.
Example 3: The matching-hats problem
Problem: Five people leave their hats at a party, and the hats are returned in random order. How many people, on average, receive their own hat?
Let Iₖ = 1 if person k gets their own hat. The chance that a specific person receives their own hat is 1 in 5, so E[Iₖ] = 1/5. There are five people, so the expected number of matches is 5 × 1/5 = 1.
Notice that the indicators are not independent: if four people have their own hats, the fifth must too. Linearity does not care. To confirm the answer, list all 5! = 120 possible returns (the counting rule from permutations and combinations). The number of matches follows this distribution:
| Matches | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| Arrangements | 44 | 45 | 20 | 10 | 0 | 1 |
The average is (0 × 44 + 1 × 45 + 2 × 20 + 3 × 10 + 4 × 0 + 5 × 1) ÷ 120 = 120 ÷ 120 = 1. Exactly as linearity predicted. Better still, the answer is 1 whether there are 5 guests or 5,000, because n × (1/n) = 1 for every n. This makes the average count of matches surprisingly stable even as the chance of at least one match settles near 1 − 1/e ≈ 63%. Here, P(no matches) = 44 ÷ 120 ≈ 0.367, close to the limit of 1/e ≈ 0.368.
Example 4: Distinct faces in ten rolls
Problem: A fair die is rolled 10 times. How many different faces appear, on average?
For each face, define an indicator that is 1 if that face shows up at least once. The probability that a particular face never appears in 10 rolls is (5/6)¹⁰ ≈ 0.1615, so it appears at least once with probability 1 − 0.1615 = 0.8385. Summing over the six faces gives:
A direct approach would need the distribution of the number of distinct faces, a messy counting problem. A simulation of 200,000 sets of ten rolls gives an average of about 5.03.
Example 5: The coupon collector
Problem: How many rolls of a fair die are needed, on average, to see all six faces?
Split the wait into stages. Once k faces have been seen, each roll shows a new face with probability (6 − k) ÷ 6, so the wait for the next new face is geometric with mean 6 ÷ (6 − k) (see the geometric distribution). Linearity lets us simply add the stage means:
Linearity would work even if the stages were dependent; here they happen to be independent. A simulation averages about 14.67 rolls over 200,000 trials, consistent with 14.7. The general result for n equally likely coupons is n × (1 + 1/2 + … + 1/n), which grows a little faster than n. The last few new items are always the slowest to arrive.
Where Linearity Stops
The rule is specific to sums and constant multiples. It does not extend to everything:
- Products. E[XY] equals E[X] × E[Y] only when X and Y are uncorrelated (for example, independent). In general, E[XY] = E[X]E[Y] + Cov(X, Y).
- Non-linear functions. E[g(X)] is usually not g(E[X]). For a die, E[X²] = 91/6 ≈ 15.17, while (E[X])² = 12.25.
- Variance. Var(X + Y) = Var(X) + Var(Y) + 2Cov(X, Y), so variance adds only when the covariance is zero. Take Y = X: then Var(X + X) = Var(2X) = 4Var(X), not 2Var(X).
Real-World Uses
Computer science: analysing randomized algorithms, such as the expected number of comparisons in a sort or collisions in a hash table, is often done by summing indicator variables for each pair of items.
Quality and inventory planning: the expected number of defective items in a batch, or distinct products ordered by a group of customers, follows directly from per-item probabilities, without modelling how items depend on each other.
Forecasting totals: the expected total demand across products, or expected total claims across policies, is just the sum of individual expectations; no model of how items depend on each other is needed. The law of large numbers then explains why observed totals settle near those sums.
Common Mistakes
Thinking independence is required. It is not, for sums. This is the feature that makes the method so useful for problems like matching hats, where the events are dependent.
Carrying the rule over to variance or products. Those need independence or covariance terms. The distinction is a frequent exam trap.
Wrong indicator probabilities. Each indicator's probability must be derived from the setup, and every indicator must describe the same kind of occurrence (one per person, or one per face), so that nothing is counted twice or skipped.
Reporting an expected count as a likely outcome. An expected value of 1 match does not mean exactly one match is likely. In the hats example, exactly one match occurs in 45 of 120 cases, and zero matches in 44.
Does linearity of expectation require independent variables?
What is an indicator variable?
Why does the matching-hats answer not depend on the number of guests?
Can linearity be used to find variances?
Share this article
Written by
Statistics Fundamentals Editorial Team
Written and reviewed by our team of statistics educators. Content is aligned with GCSE, A-Level, AP Statistics, and undergraduate curricula.
About Statistics Fundamentals →