The Indicator-Variable Trick
Rewriting a hard counting problem as a sum of simple 0/1 random variables so linearity of expectation solves it in one line, without ever computing the full distribution.
Prerequisites: Conditional Probability
The problem. In a shuffled deck of 52 cards, how many cards, on average, are in their original "sorted" position (card 1 in slot 1, card 2 in slot 2, and so on)? The distribution of that count is genuinely ugly — computing it directly means wading through inclusion-exclusion over all 52 positions. The expected value, though, is one line, if you know the trick.
The trick: split a hard sum into simple 0/1 pieces
Instead of thinking about "the number of matches" as one complicated random variable, define 52 tiny ones: let if card lands in position , and otherwise. The total number of matches is just their sum, . This looks like it hasn't helped — is exactly as hard to describe as before — but linearity of expectation says regardless of whether the are independent. That "regardless of independence" clause is the entire trick: you never have to worry about how one card's position affects another's, because expectation of a sum is always the sum of expectations.
Each is an indicator variable, and for an indicator, — the expectation of a 0/1 variable is just the probability it equals 1. For a uniformly random shuffle, for every , by symmetry. So:
In plain English: on average, exactly one card ends up in its original spot, no matter how the deck is shuffled — a strikingly clean answer to a question whose full distribution is genuinely messy.
Worked example: expected number of fixed points in general
The argument never used the number 52 in an essential way. For cards shuffled uniformly at random, define if card is in position . Then by the same symmetry argument, so — the expected number of matches is exactly 1 for any deck size , from a 2-card deck to a million-card one. That the answer doesn't depend on is itself the tell that indicator variables were the right tool: a direct combinatorial approach would need -dependent inclusion-exclusion terms that all happen to cancel down to this constant.
The general technique: when to reach for indicators
Whenever a question asks for the expected count of something — matches, collisions, empty bins, fixed points, inversions — and the something can be described as "does event happen," define one indicator per potential occurrence, sum them, and apply linearity. You never need independence, you never need the joint distribution, and you rarely need more than a one-line probability calculation per indicator. This is the single most reusable trick in probability interviews precisely because it converts "count something complicated" into "add up simple probabilities."
To find the expected count of anything, write it as a sum of 0/1 indicator variables, one per possible occurrence, and apply linearity of expectation: . This works even when the events are dependent, which is what makes it so powerful.
If a problem asks "how many on average," reach for indicators before reaching for the full distribution — you almost never need the distribution to answer an expectation question.
Related concepts
Practice in interviews
Further reading
- Grinstead & Snell, Introduction to Probability, ch. 6