Quant interview toolkit · geometric distribution

The first success is geometric, and it has no memory

Roll until a 6. Flip until heads. Play rounds until someone wins. Whenever something happens in rounds and each round independently stops the process with the same probability p, the round where it stops is geometric. Spot that pattern and the mean, the tail, and a surprising amount of interview algebra come for free.

1P(T>k)=(1−p)kP(T > k) = (1-p)^k “Still going after k rounds” means “k misses in a row”. Independent, so multiply. Start here, not with P(T = k).
2P(T=k)=(1−p)k−1 p=P(T>k−1)−P(T>k)P(T = k) = (1-p)^{k-1}\,p = P(T > k-1) - P(T > k) k − 1 misses, then a hit. Or: still going after k − 1, minus still going after k.
3E[T]=∑k≥0(1−p)k=1/pVar(T)=(1−p)/p2E[T] = \sum_{k \ge 0} (1-p)^k = 1/p \qquad \mathrm{Var}(T) = (1-p)/p^2 The tail-sum trick on step 1. A 1-in-6 event takes 6 rounds on average.
4P(T>m+n∣T>m)=P(T>n)P(T > m + n \mid T > m) = P(T > n) Memoryless: after m misses, the rounds still to go have the original distribution.
Spotting it

The round where something stops is geometric

The test has two parts. Rounds are independent, and each round has the same chance p of stopping things. If both hold, T = “the round it stops” is Geometric(p), whatever the story is about:

  • Rolls of a die until the first 6: p = 1/6, so E[T] = 6.
  • Two dice rolled each round, until at least one shows 6: p = 1 − (5/6)² = 11/36, so E[T] = 36/11.
  • A game where each round ends in a win, a loss, or a replay: p = P(the round is decisive).
  • A trading signal that fires with probability 2% each day: the wait is Geometric(0.02), mean 50 days.

The tail is the easy object, exactly as in the max trick: “not yet stopped after k rounds” is a product of k independent misses. Everything else follows from it.

p (stop in a round)1/6
Show
E[T] = 1/p
median round
standard deviation √(1−p)/p

Two things to notice. The most likely stopping round is always round 1, for every p, because each later round needs extra misses first. And the distribution is skewed: for a die, the median is 4 but the mean is 6, pulled up by long unlucky runs. Switch to the tail view to see the long right side.

Expected value

Three ways to get E[T] = 1/p

Tail sum. For any variable on 1, 2, 3, …, E[T] = P(T ≥ 1) + P(T ≥ 2) + ⋯ = P(T > 0) + P(T > 1) + ⋯:

E[T]=∑k=0∞(1−p)k=11−(1−p)=1pE[T] = \sum_{k=0}^{\infty} (1-p)^k = \frac{1}{1 - (1-p)} = \frac{1}{p}

First-step analysis. One round always happens. With probability 1 − p it misses, and you are back where you started (see first-step analysis):

E[T]=1+(1−p) E[T]⟹p E[T]=1E[T] = 1 + (1-p)\,E[T] \quad\Longrightarrow\quad p\,E[T] = 1

Rate intuition. Over many rounds, a fraction p of them are successes, so the average gap between successes is 1/p. Use this one to sanity-check, and one of the first two to prove it.

The variance is (1−p)/p2(1-p)/p^2, so for the die the standard deviation is 30≈5.5\sqrt{30} \approx 5.5 rounds, almost as big as the mean. Geometric waits are noisy.

import numpy as np
rng = np.random.default_rng(0)
T = rng.geometric(1/6, size=1_000_000)   # NumPy counts trials: 1, 2, 3, ...
print(T.mean(), T.var(), np.median(T))   # ≈ 6.0, 30.0, 4.0
Memorylessness

Waiting doesn’t make it “due”

Suppose you have already rolled m times without a 6. How many more rolls do you expect? Still 6. The die doesn’t know about your bad luck. The algebra is one line, because the tail is a power:

