I was just looking at the big-Oh notation. I wanted to know if the following is true in general $$f(n)=O(g(n)) \implies \log (f(n)) = O(\log (g(n)))$$

I can prove that this is true if $g$ is monotonically increasing, but am not sure if this holds in general.

  • 2
    $\begingroup$ Welcome to CS.SE! Thank you for your clear, well-typeset question. (In the future, you might share with us in the question what you have tried: e.g., how you tried to prove it and where you got stuck, what kinds of examples you looked at, etc. That might help enable others to clear up any potential misunderstandings.) Anyway, welcome to the site! $\endgroup$ – D.W. Jun 29 '14 at 3:59

By definition, $$ f(n) \in O(g(n))$$ means there exists some positive constant $c$, such that for any large enough $n$, $$ |f(n)| \le c |g(n)|$$ or equivalently, $\lim_{n\to\infty} \frac{f(n)}{g(n)} \le c < \infty$

Taking $\log$ of both sides, for any large enough $n$ it holds that $$ \log (f(n)) \le log (c) + \log(g(n)) $$

so, $$\frac{\log f(n)}{\log g(n)} \le \frac{\log c}{\log g(n)}+ c$$

Now can this go to infinity? only if $\log(g(n)) \to 0$

So let's try, and take $f(n)=2^{-n}$ and $g(n)=1/n$. Obviously $f(n) \in O(g(n))$. Yet, taking the logs we have $\log f(n) = -n$, $\log g(n) =-\log n$, and it is clear that no constant $c'$ will satisfy $|\log f(n)| \le c' |\log g(n)|$ for large enough $n$. Yet, I always find it weird to discuss $O$ of negative functions.


Here's example w/o negative function. Get back to the requirement of $\log(g(n)) \to 0$. Take $g(n) = 1+1/n$. Thus $\log (g(n)) \to 0$.
(actually, the above example of $2^{-n}$ vs $1/n$ satisfies $g(n)\to 0$ rather than $log(g(n))\to 0$. Oops).

If we take $f(n) = 2 + 1/n$ then $\log f(n) \to 1$ (binary log, obviously).

so while $f(n) \le 3g(n)$ for every $n\ge 1$, it is not true that $\log f(n) \le c' \log g(n)$ for all large enough $n$, as the right-hand side approaches zero, while the left-hand side approaches 1.

  • 1
    $\begingroup$ "or equivalently" -- wrong, unfortunately. There are cases in which the limit does not exist; consider $f : n \mapsto 1$ and $g : n \mapsto |\sin(n)|$. $\endgroup$ – Raphael Jun 29 '14 at 19:11
  • $\begingroup$ @Raphael I'm not sure what you mean. For your example f is not $O(g)$ by both definitions. There was a related question somewhere, let me try to find it. cs.stackexchange.com/questions/1780/… $\endgroup$ – Ran G. Jun 29 '14 at 21:07
  • $\begingroup$ Sorry, wrong way round; $g \in O(f)$ by definition with $c \geq 1$ but the limit of the quotient does not exist. You need $\lim\sup$ for an equivalent definition; cf here. $\endgroup$ – Raphael Jun 29 '14 at 22:08
  • $\begingroup$ Right, right... $\endgroup$ – Ran G. Jun 30 '14 at 0:09

while g(n) and f(n) are non negative , and bigger than 1, this is true for every functions.

  • $\begingroup$ take $f(n)=10+1/n$ and $g(n)=1+ 1/n$ as a counterexample. $\endgroup$ – Ran G. Jun 29 '14 at 21:04
  • $\begingroup$ @RanG. How is that a counterexample? Both $f$ and $g$ are $\Theta(1)$ and so are their logarithms. $\endgroup$ – David Richerby Sep 26 '18 at 22:39
  • $\begingroup$ @DavidRicherby $\log 1=0$, and it is a bit extreme to say that $\log(10)=O(0)$. See also my posted answer above. When the variables go to 0 rather than to $\infty$, the big-O is sometimes a bit misleading. $\endgroup$ – Ran G. Sep 28 '18 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.