Recurrence Relations

A recurrence relation is an equation that defines each term of a sequence from earlier terms, such as a_n = 2a_{n-1} + 1. Together with initial conditions like a_1 = 1, it fixes every term. You find the terms by iterating: plug each new value back into the rule to get the next one.

Before this lesson: Arithmetic Sequences, Geometric Sequences and Strong Induction

The idea

Start with 3. To get each new number, double the last one and subtract 1. The list is 3, 5, 9, 17, 33, …, and you never needed a formula for the 5th term; you built it from the 4th.

That rule is a recurrence relation: a_n = 2a_{n-1} - 1 with a_1 = 3. Many counting problems are easiest to describe this way, because a problem of size n often breaks into smaller problems of the same kind.

Recurrence relations and initial conditions

A recurrence relation of order k gives each term from the k terms before it:

a_n = f(a_{n-1}, a_{n-2}, \ldots, a_{n-k}) \quad \text{for } n \ge k

The first k terms must be given separately; these are the initial conditions. A first-order recurrence needs one starting value, and a second-order recurrence needs two. A solution is a sequence that satisfies the relation, and a closed formula (or explicit formula) gives a_n directly from n.

SequenceRecurrence relationInitial conditionsClosed formula
Arithmetica_n = a_{n-1} + da_0a_n = a_0 + dn
Geometrica_n = r \cdot a_{n-1}a_0a_n = a_0 r^n
Factoriala_n = n \cdot a_{n-1}a_0 = 1a_n = n!
FibonacciF_n = F_{n-1} + F_{n-2}F_0 = 0,\ F_1 = 1See Solving Linear Recurrence Relations

A recurrence like a_n = 3a_{n-1} - 2a_{n-2} is called linear with constant coefficients, because each earlier term is multiplied by a constant and added. It is homogeneous if there is no extra term that is not a multiple of an earlier term; a_n = 2a_{n-1} + 1 is not homogeneous because of the + 1.

How to work with a recurrence relation

  1. Read the relation and the initial conditions, and note where the index starts (n = 0 or n = 1).
  2. To find terms, iterate: substitute the known terms to get the next term, one at a time.
  3. To model a problem, describe a case of size n in terms of smaller cases, then find the first few cases directly.
  4. To guess a closed formula, list several terms or substitute the relation into itself (backward substitution) and look for a pattern.
  5. Check any closed formula: it must match the initial conditions and satisfy the relation, which you can prove by mathematical induction.

Recurrence relation examples

Example 1: Iterating a first-order recurrence

Find a_1 through a_4 for a_n = 3a_{n-1} - 2 with a_0 = 4.

a_1 = 3(4) - 2

Substitute a0 = 4.

a_1 = 12 - 2 = 10

Multiply first, then subtract.

a_2 = 3(10) - 2 = 28

Substitute a1 = 10: 30 − 2 = 28.

a_3 = 3(28) - 2 = 82

Substitute a2 = 28: 84 − 2 = 82.

a_4 = 3(82) - 2 = 244

Substitute a3 = 82: 246 − 2 = 244.

Answer: 10, 28, 82, 244. Each term is one more than a power of 3, which suggests the closed formula a_n = 3^{n+1} + 1.

Example 2: A second-order recurrence

Find a_2 through a_5 for a_n = a_{n-1} + 2a_{n-2} with a_0 = 2 and a_1 = 1.

a_2 = a_1 + 2a_0 = 1 + 2(2)

Use the two terms before a2.

a_2 = 1 + 4 = 5

Multiply, then add.

a_3 = a_2 + 2a_1 = 5 + 2(1) = 7

Use a2 = 5 and a1 = 1: 5 + 2 = 7.

a_4 = a_3 + 2a_2 = 7 + 2(5) = 17

Use a3 = 7 and a2 = 5: 7 + 10 = 17.

a_5 = a_4 + 2a_3 = 17 + 2(7) = 31

Use a4 = 17 and a3 = 7: 17 + 14 = 31.

