A "tracing tree" shows the order of the execution for the chain of function calls, to help us better
understand how the output is generated and what the memory looks like for each function call.
When function A calls function B, the name of function B should be written underneath A, with an
indentation. We use an arrow to show A called B (see the blue arrow below). The return value is
also shown next to the arrow that follows the name of the function (see the red arrows below)
A(A's actual parameters) return value of function A
B(B's actual parameters) return value of function B
We can use the tracing tree to get an understanding of how a recursion works.
In this activity, suppose we call the given method with (input, 0, 4), where input is an integer array
containing {1, 2, 3, 4, 5}. Fill in the gaps in the tracing tree that shows the correct order of function
call in this recursion.
public static int func1(int[] input, int s, int e) {
if (s == e)
return input[s];
else {
return func1(input, s, (s+e)/2) + func1(input, (s+e)/2+1, e);
}
}