Definition
A recurrence relation defines a sequence where each term is expressed as a function of previous terms.
an=f(an−1,an−2,…,an−k)
with initial conditions specifying a0,a1,…,ak−1.
Famous Examples
Fibonacci Sequence
Fn=Fn−1+Fn−2,F0=0,F1=1
Sequence: 0,1,1,2,3,5,8,13,21,34,…
Tower of Hanoi
Tn=2Tn−1+1,T1=1
Minimum moves to transfer n disks: Tn=2n−1
Factorial
n!=n⋅(n−1)!,0!=1
Linear Homogeneous Recurrences
Constant Coefficients
an=c1an−1+c2an−2+⋯+ckan−k
Characteristic Equation
Replace an with rn:
rn=c1rn−1+c2rn−2+⋯+ckrn−k
Divide by rn−k:
rk−c1rk−1−c2rk−2−⋯−ck=0
Solutions
Distinct roots r1,r2,…,rk:
an=α1r1n+α2r2n+⋯+αkrkn
Repeated root r with multiplicity m:
(α1+α2n+α3n2+⋯+αmnm−1)rn
Use initial conditions to solve for α values.
Second-Order Examples
Example 1: Fibonacci
Fn=Fn−1+Fn−2
Characteristic equation: r2−r−1=0
Roots: r=21±5
Let ϕ=21+5 (golden ratio) and ϕ^=21−5
General solution: Fn=α1ϕn+α2ϕ^n
Using F0=0,F1=1:
Fn=5ϕn−ϕ^n=51[(21+5)n−(21−5)n]
Example 2: Repeated Roots
an=4an−1−4an−2,a0=1,a1=4
Characteristic equation: r2−4r+4=0
Root: r=2 (multiplicity 2)
General solution: an=(α1+α2n)2n
Using initial conditions:
- a0=1: α1=1
- a1=4: (α1+α2)⋅2=4⇒α2=1
Solution: an=(1+n)2n
Non-Homogeneous Recurrences
Form: an=c1an−1+⋯+ckan−k+f(n)
Method: Particular + Homogeneous
- Find general solution to homogeneous part: an(h)
- Find one particular solution: an(p)
- General solution: an=an(h)+an(p)
Finding Particular Solutions
| f(n) | Try |
|---|
| Constant c | an(p)=A |
| Polynomial nd | an(p)=Adnd+⋯+A0 |
| Exponential sn | an(p)=Asn |
If the trial solution is already part of the homogeneous solution, multiply by n.
Example
an=2an−1+3n,a0=1
Homogeneous solution: an(h)=α⋅2n
Particular solution: Try an(p)=A⋅3n
Substituting: A⋅3n=2A⋅3n−1+3n
A=32A+1⇒A=3
General solution: an=α⋅2n+3⋅3n
Using a0=1: α+3=1⇒α=−2
Solution: an=−2⋅2n+3n+1=3n+1−2n+1
Divide and Conquer Recurrences
Master Theorem
For T(n)=aT(n/b)+f(n) where a≥1, b>1:
Let c=logba. Compare f(n) to nc:
- If f(n)=O(nc−ϵ) for some ϵ>0: T(n)=Θ(nc)
- If f(n)=Θ(nc): T(n)=Θ(nclogn)
- If f(n)=Ω(nc+ϵ) and regularity condition: T(n)=Θ(f(n))
Common Examples
| Recurrence | Solution |
|---|
| T(n)=T(n/2)+O(1) | O(logn) (binary search) |
| T(n)=2T(n/2)+O(n) | O(nlogn) (merge sort) |
| T(n)=2T(n/2)+O(1) | O(n) (tree traversal) |
| T(n)=T(n/2)+O(n) | O(n) |
Generating Functions
Define G(x)=∑n=0∞anxn
Recurrence becomes an algebraic equation in G(x).
Example: For an=2an−1+1, a0=0:
G(x)=2xG(x)+1−x1
G(x)=(1−x)(1−2x)1
Expand using partial fractions to find an.