পরিমাণগত অর্থায়ন · বই 18 · ক্যারিয়ার

Interviews I: Maths, Probability and Speed

এই বইটি এখনো বাংলা ভাষায় পাওয়া যায় না। সংস্করণ: English, Français।

Interviews I: Maths, Probability and Speed · ক্যারিয়ার

10Waiting Times and Markov Chains

Long-run behaviour and waiting times in random processes: how long until something happens, which of two things happens first, and where the process spends its time. The later questions need you to find the right states, or a symmetry that removes most of the algebra.

Question 10.1 ★ QR, QT, Trader, Analyst • any • junior

You flip a fair coin until two heads in a row appear. What is the expected number of flips? How does that change if you wait instead for a head followed immediately by a tail?

Answer

Answer to Question 10.1.

Two heads in a row takes 6 flips on average. A head followed by a tail takes 4.

Use first-step analysis on the states of Figure 10.1. For two heads, let xx be the expected number of flips from the start and yy the number after one head. A tail from either state sends you back to the start:

x=1+12x+12y,y=1+12x,x = 1 + \tfrac12 x + \tfrac12 y, \qquad y = 1 + \tfrac12 x,

which gives x=6x = 6 and y=4y = 4. For a head then a tail, wait for the first head, 2 flips on average, and then for the first tail, 2 more. A further head after the first head loses nothing.

Waiting for HH (left) and for HT (right). A wrong flip on the way to HH sends you back to the start, while a wrong flip on the way to HT keeps you where you are.
Figure 10.1. Waiting for HH (left) and for HT (right). A wrong flip on the way to HH sends you back to the start, while a wrong flip on the way to HT keeps you where you are.

Classic wrong answer. “Each pattern has probability 1/41/4 at any place, so both take 4 flips.” Both do occur once per 4 flips in the long run, but occurrences of HH come in clumps, because HHH holds two of them. A clumpy pattern has longer gaps between clumps, so the first occurrence takes longer.

Question 10.2 ★ QR, QT, Trader, Analyst • any • junior

You roll a fair die until two sixes come up in a row. What is the expected number of rolls? And for three heads in a row with a fair coin?

Answer

Answer to Question 10.2.

Two sixes in a row take 42 rolls on average. Three heads in a row take 14 flips.

Build up one at a time with first-step analysis. To get kk in a row, first get k−1k - 1 in a row, which takes Ek−1E_{k-1} rolls, then roll once more. With probability pp you are done; otherwise you start again from nothing:

Ek=Ek−1+1+(1−p) Ek,soEk=Ek−1+1p.E_k = E_{k-1} + 1 + (1 - p)\,E_k, \quad\text{so}\quad E_k = \frac{E_{k-1} + 1}{p}.

For the die, E1=6E_1 = 6 and E2=(6+1)⋅6=42E_2 = (6 + 1) \cdot 6 = 42. For the coin, E1=2E_1 = 2, E2=6E_2 = 6 and E3=14E_3 = 14.

Classic wrong answer. 36, the reciprocal of the chance of a pair of sixes at a given place. That is the long-run frequency, and it ignores the clumping that makes a first occurrence later.

Follow-up. Three sixes in a row? (42+1)⋅6=258(42 + 1) \cdot 6 = 258. The general form is 6(6k−1)/56(6^k - 1)/5.

Question 10.3 ★ QR, QT, Trader, Analyst, Risk • any • junior

You and a friend take turns rolling a fair die, and you go first. The first to roll a six wins. What is your probability of winning?

Answer

Answer to Question 10.3.

Your probability of winning is 6/11≈0.5456/11 \approx 0.545.

Use first-step analysis over a full round: you win now with probability 1/61/6, or both of you miss, with probability (5/6)2(5/6)^2, and the game restarts as if new, so

P=16+(56)2P,which givesP=1/611/36=611.P = \tfrac16 + \bigl(\tfrac56\bigr)^2 P, \quad\text{which gives}\quad P = \frac{1/6}{11/36} = \frac{6}{11}.

Follow-up. You flip a coin with heads probability 1/61/6 and your opponent one with 1/31/3, you going first, and the first head wins. Your chance? 1/61−(5/6)(2/3)=3/8\frac{1/6}{1 - (5/6)(2/3)} = 3/8. Going first does not make up for the weaker coin.

Question 10.4 ★ QR, QT, Trader • any • junior

Two players are level, and the first to lead by two points wins. Player A wins each point with probability 0.60.6, independently. What is the probability that A wins, and how many more points are played on average?

Answer

Answer to Question 10.4.

A wins with probability 9/13≈0.6929/13 \approx 0.692, and the game lasts 50/13≈3.8550/13 \approx 3.85 more points on average.

Look at the game two points at a time, using first-step analysis. From a level score, A wins both with p2=0.36p^2 = 0.36, B wins both with q2=0.16q^2 = 0.16, and otherwise the players are level again, with probability 2pq=0.482pq = 0.48. So

W=p2+2pq W  ⇒  W=p2p2+q2=0.360.52=913,W = p^2 + 2pq\,W \;\Rightarrow\; W = \frac{p^2}{p^2 + q^2} = \frac{0.36}{0.52} = \frac{9}{13},
L=2+2pq L  ⇒  L=2p2+q2=5013.L = 2 + 2pq\,L \;\Rightarrow\; L = \frac{2}{p^2 + q^2} = \frac{50}{13}.

Why it matters. The rule amplifies an edge: a 60% point becomes a 69% game. It is the simplest example of how repetition with a stopping rule turns a small edge into a large one, at the cost of a longer game.

Question 10.5 ★★ QR, QT, DS, Risk • any • junior

A process has two states. In state A it stays with probability 0.90.9 at each step and otherwise moves to B. In state B it stays with probability 0.70.7 and otherwise moves to A. In the long run, what fraction of time is spent in B? How long does a visit to B last on average? Once the process has settled into its long-run behaviour, what is the correlation between “in B now” and “in B after nn steps”?

Answer

Answer to Question 10.5.

The process spends a quarter of its time in B, a visit to B lasts 10/310/3 steps on average, and the correlation is 0.6n0.6^n.

For the stationary distribution, the flow from A to B must balance the flow back: πA⋅0.1=πB⋅0.3\pi_A \cdot 0.1 = \pi_B \cdot 0.3, and so πA=3/4\pi_A = 3/4 and πB=1/4\pi_B = 1/4. A visit to B ends with probability 0.30.3 at each step, so its length is geometric with mean 1/0.3=10/31/0.3 = 10/3.

For the correlation, a two-state chain has eigenvalues 1 and λ=0.9+0.7−1=0.6\lambda = 0.9 + 0.7 - 1 = 0.6. The deviation from the stationary distribution shrinks by λ\lambda at each step, so the lag-nn correlation is λn=0.6n\lambda^n = 0.6^n.

Follow-up. A bit passes through 10 copiers, and each flips it with probability 0.10.1. What is the chance that it arrives correct? This is the same chain with λ=0.8\lambda = 0.8: 12(1+0.810)≈0.554\tfrac12(1 + 0.8^{10}) \approx 0.554.

Why it matters. This is the two-state regime model. Given the persistence of each state, it gives the share of time in the state, the length of a stay and the decay of any signal based on the state. Here the decay of 0.60.6 per step means a half-life of little over one step, even though a stay in A lasts 10 steps.

Question 10.6 ★★ QR, QT, Trader • any • junior

A fair coin is flipped until either heads-heads-tails or tails-heads-heads appears as three consecutive flips. You win if heads-heads-tails comes first. What is your probability of winning?

Answer

Answer to Question 10.6.

Your probability of winning is 1/41/4.

Think about when heads-heads-tails can win. If the first two flips are both heads, then you win for certain: the first tail that follows completes HHT, and THH needs a tail earlier. That has probability 1/41/4. In every other case a tail appears before the first HH. Then the first HH to appear is preceded by a tail, and so THH is completed first.

Classic wrong answer. One half, by symmetry. The patterns are mirror images of each other, but a race reads flips forward only, so the symmetry between them fails.

Follow-up. And with a coin that shows heads with probability 2/32/3? The argument is unchanged: HHT wins only by opening with HH, so its chance is (2/3)2=4/9(2/3)^2 = 4/9.

Follow-up. How long does the game last? 13/213/2 flips on average, shorter than the 8 flips that either pattern needs alone.

Question 10.7 ★★ QR, QT, Trader • market maker, hedge fund, bank • junior, experienced

You flip a fair coin until the pattern HTHTH appears. What is the expected number of flips? What is it for HHHTT, and why are the two different when each pattern has the same chance of appearing at any given place?

Answer

Answer to Question 10.7.

HTHTH takes 42 flips on average, and HHHTT takes 32. The gap comes from how each pattern overlaps with itself.

Conway’s formula says that the expected wait is the sum of 2k2^k over all kk such that the last kk letters equal the first kk letters. HTHTH overlaps itself at k=1,3,5k = 1, 3, 5, which gives 2+8+32=422 + 8 + 32 = 42. HHHTT overlaps only at k=5k = 5, which gives 32.

To see why, use a casino argument. Before each flip, a new gambler arrives with $1 and bets it on the next flip being the pattern’s first letter. A winner bets all of the $2 on the second letter, and so on, until the gambler loses or completes the pattern. All bets are fair, so at the moment you stop, the casino’s expected profit is zero: the TT dollars taken from gamblers equal in expectation what it pays out. At the end, the only gamblers still holding money are those who started kk flips ago, with the last kk flips being the first kk letters of the pattern. Each of those holds 2k2^k. So E[T]=∑2kE[T] = \sum 2^k over those kk.

Follow-up. On a die, the pair 4 then 5 against the pair 4 then 4? 62=366^2 = 36 rolls, against 36+6=4236 + 6 = 42.

Follow-up. A monkey types uniform capital letters. How long until ABRACADABRA? The word overlaps itself at lengths 1, 4 and 11, so 2611+264+2626^{11} + 26^4 + 26 keystrokes.

Question 10.8 ★★ QR, QT, Trader, QD • any • junior

An ant starts at one corner of a cube. At each step it walks along one of the three edges at that corner, chosen at random. On average, how many steps does it take to reach the diagonally opposite corner?

Answer

