xxxxxxxxxx
The idea of recursion is that instead of conquering the problem top to bottom
for graph/tree or start to end for array/string in normal for/while loops,
in recursion you conquer the problem from bottom to top or end to start.
What's before the recursive call(s) gets executed going top to bottom
or start to end and what's after the recursive call(s) gets executed
going bottom to top or end to start.
xxxxxxxxxx
The process in which a function calls itself directly or indirectly
is called recursion.
// Recursive Addition
f(n) = 1 n = 1
f(n) = n + f(n-1) n > 1
xxxxxxxxxx
When a method in any programming language calls itself for a smaller task,
then it is called as recursion and the method is called as recursive method
Recursion follows devide and conqure technique in which a problem is solved
by breaking it into a smaller problem
Whenever a recursion is not handled with a proper base condition, it gives a
stack overflow error
A base condition is a condition in recursive calls that is used to return a
recursive call and it makes recursion possible in programming
EXAMPLE JAVA CODE:
public static long factorial(int n){
if (n == 1)
return 1;
else
return n * factorial(n-1);
}