Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Algorithms  >  Different Types of Recurrence Relations & Their Solutions

Different Types of Recurrence Relations & Their Solutions | Algorithms - Computer Science Engineering (CSE) PDF Download

Type 1: Divide and conquer recurrence relations

Following are some of the examples of recurrence relations based on divide and conquer.
T(n) = 2T(n / 2) + cn
T(n) = 2T(n / 2) + √n
These types of recurrence relations can be easily solved using Master Method.
For recurrence relation T(n) = 2T(n / 2) + cn, the values of a = 2, b = 2 and k =1. Here logb(a) = log2(2) = 1 = k. Therefore, the complexity will be Θ(nlog2(n)).
Similarly for recurrence relation T(n) = 2T(n/2) + √n, the values of a = 2, b = 2 and k =1/2.
Here logb(a) = log2(2) = 1 > k. Therefore, the complexity will be Θ(n).

Type 2: Linear recurrence relations

Following are some of the examples of recurrence relations based on linear recurrence relation.
T(n) = T(n - 1) + n for n > 0 and T(0) = 1
These types of recurrence relations can be easily solved using substitution method.
For example,
T(n) = T(n - 1) + n
       = T(n - 2) + (n - 1) + n
       = T(n - k) + (n - (k - 1))….. (n - 1) + n
Substituting k = n, we get
T(n) = T(0) + 1 + 2+….. +n = n(n + 1) / 2 = O(n2)

Type 3: Value substitution before solving

Sometimes, recurrence relations can’t be directly solved using techniques like substitution, recurrence tree or master method. Therefore, we need to convert the recurrence relation into appropriate form before solving. For example,
T(n) = T(√n) + 1
To solve this type of recurrence, substitute n = 2^m as:
T(2m) = T(2^m /2) + 1
Let T(2m) = S(m),
S(m) = S(m / 2) + 1
Solving by master method, we get
S(m) = Θ(logm)
As n = 2^m or m = log2(n),
T(n) = T(2^m) = S(m) = Θ(logm) = Θ(loglogn)

Let us discuss some questions based on the approaches discussed.
Q.1. What is the time complexity of Tower of Hanoi problem?
(a) T(n) = O(sqrt(n))
(b) T(n) = O(n2)
(c) T(n) = O(2n)
(d) None
Solution: For Tower of Hanoi, T(n) = 2T(n - 1) + c for n > 1 and T(1) = 1. Solving this,
T(n) = 2T(n - 1) + c
        = 2(2T(n - 2) + c) + c  = 2* T(n - 2) + (c + 2c)
       = 2k * T(n - k) + (c + 2c + .. kc)
Substituting k = (n - 1), we get
T(n) = 2(n - 1)*T(1) + (c + 2c + (n - 1)c) = O(2^n)

Q.2. Consider the following recurrence:
T(n) = 2 * T(ceil (sqrt(n) ) ) + 1, T(1) = 1
Which one of the following is true?
(a) T(n) = (loglogn)
(b) T(n) = (logn)
(c) T(n) = (sqrt(n))
(d) T(n) = (n)
Solution: To solve this type of recurrence, substitute n = 2m as:
T(2m) = 2T(2m / 2) + 1
Let T(2m) = S(m),
S(m) = 2S(m / 2) + 1
Solving by master method, we get
S(m) = Θ(m)
As n = 2m or m = log2n,
T(n) = T(2m) = S(m) = Θ(m) = Θ(logn)

The document Different Types of Recurrence Relations & Their Solutions | Algorithms - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Algorithms.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
81 videos|80 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Different Types of Recurrence Relations & Their Solutions - Algorithms - Computer Science Engineering (CSE)

1. What is a recurrence relation in computer science engineering?
Ans. A recurrence relation in computer science engineering is a mathematical equation that defines a sequence of values based on the previously calculated values. It is commonly used to model the time complexity of algorithms and analyze their efficiency.
2. What are the different types of recurrence relations?
Ans. There are several types of recurrence relations in computer science engineering, including linear recurrence relations, homogeneous recurrence relations, non-homogeneous recurrence relations, and divide-and-conquer recurrence relations.
3. How do we solve linear recurrence relations?
Ans. Linear recurrence relations can be solved using various methods, such as solving the characteristic equation, finding the roots of the equation, and using initial conditions to determine the coefficients of the equation. The solution can then be expressed as a linear combination of the roots.
4. How do we solve homogeneous recurrence relations?
Ans. Homogeneous recurrence relations can be solved by assuming a solution of the form xn = r^n, where r is a constant. The equation is then substituted into the recurrence relation, and the value of r is determined by solving the resulting characteristic equation. The general solution is expressed as a linear combination of the powers of r.
5. Can you provide an example of solving a divide-and-conquer recurrence relation?
Ans. Sure! Let's consider the recurrence relation for the merge sort algorithm: T(n) = 2T(n/2) + n. To solve this, we can use the master theorem, which states that if a recurrence relation is of the form T(n) = aT(n/b) + f(n), where a ≥ 1, b > 1, and f(n) is an asymptotically positive function, then the time complexity can be determined based on the value of f(n) and the relationship between a, b, and n. In this case, f(n) = n, a = 2, and b = 2. According to the master theorem, the time complexity of merge sort is O(n log n).
81 videos|80 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Semester Notes

,

video lectures

,

Extra Questions

,

MCQs

,

mock tests for examination

,

Different Types of Recurrence Relations & Their Solutions | Algorithms - Computer Science Engineering (CSE)

,

Sample Paper

,

pdf

,

Different Types of Recurrence Relations & Their Solutions | Algorithms - Computer Science Engineering (CSE)

,

shortcuts and tricks

,

Viva Questions

,

Summary

,

Previous Year Questions with Solutions

,

Important questions

,

Free

,

Objective type Questions

,

Exam

,

study material

,

Different Types of Recurrence Relations & Their Solutions | Algorithms - Computer Science Engineering (CSE)

,

ppt

,

past year papers

,

practice quizzes

;