What does $\log^{O(1)}n$ mean?

I am aware of big-O notation, but this notation makes no sense to me. I can't find anything about it either, because there is no way a search engine interprets this correctly.

For a bit of context, the sentence where I found it reads "[...] we call a function [efficient] if it uses $O(\log n)$ space and at most time $\log^{O(1)}n$ per item."

  • 1
    $\begingroup$ I agree that one should not write things like this, unless one is very clear about what it is to mean (and tells the reader what that is) and uses it the same rules consistently. $\endgroup$ – Raphael Oct 21 '15 at 16:35
  • 1
    $\begingroup$ Yes, one should instead write it as $\: (\log(n))^{O(1)} \;$. $\;\;\;\;$ $\endgroup$ – user12859 Oct 21 '15 at 17:16
  • 1
    $\begingroup$ @RickyDemer That's not the point that Raphael is making. $\log^{\mathrm{blah}}n$ means exactly $(\log n)^{\mathrm{blah}}$. $\endgroup$ – David Richerby Oct 21 '15 at 19:35
  • 4
    $\begingroup$ @Raphael This is standard notation in the field. Anyone in the know would know what it means. $\endgroup$ – Yuval Filmus Oct 21 '15 at 19:45
  • 1
    $\begingroup$ @YuvalFilmus I think the variety of disagreeing answers is conclusive proof that your claim is false, and that one should indeed refrain from using such notation. $\endgroup$ – Raphael Oct 27 '15 at 9:07

You need to ignore for a moment the strong feeling that the "$O$" is in the wrong place and plough on with the definition regardless. $f(n) = \log^{O(1)}n$ means that there exist constants $k$ and $n_0$ such that, for all $n\geq n_0$, $f(n) \leq \log^{k\cdot 1}n = \log^k n$.

Note that $\log^k n$ means $(\log n)^k$. Functions of the form $\log^{O(1)}n$ are often called polylogarithmic and you might hear people say, "$f$ is polylog $n$."

You'll notice that it's easy to prove that $2n=O(n)$, since $2n\leq k n$ for all $n\geq 0$, where $k=2$. You might be wondering if $2\log n = \log^{O(1)}n$. The answer is yes since, for large enough $n$, $\log n\geq 2$, so $2\log n \leq \log^2n$ for large enough $n$.

On a related note, you'll often see polynomials written as $n^{O(1)}$: same idea.

  • $\begingroup$ This is not supported by the common placeholder convention. $\endgroup$ – Raphael Oct 21 '15 at 16:29
  • $\begingroup$ I retract my comment: you write $\leq$ in all the important places, which is sufficient. $\endgroup$ – Raphael Oct 22 '15 at 7:27
  • $\begingroup$ @Raphael OK. I hadn't had time to check it yet but my feeling was you might be ordering quantifiers differently from the way I am. I'm not actually sure we're defining the same class of functions. $\endgroup$ – David Richerby Oct 22 '15 at 7:34
  • $\begingroup$ I think you are defining my (2), and Tom defines $\bigcup_{c \in \mathbb{R}_{>0}} \{ \log^c n \}$. $\endgroup$ – Raphael Oct 22 '15 at 7:39

This is an abuse of notation that can be made sense of by the generally accepted placeholder convention: whenever you find a Landau term $O(f)$, replace it (in your mind, or on the paper) by an arbitrary function $g \in O(f)$.

So if you find

$\qquad f(n) = \log^{O(1)} n$

you are to read

$\qquad f(n) = \log^{g(n)} n$ for some $g \in O(1). \hspace{5cm} (1)$

Note the difference from saying "$\log$ to the power of some constant": $g = n \mapsto 1/n$ is a distinct possibility.

Warning: The author may be employing even more abuse of notation and want you to read

$\qquad f(n) \in O(\log^{g(n)} n)$ for some $g \in O(1). \hspace{4.3cm} (2)$

