6.4k views
4 votes
What are the advantages and disadvantages of solving a problem that can be broken down into repetitive tasks with recursion as opposed to a loop? Explain your answer.

User JBausmer
by
3.9k points

1 Answer

7 votes

Answer:

Answered below

Step-by-step explanation:

Recursion refers to the process of a function calling itself within its own definition. It calls itself repeatedly until a base condition is met and the loop breaks.

The advantages of recursion over loops include;

A) Recursion reduces time complexity.

B) Recursion is better at tree traversal and graphs.

C) Recursion reduces the time needed to write and debug code and also adds clarity to code.

Disadvantages of recursion include;

A) Recursion uses more memory because each function call remains in stack until the base case is met.

B) Recursion can be slow.

C) Recursion

User Monners
by
4.7k points