Question: Problem 1 : A method that makes multiple recursive calls 8 points; individual - only A number of the algorithms that we consider in CS
Problem : A method that makes multiple recursive calls
points; individualonly
A number of the algorithms that we consider in CS involve recursive methods in which a given invocation of the method may make two or more recursive calls. To understand how this type of algorithm works, it helps to draw a call tree for a given set of initial parameters.
In this problem, you will draw such a call tree to illustrate the execution of a simple recursive method that operates on integers. You may find it helpful to review our solutions to the similar problem in Lab problem before continuing.
Here is the method you will trace:
public static int fooint x int y
if y x Math.absxy
return xy;
else
int result foox y ;
int result foox y ;
return result result;
Assume that we begin with the following initial call to this method:
foo
Construct a call tree that shows each invocation of the method, and that uses lines to connect a given invocation to the recursive calls that it makes if any Follow the same format that we use in our solutions for Lab
In section of pspartI, we have given you an initial diagram.
You should take the following steps to complete it:
Add each subsequent call with its parameters to the call tree in the appropriate place.
If a given call is a base case, simply put its return value under the call, as we do in our Lab Task solution for calls to fib and fib
If a given call is not a base case, use lines composed of or characters to connect the call to the recursive calls that it makes.
Precede each call with a number that indicates the overall order in which the calls were made.
Underneath your call tree, list the order in which the calls return, as well as their return values. When you refer to a given call in this part of the problem, use its number from the call tree.
For example, the initial call always returns last, so the last line in this part of the problem should look like this:
call foo returns
where you replace the with its return value.
See our solution for Lab for another example of what this part of your solution should look like.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
