Computer Science EngineeringVery hard

What is the Theta bound of: for(i=1;i<=n;i++) for(j=1;j<=n;j*=2) count++;

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

Correct answer: A. Theta(n log n)

The inner loop runs about log2 n times for each of the n iterations of the outer loop.

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

Exams that ask this topic