maths.freeDiscrete Math & Logic › Solving linear recurrence relations

Solving linear recurrence relations

Setting up recurrences, the characteristic equation, repeated roots, and non-homogeneous terms.

A recurrence relation defines each term of a sequence from earlier ones, and many counting problems produce one naturally. Moving a tower of \( n \) discs in the Tower of Hanoi means moving \( n - 1 \) discs aside, the largest disc across, and \( n - 1 \) discs back on top: \( h_n = 2h_{n-1} + 1 \) with \( h_1 = 1 \). Binary strings of length \( n \) with no two consecutive 1s either end in 0 (after any good string of length \( n-1 \)) or in 01 (after any good string of length \( n-2 \)): \( s_n = s_{n-1} + s_{n-2} \). Solving a recurrence means finding a closed formula for the \( n \)-th term.

A linear homogeneous recurrence with constant coefficients of order 2 has the form \( a_n = c_1 a_{n-1} + c_2 a_{n-2} \). Try \( a_n = r^n \): dividing by \( r^{n-2} \) gives the characteristic equation \( r^2 = c_1 r + c_2 \). If it has two distinct roots \( r_1, r_2 \), every solution is \[ a_n = A\,r_1^n + B\,r_2^n, \] with \( A \) and \( B \) fixed by the two initial values. For \( a_n = 5a_{n-1} - 6a_{n-2} \) the example solves \( r^2 - 5r + 6 = 0 \) to get \( r = 2, 3 \); with \( a_0 = 2 \) and \( a_1 = 5 \), the equations \( A + B = 2 \) and \( 2A + 3B = 5 \) give \( A = B = 1 \), so \( a_n = 2^n + 3^n \).

If the characteristic equation has a repeated root \( r \), the second solution is \( n r^n \), and the general solution is \( a_n = (A + Bn)\,r^n \). The same idea extends to order \( k \): each root of multiplicity \( m \) contributes \( r^n, nr^n, \dots, n^{m-1}r^n \). The Fibonacci recurrence has roots \( (1 \pm \sqrt 5)/2 \), which gives Binet's formula \( F_n = (\varphi^n - \psi^n)/\sqrt 5 \).

A non-homogeneous recurrence \( a_n = c_1 a_{n-1} + c_2 a_{n-2} + g(n) \) is solved as general homogeneous solution plus one particular solution, guessed in the shape of \( g \): a constant for a constant, a polynomial of the same degree for a polynomial, \( C\,s^n \) for \( s^n \). If \( s \) is a characteristic root of multiplicity \( m \), multiply the guess by \( n^m \) (for a constant or polynomial term, \( s = 1 \)). For Hanoi, try the constant \( h_n = C \): \( C = 2C + 1 \) gives \( C = -1 \), so \( h_n = A\,2^n - 1 \), and \( h_1 = 1 \) gives \( h_n = 2^n - 1 \).

Picture it: plot the terms on a log scale. The solution \( A r_1^n + B r_2^n \) quickly becomes a straight line whose slope is the logarithm of the largest root: the dominant root decides the growth rate, and the others fade into a correction.

Think it: this is the discrete twin of solving \( y'' - 5y' + 6y = 0 \) with \( e^{rx} \), and the reasons are the same: the solutions form a vector space whose dimension is the order, and the characteristic roots give a basis. Always check the formula against the first few terms computed directly from the recurrence.

Worked example · solve r^2 - 5r + 6 = 0

Solve r^2 - 5r + 6 = 0

r^{2} - 5 r + 6 = 0

Step by step

  1. r^{2} - 5 r + 6 = 0

    Start from the equation as given.

  2. a = 1,\quad b = -5,\quad c = 6

    Read off the coefficients of the standard form ax² + bx + c = 0.

  3. \left(r - 3\right) \left(r - 2\right) = 0

    Factor the quadratic into two linear factors.

  4. r - 3 = 0 \;\Rightarrow\; r = 3

    A product is zero only when one of its factors is zero (zero-product property).

  5. r - 2 = 0 \;\Rightarrow\; r = 2

    A product is zero only when one of its factors is zero (zero-product property).

Reveal the answer
r = 3 \quad\text{or}\quad r = 2

Now you Pick a problem, or type or draw your own. Every step, a picture, the answer hidden until you ask.

Keep your own working

A free account adds notes on every lesson, a record of what you have finished, your solved problems in one place, and a tutor you can ask about this page. The maths itself is open to everyone, signed in or not.

Sign Up Login

Symbols used here

Tap any symbol for the full definition, a picture, and what every letter in it means.

How to: Solving linear recurrence relations

  1. Write the recurrence in the form a_n = c_1 a_(n-1) + c_2 a_(n-2) + g(n) and note the initial values.
  2. Solve the characteristic equation r^2 = c_1 r + c_2.
  3. Write the homogeneous solution: A r_1^n + B r_2^n, or (A + B n) r^n for a repeated root.
  4. If g(n) is not zero, add a particular solution guessed in the shape of g(n).
  5. Use the initial values to find A and B, then check the formula on the first few terms.

Questions people ask

What if the characteristic roots are complex?

The formula still works with complex A and B, and the answer comes out real. Writing the roots in polar form turns it into r^n (C cos nθ + D sin nθ), which shows the oscillation.

How many initial values do I need?

As many as the order of the recurrence: a recurrence reaching back k terms needs k starting values to determine the sequence.

What makes mathematics "discrete"?

It deals with separate, countable objects (integers, graphs, statements) rather than continuous quantities. No limits, no infinitesimals; instead induction, counting and logic.

How does a proof by induction work?

Show the statement for the first case, then show that whenever it holds for n it holds for n + 1. Like dominoes: the first falls, and each knocks over the next.

What order should I take these lessons in?

Logic and proof first, because every later lesson proves things. Then induction, sets, relations and functions, counting, recurrences, graphs, Boolean algebra and automata, and finally algorithms and complexity, which use nearly everything before them.

Is discrete mathematics the same as the maths of computer science?

Largely. Data structures are graphs and trees, correctness arguments are induction, running times are recurrences and sums, circuits are Boolean algebra, and what a computer can do efficiently is the subject of the last lessons. It is also ordinary mathematics in its own right.

Do I need calculus for this course?

No. School algebra is enough. A little familiarity with limits helps when comparing growth rates, and the lesson on asymptotic analysis explains the one limit fact it uses.

More in Discrete Math & Logic