Big O notation


Big O notation is a mathematical notation that describes the approximate size of a function on a domain. Big O is a member of a [|family of notations] invented by German mathematicians Paul Bachmann and Edmund Landau
and expanded by others, collectively called Bachmann–Landau notation. The letter O was chosen by Bachmann to stand for Ordnung, meaning the order of approximation.
In computer science, big O notation is used to classify algorithms according to how their run time or space requirements
grow as the input size grows.
In analytic number theory, big O notation is often used to express bounds on the growth of an arithmetical function; one well-known example is the remainder term in the prime number theorem.
In mathematical analysis, including calculus,
Big O notation is used to bound the error when truncating a power series and to express the quality
of approximation of a real or complex valued function
by a simpler function.
Often, big O notation characterizes functions according to their growth rates as the variable becomes large: different functions with the same asymptotic growth rate may be represented using the same O notation. The letter O is used because the growth rate of a function is also referred to as the order of the function. A description of a function in terms of big O notation only provides an upper bound on the growth rate of the function.
Associated with big O notation are several related notations, using the symbols,,,,,,, and to describe other kinds of bounds on growth rates.

Formal definition

Let the function to be estimated, be either a real or complex valued function defined on a domain and let the comparison function, be a non-negative real valued function defined on the same set Common choices for the domain are intervals of real numbers, bounded or unbounded, the set of positive integers, the set of complex numbers and tuples of real/complex numbers. With the domain written explicitly or understood implicitly, one writes
which is read as is of if there exists a positive real number such that
If throughout the domain an equivalent definition is that the ratio is bounded, i.e. there is a positive real number so that for all These encompass all the uses of in computer science and mathematics, including its use where the domain is finite, infinite, real, complex, single variate, or multivariate. In most applications, one chooses the function appearing within the argument of to be as simple a form as possible, omitting constant factors and lower order terms. The number is called the implied constant because it is normally not specified. When using notation, what matters is that some finite exists, not its specific value. This simplifies the presentation of many analytic inequalities.
For functions defined on positive real numbers or positive integers, a more restrictive and somewhat conflicting definition
is still in common use, especially in computer science.
When restricted to functions which are eventually positive, the notation
means that for some real number in the domain Here, the expression doesn't indicate a limit, but the notion that the inequality holds for large enough The expression often is omitted.
Similarly, for a finite real number the notation
means that for some constant on the interval that is, in a small neighborhood of
In addition, the notation
means [|More complicated expressions] are also possible.
Despite the presence of the equal sign as written, the expression does not refer to an equality, but rather to an inequality relating and
In the 1930s, the Russian number theorist introduced the notation which has been increasingly used in number theory and other branches of mathematics, as an alternative to the notation. We have
Frequently both notations are used in the same work.

Set version of big O

In computer science it is common to define as also defining a set of functions. With the positive function specified, one interprets as representing the set of all functions that satisfy One can then equivalently write read as "the function is among the set of all functions of

Examples with an infinite domain

In typical usage the notation is applied to an infinite interval of real numbers and captures the behavior of the function for very large. In this setting, the contribution of the terms that grow "most quickly" will eventually make the other ones irrelevant. As a result, the following simplification rules can be applied:
  • If is a sum of several terms, if there is one with largest growth rate, it can be kept, and all others omitted.
  • If is a product of several factors, any constants can be omitted.
For example, let, and suppose we wish to simplify this function, using notation, to describe its growth rate for large. This function is the sum of three terms:,, and. Of these three terms, the one with the highest growth rate is the one with the largest exponent as a function of, namely. Now one may apply the second rule: is a product of and in which the first factor does not depend on. Omitting this factor results in the simplified form. Thus, we say that is a "big O" of. Mathematically, we can write for all. One may confirm this calculation using the formal definition: let and. Applying the [|formal definition] from above, the statement that is equivalent to its expansion,
for some suitable choice of a positive real number and for all. To prove this, let. Then, for all :
so
While it is also true, by the same argument, that
, this is a less precise
approximation of the function.
On the other hand, the statement is false, because the term causes
to be unbounded.
When a function describes the number
of steps required in an algorithm with input, an expression such as
with the implied domain being the set of positive integers, may be interpreted as saying that the algorithm has at most the order of time complexity.

Example with a finite domain

Big O can also be used to describe the error term in an approximation to a mathematical function on a finite interval. The most significant terms are written explicitly, and then the least-significant terms are summarized in a single big O term. Consider, for example, the exponential series and two expressions of it that are valid when is small:
The middle expression the line with means the absolute-value of the error
is at most some constant times when is small.
This is an example of the use of Taylor's theorem.
The behavior of a given function may be very different on finite domains than on infinite domains, for example,
while

Multivariate examples

Here we have a complex variable function of two variables.
In general, any bounded function is.
The last example illustrates a mixing of finite and infinite domains on the different variables.
In all of these examples, the bound is uniform
in both variables. Sometimes in a multivariate expression, one variable is
more important than others, and one may express
that the implied constant depends on one
or more of the variables using subscripts to the big O symbol or the symbol. For example, consider the expression
This means that for each real number, there
is a constant, which depends on , so that for all,
This particular statement follows from the general binomial theorem.
Another example, common in the theory of Taylor series, is
Here the implied constant depends on the size of the domain.
The subscript convention applies to all of the other
notations in this page.

Properties

Product

Sum

If and then. It follows that if and then.

Multiplication by a constant

Let be a nonzero constant. Then. In other words, if, then

Transitive property

If and then
If the function of a positive integer
can be written as a finite sum of other functions, then the fastest growing one determines the order of. For example,
Some general rules about growth toward infinity; the 2nd and 3rd property below
can be proved rigorously using L'Hôpital's rule:

Large powers dominate small powers

For, then

Powers dominate logarithms

For any positive
no matter how large is and how small
is. Here, the implied constant depends
on both and.

Exponentials dominate powers

For any positive
no matter how large is and how small
is.
A function that grows faster than for any is called superpolynomial. One that grows more slowly than any exponential function of the form with is called subexponential. An algorithm can require time that is both superpolynomial and subexponential; examples of this include the fastest known algorithms for integer factorization and the function.
We may ignore any powers of inside of the logarithms. For any positive, the notation means exactly the same thing as, since. Similarly, logs with different constant bases are equivalent with respect to Big O
notation. On the other hand, exponentials with different bases are not of the same order. For example, and are not of the same order.

More complicated expressions

In more complicated usage, can appear in different places in an equation, even several times on each side. For example, the following are true for a positive integer:
The meaning of such statements is as follows: for any functions which satisfy each on the left side, there are some functions satisfying each on the right side, such that substituting all these functions into the equation makes the two sides equal. For example, the third equation above means: "For any function satisfying, there is some function such that ". The implied constant in the statement "" may
depend on the implied constant in the expression
"".
Some further examples: