The hat problem
At a party, 10 guests toss their hats into a pile. Each guest then picks a hat at random.
This seems impossibly hard — the assignments are all tangled up with dependencies. But with indicator variables, it becomes a one-line calculation.
What is an indicator variable?
For any event , the indicator variable is:
Its expected value is simply the probability: .
The core property of indicator variables: . Expectation equals probability!
The indicator trick
Here's the strategy for "how many of these things happen?" problems:
- Define indicators: For each item , let if the event of interest happens for item
- Write the total:
- Apply linearity: (see linearity of expectation)
- Compute each : This is just
You never need to worry about dependence between the indicators. Linearity handles that automatically.
Solving the hat problem
Let if person gets their own hat.
Step 1: = total matches
Step 2:
(Out of hats, exactly 1 is theirs.)
Step 3:
The indicators are not independent! If Alice got her own hat, it changes the odds for everyone else. But linearity of expectation doesn't care about dependence.
More examples
Fixed points in a random shuffle
Shuffle a deck of 52 cards. How many cards end up in their original position?
Coupon collector (how many needed?)
A cereal box contains 1 of 5 toy types, equally likely. You want all 5.
When you have types, the probability the next box gives a new type is .
The expected boxes needed for the next new type = .
Simulate the coupon collector problem and see the indicator decomposition in action:
| Phase | New types left | P(new) | E[draws] |
|---|---|---|---|
| 1→1 | 6/6 | 1.00 | 1.00 |
| 2→2 | 5/6 | 0.83 | 1.20 |
| 3→3 | 4/6 | 0.67 | 1.50 |
| 4→4 | 3/6 | 0.50 | 2.00 |
| 5→5 | 2/6 | 0.33 | 3.00 |
| 6→6 | 1/6 | 0.17 | 6.00 |
| Total E[T] = sum | 14.70 | ||
Expected inversions in a random permutation
Shuffle numbers 1 through . An inversion is a pair where but the value at position is greater than the value at position .
Let if positions and form an inversion. For any pair, (one of the two orderings is equally likely).
When to use indicator variables
The indicator trick is perfect when you're asked:
- "How many…" things satisfy a condition?
- "What fraction…" of items have a property?
- "Expected number…" of successes?
The pattern:
- Identify the individual items
- Define for each
- Use linearity:
If you find yourself thinking "but the events are dependent!" — that's exactly when indicators shine. Independence is not required.
Summary
| Concept | Formula |
|---|---|
| Indicator variable | if occurs, otherwise |
| Expectation of indicator | |
| Expected count | |
| Key insight | Dependence between indicators doesn't matter |
The indicator method: Decompose a complex count into a sum of binary questions. Each binary question is easy. Linearity adds them up for free.
Test your understanding
What's next
Next we'll meet the geometric distribution — the waiting-time distribution for "how long until the first success?"