Answer to Question 10.8.

It takes 10 steps on average.

Use symmetry to lump the corners by distance from the target, as in Figure 10.2. Let aa, bb, cc be the expected steps from distance 3, 2, 1. From distance 3, every edge leads to distance 2. From distance 2, two of three edges lead closer. From distance 1, one of three reaches the target:

a=1+b,b=1+13a+23c,c=1+23b.a = 1 + b, \qquad b = 1 + \tfrac13 a + \tfrac23 c, \qquad c = 1 + \tfrac23 b.

These give b=9b = 9, c=7c = 7 and a=10a = 10.

The ant’s distance from the opposite corner. The eight corners of the cube reduce to four states, with one, three, three and one corners in them.
Figure 10.2. The ant’s distance from the opposite corner. The eight corners of the cube reduce to four states, with one, three, three and one corners in them.

Follow-up. How long to return to the start? 8 steps. The walk is uniform over 8 corners in the long run, and a state with long-run share π\pi recurs every 1/π1/\pi steps on average.

Follow-up. How long to reach a neighbouring corner? 7 steps. The commute time across an edge is 2⋅12⋅712=142 \cdot 12 \cdot \tfrac{7}{12} = 14, and by symmetry half of it goes each way.

Follow-up. And on a four-dimensional cube? The same distance chain gives 64/3≈21.3364/3 \approx 21.33.

Question 10.9 ★★ QR, QT, Trader • hedge fund, market maker • junior

You roll a fair die repeatedly and keep a running total. On average, how many rolls does it take until the total is divisible by 6?

Answer

Answer to Question 10.9.

On average it takes 6 rolls.

No first-step system is needed. The residue of the total modulo 6 is uniform after every roll, whatever came before, because the six faces reach each of the six residues exactly once from any starting residue. So each roll makes the total divisible by 6 with probability 1/61/6, independently of the past, and the wait is geometric with mean 6.

Follow-up. And divisible by 7? 7 rolls. The first roll can never succeed, since it gives 1 to 6. After that, from any non-zero residue, exactly one face reaches a multiple of 7, and a failure leaves you at another non-zero residue. So it is one roll, plus a geometric wait with mean 6.

Follow-up. Why does this not work for 5? Five residues and six faces do not divide evenly, so the residue is not uniform and you need the first-step equations.

Question 10.10 ★★ QR, QT, Trader • bank, hedge fund • junior

You roll a fair die repeatedly and keep a running total. On average, how many rolls does it take until the total is 10 or more? Give an exact method and a quick approximation to check it, and then the approximation for a total of 100 or more.

Answer

Answer to Question 10.10.

To reach 10 or more takes about 3.323.32 rolls. To reach 100 or more takes about 29.0529.05 rolls.

The exact method is a recursion by first-step analysis. Let T(n)T(n) be the expected rolls to add at least nn. One roll of kk leaves n−kn - k to go, and T(n)=0T(n) = 0 for n≤0n \le 0:

T(n)=1+16∑k=16T(n−k).T(n) = 1 + \frac16 \sum_{k=1}^{6} T(n - k).

So T(1)=1T(1) = 1, T(2)=7/6T(2) = 7/6, T(3)=49/36T(3) = 49/36, and the table goes on to T(10)≈3.32T(10) \approx 3.32.

For the check, use Wald’s identity: the total when you stop averages 3.5 E[T]3.5\,E[T], and that total is nn plus an overshoot. For large nn the overshoot has mean

E[X2]2E[X]−12=91/67−12=53.\frac{E[X^2]}{2E[X]} - \frac12 = \frac{91/6}{7} - \frac12 = \frac53.

So E[T]≈(n+5/3)/3.5E[T] \approx (n + 5/3)/3.5, which gives 3.333.33 for n=10n = 10, and 29.0529.05 for n=100n = 100.

Classic wrong answer. n/3.5n/3.5, which is 2.862.86 for n=10n = 10. It forgets that you stop past the target, not on it.

Question 10.11 ★★ QR, QT, Trader • any • junior

You repeatedly roll a pair of fair dice and look at their sum. What is the probability that a sum of 12 appears before two consecutive sums of 7?

Answer

Answer to Question 10.11.

The probability is 7/13≈0.5387/13 \approx 0.538.

Each roll of the pair gives a 12 with probability 1/361/36, a 7 with probability 1/61/6, and something else with probability 29/3629/36. The only memory you need is whether the last sum was a 7. Let aa be the chance that 12 comes first when the last sum was not a 7, and bb the chance when it was. By first-step analysis, a 7 in the second state ends the game with a loss:

a=136+16b+2936a,b=136+2936a.a = \tfrac{1}{36} + \tfrac16 b + \tfrac{29}{36} a, \qquad b = \tfrac{1}{36} + \tfrac{29}{36} a.

Substituting bb into the first equation and multiplying through by 216 gives 42a=7+29a42a = 7 + 29a, so a=7/13a = 7/13.

Classic wrong answer. Comparing the chance of a 12 per roll, 1/361/36, with the chance of two sevens, 1/361/36, and answering 1/21/2. Two consecutive sevens need two rolls that overlap, which makes them slower to arrive than a 12.

