It was invented by the German number theorist Edmund Landau, hence it is also called Landau's symbol. The letter O was originally a capital omicron, and is never a digit zero.
In Wikipedia, the various notations described in this article are used for approximating formulas (e.g. those in the sum article), for analysis of algorithms (e.g. those in the heapsort article), and for the definitions of terms in complexity theory (e.g. polynomial time).
Table of contents |
2 Common orders of functions 3 Formal definition 4 Multiple Variables 5 Related notation |
There are two formally close, but noticeably different usages of his notation: infinite asymptotics an infinitesimal asymptotics
Big O notation is useful when analyzing algorithms for efficiency. For example, the time (or the number of steps) it takes to complete a problem of size n might be found to be T(n) = 4n^{2} - 2n + 2.
As n grows large, the n^{2} term will come to dominate, so that all other terms can be neglected. Further, the constants will depend on the precise details of the implementation and the hardware it runs on, so they should also be neglected. Big O notation captures what remains: we write T(n) = O(n^{2}) and say that the algorithm has order of n^{2} time complexity.
O(n^{c}) and O(c^{n}) are very different. The latter grows much, much faster, no matter how big the constant c is. A function that grows faster than any power of n is called superpolynomial. One that grows slower than an exponential function of the form c^{n} is called subexponential. An algorithm can require time that is both superpolynomial and subexponential; examples of this include the fastest algorithms known for integer factorization.
O(log n) is exactly the same as O(log(n^{c})). The logarithms differ only by a constant factor, (since log(n^{c})=c log n) and thus the big O notation ignores that. Similarly, logs with different constant bases are equivalent.
notation | name | |
O(1) | constant | |
O(log n) | logarithmic | |
O((log n)^{c}) | polylogarithmic | |
O(n) | linear | |
O(n log n) | sometimes called "linearithmic" | |
O(n^{2}) | quadratic | |
O(n^{c}) | polynomial, sometimes "geometric" | |
O(c^{n}) | exponential | |
O(n!) | factorial |
The formal definition of big O uses limitss. Suppose f(x) and g(x) are two functions defined on some subset of the real numbers.
In mathematics, both limits at ∞ and limits at a are used. In computer science, only limits at ∞ are used; furthermore, only positive functions are considered, so the absolute value bars may be left out.
Therefore, to be more formally correct, some people prefer to define O(g) as a function that maps functions into sets of functions, with the value O(g(x)) being the set of all functions that do not grow faster then g(x). Under this convention, it is said, e.g., that f(x) belongs to class (or set) O(g(x)) and the corresponding set membership notation is used.
Perhaps most commonly, one simply says "f(x) is O(g(x))" without any formal notation for "is".
Another point of difficulty is that the parameter whose asymptotic behavior is being examined is not always clear. A statement such as f(x,y) = O(g(x,y)) requires some additional explanation to make clear what is meant. Still, this problem is rare in practice.
Notation | Analogy | |
f(n) = O(g(n)) | asymptotic upper bound | |
f(n) = o(g(n)) | asymptotically negligible (M = 0) | |
f(n) = Ω(g(n)) | asymptotic lower bound (iff g(n) = O(f(n))) | |
f(n) = ω(g(n)) | asymptoticaly dominant (iff g(n) = o(f(n))) | |
f(n) = Θ(g(n)) | asymptotically tight bound
(iff both f(n) = O(g(n))
and g(n) = O(f(n))) |
In casual use, O is commonly used where Θ is meant, i.e., a tight esitmate is implied. For example, one might say "heapsort is O(n log n) in average case" when the intended meaning was "heapsort is Θ(n log n) in average case". Both statements are true, but the latter is a stronger claim.
Another notation sometimes used in computer science is Õ (read Soft-O). f(n) = Õ(g(n)) is shorthand for f(n) = O(g(n) log^{k}n) for some k. Essentially, it is Big-O, ignoring logarithmic factors. This notation is often used to describe a class of "nitpicking" estimates (since log^{k}n is always o(n) for any constant k).