KEMBAR78
Mathematical Analysis of Recursive Algorithm. | PPTX
Mathematical analysis of
recursive algorithm
Bharati. C
M.tech
General plans for analysis of recursive
algorithm
1) decide the input size.
2) identify the basic operation.
3) check how many time the basic operation
performed and determine the best worst and
average case.
4) set up a recursive relation with some initial
condition expressing the basic operation.
5)solve recursion with using forward and backward
substitution and correct formula using mathematical
induction.
Algorithm: factorial(n)
if(n==0)
return 1
else
return fact(n-1)*n
Mathematical analysis:
Step 1 :input size is n
step 2 :basic operation is multiplication
step 3 :recursive function is
F(n)=F(n-1)*n where n>0
Step 4: multiplication is given as
M(n)=M(n-1)+1
Step 4: Forwords substitution:
M(n)=M(n-1)+1
M(0)=0 n=0
M(1)=M(1-1)+1=1.............. n=1
M(2)=M(2-1)+1=2.................n=2
M(3)=M(3-1)+1=3
Backward substitution:
M(n)=M(n-1)+1
M(n)=[M(n-2)+1]+1
=M(n-2)+2
M(n)=[M(n-3)+1]+2
=M(n-3)+3
M(n)=M(n-i)+i
Now we correct the formula
Prove: M(n)=n by using mathematical induction
Let n=0
M(n)=0.
M(0)=0=n
Induction: M(n-1)=n-1
M(n)=M(n-1)+1
=n-1+1
=n
M(n)=n
Time complexity. (n)
Thank you

Mathematical Analysis of Recursive Algorithm.