A recurrence relation is an equation that uses recursion to relate terms in a sequence or elements in an array. It is a way to define a sequence or array in terms of itself. Recurrence relations have applications in many areas of mathematics:
- number theory - the Fibonacci sequence
- combinatorics - distribution of objects into bins
- calculus - Euler's method
- and many more.
Recurrence relations are used when an exhaustive approach to problem solving is simply too arduous to be practical. Although it is not ideal to compute the terms in a sequence one at a time by using previous terms, this approach can be much more efficient than the alternative of exhaustive casework.
Sometimes, a recurrence relation can be "solved" by defining the terms of a sequence in terms of its index rather than previous terms in the sequence. This gives a closed form expression for each term in the sequence and eliminates the need for an iterative process to solve for terms in the sequence. There are several ways to accomplish this:
- solving linear recurrence relations
- solving recurrence relations with generating functions
- solving recurrence relations with the substitution method
- solving recurrence relations with the method of summation factors.
Even if a solution of this form is not possible, a recurrence relation is still useful, as it can be used to develop computer algorithms. When terms in a sequence are stored, dynamic programming allows one to compute new terms in a sequence efficiently. Recurrence relations are also applicable for recursive backtracking, in which recursion is used to optimize algorithms.
Recurrence relations are used to reduce complicated problems to an iterative process based on simpler versions of the problem. An example problem in which this approach can be used is the Tower of Hanoi puzzle.
The Tower of Hanoi puzzle consists of three vertical pegs and several disks of various sizes. Each disk has a hole in its center for the pegs to go through.
The rules of the puzzle are as follows:
The puzzle begins with all disks placed on one of the pegs. They are placed in order of largest to smallest, bottom to top.
The goal of the puzzle is to move all of the disks onto another peg.
Only one disk may be moved at a time, and disks are always placed onto pegs.
Disks may only be moved onto an empty peg or onto a larger disk.
Let be defined as the minimum number of moves needed to solve a puzzle with disks.
Image Credit: Ævar Arnfjörð Bjarmason, Wikimedia Commons
It's not immediately clear that a recursion solution will work for this problem. However, there are a couple things about this problem that make it a good candidate to solve with a recurrence relation.
Identifying a candidate problem to solve with a recurrence relation:
- The problem can be reduced to simpler cases. The Tower of Hanoi puzzle can be simplified by removing some of the disks.
- There is a numerical value, , to identify each case. For the Tower of Hanoi puzzle, this numerical value is the number of disks.
- The problem increases in complexity as the numerical identifier increases. As the number of disks in the Tower of Hanoi problem increases, it becomes more difficult to find a solution.
The goal for this exercise will be to develop a recurrence relation for . Rather than try to tackle a complicated puzzle, like the one with 8 disks pictured above, it is often best to start off with the most simple version of the problem possible.
Step 1: Define a Base Case
The most simple version of the Tower of Hanoi puzzle would contain only one disk.
In terms of the recurrence relation, .
, because it would only take move to move all the disks to another peg.
The base case is often trivially simple. However, it will be necessary for developing more complicated cases. Even though the goal of this exercise is to come up with an equation for , it's not immediately clear what that equation will look like. It's necessary to do casework to get an understanding of how the problem works. After a couple of cases have been completed, one starts to develop an understanding of how to set up the recurrence relation.
Step 2: Develop More Complicated Cases
Below is the solution to a Tower of Hanoi puzzle with .
It can be seen from above that .
Below is a solution to a Tower of Hanoi puzzle with .
It can be seen from above that .
You can continue developing more complicated cases as needed. The goal of this process is to understand how the problem works, and to begin to think about how to set up the recurrence relation.
Although two cases were analyzed in the example above, it may sometimes be necessary to develop more cases in order to gain a better understanding of the problem. With the two cases above, one can probably begin to see how the cases are related to each other.
Step 3: Write the Recurrence Relation
Think about how the cases are related to each other.
With , it was a simple matter to move the disk once, and then the puzzle was complete.
With , the smaller disk had to be moved before the larger disk could be moved. Then, the smaller disk was placed on the larger disk to complete the puzzle.
With , the smaller disks had to be moved before the largest disk could be moved. Then, the smaller disks were placed on the larger disk to complete the puzzle.
One can begin to see a pattern in how these solutions are structured. You move the smaller disks, then you move the largest disk, then you move the smaller disks back onto the largest disk to complete the puzzle.
In terms of ,
Do moves to get the smaller disks off the largest disk.
Do move to move the largest disk.
Do moves to get the smaller disks back onto the largest disk.
In total, the number of moves for disks is
One can confirm the recurrence relation written above by matching it to the known values of :
The recurrence relation for the Tower of Hanoi puzzle is an example of a linear recurrence relation. It can be put into a closed form solution using the techniques discussed in the given link.
Main Article: Using Generating Functions to Solve Recurrence Relations
One method to solve recurrence relations is to use a generating function.
A generating function is a power series whose coefficients correspond to terms in a sequence of numbers.
What is the generating function of the Fibonacci sequence?
The generating function of the Fibonacci sequence is
where is the Fibonacci number. Using techniques demonstrated here, it can be shown that this generating function has a closed form expression
Use the generating function of to write a closed form expression for .
Recall the recurrence relation for :
It has already been established that , but a value for is also required. Let , and note that the recurrence relation still holds.
Define the generating function:
Recall that . Divide both sides of the equation by , which gives
Now substitute the recurrence relation for into the equation:
Provided that , the series above converges as an infinite geometric progression:
Substituting this expression gives
Solving for ,
Now that a closed form expression for the generating function has been found, the goal shifts to finding a closed-form expression for .
As the generating function is equal to a rational expression with binomial factors in the denominator, a good starting point would be to do partial fraction decomposition:
Recall infinite geometric progressions. For the next step, the two rational expressions are put back into power series form using the identities:
Substituting these identities gives
From here, it is clear that the coefficient of the generating function the series is given by
Main Article: Method of Summation Factors
There is another way of solving recurrence relations of the form , where , and are functions of , known as the method of summation factors.
This method can be used in the Tower of Hanoi problem, resolved once more in the example below.
Show that the closed form of the recurrence relation , is .
The summation factor with and is
where the 1's and 2's occur times each. Multiplying this to the recurrence relation gives
Let . Then and . So,
It follows that the closed form of is
Note that the summation above is a finite geometric series. But since , the closed form of is therefore