-
Which of the below code snippets can give stackoverflow for very large value of 'n' ( Do not consider Python while answering this question ) : I)
function foo(n){ if(n > 0) return foo(n - 1); }
II)
function x(n){ if(!n) return 0; n-=2; return x(n) + 1; }
Options: A. I only B. II only C. Both I and II D. None.
-
How a recursive function with no base case and an infinite iteration differ?
function sum(long long n){ // recursive part with no base case return 1+sum(n+1); }
n = 0; for(;;){ // iterative part with infinite iteration n+=1; }
Analyse what will happen when the two snippets will be executed
- How a tail recursion optimisation can help in handling the maximum recursion depth?