The inner loop performs n iterations, then n/2 , then n/4 , etc. Thus, the total number of iterations of the inner loop:
n + n/2 + n/4 + n/8 + ... + 1 <= n * (1 + 1/2 + 1/4 + 1/8 + ...) = 2n
(See. Geometric series ) and, therefore, O (n).
source share