1. Trace the call f(16) to the following method by showing a stack of activation records: public int f(int n) { int result = 0; if (f result = 1; else result = f(n / 2) + f(n / 4); return result; } //...


1. Trace the call f(16) to the following method by showing a stack of activation records:


public int f(int n)


{


int result = 0;


if (f


result = 1;


else


result = f(n / 2) + f(n / 4);


return result;


} // end f


2. Trace the call fibonacci(6) to the following method:


/** Computes the (n + 1)-st Fibonacci number F(n).


@param n an integer >= 0.


@return the Fibonacci number F(n) */


public static int fibonacci(int n)


{


int result = 0;


if (n


result = 1;


else


result = fibonacci(1, 1, n);


return result;


} // end fibonacci


private static int fibonacci(int one, int two, int n)


{


int result = 0;


if (n == 1)


result = one;


else


result = fibonacci(two, one + two, n - 1);


return result;


} // end fibonacci


List any recursive calls in the order they occur, giving their arguments as values instead of variables. How does this method compare to an iterative Fibonacci method with respect to required execution time?



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here