Question 10.12 ★★ QR, QT, Risk, DS, Trader • any • junior

Buses leave a stop one after another, and each gap between buses is independently 5 or 15 minutes, with equal probability. You arrive at a random moment. What is your expected wait for the next bus?

Answer

Answer to Question 10.12.

The expected wait is 6.256.25 minutes, not 5.

This is the inspection paradox. A random moment tends to fall inside a long gap: three times as much clock time lies in 15-minute gaps as in 5-minute gaps. So you land in a 15-minute gap with probability 3/43/4, and you then wait half of it on average:

34⋅7.5+14⋅2.5=6.25.\tfrac34 \cdot 7.5 + \tfrac14 \cdot 2.5 = 6.25.

The general formula is E[G2]/(2E[G])E[G^2]/(2E[G]), here 125/20125/20.

Follow-up. Bus gaps that are exponential with mean 10 minutes? The wait is 10 minutes, the same as the whole mean gap. The gap you land in averages 20 minutes. For regular 10-minute buses the wait is 5.

Follow-up. In a long sequence of coin flips, how long is the run that contains flip number 1 000? 3 on average, while a typical run has length 2. The same size-biasing applies: E[L2]/E[L]=6/2E[L^2]/E[L] = 6/2.

Why it matters. Any statistic sampled at random times sees long intervals too often. Measure the time between trades from a random clock and you overstate it, and measure the spread at random times and you over-weight quiet books. Decide whether you want an average per event or per unit of time.

Question 10.13 ★★ QR, QT, Risk • any • junior, experienced

A bacterium dies with probability 1/41/4, survives unchanged with probability 1/41/4, or splits into two with probability 1/21/2. Every bacterium does this independently, once per minute. Starting from one bacterium, what is the probability that the colony eventually dies out?

Answer

Answer to Question 10.13.

The colony eventually dies out with probability 1/21/2.

Use conditioning on the first step. Let qq be the probability of extinction. A family dies out only if each bacterium alive after the first minute starts a family that dies out, and those families are independent:

q=14+14q+12q2,or2q2−3q+1=0.q = \tfrac14 + \tfrac14 q + \tfrac12 q^2, \quad\text{or}\quad 2q^2 - 3q + 1 = 0.

The roots are q=1/2q = 1/2 and q=1q = 1. The mean number of offspring is 14+2⋅12=5/4\tfrac14 + 2 \cdot \tfrac12 = 5/4, above 1, and in that case the extinction probability is the smaller root. If the mean is at most 1 (and a bacterium is not simply replaced each time), extinction is certain.

Classic wrong answer. “q=1q = 1 solves the equation, so extinction is certain.” It always solves it. The extinction probability is the smallest root in [0,1][0, 1], which is the limit of the chance of dying out by each generation, starting from zero.

Follow-up. Starting from three bacteria? The families are independent, so (1/2)3=1/8(1/2)^3 = 1/8.

Question 10.14 ★★★ QR, QT, Trader • any • junior, experienced

You keep rolling a fair die and adding the results until your total is 1 000 or more. Which final total is most likely, and what is its probability, to three decimal places?

Answer

Answer to Question 10.14.

The most likely final total is exactly 1 000, with probability about 2/7≈0.2862/7 \approx 0.286.

Far from the start, the chance that the running total ever lands on a given number settles at u=1/3.5=2/7u = 1/3.5 = 2/7, by renewal theory: each roll advances the total by 3.53.5 on average, so in the long run one number in 3.53.5 gets visited.

To finish at 1000+k1000 + k, for k=0,…,5k = 0, \dots, 5, you must pass through one of the numbers in 1000+k−6,…,9991000 + k - 6, \dots, 999, and then roll exactly the right face. There are 6−k6 - k such numbers, each visited with chance 2/72/7, and each needs one face, with chance 1/61/6. So

P(final total=1000+k)=(6−k)⋅27⋅16=6−k21.P(\text{final total} = 1000 + k) = (6 - k) \cdot \frac27 \cdot \frac16 = \frac{6 - k}{21}.

At k=0k = 0 this is 6/21=2/76/21 = 2/7, the largest. The chances are 6/21,5/21,…,1/216/21, 5/21, \dots, 1/21, falling to the last at 1 005. Their mean overshoot is 5/35/3.

Classic wrong answer. “Uniform over 1 000 to 1 005, so 1/61/6.” That would need each of the final totals to be reached equally often, but 1 000 can be reached from six numbers, and 1 005 from only one.

Follow-up. What is the chance that the roll crossing 1 000 is a 2? By the same count, 2⋅27⋅16=2/212 \cdot \tfrac27 \cdot \tfrac16 = 2/21. Large rolls are more likely to be the crossing one: the chance for a roll of jj is j/21j/21.

Question 10.15 ★★★ QR, QT, Trader • market maker, hedge fund, crypto • junior, experienced

You and an opponent each name a pattern of three coin flips, such as HTH, and your opponent names first. A fair coin is flipped until one of the two patterns appears, and the owner of that pattern wins. If your opponent names HHH, what should you name, and what is your chance of winning? And if they name HTH? Is there a response that gives you at least some fixed chance, whatever they name?

Answer

Answer to Question 10.15.

