Recursion : Notes
Recursion: A procedure that calls itself is known as Recursion
Recursive Function: A function that calls itself in
its own body is known as recursive function.
eg.
void recursion() {
recursion();
// function calls itself
}
int main() {
recursion();
}
Direct Recursion: When a function calls itself in
its own body is known as Direct Recursion.
Eg.
Int
abc()
{
-----
abc();
-----
}
Indirect Recursion: When a function calls another
function and that function call back to first function is known as indirect
Recursion.
Eg.
int
abc()
{
-----
pqr();
-----
}
int
pqr()
{
-----
abc();
-----
}
Base Condition: Each recursive function must have a
base condition or terminating condition to stop the recursive calling of a
function. When a function /procedure calls itself then it must move closer to
the base condition.