P(T>m+n∣T>m)=(1−p)m+n(1−p)m=(1−p)n=P(T>n)P(T > m + n \mid T > m) = \frac{(1-p)^{m+n}}{(1-p)^m} = (1-p)^n = P(T > n)

Below, the left chart crosses out the m rounds you know failed. What’s left is the orange part, holding (1−p)m(1-p)^m of the probability. Dividing by that amount to condition gives the right chart, which lands exactly on the blue dots of a fresh start.

palready failed m =3

Before you start: P(T = k)

After m misses: P(T − m = j | T > m)

ruled out: we know these rounds failedstill possiblea fresh start, P(T = j)
–runs that failed the first m rounds
–their average rounds still to go
–fresh start E[T] = 1/p

Two consequences that come up in interviews:

  • Expected total, given you’ve waited: E[T∣T>m]=m+1/pE[T \mid T > m] = m + 1/p. The m rounds are spent, and the future is a fresh geometric.
  • Only the geometric does this. On 1, 2, 3, …, memorylessness forces P(T>k)=P(T>1)kP(T > k) = P(T > 1)^k, which is exactly the geometric tail. If a waiting-time distribution is memoryless, it is geometric (or, in continuous time, exponential).
Repeat until decided

Who wins doesn’t depend on how long it took

Many games are rounds that repeat until something decisive happens. Say each round A wins with probability a, B wins with probability b, and otherwise the round is replayed. Then:

T∼Geometric(a+b)P(A wins)=∑k≥1(1−a−b)k−1 a=aa+bP(A wins, T=k)=P(T=k)⋅aa+b\begin{aligned} T &\sim \text{Geometric}(a + b) \\ P(\text{A wins}) &= \sum_{k \ge 1} (1-a-b)^{k-1}\, a = \frac{a}{a+b} \\ P(\text{A wins},\ T = k) &= P(T = k)\cdot \frac{a}{a+b} \end{aligned}

The last line says the winner and the length of the game are independent. You can ignore every replayed round and look only at the decisive one: given that a round decides the game, A wins it with probability a/(a + b).

Example. A duel: A shoots first and hits with probability 0.3; if A misses, B shoots and hits with probability 0.4. Treat “A shoots, then B shoots” as one round: a = 0.3, b = 0.7 × 0.4 = 0.28. A wins with probability 0.3/0.58 = 15/29 ≈ 0.517, even though B is the better shot. The duel lasts 1/0.58 ≈ 1.72 rounds on average.

The minimum of geometrics is geometric

Several independent processes, each stopping with its own chance pip_i per round. The first one to stop: P(min⁡>k)=∏i(1−pi)k=(∏i(1−pi))kP(\min > k) = \prod_i (1-p_i)^k = \big(\prod_i (1-p_i)\big)^k, so the minimum is Geometric with p=1−∏i(1−pi)p = 1 - \prod_i (1 - p_i). Same “everyone is still going” trick as the minimum in the max trick post.

Continuous time

Shrink the rounds and you get the exponential

Let rounds last Δt and set p = λ·Δt. The chance of still waiting at time t is

(1−λ Δt)t/Δt  ⟶  e−λt(Δt→0)(1 - \lambda\,\Delta t)^{t/\Delta t} \;\longrightarrow\; e^{-\lambda t} \quad (\Delta t \to 0)

So the geometric becomes Exp(λ), mean 1/λ, and keeps its memorylessness. Every rule on this page has a continuous twin: the minimum of independent exponentials is exponential with the rates added, and the first of two competing exponentials is the one with rate λ₁ with probability λ₁/(λ₁ + λ₂).

Where people slip in interviews

  • Two conventions. Counting trials (1, 2, 3, …) gives mean 1/p. Counting failures before the success (0, 1, 2, …) gives mean (1 − p)/p. Say which one you mean, and check which one your library uses.
  • “It’s due.” After ten misses, the next round still succeeds with probability p. That is the gambler’s fallacy, and memorylessness is the precise reason it’s wrong.
  • Forgetting what’s spent. Given m misses, the remaining wait has mean 1/p, but the total has mean m + 1/p.
  • p must stay constant. Drawing cards without replacement until an ace is not geometric: every miss makes the next draw more likely to hit, so there is memory.
  • Most likely ≠ typical. Round 1 is the mode for every p, but for small p it is still unlikely in absolute terms.
