Question: Recursion Tree Goal: Predict the output of a recursive method call using a recursion tree. Draw the recursion tree of the following source code, marking
Recursion Tree Goal: Predict the output of a recursive method call using a recursion tree. Draw the recursion tree of the following source code, marking all method calls and outputs:
public static void main(String[ ] args) {
f(5, 2);
}
public static void f(int x, int y) {
if (x > 0 && y > 0) {
f(y - 1, x - 2);
f(x - 2, y);
System.out.print((x + y) + " ");
f(x - 3, y - 1);
System.out.print((x - y) + " ");
}
}
Step by Step Solution
3.37 Rating (150 Votes )
There are 3 Steps involved in it
To predict the output of the recursive method call in the provided code snippet we need to draw and ... View full answer
Get step-by-step solutions from verified subject matter experts
