Answer:
Option (C) which is 9 calls to t will be made including the original call.
Explanation:
The segment of code is about a recursive call to the method t. Recursive call is a process where a method call to itself.
public int t(int n)
{
if (n == 1 || n == 2)
return 2 * n;
else
return t(n - 1) - t(n - 2);
}
Within the function body,
Line 3-4 : if the n equal to 1 or n equal to 2, the method will return 2 multiplied with n.
Line 5-6: else a recursive call to method t with argument (n-1) and (n-2) will be made, respectively
With these in mind, we are ready to start tracking the number of recursive call to the method t by passing 5 as the argument (Please refer to the diagram in attachment).
The original calling to method t with argument n=5, t(5) will be considered as the first calling. Since the n is not equal to 1 or 2, two recursive calls, t(4) & t(3) will be made.
The recursive call t(4) and t(3) will add another four times of calling to method t : t(4) -> t(3) and t(2) whereas t(3) -> t(2) and t(1)
Among the four recursive calling to method t in the previous step, only the t(3) will result in another two additional calling to method t, t(3) -> t(2) and t(1). The rest of the callings, t(2) and t(1) will just result in 2 * n and exist from the recursive loop.
The current number of method calling is 7 + 2 = 9 (Final answer)