Learn
Lesson · Discrete Probability · Random variables

Linearity of Expectation

The most useful fact in elementary probability. It needs no independence, which lets a complicated count be decomposed into indicators and summed term by term.

E[X + Y] = E[X] + E[Y] ALWAYS E[c₁X₁ + … + cₙXₙ] = Σ cᵢE[Xᵢ] E[XY] = E[X]E[Y] only when independent Decompose into INDICATORS and sum.
No independence required

Core ideas

What this lesson establishes

Linearity is what makes hard expectations easy: split the variable into simple pieces and add.

1

Independence is not needed

E[X + Y] = E[X] + E[Y] holds for any two random variables on the same space, however entangled.

2

Indicators are the workhorse

Write a count as a sum of indicators, one per thing being counted. Each indicator's expectation is a probability.

3

Products are different

E[XY] = E[X]E[Y] requires independence. Confusing the two rules is the one real trap here.

The material

Linearity

The theorem, why independence is irrelevant, and four applications.

Theorem · Linearity of expectation

For random variables X, Y on the same sample space and constants a, b: E[aX + bY] = aE[X] + bE[Y]. No independence assumption is needed.

Summing over outcomes, E[aX + bY] = Σ_s (aX(s) + bY(s))P(s) = a Σ_s X(s)P(s) + b Σ_s Y(s)P(s) = aE[X] + bE[Y].

Nothing about the joint behaviour of X and Y entered, which is exactly why independence is not required.

□

The proof is three lines and the consequence is enormous. E[XY] by contrast genuinely depends on the joint distribution, and the two facts are worth keeping apart deliberately.

Indicator decomposition

Theorem · Expectation of an indicator

E[I_A] = 1 · P(A) + 0 · P(Ā) = P(A).

So if X counts how many of the events A₁, …, A_n occur, then X = I_{A₁} + ⋯ + I_{A_n} and E[X] = Σ P(Aᵢ). The events may overlap, depend on each other, or be governed by anything at all.

Example · Heads in n flips

X = Σ Iᵢ where Iᵢ indicates heads on flip i. Each has expectation p, so E[X] = np — without computing the binomial distribution (“Bernoulli Trials and the Binomial Distribution”) at all.

Example · Fixed points of a random permutation

X counts the elements left in place. X = Σ Iᵢ where Iᵢ indicates that i is fixed, and P(Iᵢ = 1) = 1/n. So E[X] = n · (1/n) = 1, for every n. The indicators are dependent — knowing n − 1 elements are fixed forces the last — and linearity does not care.

That result is worth pausing on. On average exactly one person gets their own hat back, whether there are 5 people or 5 million. Computing it from the derangement distribution of Combinatorics and Counting would be considerably harder.

Example · The coupon collector

There are n distinct coupons, one per box at random. How many boxes to collect them all? Let Xᵢ be the number of boxes bought while holding exactly i − 1 distinct coupons. Then E[Xᵢ] = n/(n − i + 1) (“The Geometric Distribution and Waiting Times” supplies that), so E[total] = n(1 + 1/2 + ⋯ + 1/n) ≈ n ln n. For n = 50 that is about 225 boxes.

Example · Matching pairs

Two shuffled decks are dealt face up side by side. The expected number of positions where the cards match is 52 · (1/52) = 1. Same computation as the hat problem, and again the indicators are dependent.

Theorem · Products need independence

If X and Y are independent then E[XY] = E[X]E[Y]. Without independence this fails: take Y = X with X a fair coin scored 0 or 1, so E[X] = 1/2 and E[XY] = E[X²] = 1/2 ≠ 1/4.

Interactive

Distribution, expectation, variance

Definition first, formula second

Distribution
P(X = k)E[X]

Method

Using linearity

Decompose, then add.

1

Write the variable as a sum

Usually one indicator per item, position or event being counted.

2

Compute the expectation of one piece

For an indicator this is a single probability, and symmetry often makes all the pieces identical.

3

Add, without checking independence

Linearity holds regardless. This is the step that saves the work.

4

Do not use it for products

E[XY] needs independence. If the quantity is a product, this technique does not apply.

Linearity

Score 0 / 0

Expected number of matching pairs

Two shuffled decks of n cards, dealt side by side. How many positions match?

Let Iⱼ = 1 if position j matches, 0 otherwise. X = I₁ + … + Iₙ P(Iⱼ = 1) = 1/n — whatever is in the first deck at position j, the second deck has 1 chance in n of matching By linearity: E[X] = Σⱼ E[Iⱼ] = n · (1/n) = 1 The Iⱼ are NOT independent: if n−1 positions match, the last must. Linearity does not care. Computing this from the distribution of X would require the derangement numbers of “Derangements” in Combinatorics and Counting — for one number.

The answer is 1 for every n, which connects directly to derangements: the distribution of the number of matches converges to a Poisson distribution with mean 1, and P(no match) → 1/e is exactly the derangement limit.

Common mistakes

1
Checking independence before addingUnnecessary, and the habit obscures how general linearity is. Add first.
2
Applying linearity to a productE[XY] depends on the joint distribution. Linearity says nothing about it.
3
Not looking for an indicator decompositionMost counting expectations become one line this way. If a distribution looks hard, ask what is being counted.

Check your understanding

✓
Finish when decomposition into indicators is your first move.

Compute the expected number of runs of consecutive heads in n fair flips, using one indicator per position for "a run starts here". The answer is (n + 1)/4. Adjacent indicators are dependent — a run cannot start at two consecutive positions — and linearity does not care.

Note: Linearity is the reason expectation is more tractable than probability. P(X = k) for a complicated X may be very hard while E[X] is a sum of n easy probabilities, which is why so many arguments compute the mean and never touch the distribution.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.