Recurrence Relation-Substitution Method
Recurrence Relation-Substitution Method
Recursion is a method to solve a problem where the solution depends on solutions to smaller
subproblems of the same problem. Recursive functions (function calling itself) are used to solve
problems based on Recursion. The main challenge with recursion is to find the time complexity of
the Recursive function. In this article, we will learn about how to find the time complexity of
Recursive functions using Substitution Method.
Whenever any function makes a recursive call to itself, its time can be computed by a Recurrence
Relation. Recurrence Relation is simply a mathematical relation/equation that can give the value of
any term in terms of some previous smaller terms. For example,
T(n) = T(n-1) + N
It is a recurrence relation because the value of the nth term is given in its previous term i.e (n-1)the
term.
There are different types of recurrence relation that can be possible in the mathematical world.
Some of them are-
1. Linear Recurrence Relation: In case of Linear Recurrence Relation every term is dependent
linearly on its previous term. Example of Linear Recurrence Relation can be
2. Divide and Conquer Recurrence Relation: It the type of Recurrence Relation which is obtained
from Divide and Conquer Algorithm. Example of such recurrence relation can be
T(n) = 3T(n/2) + 9n
3. First Order Recurrence Relation: It is the type of recurrence relation in which every term is
dependent on just previous term. Example of this type of recurrence relation can be-
T(n) = T(n-1)2
(4) Higher Order Recurrence Relation- It is the type of recurrence relation where one term is not only
dependent on just one previous term but on multiple previous terms. If it will be dependent on two
previous term then it will be called to be second order. Similarly, for three previous term its will be
called to be of third order and so on. Let us see example of an third order Recurrence relation
Substitution Method
Master Theorem
Substitution Method:
Substitution Method is very famous method for solving any recurrences. There are two types of
substitution methods-
1. Forward Substitution
1. Backward Substitution
1. Forward Substitution:
It is called Forward Substitution because here we substitute recurrence of any term into next terms.
It uses following steps to find Time using recurrences-
Put the value from previous recurrence into the next recurrence
Now we will use these steps to solve a problem. The problem is-
T(n) = 1, n=1
2. Put the value from previous recurrence into the next recurrence:
2. Backward Substitution:
It is called Backward Substitution because here we substitute recurrence of any term into previous
terms. It uses following steps to find Time using recurrences-
Take the main recurrence and try to write recurrences of previous terms
Again take one more previous recurrence and substitute into main recurrence
After this substitute the the value from initial condition and get the solution
Now we will use these steps to solve a problem. The problem is-
1. Take the main recurrence and try to write recurrences of previous terms:
3. 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
The Substitution method is a useful technique to solve recurrence relations, but it also has some
limitations. Some of the limitations are:
It is not guaranteed that we will find the solution as substitution method is based on
guesses.
It doesn't provide guidance on how to make an accurate guess, often relying on intuition or
trial and error.
It may only yield a specific or approximate solution rather than the most general or precise
one.
The substitution method isn't universally applicable to all recurrence relations, especially
those with complex or variable forms that do not get simplified using substitution.