Gate CS-2015-1 Question Paper With Solutions

Q. 41 Consider the following C function.

int fun1 (int n)
{
   int i, j, k, p, q = 0;
   for (i = 1; i<n; ++i)
   {
      p = 0;
      for (j = n; j > 1; j = j/2)
         ++p;
      for (k = 1; k < p; k = k*2)
         ++q;
   }
   return q;
}

Which one of the following most closely approximates the return value of the
function fun1 ?

(A) n3

(B) n (logn)2

(C) nlogn

(D) nlog(logn)

Answer: (D)

Explanation:

Gate CS-2015-1 Question Paper With Solutions

Learn More:   Gate EC-2019 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here