In Computer Science Recursion is defined as “where the solution depends on solutions to smaller instances of the same problem”
or simply put as
“a method that calls itself”
A Recursive function requires 2 things:
- A base case (which terminates or ends loop)
- A recursive case (which calls itself)
Advantage of Recursion
- Function calling related information will be maintained by recursion.
- Stack evaluation will be take place by using recursion.
- In fix prefix, post-fix notation will be evaluated by using recursion.
Disadvantage of Recursion
- It is a very slow process due to stack overlapping.
- Recursive programs can create stack overflow.
- Recursive functions can create as loops.
Why do we need recursion?
A Recursive Example
Gives us the answer
Ok so this is going to take some getting used to.