Quant Memo
Core

First-Step Analysis

A recipe for computing hitting probabilities and expected waiting times in random processes — condition on what happens in the very first step, write the unknown in terms of itself, and solve.

Prerequisites: Markov Chains, Conditional Probability

First-step analysis is the workhorse technique for a huge family of interview questions: "how likely is this to happen before that?" and "how long, on average, until it happens?" The idea is almost embarrassingly simple. You don't know the answer directly, so you condition on the one thing you can reason about — what happens on the very first step — and use the fact that after that step you're facing a smaller version of the same problem. That self-reference turns the question into an equation you can solve.

It's nothing more than the The Law of Total Probability (for probabilities) or its cousin for expectations, applied one step at a time. But naming the move and drilling it is what makes hard-looking Markov questions fall over in two lines.

The recipe

Let hih_i be the quantity you want — a probability of reaching some goal, or an expected time — starting from state ii. Condition on the first transition: from ii you move to state jj with probability PijP_{ij}, and from jj you face the same problem with value hjh_j. That gives one equation per state:

hi=jPijhj(for a hitting probability),h_i = \sum_j P_{ij}\, h_j \qquad(\text{for a hitting probability}), hi=1+jPijhj(for an expected time).h_i = 1 + \sum_j P_{ij}\, h_j \qquad(\text{for an expected time}).

The only difference is the +1+1: computing a time, you charge yourself one step for having taken the first move, then add the expected time remaining. Pin down the boundary conditions — the values at the absorbing states you're measuring to — and you have a small linear system. Solve it.

Condition on the first step: hi=jPijhjh_i = \sum_j P_{ij} h_j for a hitting probability, and hi=1+jPijhjh_i = 1 + \sum_j P_{ij} h_j for an expected time. The +1+1 pays for the step you just took. Add the boundary values and solve the resulting equations.

Worked example: waiting for two heads in a row

Flip a fair coin until you see two heads in a row (HH). How many flips on average? Set up three states by how much progress you've made toward HH:

  • S — no useful progress (start, or you just flipped a tail).
  • A — the last flip was a heads (one away from done).
  • HH — done. This is the absorbing state; its expected remaining time is 00.
S A HH H, ½ H, ½ T, ½ T, ½
Waiting for HH. A heads advances you rightward; any tails throws away your progress and sends you back to the start. Only the second consecutive heads reaches the absorbing HH state.

Let mSm_S and mAm_A be the expected flips to reach HH from each state. Reading the transitions off the diagram and charging +1+1 per flip:

mS=1+12mA+12mS,mA=1+120+12mS.m_S = 1 + \tfrac12 m_A + \tfrac12 m_S, \qquad m_A = 1 + \tfrac12 \cdot 0 + \tfrac12 m_S .

From the first equation, 12mS=1+12mA\tfrac12 m_S = 1 + \tfrac12 m_A, so mS=2+mAm_S = 2 + m_A. Substitute into the second: mA=1+12(2+mA)=2+12mAm_A = 1 + \tfrac12(2 + m_A) = 2 + \tfrac12 m_A, giving 12mA=2\tfrac12 m_A = 2, so mA=4m_A = 4 and mS=6m_S = 6. On average it takes 6 flips to see two heads in a row.

The surprise: waiting for HT instead takes only 4 flips. The same recipe on the HT machine gives 44, because a tail after a head completes the pattern instead of destroying your progress. Patterns that can overlap themselves (like HH) take longer to appear — a genuinely counterintuitive result that first-step analysis makes obvious.

The waiting-time surprise: HH takes 6 flips on average, HT only 4. Whenever a target pattern can partially overlap itself, a "miss" costs you more progress, so it takes longer to arrive. First-step analysis is how you prove which patterns are slow.

Worked example: gambler's ruin in one line

The same method derives the Gambler's Ruin result cleanly. Let hih_i be the probability of reaching NN before 00 from bankroll ii, with a fair coin. Conditioning on the first bet:

hi=12hi+1+12hi1,h0=0,  hN=1.h_i = \tfrac12\, h_{i+1} + \tfrac12\, h_{i-1}, \qquad h_0 = 0,\; h_N = 1 .

This says hih_i is the average of its neighbors, which forces the solution to be a straight line, and the only straight line hitting 00 at 00 and 11 at NN is hi=i/Nh_i = i/N. The famous ruin probability drops straight out of the recipe.

Two mistakes sink first-step analysis: forgetting the boundary conditions (without them the equations have infinitely many solutions), and dropping the +1+1 when you're computing an expected time rather than a probability. Also confirm the process actually reaches its target with probability one, or the "expected time" can be infinite.

Where it fits

First-step analysis is the elementary, no-machinery route to results that optional stopping reaches with martingales. It computes hitting probabilities, expected absorption times, and expected rewards for any Markov chain, and it's the fastest tool to reach for the moment a problem mentions "first time" or "before."

Related concepts

Practice in interviews

Further reading

  • Ross, Introduction to Probability Models, ch. 4
  • Grimmett & Stirzaker, Probability and Random Processes, ch. 6
ShareTwitterLinkedIn