Answer: 5, 7, 17, 31. A second-order recurrence needs both starting values: with only a_0 given, a_2 could not be found.

Example 3: The Tower of Hanoi (word problem)

The Tower of Hanoi puzzle has n disks of different sizes stacked on the left of three pegs, largest at the bottom. You may move one disk at a time and never put a larger disk on a smaller one. Let H_n be the least number of moves needed to move all n disks to the right peg. Find a recurrence for H_n and use it to find H_6.

Three pegs. The largest disk, in orange, sits alone on the left peg, and a stack of n − 1 smaller blue disks sits on the middle peg. Arrows show the three stages: move the top n − 1 disks from the left peg to the middle peg, move the largest disk from the left peg to the right peg in 1 move, then move the n − 1 disks from the middle peg onto the right peg.
To move n disks, first move the top n − 1 out of the way, then move the largest disk, then move the n − 1 disks back on top of it.
H_{n-1}

Stage 1: move the top n − 1 disks to the middle peg.

1

Stage 2: move the largest disk to the right peg.

H_{n-1}

Stage 3: move the n − 1 disks onto the largest disk.

H_n = 2H_{n-1} + 1,\ H_1 = 1

Add the three stages. One disk takes one move.

H_2 = 2(1) + 1 = 3

Iterate from H1 = 1.

H_3 = 2(3) + 1 = 7

Substitute H2 = 3.

H_4 = 2(7) + 1 = 15

Substitute H3 = 7.

H_5 = 2(15) + 1 = 31

Substitute H4 = 15.

H_6 = 2(31) + 1 = 63

Substitute H5 = 31.

Answer: H_n = 2H_{n-1} + 1 with H_1 = 1, and H_6 = 63 moves. The terms 1, 3, 7, 15, 31, 63 are each one less than a power of 2, so H_n = 2^n - 1. Check: 2(2^{n-1} - 1) + 1 = 2^n - 1.

Example 4: Climbing stairs (word problem)

You climb a staircase taking either 1 or 2 steps at a time. In how many different ways can you climb 8 steps?

c_n = c_{n-1} + c_{n-2}

The first move is 1 step (leaving n − 1) or 2 steps (leaving n − 2); add the two cases with the sum rule.

c_1 = 1,\ c_2 = 2

One step: 1 way. Two steps: 1 + 1 or 2.

c_3 = 2 + 1 = 3

Add c2 and c1.

c_4 = 3 + 2 = 5

Add c3 and c2.

c_5 = 5 + 3 = 8

Add c4 and c3.

c_6 = 8 + 5 = 13

Add c5 and c4.

c_7 = 13 + 8 = 21

Add c6 and c5.

c_8 = 21 + 13 = 34

Add c7 and c6.

Answer: 34 ways. These are the Fibonacci numbers shifted by one place: c_n = F_{n+1}.

Example 5: Backward substitution

Find a closed formula for a_n = a_{n-1} + 2n with a_0 = 0.

a_n = a_{n-1} + 2n

Start with the relation.

a_n = a_{n-2} + 2(n - 1) + 2n

Replace an−1 using the relation with n − 1 in place of n.

a_n = a_{n-3} + 2(n - 2) + 2(n - 1) + 2n

Replace an−2 the same way.

a_n = a_0 + 2(1 + 2 + \cdots + n)

Continue until you reach a0.

a_n = 0 + 2 \cdot \frac{n(n + 1)}{2}

Use the sum 1 + 2 + ⋯ + n = n(n + 1)/2 (see arithmetic series).

a_n = n(n + 1)

Simplify.

n(n + 1) - (n - 1)n = 2n

Check the relation: the difference of consecutive terms is 2n.

0(0 + 1) = 0

Check the initial condition.

Answer: a_n = n(n + 1), so the terms are 0, 2, 6, 12, 20, …

Common mistakes

