Page 1 of 1

Consider the following recursive method: This method is also included in the Problems5and6 class mentioned in the previo

Posted: Sun Jul 10, 2022 11:27 am
by answerhappygod
Consider the following recursive method:
This method is also included inthe Problems5and6 class mentioned in the previousproblem.
(2 points) Trace the execution of mystery(5, 6). To do so,complete the template that we have provided in section 6-1of ps4_partI. In particular, you should:
Include a separate “frame” for each call. We have filled in someof 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 youreach the base case.
Begin each frame with lines that explicitly state the valuesassigned to the parameters, as we have done for the first call.
Next, if the call is a base case, you can simply show the valuethat is returned (omitting the line for myst_rest). If thecall is a recursive case, you should show the recursive call on theline for myst_rest.
Once you have reached the base case, you should work your wayback through the frames for the previous calls. Add in both theresults of the recursive call (i.e, the value assignedto myst_rest) and the value returned by the call itself.
(1 point) What is the value returned by mystery(5, 6)? Tocheck your answer, you can add a test call toyour main method. For example:
(2 points) During the execution of mystery(5, 6), methodframes are added and then removed from the stack. How many methodframes are on the stack when the base case is reached? You shouldassume that the initial call to mystery(5, 6) is madefrom within the main method, and you should include thestack frame for main in your count.
(3 points) Give an example of valuesof a and b that would produce infiniterecursion, and explain why it would occur.