Math Core

Module 2.5 · Counting and Probability

Probability with states

Many probability problems describe a process that could, in principle, go on forever: flip until a pattern appears, walk until you hit a wall, play until someone is two points ahead. You can't list all the outcomes, but you can describe where the process is right now with a small number of states and write one equation per state.

States and first-step analysis

A state records everything about the current situation that matters for the future. For "flip a coin until you see HHHH," the only thing that matters is whether the last flip was HH. So there are two live states, "start" (or last flip TT) and "last flip HH," plus the finished state.

First-step analysis

Let xsx_s be the quantity you want (a probability or an expected count) starting from state ss. Look at one step of the process:

  • For a probability: xs=∑tP(s→t) xtx_s = \sum_t P(s \to t)\, x_t, with x=1x = 1 at winning states and x=0x = 0 at losing states.
  • For an expected number of steps: xs=1+∑tP(s→t) xtx_s = 1 + \sum_t P(s \to t)\, x_t, with x=0x = 0 at finished states.

Solve the resulting system of linear equations.

The reason this works: after one step, the process "restarts" from the new state, and it has no memory of how it got there. So the future from state tt is worth xtx_t, no matter what happened before.

Definition

Absorbing state

A state the process never leaves, such as "pattern found" or "player is broke." Probability problems ask which absorbing state you reach; expected value problems ask how long it takes to reach one.

Gambler's ruin

A player has kk dollars and repeatedly bets 11 dollar, winning with probability pp and losing with probability q=1−pq = 1 - p, until reaching 00 or NN. With xkx_k the probability of reaching NN, first-step analysis gives xk=pxk+1+qxk−1x_k = p x_{k+1} + q x_{k-1}, with x0=0x_0 = 0 and xN=1x_N = 1. The solution is

xk=1−rk1−rN,r=qp (p≠q),and xk=kN if p=q.x_k = \frac{1 - r^k}{1 - r^N}, \qquad r = \frac{q}{p} \ (p \ne q), \qquad \text{and } x_k = \frac{k}{N} \text{ if } p = q.

Patterns in coin flips

For waiting times of patterns, the states are "how much of the pattern have I matched so far?" The subtle part is what happens after a wrong flip: you may still have matched a shorter piece. For HTHHTH, if you have HTHT and flip TT, you're back to nothing; but if you have HH and flip HH, you still have HH.

Common mistake

When a flip breaks a partial match, don't automatically drop back to the start. Ask what the longest ending of the flips so far is that is also a beginning of the pattern. Going back too far is the most common error in pattern problems.

Worked example: Waiting for HH

A fair coin is flipped until two heads in a row appear. Find the expected number of flips.

Let aa be the expected number of further flips from the start (or after a TT) and bb the expected number after an HH.

a=1+12b+12a,b=1+12⋅0+12a.a = 1 + \tfrac{1}{2}b + \tfrac{1}{2}a, \qquad b = 1 + \tfrac{1}{2}\cdot 0 + \tfrac{1}{2}a.

The first gives a=2+ba = 2 + b. Substituting, b=1+12(2+b)b = 1 + \tfrac{1}{2}(2 + b), so b=4b = 4 and a=6a = 6.

Worked example: Gambler's ruin

A player starts with 11 dollar and bets 11 dollar at a time, winning each bet with probability 23\dfrac{2}{3}. Play stops when the player has 00 or 44 dollars. What is the probability of reaching 44?

Here r=1/32/3=12r = \dfrac{1/3}{2/3} = \dfrac{1}{2}, so x1=1−121−116=1/215/16=815x_1 = \dfrac{1 - \frac{1}{2}}{1 - \frac{1}{16}} = \dfrac{1/2}{15/16} = \dfrac{8}{15}.

Check with equations: x1=23x2x_1 = \tfrac{2}{3}x_2, x2=23x3+13x1x_2 = \tfrac{2}{3}x_3 + \tfrac{1}{3}x_1, x3=23+13x2x_3 = \tfrac{2}{3} + \tfrac{1}{3}x_2. Solving gives x1=815x_1 = \dfrac{8}{15}.

Worked example: A pattern race

A fair coin is flipped until either HTHT or TTTT appears. What is the probability that HTHT appears first?

Think about the first HH. Once any HH has appeared, the next TT completes HTHT, and TTTT can't happen before that (a TT right after an HH makes HTHT, not TTTT). So TTTT wins only if it appears before any HH, which means the first two flips are TTTT. That has probability 14\dfrac{1}{4}, so HTHT wins with probability 34\dfrac{3}{4}.

States would give the same answer, but look for this kind of shortcut first.

Tip

Symmetry cuts the number of states. On a cube, a bug's position only matters through its distance from the target (00, 11, 22, or 33 edges), so eight vertices become four states.

Practice

Practice 1

A fair coin is flipped until the sequence HHTHHT appears for the first time. What is the expected number of flips?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

Alice and Bob take turns rolling a fair die, with Alice first. The first person to roll a 66 wins. The probability that Alice wins is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

A fair coin is flipped until either THHTHH or HHHHHH appears as three consecutive flips. The probability that THHTHH appears first is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 4

A gambler starts with 22 dollars and bets 11 dollar at a time, winning each bet with probability 23\dfrac{2}{3}. Play stops when the gambler has 00 or 55 dollars. The probability of ending with 55 dollars is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

A bug starts at one vertex of a regular hexagon. Each second it moves to one of the two neighboring vertices, each with probability 12\dfrac{1}{2}. The probability that it is back at its starting vertex after 66 moves is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

A bug starts at a vertex of a cube. Each minute it walks along one of the three edges at its current vertex, chosen uniformly at random. What is the expected number of minutes until it first reaches the vertex farthest from its start?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

A fair die is rolled repeatedly, and a running total of the rolls is kept. The probability that the running total is ever exactly 33 is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

In a game of tennis, the first player to win at least 44 points while being ahead by at least 22 points wins the game. Petra wins each point independently with probability 23\dfrac{2}{3}. The probability that Petra wins the game is mn\dfrac{m}{n} in lowest terms. Find m+nm + n.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Real contest practice