Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Big O notation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Matters of notation == === Equals sign === The statement "{{math|''f''(''x'')}} is {{math|''O''[''g''(''x'')]}}" as defined above is usually written as {{math|1= ''f''(''x'') {{=}} ''O''[''g''(''x'')]}}. Some consider this to be an [[abuse of notation]], 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]] says, {{math|1= ''O''[''x''] {{=}} ''O''[''x''<sup>2</sup>]}} is true but {{math|1= ''O''[''x''<sup>2</sup>] {{=}} ''O''[''x'']}} is not.<ref name=deBruijn>{{cite book |first=N.G. |last=de Bruijn | author-link=N. G. de Bruijn | title=Asymptotic Methods in Analysis | place=Amsterdam | publisher=North-Holland | year=1958 | pages=5–7 | url=https://books.google.com/books?id=_tnwmvHmVwMC&q=%22The+trouble+is%22&pg=PA5 | isbn=978-0-486-64221-5 | access-date=2021-09-15 | archive-date=2023-01-17 | archive-url=https://web.archive.org/web/20230117051949/https://books.google.com/books?id=_tnwmvHmVwMC&q=%22The+trouble+is%22&pg=PA5 | url-status=live }}</ref> [[Donald Knuth|Knuth]] describes such statements as "one-way equalities", since if the sides could be reversed, "we could deduce ridiculous things like {{math|1= ''n'' {{=}} ''n''<sup>2</sup>}} from the identities {{math|1= ''n'' {{=}} ''O''[''n''<sup>2</sup>]}} and {{math|1= ''n''<sup>2</sup> {{=}} ''O''[''n''<sup>2</sup>]}}".<ref name="Concrete Mathematics">{{cite book |last1=Graham |first1=Ronald |author1-link=Ronald Graham |first2=Donald |last2=Knuth |author2-link=Donald Knuth |last3=Patashnik |first3=Oren |author3-link=Oren Patashnik |title=Concrete Mathematics |location=Reading, Massachusetts |publisher=Addison–Wesley |edition=2 |date=1994 |page=446 |url=https://books.google.com/books?id=pntQAAAAMAAJ |isbn=978-0-201-55802-9 |access-date=2016-09-23 |archive-date=2023-01-17 |archive-url=https://web.archive.org/web/20230117051955/https://books.google.com/books?id=pntQAAAAMAAJ |url-status=live }}</ref> In another letter, Knuth also pointed out that<ref>{{cite journal | author=Donald Knuth | title=Teach Calculus with Big O | date=June–July 1998 | journal=[[Notices of the American Mathematical Society]] | volume=45 | issue=6 | page=687 | url=https://www.ams.org/notices/199806/commentary.pdf | access-date=2021-09-05 | archive-date=2021-10-14 | archive-url=https://web.archive.org/web/20211014070416/https://www.ams.org/notices/199806/commentary.pdf | url-status=live }} ([http://www-cs-staff.stanford.edu/~knuth/ocalc.tex Unabridged version] {{Webarchive|url=https://web.archive.org/web/20080513234708/http://www-cs-staff.stanford.edu/~knuth/ocalc.tex |date=2008-05-13 }})</ref> {{blockquote|text= the equality sign is not symmetric with respect to such notations [as, in this notation,] mathematicians customarily use the '=' sign as they use the word 'is' in English: Aristotle is a man, but a man isn't necessarily Aristotle.}} For these reasons, it would be more precise to use [[set notation]] and write {{math|''f''(''x'') ∈ ''O''[''g''(''x'')]}}{{snd}} read as: "{{math|''f''(''x'')}} [[Element (mathematics)#Notation and terminology|is an element of]] {{math|''O''[''g''(''x'')]}}", or "{{math|''f''(''x'')}} is in the set {{math|''O''[''g''(''x'')]}}"{{snd}} thinking of {{math|''O''[''g''(''x'')]}} as the class of all functions {{math|''h''(''x'')}} such that {{math|{{abs|''h''(''x'')}} ≤ ''C'' {{abs|''g''(''x'')}}}} for some positive real number {{mvar|C}}.<ref name="Concrete Mathematics" /> However, the use of the equals sign is customary.<ref name=deBruijn/><!-- p. 7: "Once this warning has been given, there is, however, not much harm in using the sign =, and we shall maintain it, for no other reason than that it is customary." --><ref name="Concrete Mathematics"/><!-- p. 446: "why don't we use ‘⊆’ instead of abusing the equals sign? There are four reasons. First, tradition ..." --> === Other arithmetic operators === Big O notation can also be used in conjunction with other arithmetic operators in more complicated equations. For example, {{math|''h''(''x'') + ''O''(''f''(''x''))}} denotes the collection of functions having the growth of {{math|''h''(''x'')}} plus a part whose growth is limited to that of {{math|''f''(''x'')}}. Thus, <math display=block>g(x) = h(x) + O(f(x))</math> expresses the same as <math display=block>g(x) - h(x) = O(f(x)).</math> ==== Example {{anchor|Example (Matters of notation)}} ==== Suppose an [[algorithm]] is being developed to operate on a set of {{mvar|n}} elements. Its developers are interested in finding a function {{math|''T''(''n'')}} that will express how long the algorithm will take to run (in some arbitrary measurement of time) in terms of the number of elements in the input set. The algorithm works by first calling a subroutine to sort the elements in the set and then perform its own operations. The sort has a known time complexity of {{math|''O''(''n''<sup>2</sup>)}}, and after the subroutine runs the algorithm must take an additional {{math|55''n''<sup>3</sup> + 2''n'' + 10}} steps before it terminates. Thus the overall time complexity of the algorithm can be expressed as {{math|1=''T''(''n'') = 55''n''<sup>3</sup> + ''O''(''n''<sup>2</sup>)}}. Here the terms {{math|1=2''n'' + 10}} are subsumed within the faster-growing {{math|''O''(''n''<sup>2</sup>)}}. Again, this usage disregards some of the formal meaning of the "{{math|1= =}}" symbol, but it does allow one to use the big O notation as a kind of convenient placeholder. === Multiple uses === In more complicated usage, {{math|''O''(·)}} can appear in different places in an equation, even several times on each side. For example, the following are true for <math>n\to\infty</math>: <math display="block"> \begin{align} (n+1)^2 & = n^2 + O(n), \\ (n + O(n^{1/2})) \cdot (n + O(\log n))^2 & = n^3 + O(n^{5/2}), \\ n^{O(1)} & = O(e^n). \end{align}</math> The meaning of such statements is as follows: for {{em|any}} functions which satisfy each {{math|''O''(·)}} on the left side, there are {{em|some}} functions satisfying each {{math|''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 {{math|1= ''f''(''n'') = ''O''(1)}}, there is some function {{math|1= ''g''(''n'') = ''O''(''e''<sup>''n''</sup>)}} such that {{math|1= ''n''<sup>''f''(''n'')</sup> = ''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 "{{math|1= =}}" is a formal symbol that unlike the usual use of "{{math|1= =}}" is not a [[symmetric relation]]. Thus for example {{math|1=''n''<sup>''O''(1)</sup> = ''O''(''e''<sup>''n''</sup>)}} does not imply the false statement {{math|1=''O''(''e''<sup>''n''</sup>) = ''n''<sup>''O''(1)</sup>}}. === Typesetting === Big O is typeset as an italicized uppercase "{{mvar|O}}{{-"}}, as in the following example: <math>O(n^2)</math>.<ref name="KnuthArt">Donald E. Knuth, The art of computer programming. Vol. 1. Fundamental algorithms, third edition, Addison Wesley Longman, 1997. Section 1.2.11.1.</ref><ref name="ConcreteMath">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.</ref> In [[TeX]], it is produced by simply typing 'O' inside math mode. Unlike Greek-named Bachmann–Landau notations, it needs no special symbol. However, some authors use the calligraphic variant <math>\mathcal{O}</math> instead.<ref>Sivaram Ambikasaran and Eric Darve, An <math>\mathcal O (N \log N)</math> Fast Direct Solver for Partial Hierarchically Semi-Separable Matrices, ''J. Scientific Computing'' '''57''' (2013), no. 3, 477–501.</ref><ref>Saket Saurabh and Meirav Zehavi, <math>(k,n-k)</math>-Max-Cut: An <math>\mathcal{O}^*(2^p)</math>-Time Algorithm and a Polynomial Kernel, ''Algorithmica'' '''80''' (2018), no. 12, 3844–3860.</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)