What is the Recursion technique? Write Factorial program | Learn DSA

Ankit Maheshwari
3 min readMar 31, 2022

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.

Syntax to prevent a recursive function from infinite recursion:

--

--

Ankit Maheshwari
Ankit Maheshwari

Written by Ankit Maheshwari

Frontend/Backend Engineer (Angular, React Native, NodeJS, MongoDB)

Responses (1)