Asked by ...

Consider the following code.
public static int recur3(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
return recur3(n - 1) + recur3(n - 2) + recur3(n - 3);
}
What value would be returned if this method were called and passed a value of 5?
3
9
11
16

Answers

Answered by oobleck
from the last statement,
r(5) = r(4)+r(3)+r(2)
r(4) = r(3)+r(2)+r(1)
r(3) = r(2)+r(1)+r(0)
So do the math
Answered by heh
Should be 9
There are no AI answers yet. The ability to request AI answers is coming soon!

Related Questions