Recursion Flashcards
What is recursion
A function calling itself
Which DS is used to solve recursion
STACK
Every function call has its own?
Stack space and local variables
If no termination condition present in recursive program then what happens
Stack overflow which is a runtime error
For every recursive program, is non recursive program present?
Yes
Time complexity comparison of recursive and non recursive program for same algo
Same
Space complexity comparison of recursive and non recursive program for same algo
Space complexity of recursive program is more
Amount of stack space used by recursive program
Depth of stack
From one call to another call of a recursive prog does code, no. of parameters, name of parameter change?
No only value of parameters can change
Methods for solving recursive problems
Substitution, Recursive tree, Masters theorem
Constant time corresponds to
O(1)
For multiplication by recursion no. of additions for doing m*n
0 if m=0 or n=0
A(m,n-1)+1 if n>0 and m>0
For fibonacci series nth no., no. of additions
0 if n=0 or n=1(n<=1)
fib(n-1)+fib(n-2)+1
Substitution
Substitute until u get a pattern
1+2+3+—–+n
n(n+1)/2