Consider the following recursive algorithm with a positive integer parameter n>=1: int f(n)
Fantastic news! We've Found the answer you've been seeking!
Question:
Consider the following recursive algorithm with a positive integer parameter n>=1:
int f(n)
{
if (n == 1) return 3
if (n == 2) return 5
if (n == 3) return 11
int x =f(n-1)
if (n is odd) return x+1
else {
int y = f(n-2) mod n
int z = f(y)
return x + z
}
}
Suppose that we call f(8). Draw the recursion tree. Draw the entire tree even if there are repeating subtrees. Show all returned values from recursive calls including the returned value for f(8).
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date: