in Algorithms edited by
215 views
0 votes
0 votes
i=n;

while(i>0)

{

j=1;

while(j<=n)

{

j=2*j;

}

i=i/2;

}
in Algorithms edited by
215 views

2 Comments

moved by
Is it loglogn?
0
0

@Mayankprakash

it is (log n) * (log n) but not log(log n)

why?

outer loop executes log n times

inner loop executes log n times for every outer loop ===> (log n) * ( log n)

it is asymptotically equivalent to

for( i=n; i>0 ; i=i/2 )

{

   for ( j=1,j ≤ n; j=j*2)

   {

   }

}

Moreover, if you not giving explanation, add it as comment, not as answer.

3
3

1 Answer

0 votes
0 votes
The first while loop runs O(logn) times. for each outer loop inner runs O(logn) times.So.the time complexity is O(logn)*O(logn)=O((logn)^2)

Related questions

2 votes
2 votes
1 answer
4