Note the difference between (1) and (2); while it works out to define the same set of positive-valued functions here, this does not always work. Do not move $O$ around in expressions without care!

  • 3
    $\begingroup$ I think what makes it tick is that $x \mapsto \log^x(n)$ is monotonic and sufficiently surjective for each fixed $n$. Monotonic makes the position of the $O$ equivalent and gives you (2) ⇒ (1); going the other way requires $g$ to exist which could fail if $f(n)$ is outside the range of the function. If you want to point out that moving $O$ around is dangerous and doesn't cover “wild” functions, fine, but in this specific case it's ok for the kind of functions that represent costs. $\endgroup$ – Gilles Oct 24 '15 at 2:24
  • $\begingroup$ @Gilles I weakened the statement to a general warning. $\endgroup$ – Raphael Oct 25 '15 at 19:11
  • 1
    $\begingroup$ This answer has been heavily edited, and now I am confused: do you now claim that (1) and (2) are effectively the same? $\endgroup$ – Oebele Oct 26 '15 at 9:54
  • $\begingroup$ @Oebele As far as I can tell, they are not in general, but here. $\endgroup$ – Raphael Oct 26 '15 at 10:15
  • $\begingroup$ But, something like $3 log^2 n$ does not match (1) but does match (2) right? or am I just being silly now? $\endgroup$ – Oebele Oct 26 '15 at 14:33

It means that the function grows at most as $\log $ to the power of some constant, i.e. $\log^2(n)$ or $\log^5(n)$ or $\log^{99999}(n)$...

  • $\begingroup$ This can be used when the function growth is known to be bounded by some constant power of the $\log$, but the particular constant is unknown or left unspecified. $\endgroup$ – Yves Daoust Oct 21 '15 at 13:47
  • $\begingroup$ This is not supported by the common placeholder convention. $\endgroup$ – Raphael Oct 21 '15 at 16:29

"At most $\log^{O(1)} n$" means that there is a constant $c$ such that what is being measured is $O(\log^c n)$.

In a more general context, $f(n) \in \log^{O(1)} n$ is equivalent to the statement that there exists (possibly negative) constants $a$ and $b$ such that $f(n) \in O(\log^a n)$ and $f(n) \in \Omega(\log^b n)$.

It is easy to overlook the $\Omega(\log^b n)$ lower bound. In a setting where that would matter (which would be very uncommon if you're exclusively interested in studying asymptotic growth), you shouldn't have complete confidence that the author actually meant the lower bound, and would have to rely on the context to make sure.

The literal meaning of the notation $\log^{O(1)} n$ is doing arithmetic on the family of functions, resulting in the family of all functions $\log^{g(n)} n$, where $g(n) \in O(1)$. This works in pretty much the same as how multiplying $O(g(n))$ by $h(n)$ results in $O(g(n) h(n))$, except that you get a result that isn't expressed so simply.

Since the details of the lower bound are in probably unfamiliar territory, it's worth looking at some counterexamples. Recall that any $g(n) \in O(1)$ is bounded in magnitude; that there is a constant $c$ such that for all sufficiently large $n$, $|g(n)| < c$.

When looking at asymptotic growth, usually only the upper bound $g(n) < c$ matters, since, e.g., you already know the function is positive. However, in full generality you have to pay attention to the lower bound $g(n) > -c$.

This means, contrary to more typical uses of big-oh notation, functions that decrease too rapidly can fail to be in $\log^{O(1)} n$; for example, $$ \frac{1}{n} = \log^{-(\log n) / (\log \log n)} n \notin \log^{O(1)} n$$ because $$ -\frac{\log n}{\log \log n} \notin O(1) $$ The exponent here grows in magnitude too rapidly to be bounded by $O(1)$.

A counterexample of a somewhat different sort is that $-1 \notin \log^{O(1)} n$.

  • $\begingroup$ Can't I just take $b=0$ and make your claimed lower bound go away? $\endgroup$ – David Richerby Oct 26 '15 at 22:02
  • 1
    $\begingroup$ @DavidRicherby No, $b=0$ still says that $f$ is bounded below. Hurkyl: why isn't $f(n) = 1/n$ in $\log^{O(1)} n$? $\endgroup$ – Gilles Oct 27 '15 at 0:27
  • $\begingroup$ @Gilles: More content added! $\endgroup$ – Hurkyl Oct 27 '15 at 0:57
  • $\begingroup$ @Gilles OK, sure, it's bounded below by 1. Which is no bound at all for "most" applications of Landau notation in CS. $\endgroup$ – David Richerby Oct 27 '15 at 7:51
  • $\begingroup$ 1) Your "move around $O$" rule does not always work, and I don't think "at most" usually has that meaning; it's just redundant. 2) Never does $O$ imply a lower bound. That's when you use $\Theta$. 3) If and how negative functions are dealt with by a given definition of $O$ (even without abuse of notation) is not universally clear. Most definitions (in analysis of algorithms) exclude them. You seem to assume a definition that bounds the absolute value, which is fine. $\endgroup$ – Raphael Oct 27 '15 at 9:00

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.