int sum = 0;
for(int n = N; n > 0; n/=2)
for(int i = 0; i < n; i++)
sum++
This O(N), the inner loop runs just N + N/2 + N/4 + ... + 1once, this sum converges to 2Nwhen N->infinity, and therefore, it is O(N).
int sum = 0;
for(int i = 1; i < N; i*=2)
for(int j = 0; j < i; j++)
sum++
This is very similar to case1, and I'm going to leave it to you as a practice. Follow the same approach that I did there and you will get an answer.
int sum = 0;
for(int i = 1; i < N; i*=2)
for(int j = 0; j < N; j++)
sum++
, . , i N .
, , , N.
.