Please explain question 1

Find the time complexity of the given code.

int count = 0;
for (int i = N; i > 0; i /= 2)
for (int j = 0; j < i; j++)
count++;
in this question we have n+n/2+n/4+n/8…1
so we will have logn terms and each step takes some constant time so why time complexity is not logn

hello @hssharma2212000

the result of this summation is 2n-1 .
from the formula (2
n-1) we can cleary say that computation time depens on size of input so if input is of large size time will be more .
thats why we can say that time complexity will be O(n) ie time will linearly depends on input

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.