what are the advantage and disadvantage of recursion

Answer Posted / vasu jain

Recursion
Advantage
i. Usually simplicity.
ii. Although at most of the times a problem can be solved without recursion, but in some situations in programming, it is a must to use recursion. For example, a program to display a list of all files of the system cannot be solved without recursion.
iii. The recursion is very flexible in data structure like stacks, queues, linked list and quick sort.
iv. Using recursion, the length of the program can be reduced.
Disadvantage
i. It requires extra storage space. The recursive calls and automatic variables are stored on the stack. For every recursive calls separate memory is allocated to automatic variables with the same name.
ii. Often the algorithm may require large amounts of memory if the depth of the recursion is very large. If the programmer forgets to specify the exit condition in the recursive function, the program will execute out of memory.
iii. The recursion function is not efficient in execution speed and time.
iv. Some function calls inside recursion are repeated or duplicated just like fibonacci

Is This Answer Correct ?    47 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is register a keyword in c?

629


How do you sort filenames in a directory?

703


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

701


Explain what is output redirection?

661


How are variables declared in c?

597






How to delete a node from linked list w/o using collectons?

2085


Explain output of printf("Hello World"-'A'+'B'); ?

969


What language is c written?

572


Why is c so powerful?

678


Which is an example of a structural homology?

775


Explain the advantages of using macro in c language?

572


Explain what is a static function?

628


Difference between goto, long jmp() and setjmp()?

698


Explain how can you tell whether two strings are the same?

580


Explain the difference between exit() and _exit() function?

631