Solving Recurrence Relations

Using generating functions

Song Yang
4 min readAug 19, 2021
By 克勞棣 — Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=38708516

Recurrence relations, also called recursion, are functions that use previous values to calculate the next one. A famous example is the Fibonacci sequence,

The recursive Fibonacci sequence

where the sequence starts with f(0) = 1 and f(1) = 1.

It turns out that the Fibonacci sequence can be expressed in closed form, without using recursion.

Closed form of the Fibonacci sequence

where phi is the golden ratio and psi is its conjugate.

The golden ratio
The golden ratio’s conjugate

How to find the closed form expression?

In computer science undergraduate classes, students are taught to use induction to prove closed form solutions of recursions. This strategy requires you to guess the closed form. Guessing works on very simple recursions, but becomes unfeasible for anything more complicated.

The Fibonacci sequence cannot be solved using this technique. Instead, there is a systematic way of solving recurrence relations.

Introducing generating functions

A generating function is a function defined on a infinite series. For example, the geometric series.

Geometric series

When we use these series as generating functions, we don’t care about what values x is going to take. We also don’t care about where it converges. We only care about the ordering of powers of x and the coefficients of powers of x.

The overall strategy consists of bringing recursions into generating functions, then extracting a closed form expression.

General strategy
General recursion

Start with writing the recursion as a function.

Express a generating function

Build a generating function with the recursion. In this case, we use a ordinary generating function. See other kinds.

Substitute a_n into the generating function and add the base cases of the recursion.

Substitute the recursion

Finally, using calculus and properties of series, we collapse A(x) back into a sum. The closed form solution is b_n.

Let’s do an example!

Example: Recursive addition

Consider this simple recursion. With base case, a_0 = 0.

This is none other than a_n = n, but let’s use generating functions as an example.

Since the recursion is already expressed with a_n isolated on one side, we can build the generating function right away.

Substitute a_n by its recursive definition and add the base case
Replace the base case by its value and distribute the sum

The goal while at the generating functions level is to eliminate all recursive values of the original function. We do this by isolating recursive values and shifting the summation indices.

Shift the indices until the x power effectively starts at 0, like in the definition of A(x)
The series in brackets is the geometric series

Now we isolate A(x) and expand the expression back into a series. The closed form solution would be the coefficients.

Isolate A(x)

The brute force approach to expand A(x) back into a power series would be to use Taylor expansion. But since we know the sum of a geometric series, we can leverage that result by using derivatives. Alternatively, we could use partial fraction decomposition and add everything back together.

Using derivatives and multiplication to achieve the power series
The coefficients of x are the solution

So we proved that a_n = a_{n-1} + 1 = n where a_0 = 0. That took quite some gymnastics to do!

The good news is that the method of generating functions is systematic and has no guessing, unlike guessing and checking with induction. Thus, it can be used to solve any kind of recursion, as long as you know how to wrestle with power series.

--

--

Song Yang
Song Yang

No responses yet