Professional Documents
Culture Documents
Recursion
Recursion
Recursion
Need of Recursion
Properties of Recursion
How are Recursive functions stored in memory?
What is the base condition in recursion?
Format for Base Condition
Why does Stack Overflow error occur in recursion?
What is the difference between direct and indirect
recursion?
Format for direct recursion
Format for indirect recursion
1
Recursion
What is Recursion?
Need of Recursion
● Reduce the length of our code and make it easier to
read and write.
Properties of Recursion
● Base condition is needed to stop the recursion
otherwise infinite loop will occur.
2
● Performing the same operations multiple times with
different inputs.
3
// base case
if(n <= 1){
return 1;
}
4
Format for direct recursion
void directRecFun()
{
// Some code....
directRecFun();
// Some code...
}
void indirectRecFun1()
{
// Some code...
indirectRecFun2();
// Some code...
}
void indirectRecFun2()
{
// Some code...
5
indirectRecFun1();
// Some code...
}
6
7