adplus-dvertising
frame-decoration

Question

What is the time complexity of following code:
int a = 0, i = N;
while (i > 0) 
{
a += i;
i /= 2;
}

a.

O(N)

b.

O(Sqrt(N))

c.

O(N / 2)

d.

O(log N)

Answer: (d).O(log N)

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the time complexity of following code: