Why is this $O(\log \log n)$?
// Here c is a constant greater than 1
for (int i = 2; i <=n; i = pow(i, c)) {
// some O(1) expressions
}
I am trying to understand how I would derive the time complexity of something like this.
Why is this $O(\log \log n)$?
// Here c is a constant greater than 1
for (int i = 2; i <=n; i = pow(i, c)) {
// some O(1) expressions
}
I am trying to understand how I would derive the time complexity of something like this.
Note that on the $k$th iteration we have $$i=2^{c^k}$$ The loop ends if $i>n$, meaning $$2^{c^k}>n$$ $$c^k>\log_2 n$$ $$k\log_2 c>\log_2\log_2 n$$ $$k>\log_2\log_2 n/\log_2 c$$ Thus there are fewer than a constant multiple of $\log_2\log_2 n$ iterations.