MistakeExample of the errorFix
Leaving out the initial conditions“a_n = 2a_{n-1} is the sequence 3, 6, 12, …”The relation alone also gives 5, 10, 20, … State a starting value such as a_0 = 3.
Giving a second-order recurrence only one starting valueF_n = F_{n-1} + F_{n-2} with only F_0 = 0An order-k recurrence needs k initial conditions: add F_1 = 1.
Ignoring order of operationsa_1 = 3a_0 - 2 with a_0 = 4 computed as 3(4 − 2) = 6Multiply first: 3(4) − 2 = 10.
Mixing up where the index startsUsing H_0 = 1 for the Tower of HanoiZero disks take 0 moves and one disk takes 1, so H_0 = 0 and H_1 = 1.
Trusting a pattern without checking ita_n = a_{n-1} + a_{n-2} + 1, a_1 = 1, a_2 = 2 gives 1, 2, 4, so guess 2^{n-1}The next term is 7, not 8. Always check a guess against the relation.
Using the term you are trying to findWriting a_2 = a_2 + 2a_0The right side may use only earlier terms: a_2 = a_1 + 2a_0.

Related ideas

Arithmetic sequences and geometric sequences are the simplest first-order recurrences, and strong induction is the natural way to prove facts about second-order ones. Numerical methods such as Euler’s method are recurrences too, and power series solutions of differential equations give a recurrence for the coefficients. The next lesson, Solving Linear Recurrence Relations, finds closed formulas like the one for Fibonacci numbers with characteristic roots.

Practice problems

  1. Find a_1 through a_4 for a_n = 2a_{n-1} + 3 with a_0 = 1.
  2. Find a_2 through a_5 for a_n = a_{n-1} - a_{n-2} with a_0 = 2 and a_1 = 5.
  3. Show that a_n = 5 \cdot 2^n is a solution of a_n = 2a_{n-1} with a_0 = 5.
  4. Write a recurrence relation with an initial condition for 7, 11, 15, 19, …
  5. Write a recurrence relation with an initial condition for 2, 5, 11, 23, 47, …
  6. A savings account starts with $500. Each year it earns 4% interest, and then $100 is deposited. Write a recurrence for the balance B_n after n years and find B_3.
  7. Let b_n be the number of bit strings of length n with no two 1s in a row. Explain why b_n = b_{n-1} + b_{n-2} with b_1 = 2 and b_2 = 3, and find b_6.
  8. Use backward substitution to find a closed formula for a_n = a_{n-1} + 5 with a_0 = 2.
  9. Use backward substitution to find a closed formula for a_n = 3a_{n-1} with a_0 = 4.
  10. Show that a_n = 2^n + (-1)^n satisfies the recurrence in Example 2, a_n = a_{n-1} + 2a_{n-2}.
Show answers

1.

a_1 = 2(1) + 3 = 5

Substitute a0 = 1: 2 + 3 = 5.

a_2 = 2(5) + 3 = 13

Substitute a1 = 5: 10 + 3 = 13.

a_3 = 2(13) + 3 = 29

Substitute a2 = 13: 26 + 3 = 29.

a_4 = 2(29) + 3 = 61

Substitute a3 = 29: 58 + 3 = 61.

Answer: 5, 13, 29, 61

2.

a_2 = 5 - 2 = 3

Subtract a0 from a1.

a_3 = 3 - 5 = -2

Subtract a1 from a2.

a_4 = -2 - 3 = -5

Subtract a2 from a3.

a_5 = -5 - (-2) = -3

Subtract a3 from a4 (see adding and subtracting integers).

Answer: 3, −2, −5, −3

3.

5 \cdot 2^0 = 5

Check the initial condition.

2a_{n-1} = 2 \cdot 5 \cdot 2^{n-1}

Substitute the formula for an−1.

2 \cdot 5 \cdot 2^{n-1} = 5 \cdot 2^n

Combine the powers of 2: 2 · 2n−1 = 2n.

Answer: both sides equal 5 \cdot 2^n, so the formula is a solution

4.

11 - 7 = 4

Each term is 4 more than the one before.

a_n = a_{n-1} + 4,\ a_1 = 7

Write the rule and the first term.

Answer: a_n = a_{n-1} + 4 with a_1 = 7

