Fiveable

🧮Combinatorics Unit 7 Review

QR code for Combinatorics practice questions

7.3 Solving recurrence relations using generating functions

7.3 Solving recurrence relations using generating functions

Written by the Fiveable Content Team • Last updated August 2025
Written by the Fiveable Content Team • Last updated August 2025
🧮Combinatorics
Unit & Topic Study Guides

Generating functions of sequences

Definition and properties

A generating function encodes an entire sequence of numbers into a single algebraic expression. If you have a sequence {an}\{a_n\}, its ordinary generating function (OGF) is the formal power series:

G(x)=n=0anxn=a0+a1x+a2x2+a3x3+G(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \cdots

The key idea: the coefficient of xnx^n in G(x)G(x) is exactly ana_n, the nnth term of your sequence. This means all the information about the sequence lives inside one function.

A few things worth knowing upfront:

  • Generating functions are treated as formal power series, meaning you don't always need to worry about whether the series converges. You're manipulating algebraic objects, not computing actual sums.
  • The series can be finite or infinite depending on the sequence.
  • Other types exist (exponential, Dirichlet), but for solving recurrence relations, ordinary generating functions are the standard tool.

Common examples

Building intuition with a few standard generating functions helps a lot:

  • The constant sequence an=1a_n = 1 gives G(x)=11xG(x) = \frac{1}{1-x}, from the geometric series.
  • The geometric sequence an=rna_n = r^n gives G(x)=11rxG(x) = \frac{1}{1-rx}.
  • The sequence an=na_n = n gives G(x)=x(1x)2G(x) = \frac{x}{(1-x)^2}. You can derive this by differentiating 11x\frac{1}{1-x} and multiplying by xx.
  • More generally, 1(1x)k=n=0(n+k1k1)xn\frac{1}{(1-x)^k} = \sum_{n=0}^{\infty} \binom{n+k-1}{k-1} x^n, which shows up constantly.

These building blocks reappear throughout the method, so recognizing them on sight saves time.

Deriving generating functions from recurrence relations

The core technique is to convert a recurrence relation into an algebraic equation for G(x)G(x). Here's the general process:

Step-by-step process

  1. Define the generating function. Let G(x)=n=0anxnG(x) = \sum_{n=0}^{\infty} a_n x^n.

  2. Multiply both sides of the recurrence by xnx^n and sum over all valid values of nn (typically from the order of the recurrence to infinity).

  3. Rewrite each sum in terms of G(x)G(x) using shift properties. The most important ones:

    • n=1an1xn=xG(x)\sum_{n=1}^{\infty} a_{n-1} x^n = x \cdot G(x)
    • n=2an2xn=x2G(x)\sum_{n=2}^{\infty} a_{n-2} x^n = x^2 \cdot G(x)
    • More generally, shifting by kk introduces a factor of xkx^k.
  4. Incorporate initial conditions. When the summation range doesn't start at n=0n=0, you'll need to peel off the first few terms and substitute the known initial values.

  5. Solve the resulting algebraic equation for G(x)G(x).

Worked example: Fibonacci sequence

The Fibonacci recurrence is Fn=Fn1+Fn2F_n = F_{n-1} + F_{n-2} with F0=0F_0 = 0, F1=1F_1 = 1.

  1. Define G(x)=n=0FnxnG(x) = \sum_{n=0}^{\infty} F_n x^n.
  2. Multiply the recurrence by xnx^n and sum from n=2n=2 to \infty:

n=2Fnxn=n=2Fn1xn+n=2Fn2xn\sum_{n=2}^{\infty} F_n x^n = \sum_{n=2}^{\infty} F_{n-1} x^n + \sum_{n=2}^{\infty} F_{n-2} x^n

  1. Rewrite each side. The left side is G(x)F0F1x=G(x)xG(x) - F_0 - F_1 x = G(x) - x. The right side is x(G(x)F0)+x2G(x)=xG(x)+x2G(x)x(G(x) - F_0) + x^2 G(x) = xG(x) + x^2 G(x).

  2. So: G(x)x=xG(x)+x2G(x)G(x) - x = xG(x) + x^2 G(x).

  3. Solve for G(x)G(x):

G(x)(1xx2)=xG(x)=x1xx2G(x)(1 - x - x^2) = x \quad \Longrightarrow \quad G(x) = \frac{x}{1 - x - x^2}

This is the generating function for the Fibonacci numbers. The next step is extracting a closed form from it.

Definition and properties, Generating function - Wikipedia, the free encyclopedia

Another example: an=3an12an2a_n = 3a_{n-1} - 2a_{n-2}, a0=1a_0 = 1, a1=2a_1 = 2

Following the same steps, you'd arrive at:

G(x)=1x13x+2x2G(x) = \frac{1 - x}{1 - 3x + 2x^2}

The denominator factors as (1x)(12x)(1 - x)(1 - 2x), which sets up nicely for partial fractions.

Manipulating generating functions

Algebraic operations on generating functions

Once you have a generating function, algebraic operations on G(x)G(x) correspond to specific operations on the underlying sequence:

  • Addition/Subtraction: If A(x)A(x) encodes {an}\{a_n\} and B(x)B(x) encodes {bn}\{b_n\}, then A(x)+B(x)A(x) + B(x) encodes {an+bn}\{a_n + b_n\}. Term-by-term.
  • Multiplication by xkx^k: Shifts the sequence by kk positions (prepends kk zeros).
  • Multiplication of two generating functions: Produces the convolution of the two sequences. The coefficient of xnx^n in A(x)B(x)A(x) \cdot B(x) is k=0nakbnk\sum_{k=0}^{n} a_k b_{n-k}.
  • Differentiation: G(x)=n=1nanxn1G'(x) = \sum_{n=1}^{\infty} n \cdot a_n x^{n-1}, so xG(x)=n=0nanxnxG'(x) = \sum_{n=0}^{\infty} n \cdot a_n x^n. Differentiation effectively multiplies the nnth coefficient by nn.
  • Integration: 0xG(t)dt=n=0ann+1xn+1\int_0^x G(t)\,dt = \sum_{n=0}^{\infty} \frac{a_n}{n+1} x^{n+1}, which divides each coefficient by n+1n+1 and shifts the sequence.

Useful identities to recognize

  • 1(1x)k=n=0(n+k1k1)xn\frac{1}{(1-x)^k} = \sum_{n=0}^{\infty} \binom{n+k-1}{k-1} x^n
  • 114x=n=0(2nn)xn\frac{1}{\sqrt{1-4x}} = \sum_{n=0}^{\infty} \binom{2n}{n} x^n (the central binomial coefficients)
  • The generating function for Catalan numbers: C(x)=114x2xC(x) = \frac{1 - \sqrt{1-4x}}{2x}

Recognizing when your G(x)G(x) matches one of these forms lets you read off the coefficients directly.

Extracting coefficients from generating functions

Getting G(x)G(x) is only half the job. You still need to pull out ana_n, the coefficient of xnx^n.

Definition and properties, Recurrence relation - Wikipedia, the free encyclopedia

Methods for coefficient extraction

Direct expansion. If G(x)G(x) is a known generating function (like 1(1x)k\frac{1}{(1-x)^k}), you can read off the coefficients using the corresponding formula.

Partial fraction decomposition. This is the most common method for rational generating functions (where G(x)G(x) is a ratio of polynomials). You decompose G(x)G(x) into simpler fractions, each of which corresponds to a recognizable series. See the next section for details.

Binomial series expansion. For generating functions involving fractional or negative exponents, use the generalized binomial theorem:

$$$(1+x)^\alpha = \sum_{n=0}^{\infty} \binom{\alpha}{n} x^n$$

where (αn)=α(α1)(αn+1)n!\binom{\alpha}{n} = \frac{\alpha(\alpha-1)\cdots(\alpha-n+1)}{n!}.

For example, extracting the coefficient of xnx^n from 114x=(14x)1/2\frac{1}{\sqrt{1-4x}} = (1-4x)^{-1/2} gives (2nn)\binom{2n}{n}.

Taylor expansion. When other methods don't apply cleanly, you can compute derivatives: an=G(n)(0)n!a_n = \frac{G^{(n)}(0)}{n!}. This is rarely practical for finding a general closed form, but it's useful for computing specific terms.

Partial fraction decomposition for recurrence relations

Partial fractions are the workhorse for extracting closed-form solutions from rational generating functions. If G(x)G(x) is a ratio of polynomials and the degree of the numerator is less than the degree of the denominator, you can decompose it.

The method

  1. Factor the denominator of G(x)G(x) completely.
  2. Write the partial fraction form. For distinct linear factors (1rix)(1 - r_i x), write:

G(x)=A11r1x+A21r2x+G(x) = \frac{A_1}{1 - r_1 x} + \frac{A_2}{1 - r_2 x} + \cdots

  1. Solve for the constants A1,A2,A_1, A_2, \ldots by clearing denominators and comparing coefficients (or plugging in convenient values of xx).

  2. Expand each fraction as a geometric series: Ai1rix=n=0Airinxn\frac{A_i}{1 - r_i x} = \sum_{n=0}^{\infty} A_i r_i^n x^n.

  3. Read off the closed form: an=A1r1n+A2r2n+a_n = A_1 r_1^n + A_2 r_2^n + \cdots

  4. Verify by checking the initial conditions and substituting back into the recurrence.

Special cases

  • Repeated roots. If the denominator has a factor (1rx)m(1 - rx)^m, the decomposition includes terms A11rx+A2(1rx)2++Am(1rx)m\frac{A_1}{1 - rx} + \frac{A_2}{(1 - rx)^2} + \cdots + \frac{A_m}{(1 - rx)^m}. The expansion of 1(1rx)m\frac{1}{(1-rx)^m} involves (n+m1m1)rn\binom{n+m-1}{m-1} r^n, so the closed form will include polynomial factors multiplied by rnr^n.
  • Complex conjugate roots. These arise from irreducible quadratic factors. The resulting terms can be rewritten using trigonometric functions (sines and cosines with specific amplitudes and phases), though this is less common in introductory problems.

Worked example: an=5an16an2a_n = 5a_{n-1} - 6a_{n-2}, a0=0a_0 = 0, a1=1a_1 = 1

  1. Deriving the generating function (following the earlier process) gives:

G(x)=x15x+6x2G(x) = \frac{x}{1 - 5x + 6x^2}

  1. Factor the denominator: 15x+6x2=(12x)(13x)1 - 5x + 6x^2 = (1 - 2x)(1 - 3x).

  2. Decompose:

x(12x)(13x)=A12x+B13x\frac{x}{(1-2x)(1-3x)} = \frac{A}{1-2x} + \frac{B}{1-3x}

Clearing denominators: x=A(13x)+B(12x)x = A(1-3x) + B(1-2x).

Setting x=12x = \frac{1}{2}: 12=A12\frac{1}{2} = A \cdot \frac{-1}{2}, so A=1A = -1.

Setting x=13x = \frac{1}{3}: 13=B13\frac{1}{3} = B \cdot \frac{1}{3}, so B=1B = 1.

  1. So G(x)=112x+113xG(x) = \frac{-1}{1-2x} + \frac{1}{1-3x}, and expanding:

an=2n+3n=3n2na_n = -2^n + 3^n = 3^n - 2^n

  1. Check: a0=11=0a_0 = 1 - 1 = 0 ✓, a1=32=1a_1 = 3 - 2 = 1 ✓, a2=94=5=5(1)6(0)=5a_2 = 9 - 4 = 5 = 5(1) - 6(0) = 5 ✓.

This same approach works for any linear recurrence with constant coefficients, as long as you can factor the denominator. The generating function method and the characteristic equation method will always give the same answer, but generating functions generalize more easily to non-constant-coefficient and non-homogeneous recurrences.