15

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."

Raphael
  • 73,212
  • 30
  • 182
  • 400
Oebele
  • 253
  • 1
  • 4

4 Answers4

16

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.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
9

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!

Gilles 'SO- stop being evil'
  • 44,159
  • 8
  • 120
  • 184
Raphael
  • 73,212
  • 30
  • 182
  • 400
6

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)$...

Gilles 'SO- stop being evil'
  • 44,159
  • 8
  • 120
  • 184
Tom van der Zanden
  • 13,493
  • 1
  • 39
  • 56
2

"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$.