Design and analysis algorithm Theory of Automata.pptx
MUXICS
6 views
9 slides
Apr 28, 2024
Slide 1 of 9
1
2
3
4
5
6
7
8
9
About This Presentation
Good
Size: 478.58 KB
Language: en
Added: Apr 28, 2024
Slides: 9 pages
Slide Content
Design and Analysis Algorithm
The Recurrence and its example and problem solutions * Presented by BSCS-E1 (girls) (Roll no 4,5,7,9,15,19, 20) Designed by Sara Yousaf
The Recursion For example: Fact(4)=24 Solution: 4*fact(3) 4*3*fact(2) 4*3*2*fact(1) 4*3*2*1=24 In recursion one function called itself, the number of parameters never changes only the parameter value changes The process in which the function calls itself is called recursion The corresponding function is called the recursive function . THE RECURSION
The Recursion Advantages: Recursion adds clarity to the code. It can reduce time complexity Reduce time to debug It is also used for analyzing and optimizing the algorithm Disadvantages: Uses more memory Recursion becomes slow A recursive program has a greater space requirement than an iterative program as each function in the program remains in the stack until the base case is reached
THE RECURRENCE Recurrence is an equation or an in-equality that describes the function in terms of its smaller inputs Recurrences arise when an algorithm contain recursive calls to itself. The simplest form is as follows: T(n)= T(n-1)+n
The Recurrence Binary Search: T(n)=T(n/2)+1 Input size T(n)=T(n/2)+1 Reducing of input size Signifies a function 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 2 3 5 7 9 10 11 12 lo hi mid Mid =[( lo+hi )/2] Exp; mid pt= 4 approx