DAA L4-L5
DAA L4-L5
DAA L4-L5
2
Iterative Algorithm Analysis
3
Recursive Algorithm Analysis
A recursive method is a method that calls itself.
To build a recursive algorithm, you will break the given problem statement into
two parts.
The first one is the base case, and the second one is the recursive step.
The code size in recursion is smaller than the code size in iteration.
Recursive Step: It computes the result by making recursive calls to the same
function, but with the inputs decreased in size or complexity.
4
:
Example
This statement clarifies that we need to formulate a function that will calculate the
summation of all natural numbers in the range 1 to n.
5
Problem Breakdown
You can breakdown this function into two parts as follows:
6
Factorial
7
Fibonacci Series
8
Binary search
9
Insertion Sort
10
Recursive approach
In the case of recursion, we can calculate the time complexity by the use of a
recursive tree which is generated by recursive calls. The recurrence equation of
recursive tree is given as T(n) = T(n-1) + T(n-2) + c
On solving the above recurrence equation, we get the time complexity is O(2^n).
11
TASKS END OF LECTURE LEARNING (TELL):
12
TASKS END OF LECTURE LEARNING (TELL):
13
TASKS END OF LECTURE LEARNING (TELL):
14
References
• Fundamentals of Computer Algorithms 2nd Edition (2008) by Horowitz, Sahni
and Rajasekaran
• Introduction to Algorithms 3rd Edition (2012) by Thomas H Cormen, Charles E
Lieserson, Ronald
15
THANK YOU
For queries
Email: [email protected]
12/09/2024 16