What is recursion? State its advantages and disadvantages.
1 Answer

1. Recursion:

i. Recursion is a process in which the problem is specified in terms of itself.

ii. The function should be called itself to implement recursion.

iii. The function which calls itself is called as recursive function.

iv. A condition must be specified to stop recursion; otherwise it will lead to an infinite process.

v. In case of recursion, all partial solutions are combined to obtain the final solution.

vi. Example: Factorial of a number

2. Advantages:

i. The main benefit of a recursive approach to algorithm design is that it allows programmers to take advantage of the repetitive structure present in many problems.

ii. Complex case analysis and nested loops can be avoided.

iii. Recursion can lead to more readable and efficient algorithm descriptions.

iv. Recursion is also a useful way for defining objects that have a repeated similar structural form.

3. Disadvantages:

i. Slowing down execution time and storing on the run-time stack more things than required in a non recursive approach are major limitations of recursion.

ii. If recursion is too deep, then there is a danger of running out of space on the stack and ultimately program crashes.

iii. Even if some recursive function repeats the computations for some parameters, the run time can be prohibitively long even for very simple cases.

Please log in to add an answer.