2. A recurrence relation is a mathematical
expression that defines a sequence in
terms of its previous terms.
General form of a Recurrence Relation:
where f is a function that defines the relationship between
the current term and the previous terms
3. Example Recurrence Relation
Fibonacci Sequence F(n) = F(n-1) + F(n-2)
Factorial of a number
n
F(n) = n * F(n-1)
Merge Sort T(n) = 2*T(n/2) + O(n)
Tower of Hanoi H(n) = 2*H(n-1) + 1
Binary Search T(n) = T(n/2) + 1
Examples of Recurrence Relations
4. Recursion & Recurrence Relations
•Recurrence Relation:
Defines T(n) in terms of earlier values
e.g., T(n) = T(n–1) + n.
•Recursion:
Solving a problem by reducing it to smaller
instances of the same problem.
5. Types of Recurrence Relations
• Linear – depends on previous terms
(e.g., T(n)=T(n–1)+T(n–2)+T(n–3))
• Divide & Conquer – splits input into parts
(e.g., T(n)=3T(n/2)+9n)
• First-Order – depends only on immediately preceding
term
(e.g., T(n)=2T(n–1)^2)
• Higher-Order – depends on multiple previous terms
(e.g., T(n)=2T(n–1)^2 + kT(n–2) + T(n–3))
6. 3 Methods for Solving Recurrences
1. Substitution (Forward & Backward)
2. Recursion Tree
3. Master Theorem
7. Forward Substitution – Steps
Pick recurrence and base case
Expand: express T(n–1), T(n–2)…
Observe the pattern
Guess the closed form
Prove via induction
8. Recurrence Problem:
T(n) = T(n-1) + n, n>1
T(n) = 1, n=1
1. Pick Recurrence and the given initial
Condition:
T(n)=T(n-1)+n, n>1 T(n)=1, n=1
2. Put the value from previous recurrence into the next
recurrence:
T(1) = 1T(2) = T(1) + 2 = 1 + 2 = 3T(3) = T(2) + 3 = 1 + 2 + 3 = 6T(4)= T(3) + 4 = 1 + 2 +
3 + 4 = 10
3. Observe and Guess the pattern and the time:
So guessed pattern will be-T(n) = 1 + 2 + 3 .... + n = (n * (n+1))/2Time Complexity will
be O(n2
)
9. 4. Prove that the guessed result is correct using mathematical Induction:
Prove T(1) is true:
T(1) = 1 * (1+1)/2 = 2/2 = 1 and from definition of recurrence we know T(1) = 1.
Hence proved T(1) is true
Assume T(N-1) to be true:
Assume T(N-1) = ((N - 1) * (N-1+1))/2 = (N * (N-1))/2 to be true
Then prove T(N) will be true:T(N) = T(N-1) + N from recurrence definition
Now, T(N-1) = N * (N-1)/2So, T(N) = T(N-1) + N = (N * (N-1))/2 + N = (N * (N-1) +
2N)/2 =N * (N+1)/2And from our guess also T(N)=N(N+1)/2
Hence T(N) is true.
Therefore our guess was correct and time will be O(N2
)
10. Backward Substitution – Steps
● Write T(n-1), T(n-2), … in terms of T(n)
● Substitute backwards until base case
● Sum up initial condition contributions
11. Recurrence Problem: T(n) = T(n-1) + n, n>1 T(n) = 1, n=1
1. Take the main recurrence and try to write recurrences of previous terms:
T(n) = T(n-1) + nT(n-1) = T(n-2) + n - 1T(n-2) = T(n-3) + n - 2
3. Again take one more previous recurrence and substitute into main recurrence
put T(n-2) into T(n)So, T(n)=T(n-3)+ n-2 + n-1 + n
2. Take just previous recurrence and substitute into main recurrence
put T(n-2) into T(n)So, T(n)=T(n-3)+ n-2 + n-1 + n
4. Again take one more previous recurrence and substitute into main recurrence
So similarly we can find T(n-3), T(n-4)......and so on and can insert into T(n).
Eventually we will get following: T(n)=T(1) + 2 + 3 + 4 +.........+ n-1 + n
5. After this substitute the the value from initial condition and get the solution
Put T(1)=1, T(n) = 1 +2 +3 + 4 +..............+ n-1 + n = n(n+1)/2.
So Time will be O(N2
)
12. Limitations of Substitution Method
• Requires guessing the correct form
• No systematic approach for selecting the guess
• May yield approximate rather than tight solutions
• Can be cumbersome for complex recurrences