algorithmic complexity of "smallest power of 2 greater than n"

101 Views Asked by At

If an algorithm will take as long as some constant times the smallest power of 2 greater than $n$, is it $O(n)$?

In favour:

$2^{\log_2n + 1}$ would seem to imply $O(n)$

Against:

There is no $c$ where the algorithm always takes less than $cn$ time.

Thanks, Ian

1

There are 1 best solutions below

0
On BEST ANSWER

$2^{\lceil\log_2 n\rceil}< 2^{1+\log_2 n}= 2 n$

So $c = 2$ works fine.