Computer Science
What do you understand by recursion ? State the advantages and disadvantages of using recursion.
Python Functions
1 Like
Answer
Recursion refers to a programming technique in which a function calls itself either directly or indirectly.
The advantages of using recursion are as follows :
- Recursion can simplify the solution to complex problems by breaking them down into smaller, more manageable sub-problems.
- Recursive solutions often result in simple and concise code compared to iterative approaches, especially for problems that involve repeated patterns or structures.
- Recursion can make code easier to understand.
- Recursive functions can handle problems of variable size without requiring changes to the function itself, as long as the base case and recursive cases are properly defined.
The disadvantages of using recursion are as follows :
- It consumes more storage space because the recursive calls along with local variables are stored on the stack.
- The computer may run out of memory if the recursive calls are not checked.
- It is less efficient in terms of speed and execution time.
Answered By
1 Like
Related Questions
Write a function to calculate volume of a box with appropriate default values for its parameters. Your function should have the following input parameters :
(a) length of box ;
(b) width of box ;
(c) height of box.
Test it by writing complete program to invoke it.
Write a program to display first four multiples of a number using recursion.
Write a recursive function to add the first 'n' terms of the series:
1 + 1/2 - 1/3 + 1/4 - 1/5……………
Write a program to find the greatest common divisor between two numbers.