Question: Consider the following recursive algorithm with a positive integer parameter n>=1: int f(n) { if (n

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).

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

f8 f7 f6 f5 f4 f3 11 12 6 7 8 f6 f5 f4 f3 11 12 6 7 Heres a stepbystep breakdown f8 cal... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!