Recursion

·

1 min read

Recursion is defined as a process which calls itself directly or indirectly and the corresponding function is called a recursive function. It is based on the principle of mathematical induction. In recursion we solve a bigger problem by solving the smaller sub problems A function calls itself to solve its sub problem.

Questions

We assume that the function is working for f(n-1) {Just like in PMI, we have assumed that the function is working for Kth term} and now we have to just think what should we do after getting f(n-1) to get the final answer (Self work), As in PMI we have proof that the function is working for k=1, Here we have to similarly find a base case (halting condition) for n=1.

whenever a method is called a stack frame is built in the call stack, Whenever a function is called its line number is recorded And after completing the function the stack frame of the running function is removed and the execution of. the caller function continues.

Thank You For Reading.

Keep Coding.