# Why is $\log n = O(2^n)$? [duplicate]

In my theoretical computer science book I have the following statement regarding the space complexity of $f(n)=2^n$:

$$\log(n) = O(f(n))$$

I can't understand how this is true, any help will be greatly appreciated.

• Note that the question is purely about the relationships between the functions $\log n$ and $2^n$. It doesn't matter if those functions are being used to measure time complexity, space complexity or the number of seconds until a radioactive source decays. It's just about the two functions. May 31 '17 at 12:28
• The context is obscure. Where, in what book? What is the theme/chapter title? May 31 '17 at 13:02
• What is the connection to space complexity? May 31 '17 at 13:24
• Are you asking why does $\log n = O(2^n)$ holds? May 31 '17 at 13:58

As stated, $\log (n) = O (2^n)$ is trivially true.

All that it says is that $\log n$, in the end, grows no faster than $2^n$. For $2^n$, you can substitute $n$, $\sqrt n$, indeed any root of $n$.

However carelessly stated, I think this really refers to the following:

• To represent a number of size $2^n$, you need $n$ bits.
• So, to represent a number of size $n$, you need $\log n$ bits.

Bits are a measure of space.

I made heavy weather of this before, as I thought it was referring to the time it takes to calculate $2^n$. In case it is, I'll leave this in:

For $n$ a non-negative integer, and $f(n) = 2^n$

$$f(n) = \begin{cases} 1 &\text{for }\, n = 0 \\ (f (n \div 2))^2\times 2^{(n \mod 2)} &\text{for}\; n \gt 0 \end{cases}$$

The implied algorithm is clearly $\Theta (log \, n)$. But this is time complexity. In space complexity, it is $\Theta(1)$.

• $\Theta (f)$ are the functions that, adapting the words of Wolfram Mathworld, are no worse but also no better than $f$.
• $O (f)$ are the functions that are no worse than $f$.
• How does this answer the question? May 31 '17 at 12:41
• You are still avoiding the question. May 31 '17 at 12:50
• @YuvalFilmus I look forward to your solution. May 31 '17 at 13:03
• @YuvalFilmus It appears that Thumbnail has indeed answered the question, or at least one possible interpretation. $2^n$ in binary is, of course, 1 followed by $n$ 0s, so it would suffice to represent $n$, using $\log n$ bits. Thus one might say that the space complexity of $2^n$ is at most $\log n$. I would readily admit that this is just one interpretation of what could be described as an obfuscated question at best. May 31 '17 at 14:23