Against HHH, name THH and you win with probability 7/87/8. Against HTH, name HHT and win with 2/32/3. Whatever your opponent names, there is a response that gives at least 2/32/3.

This is Penney’s game. The recipe is to take your opponent’s first two letters as your last two, and to begin with the opposite of their second letter. HHH wins only if the first three flips are all heads, since any tail before that sets up THH first. That gives THH the chance 7/87/8.

In general, use Conway’s leading numbers: L(X,Y)L(X, Y) is the sum of 2k−12^{k-1} over all kk for which the last kk letters of XX equal the first kk of YY. The odds that BB beats AA are then

(L(A,A)−L(A,B)):(L(B,B)−L(B,A)).\bigl(L(A, A) - L(A, B)\bigr) : \bigl(L(B, B) - L(B, A)\bigr).

For A=A = HTH and B=B = HHT, L(A,A)=5L(A, A) = 5, L(A,B)=1L(A, B) = 1, L(B,B)=4L(B, B) = 4 and L(B,A)=2L(B, A) = 2, so the odds are 4:24:2, which is 2/32/3.

The complete table of best responses is: HHH to THH (7/87/8), HHT to THH (3/43/4), HTH to HHT (2/32/3), HTT to HHT (2/32/3), and the same with heads and tails swapped.

Classic wrong answer. “Pick a pattern that appears as often, so it is fair.” All eight appear equally often. The relation is not even transitive: THH beats HHT, which beats HTT, which beats TTH, which beats THH.

Question 10.16 ★★★ QR, QT, Trader • market maker, hedge fund • junior, experienced

You stand at the number 12 on a clock face. At each step you move to one of the two neighbouring numbers with equal probability, and you continue until you have visited every number. What is the probability that the 6 is the last new number you visit? On average, how many steps does the whole walk take?

Answer

Answer to Question 10.16.

The probability is 1/111/11. The whole walk takes 6666 steps on average.

Every number other than the start is equally likely to be visited last. For the 6 to be last, the walk must first reach one of its two neighbours, 5 or 7; it must, because it visits every number. Say it reaches 5 first. Then the 6 is last exactly if the walk goes from 5 all the way round to 7 before stepping on 6. On the line of positions from 6 round to 7, the walk stands one step from one end. A gambler’s ruin on a fair walk with 11 steps between the ends gives the chance of reaching the far end as 1/111/11. Nothing in this depends on which number you chose, so all 11 have the same chance.

For the steps, at any time the visited numbers form an arc. With an arc of jj numbers you stand at one end of it, and the next new number takes jj steps on average: it is a fair walk on j+2j + 2 positions that starts next to one end, and such a walk takes 1⋅j1 \cdot j steps. Summing from j=1j = 1 to 11 gives 6666, or n(n−1)/2n(n-1)/2 in general.

Classic wrong answer. Assuming the 6, being farthest away, is most likely to be last. It takes longest to reach on average, at 6⋅6=366 \cdot 6 = 36 steps, but that is a different question.

Question 10.17 ★★★ QR, QT, Trader • hedge fund, market maker, bank • junior, experienced

A knight starts in a corner of an empty chessboard and moves at random, choosing with equal probability among its legal moves each time. On average, how many moves does it take to return to that corner?

Answer

Answer to Question 10.17.

It takes 168 moves on average.

No calculation over the board is needed. For a random walk on a graph, which picks a uniformly random edge at each step, the stationary distribution is proportional to the degree, the number of edges at a vertex:

π(v)=deg⁡(v)∑udeg⁡(u).\pi(v) = \frac{\deg(v)}{\sum_u \deg(u)}.

You can verify this in one line: the flow into vv is ∑u∼vπ(u)/deg⁡(u)\sum_{u \sim v} \pi(u)/\deg(u), which has deg⁡(v)\deg(v) equal terms, each 1/∑udeg⁡(u)1/\sum_u \deg(u). The expected return time to a state is 1/π(v)1/\pi(v), by Kac’s lemma.

Now count the knight’s moves. A knight move has 2 orientations and 4 sign choices, and each of the 8 kinds has 7⋅67 \cdot 6 placements on the board, so ∑udeg⁡(u)=8⋅42=336\sum_u \deg(u) = 8 \cdot 42 = 336. A corner has degree 2, so the return takes 336/2=168336/2 = 168 moves.

Classic wrong answer. Trying to solve 63 linear equations on the board. An interviewer asking this wants the degree argument.

Follow-up. From a central square? Degree 8, so 336/8=42336/8 = 42 moves.

Follow-up. A king starting in a corner? The king’s degrees add up to 420, and a corner has degree 3, so 140 moves.

Question 10.18 ★★★ QR, QT • hedge fund, market maker • experienced

A token sits at a corner of a 3-by-3 grid of squares joined edge to edge, so it has 9 positions and 12 connections between neighbours. At each step it moves to a uniformly chosen neighbouring position. On average, how many steps does it take to reach the opposite corner?

Answer

Answer to Question 10.18.

It takes 18 steps on average.

Reflection across the line from start to target lumps the positions into classes. First-step analysis on them gives the values in Figure 10.3:

s=1+a,a=1+13(s+m+c),m=1+14(2a+2b),c=1+12(a+b),b=1+13(m+c),s = 1 + a, \quad a = 1 + \tfrac13(s + m + c), \quad m = 1 + \tfrac14(2a + 2b), \quad c = 1 + \tfrac12(a + b), \quad b = 1 + \tfrac13(m + c),

where ss, aa, mm, cc, bb are the start, its neighbours, the centre, the two other corners and the target’s neighbours. The equations for mm and cc have the same right-hand side, so m=cm = c. The solution is s=18s = 18, a=17a = 17, m=c=15m = c = 15 and b=11b = 11.

Expected steps to reach the top-right corner from each position of the grid. Each value is one more than the average over its neighbours.
Figure 10.3. Expected steps to reach the top-right corner from each position of the grid. Each value is one more than the average over its neighbours.

A neater route is the commute time identity: treat each connection as a 1-ohm resistor. The expected round trip between two vertices is then 2⋅(number of edges)⋅R2 \cdot (\text{number of edges}) \cdot R, with RR the effective resistance. Here R=3/2R = 3/2, so a round trip takes 2⋅12⋅3/2=362 \cdot 12 \cdot 3/2 = 36 steps. By symmetry each way takes half of that.

Follow-up. Is the time always the same each way? No. From centre to corner takes 15 steps, and from corner to centre only 6. Their sum, 21, is 2⋅12⋅7/82 \cdot 12 \cdot 7/8, as the identity says.

Question 10.19 ★★★ QR, QT • hedge fund, market maker • junior, experienced

You flip a fair coin until two heads in a row appear. The expected number of flips is 6. What is the variance of the number of flips? How does this compare with the wait for a head followed by a tail?

Answer

Answer to Question 10.19.

The variance is 22, so the standard deviation is about 4.74.7, close to the mean of 6. For a head then a tail, the mean is 4 and the variance is only 4.

Use first-step analysis on the second moment. With means m0=6m_0 = 6 from the start and m1=4m_1 = 4 after a head, let a=E[T02]a = E[T_0^2] and b=E[T12]b = E[T_1^2]. One flip adds one to the remaining time, and E[(1+T)2]=1+2E[T]+E[T2]E[(1 + T)^2] = 1 + 2E[T] + E[T^2]. So

a=12(1+2⋅6+a)+12(1+2⋅4+b)=11+12a+12b,a = \tfrac12(1 + 2 \cdot 6 + a) + \tfrac12(1 + 2 \cdot 4 + b) = 11 + \tfrac12 a + \tfrac12 b,
b=12⋅1+12(1+2⋅6+a)=7+12a.b = \tfrac12 \cdot 1 + \tfrac12(1 + 2 \cdot 6 + a) = 7 + \tfrac12 a.

This gives a=58a = 58 and b=36b = 36, so the variance is 58−62=2258 - 6^2 = 22.

The wait for a head then a tail is the sum of two independent geometric waits, each with mean 2 and variance 2, so it has variance 4.

Follow-up. And for three heads in a row? The same method gives a mean of 14 and a variance of 142.

Why it matters. Two waits with similar means can have very different risk. A wait whose failures send it back to the beginning has a standard deviation close to its mean, so plan for a long tail and do not quote the mean alone.

Question 10.20 ★★★ QR, QT • hedge fund, market maker • experienced

You shuffle a 52-card deck by repeatedly taking the top card and inserting it at a uniformly random one of the 52 possible positions, which include the top and the bottom. Follow the card that began at the bottom. On average, how many moves does it take until that card has reached the top and has then been inserted? Why is the deck perfectly shuffled at that moment?

Answer

Answer to Question 10.20.

It takes 52 H52≈23652\,H_{52} \approx 236 moves on average, where Hn=∑k≤n1/kH_n = \sum_{k \le n} 1/k.

Follow the card that started at the bottom. When ii cards are below it, the top card lands below it with probability (i+1)/52(i + 1)/52, because there are i+1i + 1 positions below it. So the wait for that card to move up one place has mean 52/(i+1)52/(i + 1). It reaches the top when i=51i = 51, and one more move inserts it:

∑i=05052i+1+1=52 H51+1=52 H52≈236.\sum_{i=0}^{50} \frac{52}{i+1} + 1 = 52\,H_{51} + 1 = 52\,H_{52} \approx 236.

This is the coupon collector in another guise.

The deck is perfectly shuffled at that moment by induction. The cards below the marked card are always in uniformly random order: a new card goes to a uniformly random one of the i+1i + 1 places among the ii cards already there. When the marked card reaches the top, the 51 cards beneath it are in uniform order. The final insertion places it uniformly among the 52 positions, so the entire deck is uniform.

Follow-up. Is 236 the mixing time? It is an upper bound in expectation: the deck may already be close to uniform earlier. It tells you what order of work to expect: nln⁡nn \ln n moves.

Question 10.21 ★★★ QR, QT • hedge fund, market maker • experienced

Ten coins lie on a table, all showing tails. At each step you pick one coin uniformly at random and turn it over. On average, how many steps does it take to reach all heads? And how many steps does it take to come back to all tails for the first time?

Answer

Answer to Question 10.21.

