-1
for(i=0;i<n;i+=2) {
  for(j=1;j<=n;j*=2) {
      printf(ā€œ%d,%d\nā€,i,j);
    }
}

What would be the Big O notation of this loop?

Ludwig
  • 99
  • 1
  • 2
  • 11

1 Answers1

4

The outer loop will do n/2 iterations, and each inner loop will do lg_2(n) iterations.

The overall running time should be O(n*lgn) (here I use lg to represent log base 2).

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360