This is O(n):
The outer loop has O(logn)iterations, since it istarts with nand decreases by half by each iteration.
Now consider the number of iterations of the inner loop:
- In the first iteration of the outer loop, the inner loop has
niterations (starting at i==n). n/2 ( i==n/2).
...
log(n)'th ( ) 1 ( i==1).
, :
n + n/2 + n/4 + ... + 1 <= 2*n = O(n)