Reaching all heads takes 74752/63≈1186.574752/63 \approx 1186.5 steps on average. Coming back to all tails takes exactly 1 024.

The return time needs almost no algebra. The state is a corner of a 10-dimensional cube, and the walk has a uniform stationary distribution over the 2102^{10} corners, because each corner has the same degree. So by Kac’s lemma the mean return time is 210=10242^{10} = 1024.

For reaching all heads, track only the number of tails. Let eke_k be the expected steps to go from kk tails to k−1k - 1. With probability k/10k/10 you flip a tail and are done. Otherwise you create a tail, and you must come down from k+1k + 1 and then from kk again:

ek=1+10−k10(ek+1+ek)⇒ek=10k+10−kk ek+1,e_k = 1 + \frac{10 - k}{10}(e_{k+1} + e_k) \quad\Rightarrow\quad e_k = \frac{10}{k} + \frac{10 - k}{k}\,e_{k+1},

with e10=1e_{10} = 1. Working downwards and summing e10+⋯+e1e_{10} + \dots + e_1 gives 74752/6374752/63. The same recursion with 3 coins gives 10, the ant on the cube.

Classic wrong answer. Assuming the far state needs far longer. Both times are of order 2102^{10}, because the bulk of the time is spent wandering around the middle, near five heads, before a rare run to either extreme.

Question 10.22 ★★★★ QR, QT • market maker, hedge fund • experienced

You and an opponent each name a pattern of four coin flips, and your opponent names first. A fair coin is flipped until one of the patterns appears, and its owner wins. Your opponent names HTHH. Which pattern gives you the best chance, what is that chance, and what is the expected number of flips before the game ends?

Answer

Answer to Question 10.22.

Name THTH. You win with probability 9/14≈0.6439/14 \approx 0.643, and the game lasts 90/7≈12.8690/7 \approx 12.86 flips on average.

Use Conway’s leading numbers with two casinos. As with one pattern, a gambler who started kk flips ago holds 2k2^k if the last kk flips match the first kk letters of the pattern that gambler is betting on. Run one casino of gamblers betting on AA and another betting on BB. Let L(X,Y)=∑2k−1L(X, Y) = \sum 2^{k-1} over the kk for which the last kk letters of XX are the first kk of YY, and let pp be the chance that AA wins. Each casino breaks even in expectation, so

E[T]=2p L(A,A)+2(1−p) L(B,A)=2p L(A,B)+2(1−p) L(B,B).E[T] = 2p\,L(A,A) + 2(1-p)\,L(B,A) = 2p\,L(A,B) + 2(1-p)\,L(B,B).

Equating the two right-hand sides gives the odds of BB against AA,   L(A,A)−L(A,B):L(B,B)−L(B,A)\;L(A,A) - L(A,B) : L(B,B) - L(B,A).

The best responses start with one letter and then copy the first three of AA, here xxHTH, so that BB needs one flip less whenever AA is under way. For A=A = HTHH and B=B = THTH, L(A,A)=9L(A,A) = 9, L(A,B)=0L(A,B) = 0, L(B,B)=10L(B,B) = 10 and L(B,A)=5L(B,A) = 5. The odds are 9:59:5, so 9/149/14. Then E[T]=2⋅514⋅9+2⋅914⋅5=90/7E[T] = 2 \cdot \tfrac{5}{14} \cdot 9 + 2 \cdot \tfrac{9}{14} \cdot 5 = 90/7. The second casino gives the same: 2⋅914⋅10=90/72 \cdot \tfrac{9}{14} \cdot 10 = 90/7. The other candidate, HHTH, scores only (9−3):(9−5)(9-3):(9-5), or 3/53/5.

Classic wrong answer. Using the three-flip recipe without checking: begin with the opposite of the second letter of AA, then copy the first three letters of AA. It gives HHTH, and that is not the best. For four flips the first letter must be chosen by computing both.

Question 10.23 ★★★★ QR, QT • market maker, hedge fund • experienced

You roll a fair die and stop as soon as the last six rolls are all different, that is, when they contain every face once. What is the expected number of rolls?

Answer

Answer to Question 10.23.

The expected number of rolls is 416/5=83.2416/5 = 83.2.

Find the right states. Let the state jj be the number of most recent rolls that are all different, so you start at state 1 after one roll and stop at state 6. From state jj, a new face has probability (6−j)/6(6 - j)/6 and moves you to j+1j + 1. Otherwise the roll repeats the face that appeared ii rolls ago, for one of i=1,…,ji = 1, \dots, j, each with probability 1/61/6, and the new distinct tail has length exactly ii, as in Figure 10.4.

Let eje_j be the expected time to first reach j+1j + 1 from jj. A drop to state ii costs the climb back, ei+⋯+eje_i + \dots + e_j. Writing out the first step and collecting terms,

ej=1+16∑i=1j∑m=ijem=1+16∑m=1jm em⇒(6−j) ej=6+∑m<jm em.e_j = 1 + \frac16 \sum_{i=1}^{j} \sum_{m=i}^{j} e_m = 1 + \frac16 \sum_{m=1}^{j} m\,e_m \quad\Rightarrow\quad (6 - j)\,e_j = 6 + \sum_{m < j} m\,e_m.

