What's the time complexity of the following code?
a = 2;
while (a <= n)
{
for (k=1; k <= n; k++)
{
b = n;
while (b > 1)
b = b / 2;
}
a = a * a * a;
}
I'm struggling with the outer while loop, which is loglogn
, I can't understand why. How would the time complexity change if the last line was a = a * a * a * a;
?
the for loop is O(n)
, and inner one is O(logn)
.
So in total, O(n*logn*loglogn)