Practice

Try these before you open the answer

Warm-upFlip a fair coin. What is the chance the first head is on flip 4?
Show answer
P(T=4)=(12)3⋅12=116P(T = 4) = \left(\tfrac12\right)^3 \cdot \tfrac12 = \tfrac{1}{16}
Warm-upWhat is the chance you need more than 10 rolls to get a 6?
Show answer
P(T>10)=(56)10≈0.162P(T > 10) = \left(\tfrac56\right)^{10} \approx 0.162

No sum needed: it is just ten misses in a row.

MemorylessYou've rolled a die 3 times with no 6. What is the expected total number of rolls, counting those 3?
Show answer
E[T∣T>3]=3+6=9E[T \mid T > 3] = 3 + 6 = 9
ShapeRolling until a 6: what is the median number of rolls? Compare it with the mean.
Show answer

The median is the smallest k with P(T≤k)=1−(5/6)k≥12P(T \le k) = 1 - (5/6)^k \ge \tfrac12:

1−(56)3≈0.421,1−(56)4≈0.518⟹median=41 - \left(\tfrac56\right)^3 \approx 0.421, \qquad 1 - \left(\tfrac56\right)^4 \approx 0.518 \quad\Longrightarrow\quad \text{median} = 4

The mean is 6. The long right tail pulls the mean above the median.

VarianceWhat is the variance of the number of rolls until the first 6?
Show answer
Var(T)=1−pp2=5/61/36=30\mathrm{Var}(T) = \frac{1-p}{p^2} = \frac{5/6}{1/36} = 30
DuelA and B take turns shooting, A first. A hits with probability 1/2, B with 1/3. What is the chance A wins?
Show answer

One round = A shoots, then B shoots. a = 1/2, b = 1/2 · 1/3 = 1/6:

P(A wins)=aa+b=1/22/3=34P(\text{A wins}) = \frac{a}{a+b} = \frac{1/2}{2/3} = \frac34
Two diceRoll two dice each round until at least one shows a 6. Expected rounds? And given the round that stops it, what is the chance both dice are 6?
Show answer
p=1−(56)2=1136,E[T]=3611≈3.27p = 1 - \left(\tfrac56\right)^2 = \tfrac{11}{36}, \qquad E[T] = \tfrac{36}{11} \approx 3.27P(both 6∣round stops)=1/3611/36=111P(\text{both 6} \mid \text{round stops}) = \frac{1/36}{11/36} = \frac{1}{11}

The winner-style question ignores how many rounds it took.

StagesRoll a die until you have seen both a 1 and a 2. Expected number of rolls?
Show answer

Split the wait into two geometric stages. First, wait for either a 1 or a 2 (p = 1/3). Then wait for the other one (p = 1/6):

E=3+6=9E = 3 + 6 = 9
StagesFlip a fair coin until you have seen both a head and a tail. Expected number of flips?
Show answer

The first flip gives you one face. Then wait for the other face, p = 1/2:

E=1+2=3E = 1 + 2 = 3
StretchRoll a die until the first 6. What is the expected sum of all the rolls, including the 6?
Show answer

Before the 6 there are T − 1 non-6 rolls, on average 5. Each is uniform on 1–5, mean 3. Then add the final 6:

E[sum]=5⋅3+6=21=3.5×6=E[one roll]⋅E[T]E[\text{sum}] = 5 \cdot 3 + 6 = 21 = 3.5 \times 6 = E[\text{one roll}] \cdot E[T]

The last form is Wald’s identity: for a stopping time T, the expected sum is E[roll] · E[T].

Every answer on this page was checked against a simulation. The figures compute their exact values from the formulas shown, apart from the random runs.