This solves from the bottom up: e1=65e_1 = \tfrac65, e2=95e_2 = \tfrac95, e3=185e_3 = \tfrac{18}{5}, e4=545e_4 = \tfrac{54}{5}, e5=3245e_5 = \tfrac{324}{5}. Adding the first roll, the total is 1+411/5=416/51 + 411/5 = 416/5.

The chain on the number of distinct recent rolls, showing only the moves from state 4. A repeat of the face seen i rolls ago drops you to state i. Every state behaves the same way.
Figure 10.4. The chain on the number of distinct recent rolls, showing only the moves from state 4. A repeat of the face seen ii rolls ago drops you to state ii. Every state behaves the same way.

Classic wrong answer. 66/6!=64.86^6/6! = 64.8, the reciprocal of the chance that a given window of six is all different. That is the long-run frequency of such windows, and the windows overlap and clump, so the first one comes later.

Question 10.24 ★★★★ QR, QT, Risk • hedge fund, crypto • experienced

A cell either dies, with probability 1/31/3, or splits into two cells, with probability 2/32/3. Every cell behaves independently. You start with one cell. What is the probability that the family eventually dies out? Given that it does, what is the expected total number of cells that ever lived, counting the first?

Answer

Answer to Question 10.24.

The family dies out with probability 1/21/2, and given that, the expected total is 3 cells.

The extinction probability solves q=13+23q2q = \tfrac13 + \tfrac23 q^2, by conditioning on the first step. The roots are 1/21/2 and 1, and with mean offspring 4/34/3 above 1 the answer is the smaller root.

Unconditionally, the expected total is infinite, because the family grows without limit half the time. The idea is to condition on extinction. A cell that has kk children has a family that dies out with probability qkq^k, independently for each child, so the conditional law of the number of children is P(k children∣extinct)=pk qk/qP(k \text{ children} \mid \text{extinct}) = p_k\,q^k / q:

P(0∣extinct)=1/31/2=23,P(2∣extinct)=(2/3)(1/4)1/2=13.P(0 \mid \text{extinct}) = \frac{1/3}{1/2} = \frac23, \qquad P(2 \mid \text{extinct}) = \frac{(2/3)(1/4)}{1/2} = \frac13.

Each child’s family, given that it dies out, is again a copy of the same conditional process. So conditional on extinction you have a branching process with mean offspring 23\tfrac23. Generation nn has expected size (2/3)n(2/3)^n, and the total is

∑n≥0(23)n=3.\sum_{n \ge 0} \Bigl(\frac23\Bigr)^n = 3.

Classic wrong answer. Saying that the total is infinite, or computing the mean with the original probabilities. Conditioning changes the offspring law, and this is the step that makes the question hard.

Follow-up. Given extinction, what is the chance the first cell dies at once? 2/32/3, the first probability above, up from 1/31/3.

Question 10.25 ★★★★ QR, QT, Risk • hedge fund • experienced

Each individual in a population independently has kk children with probability (1/2)k+1(1/2)^{k+1}, for k=0,1,2,…k = 0, 1, 2, \dots, and then dies, so one child is the average. You start with one individual in generation 0. What is the probability that generation 10 is empty? Given that it is not empty, what is its expected size? What is the expected generation at which the family dies out?

Answer

Answer to Question 10.25.

Generation 10 is empty with probability 10/1110/11. If it is not empty, its expected size is 11. The expected generation of extinction is infinite, although extinction is certain.

Use the probability generating function. The offspring law has f(s)=∑ksk/2k+1=1/(2−s)f(s) = \sum_k s^k/2^{k+1} = 1/(2 - s), and generation nn has the nn-fold composition fnf_n of ff. The idea that removes the algebra is that this map is linear after a change of variable:

11−f(s)=2−s1−s=1+11−s.\frac{1}{1 - f(s)} = \frac{2 - s}{1 - s} = 1 + \frac{1}{1 - s}.

So each iteration adds 1, and 11−fn(s)=n+11−s\dfrac{1}{1 - f_n(s)} = n + \dfrac{1}{1 - s}. At s=0s = 0 this gives 1/(1−fn(0))=n+11/(1 - f_n(0)) = n + 1, and so P(generation n is empty)=fn(0)=n/(n+1)P(\text{generation } n \text{ is empty}) = f_n(0) = n/(n+1). For n=10n = 10 that is 10/1110/11.

The mean offspring is 1, so E[Xn]=1E[X_n] = 1 for every nn. Given survival, E[Xn∣Xn>0]=1/P(Xn>0)=n+1E[X_n \mid X_n > 0] = 1/P(X_n > 0) = n + 1, which is 11.

The family outlasts generation nn with probability 1/(n+1)1/(n + 1). Summing these tails for the expected extinction time gives the harmonic series, which diverges.

Classic wrong answer. “Mean offspring of one means a stable population.” A critical family dies out with certainty. The mean stays at 1 only because the rare survivors grow: at generation nn only one family in n+1n + 1 survives, with size n+1n + 1 on average.

Why it matters. Anything that reproduces at exactly its replacement rate behaves like this: most lines die early, and the few survivors look large. Reading only the survivors overstates growth by a factor that rises with time.