Advantages and Disadvantages
This lesson explains the advantages and disadvantages of recursion.
We'll cover the following
Disadvantages of Recursion
Recursion, broadly speaking, has the following disadvantages:
- A recursive program has greater space requirements than an iterative program as each function call will remain in the stack until the base case is reached.
- It also has greater time requirements because each time the function is called, the stack grows and the final answer is returned when the stack is popped completely.
Advantages of Recursion
On the other hand, recursion has the following advantages:
- For a recursive function, you only need to define the base case and recursive case, so the code is simpler and shorter than an iterative code.
- Some problems are inherently recursive, such as Graph and Tree Traversal.
Now that you have learned the basics of recursion, in the next few chapters, you will learn how to do recursion on numbers, strings, arrays and data structures. Each lesson includes a couple of challenges and quizzes to give you hands-on practice. So let’s get started!