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