Consider the following C-program fragment in which i, j and n are integer…

PYQ GATE 2006

Consider the following C-program fragment in which i, j and n are integer variables.

for (i = n, j = 0; i >0; i /= 2, j += i);

Let val(j) denote the value stored in the variable j after termination of the for loop. Which one of the following is true?

  1. A.

    val(j) = Θ(logn)

  2. B.

    vaI(j) = Θ(sqrt(n))

  3. C.

    val(j) =Θ (n)

  4. D.

    val(j) = Θ(nlogn)

Attempted by 237 students.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…