This answer is not selected as best answer. This answer may not be sufficient for exam.
Your limit has been exceed. We have implemented this system because, We got difficulty on managing our servers. Please donate some amount to remove this limit.
Quota: 0 / 30
Recursion is made for solving problems that can be broken down into smaller, repetitive problems. It is especially good for working on things that have many possible branches and are too complex for an iterative approach. One good example of this would be searching through a file system.
Recursion is required because there are problems to solve which are recursive by nature. Non-recursive solutions to those problems are
- Complicated (because of the mismatch between the problem and the code) Fragile (be
- cause complicated)
- Harder to maintain and analyze (because of points 1 and 2)
- Potentially less efficient
Merits of recursion
- The code may be easier to write.
- To solve such problems which are naturally recursive such as tower of Hanoi.
- Reduce unnecessary calling of function.
- Extremely useful when applying the same solution.
- Recursion reduce the length of code.
- It is very useful in solving the data structure problem.
- Stacks evolutions and infix, prefix, postfix evaluations etc.
Demerits of recursion:
- Recursive functions are generally slower than non-recursive function.
- It may require a lot of memory space to hold intermediate results on the system stacks.
- Hard to analyze or understand the code.
- It is not more efficient in terms of space and time complexity.
- The computer may run out of memory if the recursive calls are not properly checked.