GATE CS 2006 · Asymptotic Analysis & Recurrences

MCQ · 1 mark · Problem PROG-DIVC-0142

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)=\(\Theta\)(logn)
  2. B
    val(j)=\(\Theta\)(sqrt(n))
  3. C
    val(j)=\(\Theta\)(n)
  4. D
    val(j)=\(\Theta\)(nlogn)

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionOfficial GATE Answer Key: Option C.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/976/gate2006-15

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com