answersLogoWhite

0


Best Answer

The advantages of recursion tend to revolve around the fact that there are quite a few algorithms which lend themselves to recursion (tree traversal, binary searches, quick sort, etc.)

The disadvantages of recursion include:

* finite number of recursive steps (limited heap space) * speed/efficiency (easier to increment a loop counter than call a function)

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

The merit of recursion is that each call maintains the state of all the local variables in the previous call. However this is only useful if the variables are required after each recursion returns. If they are not required then it is a demerit, as each recursive call will add an overhead in making an unnecessary function call (which is expensive). The function will therefore perform much better if implemented as an iterative loop rather than as a recursive function.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Pros: it's easy ie: factorial

int factorial(int n) { return n>=1 ? n * factorial(n-1) : 1; }

Cons: your program can crash because of it's stack limit.

In example above try n=200 :)

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the merits and demerit of recursion in algorithm?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


How do you overcome limitations of stacks in polygon filling?

You overcome limitations of the stack in polygon filling, or in any other algorithm, far that matter, but using an iterative technique, rather than a recursive technique. Recursion is quite useful, and can simplify algorithm design. Polygon filling, however, is a class of algorithm can potentially have a very deep recursion depth. This causes stress on the stack, hence the need for iteration.


What is the difference between left recursion and right recursion in a grammar?

Recursion is what it's called when a function calls itself. When a function calls itself immediately before returning, it's called tail recursion. Tail recursion can be more efficiently written as iteration. In fact a good compiler will recognize tail recursion and compile it as iteration. There is no such thing as left or right recursion in C programming.


How do you choose between recursion and iteration?

Some problems cry out for recursion. For example, an algorithm might be defined recursively (e.g. the Fibonacci function). When an algorithm is given with a recursive definition, the recursive implementation is straight-forward. However, it can be shown that all recursive implementations have an iterative functional equivalent, and vice versa. Systems requiring maximum processing speed, or requiring execution within very limited resources (for example, limited stack depth), are generally better implemented using iteration.


What is a high speed data searching and sorting in data structure algorithm?

Binary Search is the high speed data searching.Here in each recursion the is divided in two equal halves so that execution becomes easier.

Related questions

What are merits and demerits in use of antibiotics?

demerit of antibiotics


What are merit and demerit of chemistry?

merits and demerits of chemistry


Merits and demerit of manual data processing?

100pre


What is the Merits and demerits of BPO job?

BPO is merit and demerit


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


What are the merit and demerit?

Merits are the good thing- Demerits are the bad things-


What are the merits and demerits of recursion?

Ans: Merits of recursion are: Mathematical functions, such as Fibonacci series generation can be easily implemented using recursion as compared to iteration technique. Demerits of recursion are: Many programming languages do not support recursion; hence, recursive mathematical function is implemented using iterative methods. Even though mathematical functions can be easily implemented using recursion, it is always at the cost of execution time and memory space. The recursive programs take considerably more storage and take more time during processing.


What are the merits and demerits of public and private administration?

merit and demerit public and private administration


What are the Merits and Demerits of using HTML?

The merit of HTML is it's simplicity. The demerit is the lack of conditional statements.


What are the advantages and disadvantages of sorting algorithm?

shell sort merits and demerits


How do you overcome limitations of stacks in polygon filling?

You overcome limitations of the stack in polygon filling, or in any other algorithm, far that matter, but using an iterative technique, rather than a recursive technique. Recursion is quite useful, and can simplify algorithm design. Polygon filling, however, is a class of algorithm can potentially have a very deep recursion depth. This causes stress on the stack, hence the need for iteration.


Explain various pricing method with their merits and demerits?

The merits of the sampling methods takes the right products to the right customers. The demerit of this pricing method is that there are some goods which can't be sold therefore leading to losses.