Interpreting the Time Complexity for this problem

20 Views Asked by At

Say I have a loop that runs, and after k iterations we find that it stops when:

$\left \lfloor{\frac{n}{2^k}}\right \rfloor <1$

We solve for k to find the number of iterations like so:

$0\le\frac{n}{2^k} <1$

$0\le n <2^k$

$-\infty \le log_2n <k$

So is it $ k \in O(log n)$ ?

1

There are 1 best solutions below

0
On BEST ANSWER

Since it stops exactly when this relation is satisfied, we have $$ \log n < k \leq c' \log n $$ for any $c'>1,$ so you have the exact order, $$ k=\theta(\log n). $$