PA of Algorithms Q48

0. 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?

  • Option : C
  • Explanation :
    If n is a power of 2, then
    term
    If n is not a power of 2, then there will be minor differences of 1 at wherever is odd.
    Hence val(j) computed on the basis of n = 2n will give a fair answer

    = 2(n – 1) = θ(n)
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *