Let say N is power of 2 ,
For example let say N = 16 ,
Now according to code ,
it runs 16 + 8 + 4 + 2 + 1
Its a Geometric Progression , formula for sum of GP is ( a * ( r^n - 1 ) / ( r - 1 ) )
a = first term , r = common ratio.
Here a = 1 and r = 2 ,
Now sum = 2 ^ n - 1 where n = number of terms.
As number of terms will always log2(N) because each time i is divide by 2.
That measn 2 ^ log2(N) - 1 , log cancels out .
Left part is N , Hence overall complexity should ne linear
O(N) is correct answer