Skip to content

Recurrence Relations

6.1 Definition

A recurrence relation defines a sequence {an}\{a_n\} by expressing ana_n in terms of previous terms.

Example. Fibonacci: Fn=Fn1+Fn2F_n = F_{n-1} + F_{n-2}With F0=0F_0 = 0, F1=1F_1 = 1.

6.2 Linear Homogeneous Recurrences with Constant Coefficients

an+c1an1++ckank=0a_n + c_1 a_{n-1} + \cdots + c_k a_{n-k} = 0

Solution method. Form the characteristic equation:

rk+c1rk1++ck=0r^k + c_1 r^{k-1} + \cdots + c_k = 0

Case 1 (distinct roots). If r1,,rkr_1, \ldots, r_k are distinct, then an=A1r1n++Akrkna_n = A_1 r_1^n + \cdots + A_k r_k^n.

Case 2 (repeated roots). If rr has multiplicity mmThe contribution is (A1+A2n++Amnm1)rn(A_1 + A_2 n + \cdots + A_m n^{m-1}) r^n.

6.3 Worked Example

Problem. Solve an=5an16an2a_n = 5a_{n-1} - 6a_{n-2} with a0=1a_0 = 1, a1=4a_1 = 4.

Solution. Characteristic equation: r25r+6=0r^2 - 5r + 6 = 0Giving r1=2r_1 = 2, r2=3r_2 = 3.

an=A2n+B3na_n = A \cdot 2^n + B \cdot 3^n.

From initial conditions: a0=A+B=1a_0 = A + B = 1 a1=2A+3B=4a_1 = 2A + 3B = 4

Solving: B=2B = 2, A=1A = -1. So an=2n+23n=23n2na_n = -2^n + 2 \cdot 3^n = 2 \cdot 3^n - 2^n. \blacksquare

Worked Example. Solve an=4an14an2a_n = 4a_{n-1} - 4a_{n-2} with a0=1a_0 = 1, a1=6a_1 = 6.

Solution

Characteristic equation: r24r+4=0r^2 - 4r + 4 = 0So (r2)2=0(r - 2)^2 = 0. Root r=2r = 2 with multiplicity 2.

an=(A+Bn)2na_n = (A + Bn) \cdot 2^n.

From initial conditions: a0=A=1a_0 = A = 1 a1=(1+B)2=6    B=2a_1 = (1 + B) \cdot 2 = 6 \implies B = 2

So an=(1+2n)2na_n = (1 + 2n) \cdot 2^n. \blacksquare

6.4 Generating Functions

The generating function of a sequence {an}\{a_n\} is

G(x)=n=0anxnG(x) = \sum_{n=0}^{\infty} a_n x^n

Example. The generating function for an=1a_n = 1 (all ones) is G(x)=1/(1x)G(x) = 1/(1-x).

Example. The generating function for an=rna_n = r^n is G(x)=1/(1rx)G(x) = 1/(1 - rx).

Generating functions can solve recurrences by converting them to algebraic equations in G(x)G(x) Then extracting coefficients.

Worked Example. Use generating functions to solve the Fibonacci recurrence Fn=Fn1+Fn2F_n = F_{n-1} + F_{n-2} With F0=0F_0 = 0, F1=1F_1 = 1.

Solution

Let G(x)=n=0FnxnG(x) = \sum_{n=0}^{\infty} F_n x^n.

G(x)=x+n=2(Fn1+Fn2)xn=x+x(G(x)F0)+x2G(x)=x+xG(x)+x2G(x)G(x) = x + \sum_{n=2}^{\infty} (F_{n-1} + F_{n-2}) x^n = x + x(G(x) - F_0) + x^2 G(x) = x + xG(x) + x^2 G(x)

G(x)(1xx2)=x    G(x)=x1xx2G(x)(1 - x - x^2) = x \implies G(x) = \frac{x}{1 - x - x^2}

Factor: 1xx2=(1αx)(1βx)1 - x - x^2 = (1 - \alpha x)(1 - \beta x) where α=(1+5)/2\alpha = (1 + \sqrt{5})/2 and β=(15)/2\beta = (1 - \sqrt{5})/2.

Partial fractions give G(x)=15(11αx11βx)G(x) = \frac{1}{\sqrt{5}} \left(\frac{1}{1 - \alpha x} - \frac{1}{1 - \beta x}\right) So Fn=15(αnβn)F_n = \frac{1}{\sqrt{5}}(\alpha^n - \beta^n) (Binet”s formula). \blacksquare

Worked Example. Use generating functions to solve an=2an1+1a_n = 2a_{n-1} + 1 with a0=0a_0 = 0.

Solution

Let G(x)=n=0anxnG(x) = \sum_{n=0}^{\infty} a_n x^n.

G(x)=n=1(2an1+1)xn=2xG(x)+n=1xn=2xG(x)+x1xG(x) = \sum_{n=1}^{\infty} (2a_{n-1} + 1) x^n = 2x G(x) + \sum_{n=1}^{\infty} x^n = 2x G(x) + \frac{x}{1-x}

(12x)G(x)=x1x    G(x)=x(1x)(12x)(1 - 2x) G(x) = \frac{x}{1-x} \implies G(x) = \frac{x}{(1-x)(1-2x)}

Partial fractions: x(1x)(12x)=A1x+B12x\frac{x}{(1-x)(1-2x)} = \frac{A}{1-x} + \frac{B}{1-2x}.

x=A(12x)+B(1x)x = A(1-2x) + B(1-x). Setting x=0x = 0: A+B=0A + B = 0So B=AB = -A. Setting x=1x = 1: 1=A1 = -ASo A=1A = -1, B=1B = 1.

G(x)=112x11xG(x) = \frac{1}{1-2x} - \frac{1}{1-x}Giving an=2n1a_n = 2^n - 1. \blacksquare

:::caution Common Pitfall Generating functions are formal power series; they may not converge for any x0x \neq 0. Convergence Is irrelevant for combinatorial applications — the series is manipulated algebraically.

6.5 The Master Theorem

The Master Theorem provides asymptotic solutions to recurrences of the form

T(n)=aT(n/b)+f(n)T(n) = a\,T(n/b) + f(n)

Where a1a \geq 1, b>1b \gt 1 are constants and f(n)f(n) is asymptotically positive. Define c_{\mathrm{crit{}} = \log_b a (the critical exponent).

Theorem 6.1 (Master Theorem). Let T(n)T(n) be defined as above.

Case 1: If f(n)=O(nc)f(n) = O(n^c) for some c \lt c_{\mathrm{crit{}}Then T(n) = \Theta(n^{c_{\mathrm{crit{}}}).

Case 2: If f(n) = \Theta(n^{c_{\mathrm{crit{}}} \log^k n) for some k0k \geq 0Then T(n) = \Theta(n^{c_{\mathrm{crit{}}} \log^{k+1} n).

Case 3: If f(n)=Ω(nc)f(n) = \Omega(n^c) for some c \gt c_{\mathrm{crit{}}And af(n/b)δf(n)a\,f(n/b) \leq \delta\, f(n) For some δ<1\delta \lt 1 and sufficiently large nn (the regularity condition), then T(n)=Θ(f(n))T(n) = \Theta(f(n)).

Worked Example. Solve T(n)=3T(n/2)+n2T(n) = 3T(n/2) + n^2.

Solution

a=3a = 3, b=2b = 2, f(n)=n2f(n) = n^2. Critical exponent: c_{\mathrm{crit{}} = \log_2 3 \approx 1.585.

Since f(n)=n2=Ω(nc)f(n) = n^2 = \Omega(n^c) for any c<2c \lt 2And 2 \gt 1.585 = c_{\mathrm{crit{}}We are in Case 3 (provided the regularity condition holds). Check: 3(n/2)2=3n2/4=0.75n2δn23 \cdot (n/2)^2 = 3n^2/4 = 0.75\, n^2 \leq \delta\, n^2 For δ=0.75<1\delta = 0.75 \lt 1. ✓

Therefore T(n)=Θ(n2)T(n) = \Theta(n^2).

Worked Example. Solve T(n)=2T(n/2)+nT(n) = 2T(n/2) + n.

Solution

a=2a = 2, b=2b = 2, f(n)=nf(n) = n. Critical exponent: c_{\mathrm{crit{}} = \log_2 2 = 1.

f(n)=n=Θ(n1log0n)f(n) = n = \Theta(n^1 \log^0 n)So we are in Case 2 with k=0k = 0.

Therefore T(n)=Θ(nlogn)T(n) = \Theta(n \log n).

Worked Example. Solve T(n)=4T(n/2)+nT(n) = 4T(n/2) + n.

Solution

a=4a = 4, b=2b = 2, f(n)=nf(n) = n. Critical exponent: c_{\mathrm{crit{}} = \log_2 4 = 2.

f(n)=n=O(nc)f(n) = n = O(n^c) for any c>0c \gt 0 with c<2c \lt 2So we are in Case 1.

Therefore T(n)=Θ(n2)T(n) = \Theta(n^2).

Proof sketch of the Master Theorem. Expand the recurrence tree. At level jj (root is level 0), There are aja^j subproblems, each of size n/bjn/b^jEach contributing f(n/bj)f(n/b^j) work. The tree has logbn\log_b n levels, with a^{\log_b n} = n^{c_{\mathrm{crit{}}} leaves. The total work is

T(n) = \Theta\!\left(n^{c_{\mathrm{crit}}\right) + \sum_{j=0}^{\log_b n - 1} a^j \, f(n/b^j)}

  • Case 1: f(n)=O(nc)f(n) = O(n^c) with c \lt c_{\mathrm{crit{}}. The sum is dominated by the leaves, giving T(n) = \Theta(n^{c_{\mathrm{crit{}}}).
  • Case 2: f(n) = \Theta(n^{c_{\mathrm{crit{}}} \log^k n). Each level contributes the same order, with logbn\log_b n levels, giving T(n) = \Theta(n^{c_{\mathrm{crit{}}} \log^{k+1} n).
  • Case 3: f(n)=Ω(nc)f(n) = \Omega(n^c) with c \gt c_{\mathrm{crit{}}. The root level dominates, giving T(n)=Θ(f(n))T(n) = \Theta(f(n)). The regularity condition af(n/b)δf(n)a\,f(n/b) \leq \delta\,f(n) ensures the root dominates all levels below. The Master Theorem does not apply to recurrences like T(n)=T(n1)+nT(n) = T(n-1) + n (not of the form aT(n/b)+f(n)a\,T(n/b) + f(n)). Also, if f(n)f(n) falls between cases (e.g., f(n)=nlognf(n) = n \log n with c_{\mathrm{crit{}} = 1), the Master Theorem does not apply and the Akra—Bazzi method should be used Instead. :::