Quant Memo
Core

Linearity of Expectation, Even Without Independence

The expected value of a sum always equals the sum of the expected values — even when the pieces are wildly dependent on each other. That one fact quietly solves half the hard-looking counting puzzles in an interview.

Prerequisites: Expectation, Variance & Moments

A hundred people check their coats at a party, and the coats are handed back in a completely random order. What's the expected number of people who get their own coat back? Nobody wants to compute the probability of "exactly kk matches" for every kk from 0 to 100 and average — that's a nightmare of derangement counting. Yet the answer is one line, exactly 1, regardless of whether there are 5 people or 5 million.

Try it before reading on: guess whether the answer depends on the number of people, then see if you can find the one-line argument.

The trap: trying to compute the full distribution

The instinct is to find P(exactly k matches)P(\text{exactly } k \text{ matches}) for every kk, using derangement formulas, then compute kkP(k)\sum_k k \cdot P(k). That's real combinatorics, genuinely hard to do under time pressure, and completely unnecessary — because expectation of a sum doesn't care about the joint distribution of the pieces at all.

Linearity of expectation: for any random variables X1,,XnX_1, \dots, X_n, E[X1++Xn]=E[X1]++E[Xn]E[X_1+\cdots+X_n] = E[X_1]+\cdots+E[X_n] — always, with no assumption of independence. Break a hard total into a sum of simple 0/1 indicator variables, find each one's easy individual expectation, and add.

This is the single most useful sentence in interview probability because it lets you dodge every hard joint-distribution question by never asking about the joint distribution at all.

Worked example: the hat-check problem

Let XiX_i be the indicator variable that equals 1 if person ii gets their own coat back, 0 otherwise, for i=1,,ni=1,\dots,n. The total number of matches is X=X1++XnX = X_1+\cdots+X_n, and

E[X]=E[X1]++E[Xn]=i=1nP(Xi=1).E[X] = E[X_1]+\cdots+E[X_n] = \sum_{i=1}^n P(X_i=1).

In words: the expected total number of matches is just the sum, over each person, of the chance that particular person matches — and crucially this holds even though X1,,XnX_1,\dots,X_n are heavily dependent (if person 1 gets their coat, that changes the odds for everyone else). Linearity doesn't care.

Each individual P(Xi=1)P(X_i=1) is easy: with a uniformly random permutation of nn coats, person ii's coat lands in any of the nn positions with equal probability, so P(Xi=1)=1/nP(X_i=1)=1/n. Summing nn copies of 1/n1/n: E[X]=n×1n=1E[X] = n\times\frac1n = 1. Exactly one match expected, for any nn — 5 people or 5 million, the answer never changes, which is the counterintuitive punchline that makes this a favourite interview question.

Worked example: the birthday-collision count, not just the probability

A room has 30 people. Instead of the classic "probability at least two share a birthday," ask the linearity-friendly version: what's the expected number of pairs who share a birthday? There are (302)=435\binom{30}{2}=435 pairs. For any specific pair, the chance they share a birthday (ignoring leap years, 365 equally likely days) is 1/3651/365, because once the first person's birthday is fixed, the second matches it with probability 1/3651/365 regardless of everyone else.

E[matching pairs]=(302)×1365=435×13651.19.E[\text{matching pairs}] = \binom{30}{2}\times\frac{1}{365} = 435 \times \frac{1}{365} \approx 1.19.

In words: sum, over all (302)\binom{30}{2} possible pairs, the (tiny, identical) probability that that specific pair matches. You'd expect just over one matching pair among 30 people — consistent with the well-known fact that the probability of at least one match at 30 people is already around 70%, since even a fractional expected count above 1 corresponds to a substantial chance of at least one occurring.

X = X1 + X2 + X3 + ... + Xn (dependent on each other) X1 X2 X3 ... Xn linearity — no independence needed

E[X] = E[X1] + E[X2] + ... + E[Xn] — each term computed alone, ignoring the rest

Linearity lets you compute each indicator's expectation in isolation, pretending the others don't exist, and just add — the dependence between them never enters the calculation.

The recipe is always the same three steps: (1) write the quantity you want as a sum of 0/1 indicators for simple events, (2) find each indicator's expectation — usually just "the probability of one thing happening," often by symmetry, (3) add them up. Step 2 is almost always the easy part; the skill is spotting step 1, seeing which sum of indicators reconstructs your total.

Linearity of expectation gives you E[X]E[X], not the distribution or variance of XX — you cannot use it to claim, say, that matches are unlikely to cluster, or to compute P(X=0)P(X=0). People sometimes over-extend "the pieces don't need to be independent" into "so I don't need to think about dependence at all," which is true for the mean and false for everything else about the distribution. If a question asks for a probability, not an expectation, linearity alone won't finish the job.

The transferable technique

Whenever a problem asks for an expected count of something — matches, fixed points, collisions, successes, inversions — resist counting all the ways it can happen and instead decompose the count into indicator variables for the smallest atomic event you can name, compute each one's probability using symmetry or a direct argument, and sum. This single habit turns some of the ugliest-looking combinatorics questions in an interview into two lines of arithmetic.

Related concepts

Practice in interviews

Further reading

  • Blitzstein & Hwang, Introduction to Probability, ch. 4
ShareTwitterLinkedIn