Formal definition
Let , the function to be estimated, be a real or complex valued function and let , the comparison function, be a real valued function. Let both functions be defined on some unbounded subset of the positive real numbers, and be strictly positive for all large enough values of . One writes if theExample
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 theUsage
Big O notation has two main areas of application: * In 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 orInfinite asymptotics
Infinitesimal asymptotics
Big O can also be used to describe the error term 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 forProduct
: :Sum
If and then . It follows that if and then . In other words, this second statement says that is aMultiplication by a constant
Let be a nonzero constant. Then . In other words, if , thenMultiple 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__Matters_of_notation_
__Equals_sign_
The_statement_"''f''(''x'')_is_''O''(''g''(''x''))"_as_defined_above_is_usually_written_as_._Some_consider_this_to_be_an_Matters of notation
Equals sign
The statement "''f''(''x'') is ''O''(''g''(''x''))" as defined above is usually written as . Some consider this to be anOther arithmetic operators
Big O notation can also be used in conjunction with other arithmetic operators in more complicated equations. For example, denotes the collection of functions having the growth of ''h''(''x'') plus a part whose growth is limited to that of ''f''(''x''). Thus, : expresses the same as :Example
Suppose anMultiple uses
In more complicated usage, ''O''(·) can appear in different places in an equation, even several times on each side. For example, the following are true for : The meaning of such statements is as follows: for ''any'' functions which satisfy each ''O''(·) on the left side, there are ''some'' functions satisfying each ''O''(·) 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 ''f''(''n'') = ''O''(1), there is some function ''g''(''n'') = ''O''(''e''''n'') such that ''n''''f''(''n'') = ''g''(''n'')." In terms of the "set notation" above, the meaning is that the class of functions represented by the left side is a subset of the class of functions represented by the right side. In this use the "=" is a formal symbol that unlike the usual use of "=" is not aTypesetting
Big O is typeset as an italicized uppercase "O", as in the following example: .Donald E. Knuth, The art of computer programming. Vol. 1. Fundamental algorithms, third edition, Addison Wesley Longman, 1997. Section 1.2.11.1.Ronald L. Graham, Donald E. Knuth, and Oren Patashnik, ''Concrete Mathematics: A Foundation for Computer Science (2nd ed.)'', Addison-Wesley, 1994. Section 9.2, p. 443. In TeX, it is produced by simply typing O inside math mode. Unlike Greek-named Bachmann–Landau notations, it needs no special symbol. Yet, some authors use the calligraphic variant instead.Orders of common functions
Here is a list of classes of functions that are commonly encountered when analyzing the running time of an algorithm. In each case, ''c'' is a positive constant and ''n'' increases without bound. The slower-growing functions are generally listed first. The statement is sometimes weakened to to derive simpler formulas for asymptotic complexity. For any and is a subset of for any so may be considered as a polynomial with some bigger order.Related asymptotic notations
Big ''O'' is widely used in computer science. Together with some other related notations it forms the family of Bachmann–Landau notations.Little-o notation
Intuitively, the assertion " is " (read " is little-o of ") means that grows much faster than . As before, let ''f'' be a real or complex valued function and ''g'' a real valued function, both defined on some unbounded subset of the positive real numbers, such that ''g''(''x'') is strictly positive for all large enough values of ''x''. One writes : if for every positive constant there exists a constant such that : For example, one has : and both as The difference between the definition of the big-O notation and the definition of little-o is that while the former has to be true for ''at least one'' constant ''M'', the latter must hold for ''every'' positive constant , however small.Thomas H. Cormen et al., 2001Big Omega notation
Another asymptotic notation is , read "big omega". There are two widespread and incompatible definitions of the statement : as , where ''a'' is some real number, ∞, or −∞, where ''f'' and ''g'' are real functions defined in a neighbourhood of ''a'', and where ''g'' is positive in this neighbourhood. The Hardy–Littlewood definition is used mainly inThe Hardy–Littlewood definition
In 1914 Godfrey Harold Hardy and= Simple examples
= We have : as and more precisely : as We have : as and more precisely : as however : asThe Knuth definition
In 1976Family of Bachmann–Landau notations
The limit definitions assume for sufficiently large . The table is (partly) sorted from smallest to largest, in the sense that (Knuth's version of) on functions correspond to on the real line (the Hardy–Littlewood version of , however, doesn't correspond to any such description). Computer science uses the big , big Theta , little , little omega and Knuth's big Omega notations. Analytic number theory often uses the big , small , Hardy–Littlewood's big Omega (with or without the +, − or ± subscripts) and notations. The small omega notation is not used as often in analysis.Use in computer science
Informally, especially in computer science, the big ''O'' notation often can be used somewhat differently to describe an asymptoticOther notation
In their book '' Introduction to Algorithms'', Cormen, Leiserson, Rivest andExtensions to the Bachmann–Landau notations
Another notation sometimes used in computer science is Õ (read ''soft-O''): ''f''(''n'') = ''Õ''(''g''(''n'')) is shorthand for for some ''k''. Some authors write O* for the same purpose. Essentially, it is big O notation, ignoring logarithmic factors because the growth-rate effects of some other super-logarithmic function indicate a growth-rate explosion for large-sized input parameters that is more important to predicting bad run-time performance than the finer-point effects contributed by the logarithmic-growth factor(s). This notation is often used to obviate the "nitpicking" within growth-rates that are stated as too tightly bounded for the matters at hand (since log''k'' ''n'' is always ''o''(''n''ε) for any constant ''k'' and any ). Also the L notation, defined as : is convenient for functions that are betweenGeneralizations and related usages
The generalization to functions taking values in anyHistory (Bachmann–Landau, Hardy, and Vinogradov notations)
The symbol O was first introduced by number theorist Paul Bachmann in 1894, in the second volume of his book ''Analytische Zahlentheorie'' ("See also
*References and notes
Further reading
* * * * * * * * * *External links