How can I find the complexity of
i = 1;
while( i <n)
{
i = 2*i;
}
using summation?
I have $f(n) = \sum_{i=1, i=2*i}^{n-1}1$, but I am not sure how to solve that. I think $f \in O(\log(n))$
How can I find the complexity of
i = 1;
while( i <n)
{
i = 2*i;
}
using summation?
I have $f(n) = \sum_{i=1, i=2*i}^{n-1}1$, but I am not sure how to solve that. I think $f \in O(\log(n))$
In your while-loop $i$ increases exponentially.
On the $k^{th}$ iteration, you have $i= 2^{k}$ and will end when $2^k\ge n$.
So, the loop will exit as soon as $k\ge \log_2(n)$.