i <-- 1
while(i < n)
j <--1
while(j < i)
j <-- j * 2
i <-- i + 1
done
My shot at this would be O(log n)
for the inner loop. And I'm guessing the outer loop is O(n)
, for an overall complexity of O(n log n)
. Confirm?
You may proceed formally, step by step, using Sigma notation to obtain the exact number of iterations - Look at Discrete Loops and Worst Case Performance paper (page 10).
The result has been empirically verified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With