5.

2(2) + 1 = 5,\ 2(5) + 1 = 11

Each term is double the one before, plus 1.

2(11) + 1 = 23,\ 2(23) + 1 = 47

The rule fits every later term.

Answer: a_n = 2a_{n-1} + 1 with a_1 = 2

6.

B_n = 1.04B_{n-1} + 100,\ B_0 = 500

Grow by 4%, then add $100.

B_1 = 1.04(500) + 100 = 620

520 + 100 = 620.

B_2 = 1.04(620) + 100 = 744.80

644.80 + 100 = 744.80.

B_3 = 1.04(744.80) + 100 = 874.592

774.592 + 100 = 874.592.

Answer: about $874.59

7.

b_{n-1}

Strings that end in 0: any good string of length n − 1, then 0.

b_{n-2}

Strings that end in 1 must end in 01: any good string of length n − 2, then 01.

b_3 = 3 + 2 = 5,\ b_4 = 5 + 3 = 8

Iterate from b1 = 2 (0, 1) and b2 = 3 (00, 01, 10).

b_5 = 8 + 5 = 13,\ b_6 = 13 + 8 = 21

Keep adding the last two terms.

Answer: 21 strings

8.

a_n = a_{n-1} + 5 = a_{n-2} + 5 + 5

Substitute the relation into itself.

a_n = a_{n-k} + 5k

After k substitutions, 5 has been added k times.

a_n = a_0 + 5n

Take k = n.

a_n = 2 + 5n

Substitute a0 = 2.

Answer: a_n = 5n + 2

9.

a_n = 3a_{n-1} = 3 \cdot 3a_{n-2}

Substitute the relation into itself.

a_n = 3^k a_{n-k}

After k substitutions there are k factors of 3.

a_n = 3^n a_0

Take k = n.

a_n = 4 \cdot 3^n

Substitute a0 = 4.

Answer: a_n = 4 \cdot 3^n

10.

a_{n-1} + 2a_{n-2} = 2^{n-1} + (-1)^{n-1} + 2 \cdot 2^{n-2} + 2(-1)^{n-2}

Substitute the formula into the right side.

2 \cdot 2^{n-2} = 2^{n-1}

Combine the powers of 2.

2^{n-1} + 2^{n-1} = 2^n

Add the two powers of 2.

(-1)^{n-1} = -(-1)^n,\ (-1)^{n-2} = (-1)^n

Rewrite the signs in terms of (−1)n.

-(-1)^n + 2(-1)^n = (-1)^n

Combine the sign terms.

Answer: the right side equals 2^n + (-1)^n = a_n, so the formula satisfies the recurrence

Recurrence relations FAQ

What is a recurrence relation?

It is a rule that gives each term of a sequence in terms of earlier terms, such as a_n = a_{n-1} + a_{n-2}. With initial conditions, it determines the whole sequence.

What are initial conditions in a recurrence relation?

They are the starting terms that the rule cannot produce, such as a_0 = 2. A recurrence of order k needs k of them.

What is the difference between a recurrence relation and a closed formula?

A recurrence builds each term from the terms before it, so you must compute all the earlier terms first. A closed formula, like H_n = 2^n - 1, gives any term directly from n.

What is the recurrence relation for the Tower of Hanoi?

H_n = 2H_{n-1} + 1 with H_1 = 1, because you move n − 1 disks aside, move the largest disk, and move the n − 1 disks back. Its closed formula is H_n = 2^n - 1.

Summary

  • A recurrence relation defines each term from earlier terms; initial conditions supply the starting terms.
  • An order-k recurrence uses the k previous terms and needs k initial conditions.
  • Find terms by iterating, one term at a time.
  • Model a problem by splitting a case of size n into smaller cases, as in the Tower of Hanoi and stair-climbing problems.
  • Guess a closed formula from the terms or by backward substitution, then check it against the relation and the initial conditions.

Previous lesson: Inclusion-Exclusion Principle

Next lesson: Solving Linear Recurrence Relations

Back to the Discrete Math Index