0% found this document useful (0 votes)
11 views11 pages

Amity - Mod - 1 - L-5 Analyzing Recursive Algorithms

This document discusses analyzing recursive algorithms. It provides examples of recursive functions and their recurrence relations. The objectives are to analyze recursive algorithms using techniques like substitution method, recursion trees, and the master method. Examples shown include a recursive function to calculate factorials and its O(n) time complexity derived through back substitution of the recurrence relation. Analyzing recursive algorithms helps determine their time complexity.

Uploaded by

Prajjwal Mehra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views11 pages

Amity - Mod - 1 - L-5 Analyzing Recursive Algorithms

This document discusses analyzing recursive algorithms. It provides examples of recursive functions and their recurrence relations. The objectives are to analyze recursive algorithms using techniques like substitution method, recursion trees, and the master method. Examples shown include a recursive function to calculate factorials and its O(n) time complexity derived through back substitution of the recurrence relation. Analyzing recursive algorithms helps determine their time complexity.

Uploaded by

Prajjwal Mehra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Amity School of Engineering & Technology (CSE)

Analysis and Design of Algorithm(ADA)

Module-1[Lecture-3]
Analyzing Recursive algorithm

1
Amity School of Engineering & Technology (CSE)

OBJECTIVES
After completing this section, you will be able to

 Analyse recursive algorithms

2
Amity School of Engineering & Technology (CSE)

3
Amity School of Engineering & Technology (CSE)

Analyse Recursive algorithm


• Idea
Solving Recurrences
using
Recursive Recurrence  Substitution Method
Program Relation  Recursion tree method
 Master Method etc.

Time complexity

4
Amity School of Engineering & Technology (CSE)

•Example1:
 
------ T(n)  Amount of work done is
nothing but number of
function calls.
For ‘n’ it makes (n+1) calls
and print ‘n’ times.
----- 1 unit For Example: n=3, we have
----- T(n-1) fun(3), fun(2), fun(1) and
fun(0) calls=> n+1calls=O(n)
----------------------------
T(n)=T(n-1)+1
Recurrence relation:

  1 𝑛= 0
𝑇 (𝑛)=
{ 𝑇 ( 𝑛 − 1 ) +1 𝑛>0
5
Amity School of Engineering & Technology (CSE)

•  
Using Back substitution:

……..

6
Amity School of Engineering & Technology (CSE)

•Example2:
 
------ T(n)

--- 1

--- n+1

--- n

----- T(n-1)

----------------------------
T(n)=T(n-1)+2n+2=T(n-1)+O(n)
Recurrence relation:
  1 𝑛=0
𝑇 (𝑛)=
{ 𝑇 ( 𝑛 − 1 ) +𝑛 𝑛>0 7
Amity School of Engineering & Technology (CSE)

•  
Using Back substitution:

……..
= (n-k)
(n-k)

8
Amity School of Engineering & Technology (CSE)

Check your progress

Ex.1: Ex.2:

9
Amity School of Engineering & Technology (CSE)

Important results [Decreasing function]:

Sr No. Recurrence Solution


1.
1.

2.
2.

3.
4.
3.
5. ???
4.
5. ???

10
Amity School of Engineering & Technology (CSE)

Master Method [Decreasing function]:

Where
Case1
Case1

Case2
Case2
Case3
Case3

Example Recurrence Relation Solution


1
2
3
3

11

You might also like