Why is the running time for the above algorithm extremely


The code below is for a recursive solution to computing the nth Fibonacci number.

public long fibRecursive(int n)

{

   if (n <= 1)

   {

       return n;

   }

   else

   {

       return fibRecursive(n - 1) + fibRecursive(n - 2);

   }

}

Why is the running time for the above algorithm extremely inefficient? 

a) The recursive call, fibRecursive(n - 1) causes the algorithm to perform redundant calculations. 

b) The recursive call, fibRecursive(n - 2) causes the algorithm to perform redundant calculations. 

c) Both recursive calls cause the algorithm to perform redundant calculations. 

d) The algorithm is recursive, and is thus inherently inefficient. 

e) The recursive calls are performed in the wrong sequence; i.e., fibRecursive(n - 2) should be called before fibRecursive(n - 1). 

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Why is the running time for the above algorithm extremely
Reference No:- TGS02294561

Now Priced at $25 (50% Discount)

Recommended (99%)

Rated (4.3/5)