Question

In: Computer Science

what we have learned about the plusses and minuses (benefits and costs) of using recursion as...

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.

Solutions

Expert Solution

Recursion Advantages

  1. Recursion can reduce time complexity.

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

  1. Recursion may be a memory eater.

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 .


Related Solutions

Using what you learned about private and social costs as well as private and social benefits...
Using what you learned about private and social costs as well as private and social benefits in private decisions-making, explain why managed isolation has been imposed on cross-border travellers and explain the economic consequences of not charging for managed isolation upon entry.
a) Using what you learned about private and social costs as well as private and social benefits in private decision-making
a) Using what you learned about private and social costs as well as private and social benefits in private decision-making, explain why managed isolation has been imposed on cross-border travelers entering into New Zealand. Use a diagram of the market for international air travel to illustrate your point.b) Using what you learned about private and social costs as well as private and social benefits in private decision-making, explain the economic consequences of not charging for managed isolation upon entry.c) Given...
We have learned about the components that make up the manufacturing costs also known as products...
We have learned about the components that make up the manufacturing costs also known as products costs (direct materials, direct labor, manufacturing overhead, and/or conversion costs). Of all the components that make up the manufacturing costs, which one do you think is most important and why? Please answer is 1 paragraph. (7-8 thorough sentences.) Include a few details. Thank you and enjoy your day!
We have learned about Standard costs and associated variances in this chapter. Can a favorable variance...
We have learned about Standard costs and associated variances in this chapter. Can a favorable variance be a bad thing? Describe a realistic scenario where a favorable variance could be detrimental(have unwanted consequences elsewhere in the business).
We have learned about tree diagrams and venn diagrams. Explain what each of these are and...
We have learned about tree diagrams and venn diagrams. Explain what each of these are and how they are helpful when calculating probability. Then post a problem that your classmates can solve using one of these two methods and respond to one of their questions as well.
We have learned about conditioning in class. There are countless ways that we encounter condition in...
We have learned about conditioning in class. There are countless ways that we encounter condition in everyday life. This assignment requires that you examine conditioning (either classical or operant) as you’ve experienced it. Provide five examples of conditioning from your own life with a detailed description of stimulus/response and reinforcement patterns.​
We are almost finished the semester and we have learned quite a lot about public speaking...
We are almost finished the semester and we have learned quite a lot about public speaking and group work. Some of you may have had some great experiences in a group and others might have had issues. This does not come from luck, but how we build relationships and how we use communication. Understanding people and contexts better enables us to better achieve win-win solutions in our interpersonal daily conversations. Think about how you communicate on dates, in friendships, and...
We have learned a great deal about the history of exposure to environmental toxins in the...
We have learned a great deal about the history of exposure to environmental toxins in the twentieth century - from lead in paint and gas, occupational exposures to toxins, to air pollution, to Love Canal. Choose three of these cases and analyze them comparatively in terms of causes, responses, and lessons for ongoing environmental health challenges. answer in few paragraphs
Assignment: Using what we have learnt about the price elasticity of demand, and what we remember...
Assignment: Using what we have learnt about the price elasticity of demand, and what we remember about short run and long run price elasticities (Chapter 2 of Perloff (2017)), along with substitution and income effects (Chapter 4 of Perloff (2017)) as a guide, choose a particular product (good or service) which you or your family purchased during the recession of 2007 – 2009, or choose a particular good which you or your family purchased at least 2 years ago (before...
Explain what we mean by “active” vs. “passive” investment management? What are the pluses and minuses...
Explain what we mean by “active” vs. “passive” investment management? What are the pluses and minuses of each alternative for investors?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT