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
Is register a keyword in c?
How do you sort filenames in a directory?
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
Explain what is output redirection?
How are variables declared in c?
How to delete a node from linked list w/o using collectons?
Explain output of printf("Hello World"-'A'+'B'); ?
What language is c written?
Why is c so powerful?
Which is an example of a structural homology?
Explain the advantages of using macro in c language?
Explain what is a static function?
Difference between goto, long jmp() and setjmp()?
Explain how can you tell whether two strings are the same?
Explain the difference between exit() and _exit() function?