In: Computer Science
what we have learned about the plusses and minuses (benefits and costs) of using recursion as a problem-solving technique for the types of programs you have encountered so far.
Recursion Advantages
This was somewhat counter-intuitive to me since, in my experience, recursion sometimes increased the time it took for a function to complete the task. An example of this is calculating Fibonacci numbers. If you calculate the Fibonacci sequence up to a number n using recursion rather than iteration, the time to complete the task when compared to that of the iterative approach was much greater. However, if you memorize the result (aka save the value of each calculation for further use in the recursive call) you can in fact reduce the time complexity
2.it allows programmers to take advantage of the repetitive structure present in many problems
3. it leads to more readable and efficient algorithm descriptions
4.Recursion is better at tree traversal.
This one is a little more advanced. An extremely simplified version of what this means is as follows: A tree is a collection object that is linked to one another (imagine leaves on a tree connected by branches that are in turn connected to other branches all the way to the roots). One of the more efficient ways to traverse these trees when looking for a specific leaf (or node) is by recursively following a single branch until the end of that branch until you find the value you are looking for. Again, this is extremely abstracted and simplified for what is actually happening and I urge you to look further into what is actually happening in the tree traversal.
Recursion Disadvantages
Because the function has to add the stack with each recursive call and keep the values there until the call is finished.the memory allocation is greater than that of an iterative function
2. Handle with care
If the recursion is not properly implemented,it leads to take more time to execute the problem. some times it take more time than iteration method. the reason behind this is that it requires the allocation of a new stack frame each time .