Computer Science EngineeringVery hard

For n a power of 2, what is the Theta bound of the loop: x=0; for(i=1;i<=n;i*=2) for(j=0;j<i;j++) x++;

  1. A. Theta(n)
  2. B. Theta(n log n)
  3. C. Theta(log n)
  4. D. Theta(n^2)

Correct answer: A. Theta(n)

Total increments are 1+2+4+...+n, a geometric series equal to 2n-1.

More Algorithms, Data Structures & Programming (ISRO CS) questions

Exams that ask this topic