Question: public static int foo(int x, int y) { if (y == 0) { return x; } else if (x
public static int foo(int x, int y) { if (y == 0) { return x; } else if (x <= y) { return y; } else { int result1 = foo(x - 1, y - 1); int result2 = foo(x - 1, y + 1); return result1 + result2; } } Assume that we begin with the following initial call to this method:
foo(5, 3)
Construct a call tree that shows each invocation of the method. In particular, you should:
Begin by copying the following initial diagram into your ps3pr1.txt file:
1:foo(5,3) / \ / \ / \
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.
If a given call is not a base case, use lines composed of / or \ characters to connect the call to the recursive call(s) that it makes.
Precede each call with a number that indicates the overall order in which the calls were made.
Draw a stack trace of the function execution from the initial call. You can draw the stack in parallel blocks to reflect the changes to the stack when a function returns.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
