Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following recursive function: def mystery(a, b): if a == b: return b else: myst_rest = mystery(a + 1, b - 2) return a

image text in transcribed

Consider the following recursive function: def mystery(a, b): if a == b: return b else: myst_rest = mystery(a + 1, b - 2) return a + myst_rest 1. Trace the execution of the following call to this function mystery(3, 9) To do so, complete the template that we have provided in section 2-1 of psZpr012. In particular, you should: Include a separate "frame" for each call. We have filled in some of the components of the frames for the first two calls for you. You should replace each ... with the appropriate integer, and you should add frames for additional calls as needed, until you reach the base case. Begin each frame with lines that explicitly state the values assigned to the parameters, as we have done for the first call. Next, if the call is a base case, you can simply show the value that is returned (omitting the line for myst_rest). If the call is a recursive case, you should show the recursive call on the line for myst_rest. . Once you have reached the base case, you should work your way back through the frames for the previous calls. Add in both the results of the recursive call (i.e, the value assigned to myst_rest) and the value returned by the call itself. We took a similar approach to tracing recursion in Lab 3. 2. What is the value returned by mystery(3, 9)? 3. During the execution of mystery(3, 9), stack frames are added and then removed from the stack. How many stack frames are on the stack when the base case is reached? You should assume that the initial call to mystery(3, 9) is made from the global scope, and you should include the stack frame for the global scope in your count. 4. Give an example of specific values of a and b that would produce infinite recursion, and explain why it would occur

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

Haere taka mua, taka muri; kaua e whai: Be a leader, not a follower

Answered: 1 week ago