A recurrence relation defines a sequence { a n } \{a_n\} { a n } by expressing a n a_n a n in terms of previous terms.
Example. Fibonacci: F n = F n − 1 + F n − 2 F_n = F_{n-1} + F_{n-2} F n = F n − 1 + F n − 2 With F 0 = 0 F_0 = 0 F 0 = 0 , F 1 = 1 F_1 = 1 F 1 = 1 .
a n + c 1 a n − 1 + ⋯ + c k a n − k = 0 a_n + c_1 a_{n-1} + \cdots + c_k a_{n-k} = 0 a n + c 1 a n − 1 + ⋯ + c k a n − k = 0
Solution method. Form the characteristic equation :
r k + c 1 r k − 1 + ⋯ + c k = 0 r^k + c_1 r^{k-1} + \cdots + c_k = 0 r k + c 1 r k − 1 + ⋯ + c k = 0
Case 1 (distinct roots). If r 1 , … , r k r_1, \ldots, r_k r 1 , … , r k are distinct, then a n = A 1 r 1 n + ⋯ + A k r k n a_n = A_1 r_1^n + \cdots + A_k r_k^n a n = A 1 r 1 n + ⋯ + A k r k n .
Case 2 (repeated roots). If r r r has multiplicity m m m The contribution is ( A 1 + A 2 n + ⋯ + A m n m − 1 ) r n (A_1 + A_2 n + \cdots + A_m n^{m-1}) r^n ( A 1 + A 2 n + ⋯ + A m n m − 1 ) r n .
Problem. Solve a n = 5 a n − 1 − 6 a n − 2 a_n = 5a_{n-1} - 6a_{n-2} a n = 5 a n − 1 − 6 a n − 2 with a 0 = 1 a_0 = 1 a 0 = 1 , a 1 = 4 a_1 = 4 a 1 = 4 .
Solution. Characteristic equation: r 2 − 5 r + 6 = 0 r^2 - 5r + 6 = 0 r 2 − 5 r + 6 = 0 Giving r 1 = 2 r_1 = 2 r 1 = 2 , r 2 = 3 r_2 = 3 r 2 = 3 .
a n = A ⋅ 2 n + B ⋅ 3 n a_n = A \cdot 2^n + B \cdot 3^n a n = A ⋅ 2 n + B ⋅ 3 n .
From initial conditions: a 0 = A + B = 1 a_0 = A + B = 1 a 0 = A + B = 1 a 1 = 2 A + 3 B = 4 a_1 = 2A + 3B = 4 a 1 = 2 A + 3 B = 4
Solving: B = 2 B = 2 B = 2 , A = − 1 A = -1 A = − 1 . So a n = − 2 n + 2 ⋅ 3 n = 2 ⋅ 3 n − 2 n a_n = -2^n + 2 \cdot 3^n = 2 \cdot 3^n - 2^n a n = − 2 n + 2 ⋅ 3 n = 2 ⋅ 3 n − 2 n . ■ \blacksquare ■
Worked Example. Solve a n = 4 a n − 1 − 4 a n − 2 a_n = 4a_{n-1} - 4a_{n-2} a n = 4 a n − 1 − 4 a n − 2 with a 0 = 1 a_0 = 1 a 0 = 1 , a 1 = 6 a_1 = 6 a 1 = 6 .
Solution Characteristic equation: r 2 − 4 r + 4 = 0 r^2 - 4r + 4 = 0 r 2 − 4 r + 4 = 0 So ( r − 2 ) 2 = 0 (r - 2)^2 = 0 ( r − 2 ) 2 = 0 . Root r = 2 r = 2 r = 2 with multiplicity 2.
a n = ( A + B n ) ⋅ 2 n a_n = (A + Bn) \cdot 2^n a n = ( A + B n ) ⋅ 2 n .
From initial conditions: a 0 = A = 1 a_0 = A = 1 a 0 = A = 1 a 1 = ( 1 + B ) ⋅ 2 = 6 ⟹ B = 2 a_1 = (1 + B) \cdot 2 = 6 \implies B = 2 a 1 = ( 1 + B ) ⋅ 2 = 6 ⟹ B = 2
So a n = ( 1 + 2 n ) ⋅ 2 n a_n = (1 + 2n) \cdot 2^n a n = ( 1 + 2 n ) ⋅ 2 n . ■ \blacksquare ■
The generating function of a sequence { a n } \{a_n\} { a n } is
G ( x ) = ∑ n = 0 ∞ a n x n G(x) = \sum_{n=0}^{\infty} a_n x^n G ( x ) = ∑ n = 0 ∞ a n x n
Example. The generating function for a n = 1 a_n = 1 a n = 1 (all ones) is G ( x ) = 1 / ( 1 − x ) G(x) = 1/(1-x) G ( x ) = 1/ ( 1 − x ) .
Example. The generating function for a n = r n a_n = r^n a n = r n is G ( x ) = 1 / ( 1 − r x ) G(x) = 1/(1 - rx) G ( x ) = 1/ ( 1 − r x ) .
Generating functions can solve recurrences by converting them to algebraic equations in G ( x ) G(x) G ( x ) Then extracting coefficients.
Worked Example. Use generating functions to solve the Fibonacci recurrence F n = F n − 1 + F n − 2 F_n = F_{n-1} + F_{n-2} F n = F n − 1 + F n − 2 With F 0 = 0 F_0 = 0 F 0 = 0 , F 1 = 1 F_1 = 1 F 1 = 1 .
Solution Let G ( x ) = ∑ n = 0 ∞ F n x n G(x) = \sum_{n=0}^{\infty} F_n x^n G ( x ) = ∑ n = 0 ∞ F n x n .
G ( x ) = x + ∑ n = 2 ∞ ( F n − 1 + F n − 2 ) x n = x + x ( G ( x ) − F 0 ) + x 2 G ( x ) = x + x G ( x ) + x 2 G ( 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 ) = x + ∑ n = 2 ∞ ( F n − 1 + F n − 2 ) x n = x + x ( G ( x ) − F 0 ) + x 2 G ( x ) = x + x G ( x ) + x 2 G ( x )
G ( x ) ( 1 − x − x 2 ) = x ⟹ G ( x ) = x 1 − x − x 2 G(x)(1 - x - x^2) = x \implies G(x) = \frac{x}{1 - x - x^2} G ( x ) ( 1 − x − x 2 ) = x ⟹ G ( x ) = 1 − x − x 2 x
Factor: 1 − x − x 2 = ( 1 − α x ) ( 1 − β x ) 1 - x - x^2 = (1 - \alpha x)(1 - \beta x) 1 − x − x 2 = ( 1 − α x ) ( 1 − β x ) where α = ( 1 + 5 ) / 2 \alpha = (1 + \sqrt{5})/2 α = ( 1 + 5 ) /2 and β = ( 1 − 5 ) / 2 \beta = (1 - \sqrt{5})/2 β = ( 1 − 5 ) /2 .
Partial fractions give G ( x ) = 1 5 ( 1 1 − α x − 1 1 − β x ) G(x) = \frac{1}{\sqrt{5}} \left(\frac{1}{1 - \alpha x} - \frac{1}{1 - \beta x}\right) G ( x ) = 5 1 ( 1 − α x 1 − 1 − β x 1 ) So F n = 1 5 ( α n − β n ) F_n = \frac{1}{\sqrt{5}}(\alpha^n - \beta^n) F n = 5 1 ( α n − β n ) (Binet”s formula). ■ \blacksquare ■
Worked Example. Use generating functions to solve a n = 2 a n − 1 + 1 a_n = 2a_{n-1} + 1 a n = 2 a n − 1 + 1 with a 0 = 0 a_0 = 0 a 0 = 0 .
Solution Let G ( x ) = ∑ n = 0 ∞ a n x n G(x) = \sum_{n=0}^{\infty} a_n x^n G ( x ) = ∑ n = 0 ∞ a n x n .
G ( x ) = ∑ n = 1 ∞ ( 2 a n − 1 + 1 ) x n = 2 x G ( x ) + ∑ n = 1 ∞ x n = 2 x G ( x ) + x 1 − x G(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} G ( x ) = ∑ n = 1 ∞ ( 2 a n − 1 + 1 ) x n = 2 x G ( x ) + ∑ n = 1 ∞ x n = 2 x G ( x ) + 1 − x x
( 1 − 2 x ) G ( x ) = x 1 − x ⟹ G ( x ) = x ( 1 − x ) ( 1 − 2 x ) (1 - 2x) G(x) = \frac{x}{1-x} \implies G(x) = \frac{x}{(1-x)(1-2x)} ( 1 − 2 x ) G ( x ) = 1 − x x ⟹ G ( x ) = ( 1 − x ) ( 1 − 2 x ) x
Partial fractions: x ( 1 − x ) ( 1 − 2 x ) = A 1 − x + B 1 − 2 x \frac{x}{(1-x)(1-2x)} = \frac{A}{1-x} + \frac{B}{1-2x} ( 1 − x ) ( 1 − 2 x ) x = 1 − x A + 1 − 2 x B .
x = A ( 1 − 2 x ) + B ( 1 − x ) x = A(1-2x) + B(1-x) x = A ( 1 − 2 x ) + B ( 1 − x ) . Setting x = 0 x = 0 x = 0 : A + B = 0 A + B = 0 A + B = 0 So B = − A B = -A B = − A . Setting x = 1 x = 1 x = 1 : 1 = − A 1 = -A 1 = − A So A = − 1 A = -1 A = − 1 , B = 1 B = 1 B = 1 .
G ( x ) = 1 1 − 2 x − 1 1 − x G(x) = \frac{1}{1-2x} - \frac{1}{1-x} G ( x ) = 1 − 2 x 1 − 1 − x 1 Giving a n = 2 n − 1 a_n = 2^n - 1 a n = 2 n − 1 . ■ \blacksquare ■
Caution
any x ≠ 0 x \neq 0 x = 0 . Convergence Is irrelevant for combinatorial applications — the series is manipulated algebraically.
The Master Theorem provides asymptotic solutions to recurrences of the form
T ( n ) = a T ( n / b ) + f ( n ) T(n) = a\,T(n/b) + f(n) T ( n ) = a T ( n / b ) + f ( n )
Where a ≥ 1 a \geq 1 a ≥ 1 , b > 1 b \gt 1 b > 1 are constants and f ( n ) 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) T ( n ) be defined as above.
Case 1: If f ( n ) = O ( n c ) f(n) = O(n^c) 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 k ≥ 0 k \geq 0 k ≥ 0 Then T(n) = \Theta(n^{c_{\mathrm{crit{}}} \log^{k+1} n) .
Case 3: If f ( n ) = Ω ( n c ) f(n) = \Omega(n^c) f ( n ) = Ω ( n c ) for some c \gt c_{\mathrm{crit{}} And a f ( n / b ) ≤ δ f ( n ) a\,f(n/b) \leq \delta\, f(n) a f ( n / b ) ≤ δ f ( n ) For some δ < 1 \delta \lt 1 δ < 1 and sufficiently large n n n (the regularity condition ), then T ( n ) = Θ ( f ( n ) ) T(n) = \Theta(f(n)) T ( n ) = Θ ( f ( n )) .
Worked Example. Solve T ( n ) = 3 T ( n / 2 ) + n 2 T(n) = 3T(n/2) + n^2 T ( n ) = 3 T ( n /2 ) + n 2 .
Solution a = 3 a = 3 a = 3 , b = 2 b = 2 b = 2 , f ( n ) = n 2 f(n) = n^2 f ( n ) = n 2 . Critical exponent: c_{\mathrm{crit{}} = \log_2 3 \approx 1.585 .
Since f ( n ) = n 2 = Ω ( n c ) f(n) = n^2 = \Omega(n^c) f ( n ) = n 2 = Ω ( n c ) for any c < 2 c \lt 2 c < 2 And 2 \gt 1.585 = c_{\mathrm{crit{}} We are in Case 3 (provided the regularity condition holds). Check: 3 ⋅ ( n / 2 ) 2 = 3 n 2 / 4 = 0.75 n 2 ≤ δ n 2 3 \cdot (n/2)^2 = 3n^2/4 = 0.75\, n^2 \leq \delta\, n^2 3 ⋅ ( n /2 ) 2 = 3 n 2 /4 = 0.75 n 2 ≤ δ n 2 For δ = 0.75 < 1 \delta = 0.75 \lt 1 δ = 0.75 < 1 . ✓
Therefore T ( n ) = Θ ( n 2 ) T(n) = \Theta(n^2) T ( n ) = Θ ( n 2 ) .
Worked Example. Solve T ( n ) = 2 T ( n / 2 ) + n T(n) = 2T(n/2) + n T ( n ) = 2 T ( n /2 ) + n .
Solution a = 2 a = 2 a = 2 , b = 2 b = 2 b = 2 , f ( n ) = n f(n) = n f ( n ) = n . Critical exponent: c_{\mathrm{crit{}} = \log_2 2 = 1 .
f ( n ) = n = Θ ( n 1 log 0 n ) f(n) = n = \Theta(n^1 \log^0 n) f ( n ) = n = Θ ( n 1 log 0 n ) So we are in Case 2 with k = 0 k = 0 k = 0 .
Therefore T ( n ) = Θ ( n log n ) T(n) = \Theta(n \log n) T ( n ) = Θ ( n log n ) .
Worked Example. Solve T ( n ) = 4 T ( n / 2 ) + n T(n) = 4T(n/2) + n T ( n ) = 4 T ( n /2 ) + n .
Solution a = 4 a = 4 a = 4 , b = 2 b = 2 b = 2 , f ( n ) = n f(n) = n f ( n ) = n . Critical exponent: c_{\mathrm{crit{}} = \log_2 4 = 2 .
f ( n ) = n = O ( n c ) f(n) = n = O(n^c) f ( n ) = n = O ( n c ) for any c > 0 c \gt 0 c > 0 with c < 2 c \lt 2 c < 2 So we are in Case 1.
Therefore T ( n ) = Θ ( n 2 ) T(n) = \Theta(n^2) T ( n ) = Θ ( n 2 ) .
Proof sketch of the Master Theorem. Expand the recurrence tree. At level j j j (root is level 0), There are a j a^j a j subproblems, each of size n / b j n/b^j n / b j Each contributing f ( n / b j ) f(n/b^j) f ( n / b j ) work. The tree has log b n \log_b n 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 ( n c ) f(n) = O(n^c) 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 log b n \log_b n log b n levels, giving T(n) = \Theta(n^{c_{\mathrm{crit{}}} \log^{k+1} n) .Case 3: f ( n ) = Ω ( n c ) f(n) = \Omega(n^c) f ( n ) = Ω ( n c ) with c \gt c_{\mathrm{crit{}} . The root level dominates, giving T ( n ) = Θ ( f ( n ) ) T(n) = \Theta(f(n)) T ( n ) = Θ ( f ( n )) . The regularity condition a f ( n / b ) ≤ δ f ( n ) a\,f(n/b) \leq \delta\,f(n) a f ( n / b ) ≤ δ f ( n ) ensures the root dominates all levels below. The Master Theorem does not apply to recurrences like T ( n ) = T ( n − 1 ) + n T(n) = T(n-1) + n T ( n ) = T ( n − 1 ) + n (not of the form a T ( n / b ) + f ( n ) a\,T(n/b) + f(n) a T ( n / b ) + f ( n ) ). Also, if f ( n ) f(n) f ( n ) falls between cases (e.g., f ( n ) = n log n f(n) = n \log n f ( n ) = n log n with c_{\mathrm{crit{}} = 1 ), the Master Theorem does not apply and the Akra—Bazzi method should be used Instead. A[6_Recurrence Relations] --> B[Key Concepts]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
D --> G[Real-world usage]
Recurrence relations define sequences where each term depends on previous terms. They logically arise in divide-and-conquer algorithms (binary search: T(n) = T(n/2) + O(1)). Solving recurrences via substitution, recursion trees, or the Master theorem determines algorithm time complexity. Linear recurrences with constant coefficients have closed-form solutions using characteristic equations, connecting discrete math to continuous analysis.
Incorrect characteristic equation. For a recurrence a n + c 1 a n − 1 + ⋯ + c k a n − k = 0 a_n + c_1 a_{n-1} + \cdots + c_k a_{n-k} = 0 a n + c 1 a n − 1 + ⋯ + c k a n − k = 0 , the characteristic equation is r k + c 1 r k − 1 + ⋯ + c k = 0 r^k + c_1 r^{k-1} + \cdots + c_k = 0 r k + c 1 r k − 1 + ⋯ + c k = 0 . A common error is using the wrong signs on the coefficients. For a n = 5 a n − 1 − 6 a n − 2 a_n = 5a_{n-1} - 6a_{n-2} a n = 5 a n − 1 − 6 a n − 2 , the characteristic equation is r 2 − 5 r + 6 = 0 r^2 - 5r + 6 = 0 r 2 − 5 r + 6 = 0 , not r 2 + 5 r − 6 = 0 r^2 + 5r - 6 = 0 r 2 + 5 r − 6 = 0 .
Misapplying the Master Theorem. The Master Theorem does not apply to recurrences that are not of the form T ( n ) = a T ( n / b ) + f ( n ) T(n) = aT(n/b) + f(n) T ( n ) = a T ( n / b ) + f ( n ) . For example, T ( n ) = T ( n − 1 ) + n T(n) = T(n-1) + n T ( n ) = T ( n − 1 ) + n cannot be solved with the Master Theorem. Also, if f ( n ) f(n) f ( n ) falls between cases (e.g., f ( n ) = n log n f(n) = n \log n f ( n ) = n log n with critical exponent 1), the theorem does not apply.
Forgetting repeated roots. When the characteristic equation has a repeated root r r r with multiplicity m m m , the general solution includes terms ( A 1 + A 2 n + ⋯ + A m n m − 1 ) r n (A_1 + A_2 n + \cdots + A_m n^{m-1}) r^n ( A 1 + A 2 n + ⋯ + A m n m − 1 ) r n , not just A r n A r^n A r n . Students often omit the polynomial factor, leading to incorrect solutions for recurrences like a n = 4 a n − 1 − 4 a n − 2 a_n = 4a_{n-1} - 4a_{n-2} a n = 4 a n − 1 − 4 a n − 2 .
[[1-algorithms/algorithm-design]] - Divide-and-conquer recurrences
[[1-algorithms/complexity-theory]] - Complexity analysis
[[1-discrete-mathematics/4_combinatorics]] - Counting sequences
[[1-algorithms/data-structures]] - Recursive data structures
Discrete Mathematics
Algorithm Implementation