Doubt in no. 1 problem

In the problem 1 ,the inner loop runs in a series of n,n/2,n/4,n/8…1. So, the answer should be O(NLogN) according to the series. In the answer sheet this same series is given but the result is given O(N).

So,can please clarify what is the correct answer.

Hey @sayangosw
in iteration 1 inner loop will run -> N time
in iteration 2 inner loop will run -> N/2 time
in iteration 3 inner loop will run -> N/2^2 time
in iteration 4 inner loop will run -> N/2^3 time

if add them u will get
N+ N/2+N/2^2 +N/2^3…+ N/2^K …+ 1

N( 1+1/2+1/4+1/8+1/16…) ==N(1/(1-1/2) ) [infinite gp sum] == 2N ==O(N)
So answer will be O(N)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.