Skip to content
LeetQuant
Probability for Quant Interviews

Module 2 · Expectation

Expected Value & Linearity

Linearity of expectation, indicator variables and first-step analysis — the three tools behind most expected-value questions.

25 min

Linearity always holds

For any random variables XX and YY and constants a,ba, b,

E[aX+bY]=a E[X]+b E[Y].\mathbb{E}[aX + bY] = a\,\mathbb{E}[X] + b\,\mathbb{E}[Y] .

This requires no independence. It is the single most useful fact in interview probability, because it lets you break a hard count into easy pieces.

Indicator variables

To compute the expected number of times something happens, write the count as a sum of indicators Ik∈{0,1}I_k \in \{0, 1\}, one per opportunity. Then

E[∑kIk]=∑kP(event k).\mathbb{E}\Big[\sum_k I_k\Big] = \sum_k P(\text{event } k) .

You never need the joint distribution of the IkI_k — only each marginal probability.

Worked example

runs in coin flips

You flip a fair coin 10 times. What is the expected number of runs (maximal blocks of identical outcomes)? For example HHTHHH has 3 runs.

Show solution

The first flip always starts a run. Each later flip k=2,…,10k = 2, \dots, 10 starts a new run exactly when it differs from flip k−1k-1, which has probability 12\tfrac12. So

E[runs]=1+9⋅12=5.5.\mathbb{E}[\text{runs}] = 1 + 9 \cdot \tfrac12 = 5.5 .

Knowledge check

You roll 12 fair dice. What is the expected number of distinct faces that appear?

First-step analysis

For waiting times and games, define the expected remaining value from each state and condition on the next step. This gives a linear system:

Es=cs+∑s′P(s→s′) Es′.E_s = c_s + \sum_{s'} P(s \to s')\,E_{s'} .

The trick is choosing states that capture exactly what matters for the future. For coin patterns, the state is "how much of the pattern is currently matched".

Worked example

expected flips until the first head

A coin lands heads with probability pp. How many flips until the first head, on average?

Show solution

Let EE be the expected number of flips. The first flip is a head with probability pp (done after 1 flip), otherwise we are back where we started having used one flip:

E=1+(1−p) E⟹E=1p.E = 1 + (1 - p)\,E \quad\Longrightarrow\quad E = \frac1p .

Knowledge check

A fair die is rolled until a 6 appears. What is the expected number of rolls?

Practice problems

Finished reading?

Answer the 2 knowledge checks to complete this lesson (0 done).