Math Core

Module 2.7 · Counting and Probability

Recursion and states

Some counting and probability problems have no clean formula you can write down directly, but they have a clean relationship between a problem and smaller copies of itself. Recursion counts things by building them one step at a time. Its probability twin, the states method, tracks "where you are" in a random process and writes an equation for each state. Both are late-AMC staples.

Counting with recursion

Suppose you want the number of ways to climb a staircase of nn steps taking 11 or 22 steps at a time. Call it ana_n. Look at the first move:

  • If it's a 11-step, the rest is a climb of n−1n - 1 steps: an−1a_{n-1} ways.
  • If it's a 22-step, the rest is a climb of n−2n - 2 steps: an−2a_{n-2} ways.

So an=an−1+an−2a_n = a_{n-1} + a_{n-2}, with a1=1a_1 = 1 and a2=2a_2 = 2. These are the Fibonacci numbers: 1,2,3,5,8,13,21,34,…1, 2, 3, 5, 8, 13, 21, 34, \dots

Building a recursion

  1. Define ana_n = the number of valid objects of size nn.
  2. Split by what happens first (or last): the first tile, the first letter, the first move.
  3. Each case leaves a smaller valid object. Write ana_n in terms of earlier terms.
  4. Compute a few starting values by hand, then iterate. On the AMC, iterating up to n=10n = 10 or 1212 by hand is normal.

When a restriction depends on what came just before (like "no two consecutive 11s"), split by how the object starts until the restriction is resolved. A string with no two consecutive 11s either starts with 00 (then anything valid of length n−1n - 1 follows) or starts with 1010 (then anything valid of length n−2n - 2). Again an=an−1+an−2a_n = a_{n-1} + a_{n-2}.

Probability with states

In a random process, a state is all the information about the present that matters for the future. Let pSp_S be the probability of winning from state SS. Condition on the next step:

pS=∑next state TP(S→T)⋅pT.p_S = \sum_{\text{next state } T} P(S \to T) \cdot p_T.

This gives one linear equation per state. Solve the system. The same idea works for expected values, with an extra "+1+1" for the step you just took.

Worked example: Tiling a strip

In how many ways can a 1×101 \times 10 strip be tiled with 1×11 \times 1 squares and 1×21 \times 2 dominoes?

Let tnt_n be the number of tilings of a 1×n1 \times n strip. The leftmost tile is a square (leaving tn−1t_{n-1}) or a domino (leaving tn−2t_{n-2}), so tn=tn−1+tn−2t_n = t_{n-1} + t_{n-2} with t1=1t_1 = 1, t2=2t_2 = 2:

1,2,3,5,8,13,21,34,55,89.1, 2, 3, 5, 8, 13, 21, 34, 55, 89.

So t10=89t_{10} = 89.

Worked example: Stairs with three step sizes

How many ways can you climb 1010 stairs taking 11, 22 or 33 steps at a time?

Now an=an−1+an−2+an−3a_n = a_{n-1} + a_{n-2} + a_{n-3}, with a0=1a_0 = 1 (one way to climb nothing), a1=1a_1 = 1, a2=2a_2 = 2:

nn001122334455667788991010
ana_n11112244771313242444448181149149274274

The answer is 274274.

Worked example: A dice race

Alex and Blair take turns rolling a fair die, Alex first. The first person to roll a 66 wins. What is the probability that Alex wins?

Let pp be the probability that the player about to roll eventually wins. Alex wins right away with probability 16\tfrac16. Otherwise (56\tfrac56), Blair becomes the player about to roll, and Alex wins only if Blair doesn't: probability 1−p1 - p. So

p=16+56(1−p)⟹116p=1⟹p=611.p = \frac16 + \frac56(1 - p) \quad\Longrightarrow\quad \frac{11}{6}p = 1 \quad\Longrightarrow\quad p = \frac{6}{11}.

Common mistake

Check your starting values carefully. Most recursion errors are off-by-one mistakes in a0a_0, a1a_1 or a2a_2. Always verify the recursion on a case small enough to list by hand, such as n=3n = 3 or n=4n = 4.

Worked example: A frog on a triangle

A frog sits on vertex AA of a triangle ABCABC. Each second it jumps to one of the other two vertices, each with probability 12\tfrac12. What is the probability that it is back at AA after 44 jumps?

Let pnp_n be the probability it's at AA after nn jumps. To be at AA after n+1n + 1 jumps, it must be not at AA after nn jumps, then jump to AA (probability 12\tfrac12). So

pn+1=12(1−pn),p0=1.p_{n+1} = \tfrac12(1 - p_n), \qquad p_0 = 1.

Then p1=0p_1 = 0, p2=12p_2 = \tfrac12, p3=14p_3 = \tfrac14, p4=38p_4 = \tfrac38.

Practice

Practice 1

In how many ways can you climb a staircase of 88 steps if each move goes up 11 or 22 steps?

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

Practice 2

Ana and Ben take turns flipping a fair coin, Ana first. The first person to flip heads wins. What is the probability that Ana wins?

Practice 3

How many subsets of {1,2,3,…,12}\{1, 2, 3, \dots, 12\}, including the empty set, contain no two consecutive integers?

Practice 4

How many strings of length 1010 made of the letters A and B contain no three consecutive A's?

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

Practice 5

A bug starts at vertex AA of triangle ABCABC. Each minute it crawls to one of the other two vertices, each with probability 12\tfrac12. What is the probability that the bug is at AA after 66 minutes?

Practice 6

How many strings of length 88 using the digits 00, 11 and 22 contain no two consecutive 00s?

Practice 7

In how many ways can a 3×83 \times 8 rectangle be tiled with 1×21 \times 2 dominoes?

Practice 8

A gambler starts with 33 chips. Each round, she wins a chip with probability 23\tfrac23 or loses a chip with probability 13\tfrac13. She stops when she has 55 chips or 00 chips. What is the probability that she ends with 55 chips?

Real contest practice