What is the Recursion technique? Write Factorial program | Learn DSA
Recursion is a process of calling itself. A function that calls itself is called a recursive function.
Example: If we place two parallel mirrors facing each other, an object in between two mirrors would be reflected recursively. In the same way, a recursive function is a function that calls itself.
Syntax to define a recursive function:
But, a recursive function must have a condition to stop calling itself. Otherwise, the function will end up in an infinite recursion loop.
Base condition: Once the condition is met, the function stops calling itself, this is called a base condition.
To prevent infinite recursion, we can use an if-else condition statement.