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++;
O(log N)
O(N)
O(N*log N)
O(N^2)
what is the answer for this question chec once?
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++;
O(log N)
O(N)
O(N*log N)
O(N^2)
what is the answer for this question chec once?
@kumawatnitesh093,
For a input integer n, the innermost statement of fun() is executed following times.
n + n/2 + n/4 + … 1
So time complexity T(n) can be written as
T(n) = O(n + n/2 + n/4 + … 1) = O(n)