GATE CS 2015, set 1 · Question 64 · Algorithms · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

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?

  1. (A) n³
  2. (B) n(log n)²
  3. (C) n log n
  4. (D) n log(log n)
Answer

Answer (D)

Answer from the official GATE CS 2015 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes