01 / 20

Linear Recurrences
Iteration & Expansion

Master the technique of unrolling recurrence relations step by step to discover closed-form solutions.

Discrete Math

What Is a Recurrence Relation?

A recurrence relation defines each term of a sequence using previous terms. Instead of a direct formula, you get a recursive rule plus an initial condition.

Our goal: convert this recursive definition into a closed-form formula that computes \( T(n) \) directly for any \( n \).

Why Use Iteration?

Intuitive
You literally "unroll" the recursion, substituting repeatedly until a pattern emerges.
General
Works on first-order linear recurrences whether homogeneous or non-homogeneous.
Foundation
Builds intuition for advanced methods like characteristic equations and generating functions.

Visualising the Unrolling Process

EXPAND STEP BY STEP
\( T(n) = T(n-1) + 5 \)
\( = [T(n-2) + 5] + 5 \)
\( = T(n-2)+2 \cdot 5 \)
\( = T(n-3) + 3 \cdot 5 \)
. . .
\( = T(0) + n \cdot 5 = 2 + 5n \)
Closed-form solution!

The General Form

A first-order linear recurrence has the form:

$$ T(n) = a \cdot T(n-1) + f(n) $$
\( a \)
The multiplicative constant: how the previous term is scaled.
\( f(n) \)
The non-homogeneous part: what is added at each step (could be constant, \( n \), etc.).
\( T(0) \)
The initial condition: the starting value that anchors the sequence.

Expansion When \( a = 1 \)

If \( T(n) = T(n-1) + f(n) \), expanding gives:

$$ T(n) = T(0) + \sum_{k=1}^{n} f(k) $$
\( T(n) = T(n-1) + f(n) \)
\( = [T(n-2) + f(n-1)] + f(n) \)
\( = T(n-2) + f(n-1) + f(n) \)
\( \vdots \)
\( = T(0) + f(1) + f(2) + \cdots + f(n) \)

Expansion When \( a \neq 1 \)

If \( T(n) = a \cdot T(n-1) + f(n) \), each substitution multiplies earlier \( f \)-terms by extra factors of \( a \):

$$ T(n) = a^n \cdot T(0) + \sum_{k=1}^{n} a^{n-k}\, f(k) $$
\( T(n) = a\,T(n-1) + f(n) \)
\( = a[a\,T(n-2) + f(n-1)] + f(n) \)
\( = a^2\,T(n-2) + a\,f(n-1) + f(n) \)
\( \vdots \)
\( = a^n\,T(0) + a^{n-1}f(1) + a^{n-2}f(2) + \cdots + f(n) \)

Homogeneous vs. Non-Homogeneous

Homogeneous Non-Homogeneous
Form \( T(n) = a\,T(n-1) \) \( T(n) = a\,T(n-1) + f(n) \)
\( f(n) \) 0 (nothing added) Non-zero driving term
Expansion result \( a^n \cdot T(0) \) \( a^n T(0) + \displaystyle\sum a^{n-k}f(k) \)
Difficulty Straightforward Requires evaluating the sum

How to Apply Iteration

1
Write the recurrence and initial condition. Identify \( a \), \( f(n) \), and \( T(0) \).
2
Substitute repeatedly. Replace \( T(n-1) \) with its definition, then \( T(n-2) \), etc.
3
Spot the pattern. After 2-3 expansions, write the general \( k \)-th expansion step.
4
Set \( k = n \) to reach the base case. This grounds the recursion at \( T(0) \).
5
Evaluate the resulting sum. Use arithmetic or geometric series formulas to simplify.

Example 1: Constant Additive

\( T(n) = T(n-1) + 3 \)
\( = [T(n-2) + 3] + 3 = T(n-2) + 2 \cdot 3 \)
\( = T(n-3) + 3 \cdot 3 \)
\( \vdots \)
\( = T(0) + n \cdot 3 \)
\( = 7 + 3n \)

Example 2: Geometric Growth

\( T(n) = 2\,T(n-1) + 1 \)
\( = 2[2\,T(n-2) + 1] + 1 = 4\,T(n-2) + 2 + 1 \)
\( = 2^k\,T(n-k) + \displaystyle\sum_{i=0}^{k-1} 2^i \)
Set \( k = n \): \( = 2^n \cdot T(0) + \displaystyle\sum_{i=0}^{n-1} 2^i \)
\( = 0 + (2^n - 1) = 2^n - 1 \)

Example 3: Variable Driving Term

\( T(n) = T(n-1) + n \)
\( = T(n-2) + (n-1) + n \)
\( = T(n-3) + (n-2) + (n-1) + n \)
\( \vdots \)
\( = T(0) + 1 + 2 + \cdots + n \)
\( = \dfrac{n(n+1)}{2} \)

Example 4: Scaling + Linear Term

\( T(n) = 3\,T(n-1) + 2 \)
\( = 3[3\,T(n-2) + 2] + 2 = 3^2\,T(n-2) + 2 \cdot 3 + 2 \)
\( = 3^k\,T(n-k) + 2\displaystyle\sum_{i=0}^{k-1}3^i \)
Set \( k = n \): \( = 3^n \cdot 1 + 2 \cdot \dfrac{3^n - 1}{3 - 1} \)
\( = 3^n + (3^n - 1) = 2 \cdot 3^n - 1 \)

The Expansion Blueprint

When \( a = 1 \)
\( T(n) = T(n-1) + f(n) \)
Expand \(n\) times:
\( T(0) + \sum_{k=1}^{n} f(k) \)
When \( a \neq 1 \)
\( T(n) = a \cdot T(n-1) + f(n) \)
Expand \(n\) times:
\( a^n T(0) + \sum_{k=1}^{n} a^{n-k} f(k) \)
Common Special Cases
\( f(n) = c \) (constant)
Sum = \( c \cdot n \)
\( f(n) = n \)
Sum = \( \frac{n(n+1)}{2} \)
\( a \neq 1, f(n) = c \)
Sum = \( c \frac{a^n-1}{a-1} \)
Always verify by plugging small values back into the original recurrence.

Common Mistakes

✕ Forgetting the Base Case
Writing only the sum but omitting \( a^n \cdot T(0) \). This shifts the entire solution by a constant or exponential term.
✕ Wrong Summation Bounds
Using \( k = 0 \) to \( n \) instead of \( k = 1 \) to \( n \), or vice versa. Always track which terms you've already peeled off.
✕ Missing Powers of \( a \)
When \( a \neq 1 \), each earlier \( f(k) \) picks up an extra factor of \( a \). Forgetting these turns a geometric sum into an arithmetic one.

Question 1 of 5

Solve by iteration: \( T(n) = T(n-1) + 4 \), \( T(0) = 5 \). What is \( T(n) \)?

Question 2 of 5

Solve: \( T(n) = 2\,T(n-1) \), \( T(0) = 3 \). What is \( T(n) \)?

Question 3 of 5

After expanding \( T(n) = 3\,T(n-1) + 5 \) with \( T(0) = 0 \), the sum you need to evaluate is:

Question 4 of 5

Solve: \( T(n) = T(n-1) + 2n \), \( T(0) = 1 \). What is \( T(n) \)?

Question 5 of 5

What value does \( T(5) \) equal for the recurrence \( T(n) = 2\,T(n-1) + 1 \), \( T(0) = 0 \)?