Big ''O'' notation is a mathematical notation that describes the
limiting behavior of a
function
Function or functionality may refer to:
Computing
* Function key, a type of key on computer keyboards
* Function model, a structured representation of processes in a system
* Function object or functor or functionoid, a concept of object-oriente ...
when the
argument
An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialectic ...
tends towards a particular value or infinity. Big O is a member of a
family of notations invented by
Paul Bachmann,
Edmund Landau
Edmund Georg Hermann Landau (14 February 1877 – 19 February 1938) was a German mathematician who worked in the fields of number theory and complex analysis.
Biography
Edmund Landau was born to a Jewish family in Berlin. His father was Leopold ...
,
and others, collectively called Bachmann–Landau notation or asymptotic notation. The letter O was chosen by Bachmann to stand for ''
Ordnung
The Ordnung is a set of rules for Amish, Old Order Mennonite and Conservative Mennonite living. ''Ordnung'' () is the German word for order, discipline, rule, arrangement, organization, or system. Because the Amish have no central church governme ...
'', meaning the
order of approximation
In science, engineering, and other quantitative disciplines, order of approximation refers to formal or informal expressions for how accurate an approximation is.
Usage in science and engineering
In formal expressions, the English_numerals#Ordi ...
.
In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, 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
In mathematics, analytic number theory is a branch of number theory that uses methods from mathematical analysis to solve problems about the integers. It is often said to have begun with Peter Gustav Lejeune Dirichlet's 1837 introduction of Diric ...
, big O notation is often used to express a bound on the difference between an
arithmetical function
In number theory, an arithmetic, arithmetical, or number-theoretic function is for most authors any function ''f''(''n'') whose domain is the positive integers and whose range is a subset of the complex numbers. Hardy & Wright include in their d ...
and a better understood approximation; a famous example of such a difference is the remainder term in the
prime number theorem
In mathematics, the prime number theorem (PNT) describes the asymptotic distribution of the prime numbers among the positive integers. It formalizes the intuitive idea that primes become less common as they become larger by precisely quantifying ...
. Big O notation is also used in many other fields to provide similar estimates.
Big O notation characterizes functions according to their growth rates: different functions with the same 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 usually only provides an
upper bound
In mathematics, particularly in order theory, an upper bound or majorant of a subset of some preordered set is an element of that is greater than or equal to every element of .
Dually, a lower bound or minorant of is defined to be an element ...
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 asymptotic growth rates.
Formal definition
Let
, the function to be estimated, be a
real
Real may refer to:
Currencies
* Brazilian real (R$)
* Central American Republic real
* Mexican real
* Portuguese real
* Spanish real
* Spanish colonial real
Music Albums
* ''Real'' (L'Arc-en-Ciel album) (2000)
* ''Real'' (Bright album) (2010)
...
or
complex
Complex commonly refers to:
* Complexity, the behaviour of a system whose components interact in multiple ways so possible interactions are difficult to describe
** Complex system, a system composed of many components which may interact with each ...
valued function and let
, the comparison function, be a real valued function. Let both functions be defined on some
unbounded subset
In mathematics, Set (mathematics), set ''A'' is a subset of a set ''B'' if all Element (mathematics), elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they are ...
of the positive
real number
In mathematics, a real number is a number that can be used to measure a ''continuous'' one-dimensional quantity such as a distance, duration or temperature. Here, ''continuous'' means that values can have arbitrarily small variations. Every real ...
s, and
be strictly positive for all large enough values of
.
One writes
if the
absolute value
In mathematics, the absolute value or modulus of a real number x, is the non-negative value without regard to its sign. Namely, , x, =x if is a positive number, and , x, =-x if x is negative (in which case negating x makes -x positive), an ...
of
is at most a positive constant multiple of
for all sufficiently large values of
. That is,
if there exists a positive real number
and a real number
such that
In many contexts, the assumption that we are interested in the growth rate as the variable
goes to infinity is left unstated, and one writes more simply that
The notation can also be used to describe the behavior of
near some real number
(often,
): we say
if there exist positive numbers
and
such that for all defined
with
As
is chosen to be strictly positive for such values of
, both of these definitions can be unified using the
limit superior
In mathematics, the limit inferior and limit superior of a sequence can be thought of as limiting (that is, eventual and extreme) bounds on the sequence. They can be thought of in a similar fashion for a function (see limit of a function). For a ...
:
if
And in both of these definitions the
limit point
In mathematics, a limit point, accumulation point, or cluster point of a set S in a topological space X is a point x that can be "approximated" by points of S in the sense that every neighbourhood of x with respect to the topology on X also contai ...
(whether
or not) is a
cluster point
In mathematics, a limit point, accumulation point, or cluster point of a set S in a topological space X is a point x that can be "approximated" by points of S in the sense that every neighbourhood of x with respect to the topology on X also contai ...
of the domains of
and
, i. e., in every neighbourhood of
there have to be infinitely many points in common. Moreover, as pointed out in the article about the
limit inferior and limit superior
In mathematics, the limit inferior and limit superior of a sequence can be thought of as limiting (that is, eventual and extreme) bounds on the sequence. They can be thought of in a similar fashion for a function (see limit of a function). For a ...
, the
(at least on the
extended real number line
In mathematics, the affinely extended real number system is obtained from the real number system \R by adding two infinity elements: +\infty and -\infty, where the infinities are treated as actual numbers. It is useful in describing the algebra ...
) always exists.
In computer science, a slightly more restrictive definition is common:
and
are both required to be functions from some unbounded subset of the
positive integers
In mathematics, the natural numbers are those numbers used for counting (as in "there are ''six'' coins on the table") and ordering (as in "this is the ''third'' largest city in the country").
Numbers used for counting are called ''cardinal n ...
to the nonnegative real numbers; then
iff there exist positive integer numbers
and
such that
for all
.
Example
In typical usage the notation is asymptotical, that is, it refers to 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 (terms in the product that do not depend on ) can be omitted.
For example, let , and suppose we wish to simplify this function, using notation, to describe its growth rate as approaches infinity. 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 . One may confirm this calculation using the formal definition: let and . Applying the
formal definition
Formal, formality, informal or informality imply the complying with, or not complying with, some set of requirements (forms, in Ancient Greek). They may refer to:
Dress code and events
* Formal wear, attire for formal events
* Semi-formal attire ...
from above, the statement that is equivalent to its expansion,
for some suitable choice of and and for all . To prove this, let and . Then, for all :
so
Usage
Big O notation has two main areas of application:
* In
mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, it is commonly used to describe
how closely a finite series approximates a given function, especially in the case of a truncated
Taylor series
In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor serie ...
or
asymptotic expansion In mathematics, an asymptotic expansion, asymptotic series or Poincaré expansion (after Henri Poincaré) is a formal series of functions which has the property that truncating the series after a finite number of terms provides an approximation to ...
* In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, it is useful in the
analysis of algorithms
In computer science, the analysis of algorithms is the process of finding the computational complexity of algorithms—the amount of time, storage, or other resources needed to execute them. Usually, this involves determining a function that re ...
In both applications, the function appearing within the is typically chosen to be as simple as possible, omitting constant factors and lower order terms.
There are two formally close, but noticeably different, usages of this notation:
*
infinite
Infinite may refer to:
Mathematics
*Infinite set, a set that is not a finite set
*Infinity, an abstract concept describing something without any limit
Music
* Infinite (group), a South Korean boy band
*''Infinite'' (EP), debut EP of American m ...
asymptotics
*
infinitesimal
In mathematics, an infinitesimal number is a quantity that is closer to zero than any standard real number, but that is not zero. The word ''infinitesimal'' comes from a 17th-century Modern Latin coinage ''infinitesimus'', which originally referr ...
asymptotics.
This distinction is only in application and not in principle, however—the formal definition for the "big O" is the same for both cases, only with different limits for the function argument.
Infinite 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 might be found to be . As grows large, the
term
Term may refer to:
* Terminology, or term, a noun or compound word used in a specific context, in particular:
**Technical term, part of the specialized vocabulary of a particular field, specifically:
***Scientific terminology, terms used by scient ...
will come to dominate, so that all other terms can be neglected—for instance when , the term is 1000 times as large as the term. Ignoring the latter would have negligible effect on the expression's value for most purposes. Further, the
coefficient
In mathematics, a coefficient is a multiplicative factor in some term of a polynomial, a series, or an expression; it is usually a number, but may be any expression (including variables such as , and ). When the coefficients are themselves var ...
s become irrelevant if we compare to any other
order of expression, such as an expression containing a term or . Even if , if , the latter will always exceed the former once grows larger than (). Additionally, the number of steps depends on the details of the machine model on which the algorithm runs, but different types of machines typically vary by only a constant factor in the number of steps needed to execute an algorithm. So the big O notation captures what remains: we write either
:
or
:
and say that the algorithm has ''order of '' time complexity. The sign "" is not meant to express "is equal to" in its normal mathematical sense, but rather a more colloquial "is", so the second expression is sometimes considered more accurate (see the "
Equals sign
The equals sign (British English, Unicode) or equal sign (American English), also known as the equality sign, is the mathematical symbol , which is used to indicate equality in some well-defined sense. In an equation, it is placed between two ...
" discussion below) while the first is considered by some as an
abuse of notation
In mathematics, abuse of notation occurs when an author uses a mathematical notation in a way that is not entirely formally correct, but which might help simplify the exposition or suggest the correct intuition (while possibly minimizing errors an ...
.
Infinitesimal asymptotics
Big O can also be used to describe the
error term In mathematics and statistics, an error term is an additive type of error. Common examples include:
* errors and residuals in statistics, e.g. in linear regression
* the error term in numerical integration
In analysis, numerical integration ...
in an approximation to a mathematical function. 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 second expression (the one with ''O''(''x''
3)) means the absolute-value of the error ''e''
''x'' − (1 + ''x'' + ''x''
2/2) is at most some constant times ''x''
3 when ''x'' is close enough to 0.
Properties
If the function can be written as a finite sum of other functions, then the fastest growing one determines the order of . For example,
:
In particular, if a function may be bounded by a polynomial in , then as tends to ''infinity'', one may disregard ''lower-order'' terms of the polynomial. The sets and are very different. If is greater than one, then the latter grows much faster. A function that grows faster than for any is called ''superpolynomial''. One that grows more slowly than any exponential function of the form 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
In number theory, integer factorization is the decomposition of a composite number into a product of smaller integers. If these factors are further restricted to prime numbers, the process is called prime factorization.
When the numbers are suf ...
and the function .
We may ignore any powers of inside of the logarithms. The set is exactly the same as . The logarithms differ only by a constant factor (since ) and thus the big O notation ignores that. Similarly, logs with different constant bases are equivalent. On the other hand, exponentials with different bases are not of the same order. For example, and are not of the same order.
Changing units may or may not affect the order of the resulting algorithm. Changing units is equivalent to multiplying the appropriate variable by a constant wherever it appears. For example, if an algorithm runs in the order of , replacing by means the algorithm runs in the order of , and the big O notation ignores the constant . This can be written as . If, however, an algorithm runs in the order of , replacing with gives . This is not equivalent to in general. Changing variables may also affect the order of the resulting algorithm. For example, if an algorithm's run time is when measured in terms of the number of ''digits'' of an input number , then its run time is when measured as a function of the input number itself, because .
Product
:
:
Sum
If
and
then
. It follows that if
and
then
. In other words, this second statement says that
is a
convex cone
In linear algebra, a ''cone''—sometimes called a linear cone for distinguishing it from other sorts of cones—is a subset of a vector space that is closed under scalar multiplication; that is, is a cone if x\in C implies sx\in C for every .
...
.
Multiplication by a constant
Let be a nonzero constant. Then
. In other words, if
, then
Multiple variables
Big ''O'' (and little o, Ω, etc.) can also be used with multiple variables. To define big ''O'' formally for multiple variables, suppose
and
are two functions defined on some subset of
. We say
:
if and only if there exist constants
and
such that
for all
with
for some
Equivalently, the condition that
for some
can be written
, where
denotes the
Chebyshev norm. For example, the statement
:
asserts that there exist constants ''C'' and ''M'' such that
:
whenever either
or
holds. This definition allows all of the coordinates of
to increase to infinity. In particular, the statement
:
(i.e.,
) is quite different from
:
(i.e.,
).
Under this definition, the subset on which a function is defined is significant when generalizing statements from the univariate setting to the multivariate setting. For example, if
and
, then
if we restrict
and
to
,_since_the_use_of_the_equals_sign_could_be_misleading_as_it_suggests_a_symmetry_that_this_statement_does_not_have._As_Nicolaas_Govert_de_Bruijn">de_Bruijn