Lably
Skip to content

Big O notation

Describes approximate behavior of a function

  • 17 min read
  • 10 chapters
  • 1 lab on Lably

Learn it on Lably

In computer science, big O notation is used to classify algorithms by how their run time or space requirements grow with the input. In analytic number theory, big O notation expresses bounds on the growth of an arithmetical function, as for the remainder term in the prime number theorem. In mathematical analysis, including calculus, Big O notation bounds the error when truncating a power series and expresses 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 o, ∼, Ω, ≪, ≫, ≍, ω, and Θ to describe other kinds of bounds on growth rates.

Bachmann proposed the notation in 1894 and Landau extended it in 1909. An earlier notation was proposed by Paul du Bois-Reymond in 1870.

Formal definition

Let f, the function to be estimated, be either a real or complex valued function defined on a domain D, and let g, the comparison function, be a non-negative real valued function defined on the same set D. 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 f(x)=O(g(x)) which is read as "f(x) is big O of g(x)" if there exists a positive real number M such that |f(x)|≤Mg(x)forallx∈D.

If g(x)>0 (i.e. g is also never zero) throughout the domain D, an equivalent definition is that the ratio f(x)g(x) is bounded, i.e. there is a positive real number M so that |f(x)g(x)|≤M for all x∈D. These encompass all the uses of big O 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 g(x) appearing within the argument of O(⋅) to be as simple a form as possible, omitting constant factors and lower order terms. The number M is called the implied constant because it is normally not specified. When using big O notation, what matters is that some finite M 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 f(x)=O(g(x))asx→∞ means that for some real number a, f(x)=O(g(x)) in the domain [a,∞). Here, the expression x→∞ does not indicate a limit, but the notion that the inequality holds for large enough x. The expression x→∞ often is omitted.

Similarly, for a real number a, the notation f(x)=O(g(x)) as x→a means that for some constant c>0, f(x)=O(g(x)) on the interval [a−c,a+c]; that is, in a small neighborhood of a. In addition, the notation f(x)=h(x)+O(g(x)) means f(x)−h(x)=O(g(x)). More complicated expressions are also possible.

Despite the presence of the equal sign (=) as written, the expression f(x)=O(g(x)) does not refer to an equality, but rather to an inequality relating f and g.

In the 1930s, the Russian number theorist I.M. Vinogradov introduced the notation ≪, which has been increasingly used in number theory and other branches of mathematics, as an alternative to the O notation. We have f≪g⟺f=O(g). Frequently both notations are used in the same work.

Set version of big O

In computer science it is common to define big O as also defining a set of functions. With the positive (or non-negative) function g(x) specified, one interprets O(g(x)) as representing the set of all functions f~ that satisfy f~(x)=O(g(x)). One can then equivalently write f(x)∈O(g(x)), read as "the function f(x) is among the set of all functions of order at most g(x)."

Sign in to keep reading

9 more chapters are free with a Lably account.

More in Theoretical computer science