<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="default.xsl"?>
<fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="true"
show-heading="true"
show-metadata="true"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>2331</fr:anchor><fr:taxon>Concept</fr:taxon><fr:addr>150-0038</fr:addr><fr:route>150-0038.xml</fr:route><fr:title>Big-<fr:tex>\mathcal {O}</fr:tex></fr:title></fr:frontmatter><fr:mainmatter><fr:p>Sometimes, we wish to simplify exact bounds, ignoring linear factors. To do this, we use big-<fr:tex>\mathcal {O}</fr:tex> notation.</fr:p><fr:p>Let <fr:tex>X</fr:tex> be a set and let <fr:tex>f, g : X \to  \mathbb {N}</fr:tex>. We say that <fr:tex>f \in  \mathcal {O}(g)</fr:tex> when there exist constants <fr:tex>a, b : \mathbb {N}</fr:tex> such that <fr:tex>f \le  ag + b</fr:tex>, i.e. <fr:tex
display="block">\forall  x : X, f(x) \le  ag(x) + b.</fr:tex></fr:p><fr:p>We write <fr:tex>\mathcal {O}(g)</fr:tex> for the set of all functions <fr:tex>f</fr:tex> bounded by <fr:tex>g</fr:tex>, i.e. <fr:tex
display="block">\mathcal {O}(g) = \{f : X \to  \mathbb {N} \mid  f \in  \mathcal {O}(g) \}.</fr:tex></fr:p><fr:p>Traditionally, <fr:tex>X = \mathbb {N}</fr:tex> and function inputs are assumed to be named <fr:tex>n</fr:tex>: for example, <fr:tex>\mathcal {O}(n^2)</fr:tex> is syntactic sugar for <fr:tex>\mathcal {O}(n \mapsto  n^2)</fr:tex>.</fr:p></fr:mainmatter><fr:backmatter><fr:contributions></fr:contributions><fr:context><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="false"
show-heading="true"
show-metadata="true"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>2330</fr:anchor><fr:addr>150-002Z</fr:addr><fr:route>150-002Z.xml</fr:route><fr:title>Asymptotic analysis</fr:title></fr:frontmatter><fr:mainmatter><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>479</fr:anchor><fr:taxon>Concept</fr:taxon><fr:addr>150-0038</fr:addr><fr:route>150-0038.xml</fr:route><fr:title>Big-<fr:tex>\mathcal {O}</fr:tex></fr:title></fr:frontmatter><fr:mainmatter><fr:p>Sometimes, we wish to simplify exact bounds, ignoring linear factors. To do this, we use big-<fr:tex>\mathcal {O}</fr:tex> notation.</fr:p><fr:p>Let <fr:tex>X</fr:tex> be a set and let <fr:tex>f, g : X \to  \mathbb {N}</fr:tex>. We say that <fr:tex>f \in  \mathcal {O}(g)</fr:tex> when there exist constants <fr:tex>a, b : \mathbb {N}</fr:tex> such that <fr:tex>f \le  ag + b</fr:tex>, i.e. <fr:tex
display="block">\forall  x : X, f(x) \le  ag(x) + b.</fr:tex></fr:p><fr:p>We write <fr:tex>\mathcal {O}(g)</fr:tex> for the set of all functions <fr:tex>f</fr:tex> bounded by <fr:tex>g</fr:tex>, i.e. <fr:tex
display="block">\mathcal {O}(g) = \{f : X \to  \mathbb {N} \mid  f \in  \mathcal {O}(g) \}.</fr:tex></fr:p><fr:p>Traditionally, <fr:tex>X = \mathbb {N}</fr:tex> and function inputs are assumed to be named <fr:tex>n</fr:tex>: for example, <fr:tex>\mathcal {O}(n^2)</fr:tex> is syntactic sugar for <fr:tex>\mathcal {O}(n \mapsto  n^2)</fr:tex>.</fr:p></fr:mainmatter></fr:tree><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>482</fr:anchor><fr:taxon>Example</fr:taxon><fr:addr>150-003B</fr:addr><fr:route>150-003B.xml</fr:route><fr:title>Big-<fr:tex>\mathcal {O}</fr:tex> bounds</fr:title></fr:frontmatter><fr:mainmatter><fr:p>We have <fr:tex>n^2 \in  \mathcal {O}(n^2 + n + 3)</fr:tex>.</fr:p>
 
   
   <fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="false"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>480</fr:anchor><fr:taxon>Proof</fr:taxon><fr:addr>#199</fr:addr><fr:route>unstable-199.xml</fr:route><fr:parent>150-003B</fr:parent></fr:frontmatter><fr:mainmatter>
  By <fr:link
href="150-0038.xml"
type="local"
addr="150-0038">the definition</fr:link>, we must choose <fr:tex>a, b : \mathbb {N}</fr:tex> such that <fr:tex>n^2 \le  a(n^2 + n + 3) + b</fr:tex>.
  Let <fr:tex>a = 1</fr:tex> and <fr:tex>b = 0</fr:tex>; we have <fr:tex>n^2 \le  n^2 + n + 3</fr:tex> immediately.
</fr:mainmatter></fr:tree>
 
<fr:p>We have <fr:tex>n^2 + n + 3 \in  \mathcal {O}(n^2)</fr:tex>.</fr:p>
 
   
   <fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="false"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>481</fr:anchor><fr:taxon>Proof</fr:taxon><fr:addr>#200</fr:addr><fr:route>unstable-200.xml</fr:route><fr:parent>150-003B</fr:parent></fr:frontmatter><fr:mainmatter>
  By <fr:link
href="150-0038.xml"
type="local"
addr="150-0038">the definition</fr:link>, we must choose <fr:tex>a, b : \mathbb {N}</fr:tex> such that <fr:tex>n^2 + n + 3 \le  an^2 + b</fr:tex>.
  Let <fr:tex>a = 2</fr:tex> and <fr:tex>b = 3</fr:tex>; we have <fr:tex>n^2 + n + 3 \le  2n^2 + 3 = n^2 + n^2 + 3</fr:tex>, since <fr:tex>n^2 \le  n^2</fr:tex>, <fr:tex>n \le  n^2</fr:tex>, and <fr:tex>3 \le  3</fr:tex>.
</fr:mainmatter></fr:tree>
 
</fr:mainmatter></fr:tree><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>483</fr:anchor><fr:taxon>Theorem</fr:taxon><fr:addr>150-0039</fr:addr><fr:route>150-0039.xml</fr:route><fr:title>Properties of big-<fr:tex>\mathcal {O}</fr:tex></fr:title></fr:frontmatter><fr:mainmatter><fr:ol><fr:li><fr:tex>\mathcal {O}</fr:tex> is a preorder:
    <fr:ul><fr:li><fr:tex>\mathcal {O}</fr:tex> is reflexive: for all <fr:tex>f</fr:tex>, we have <fr:tex>f \in  \mathcal {O}(f)</fr:tex>.</fr:li>
      <fr:li><fr:tex>\mathcal {O}</fr:tex> is transitive: for all <fr:tex>f,g,h</fr:tex>, if <fr:tex>f \in  \mathcal {O}(g)</fr:tex> and <fr:tex>g \in  O(h)</fr:tex>, then <fr:tex>f \in  O(h)</fr:tex>.</fr:li></fr:ul></fr:li>
  <fr:li>If <fr:tex>f \in  \mathcal {O}(g)</fr:tex> and <fr:tex>f' \in  \mathcal {O}(g')</fr:tex>, then <fr:tex>f + f' \in  \mathcal {O}(g + g')</fr:tex>, where <fr:tex>(f + f')(x) = f(x) + f'(x)</fr:tex>.</fr:li>
  <fr:li>For all <fr:tex>f,g : X \to  \mathbb {N}</fr:tex>, we have <fr:tex>\mathcal {O}(f + g) = \mathcal {O}(\max (f, g))</fr:tex>.</fr:li>
  <fr:li>For all <fr:tex>a, b : \mathbb {N}</fr:tex> and <fr:tex>f : X \to  \mathbb {N}</fr:tex>, we have <fr:tex>\mathcal {O}(f) = \mathcal {O}(af + b)</fr:tex>, where <fr:tex
display="block">(af + b)(x) = a \cdot  f(x) + b</fr:tex> by definition.</fr:li></fr:ol></fr:mainmatter></fr:tree><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>509</fr:anchor><fr:taxon>Concept</fr:taxon><fr:addr>150-003A</fr:addr><fr:route>150-003A.xml</fr:route><fr:title>Common big-<fr:tex>\mathcal {O}</fr:tex> classes</fr:title></fr:frontmatter><fr:mainmatter><fr:p>The following classes are distinct, ordered by inclusion from top to bottom:</fr:p>
  <html:table
xmlns:html="http://www.w3.org/1999/xhtml">
  

  
  <html:tr>
  <html:td><fr:strong>Class</fr:strong></html:td>

  <html:td><fr:strong>Common Name</fr:strong></html:td>
</html:tr>

  
    
  <html:tr>
  <html:td><fr:tex>\mathcal {O}(1)</fr:tex></html:td>

  <html:td>constant</html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>\mathcal {O}(\log  n)</fr:tex></html:td>

  <html:td>logarithmic</html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>\mathcal {O}(n)</fr:tex></html:td>

  <html:td>linear</html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>\mathcal {O}(n \log  n)</fr:tex></html:td>

  <html:td>quasilinear/log-linear</html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>\mathcal {O}(n^2)</fr:tex></html:td>

  <html:td>quadratic</html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>\mathcal {O}(n^3)</fr:tex></html:td>

  <html:td>cubic</html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>\mathcal {O}(2^n)</fr:tex></html:td>

  <html:td>exponential</html:td>
</html:tr>

  
</html:table>
</fr:mainmatter></fr:tree><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>510</fr:anchor><fr:taxon>Example</fr:taxon><fr:addr>150-003C</fr:addr><fr:route>150-003C.xml</fr:route><fr:title>Big-<fr:tex>\mathcal {O}</fr:tex> bounds for list reverse algorithms</fr:title></fr:frontmatter><fr:mainmatter><fr:p>Recall the bounds <fr:link
href="150-0034.xml"
type="local"
addr="150-0034">for <fr:code>revSlow</fr:code></fr:link>, <fr:tex>\frac {1}{2}(n^2 + n)</fr:tex>, and <fr:link
href="150-0037.xml"
type="local"
addr="150-0037">for <fr:code>rev</fr:code></fr:link>, <fr:tex>n</fr:tex>.</fr:p><fr:p>We have a tight big-<fr:tex>\mathcal {O}</fr:tex> bound <fr:tex>W_\texttt {revSlow}(n) \in  \mathcal {O}(n^2)</fr:tex>. We can prove it using <fr:link
href="150-0039.xml"
type="local"
addr="150-0039">properties of big-<fr:tex>\mathcal {O}</fr:tex></fr:link>:
<fr:tex
display="block">   \begin {aligned}     \frac {1}{2}(n^2 + n)       &amp;\in  \mathcal {O}\left (\frac {1}{2}(n^2 + n)\right ) \\       &amp;= \mathcal {O}(n^2 + n) \\       &amp;= \mathcal {O}(\max (n^2, n)) \\       &amp;= \mathcal {O}(n^2)   \end {aligned} </fr:tex>
In your analyses, you need not justify your asymptotic bounds formally in this way; for example, you are welcome to immediately state that <fr:tex>\frac {1}{2}(n^2 + n) \in  \mathcal {O}(n^2)</fr:tex> without justification.
</fr:p><fr:p>We also have a tight big-<fr:tex>\mathcal {O}</fr:tex> bound <fr:tex>W_\texttt {rev}(n) \in  \mathcal {O}(n)</fr:tex>, by reflexivity.</fr:p></fr:mainmatter></fr:tree><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>536</fr:anchor><fr:taxon>Table</fr:taxon><fr:addr>150-003E</fr:addr><fr:route>150-003E.xml</fr:route><fr:title>Solutions to common recurrences</fr:title></fr:frontmatter><fr:mainmatter><fr:p>In the below table, we include solutions to common recurrences, where we let <fr:tex>T(0) = c_0</fr:tex>.</fr:p>
  <html:table
xmlns:html="http://www.w3.org/1999/xhtml">
  

  
  <html:tr>
  <html:td><fr:strong>Recurrence</fr:strong> <fr:tex>T(n) = \cdots </fr:tex></html:td>

  <html:td><fr:strong>Exact Solution</fr:strong></html:td>

  <html:td><fr:strong><fr:tex>\mathcal {O}(-)</fr:tex></fr:strong></html:td>
</html:tr>

  
    
  <html:tr>
  <html:td><fr:tex>T(n-1) + c_1</fr:tex></html:td>

  <html:td><fr:tex>c_0 + c_1n</fr:tex></html:td>

  <html:td><fr:tex>\mathcal {O}(n)</fr:tex></html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>2T(n-1) + c_1</fr:tex></html:td>

  <html:td><fr:tex>c_02^n + c_1\left (2^n-1\right )</fr:tex></html:td>

  <html:td><fr:tex>\mathcal {O}(2^n)</fr:tex></html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>T(n-1) + c_1n + c_2</fr:tex></html:td>

  <html:td><fr:tex>c_0 + c_1\frac {n(n+1)}{2} + c_2n</fr:tex></html:td>

  <html:td><fr:tex>\mathcal {O}(n^2)</fr:tex></html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>2T(n-1) + c_1n + c_2</fr:tex></html:td>

  <html:td><fr:tex>c_02^n + c_1\left (2^{n+1}-n-2\right ) + c_2(2^n - 1)</fr:tex></html:td>

  <html:td><fr:tex>\mathcal {O}(2^n)</fr:tex></html:td>
</html:tr>

  
  
    
  <html:tr>
  <html:td><fr:tex>T(n-1) + c_1\log _2(n) + c_2</fr:tex></html:td>

  <html:td><fr:tex>c_0 + c_1\log (n!) + c_2n</fr:tex></html:td>

  <html:td><fr:tex>\mathcal {O}(n \log  n)</fr:tex></html:td>
</html:tr>

  
</html:table>
</fr:mainmatter></fr:tree></fr:mainmatter></fr:tree></fr:context><fr:related></fr:related><fr:backlinks><fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="true"
numbered="false"
show-heading="true"
show-metadata="true"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>2329</fr:anchor><fr:taxon>Example</fr:taxon><fr:addr>150-003B</fr:addr><fr:route>150-003B.xml</fr:route><fr:title>Big-<fr:tex>\mathcal {O}</fr:tex> bounds</fr:title></fr:frontmatter><fr:mainmatter><fr:p>We have <fr:tex>n^2 \in  \mathcal {O}(n^2 + n + 3)</fr:tex>.</fr:p>
 
   
   <fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="false"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>480</fr:anchor><fr:taxon>Proof</fr:taxon><fr:addr>#199</fr:addr><fr:route>unstable-199.xml</fr:route><fr:parent>150-003B</fr:parent></fr:frontmatter><fr:mainmatter>
  By <fr:link
href="150-0038.xml"
type="local"
addr="150-0038">the definition</fr:link>, we must choose <fr:tex>a, b : \mathbb {N}</fr:tex> such that <fr:tex>n^2 \le  a(n^2 + n + 3) + b</fr:tex>.
  Let <fr:tex>a = 1</fr:tex> and <fr:tex>b = 0</fr:tex>; we have <fr:tex>n^2 \le  n^2 + n + 3</fr:tex> immediately.
</fr:mainmatter></fr:tree>
 
<fr:p>We have <fr:tex>n^2 + n + 3 \in  \mathcal {O}(n^2)</fr:tex>.</fr:p>
 
   
   <fr:tree
xmlns:fr="http://www.jonmsterling.com/jms-005P.xml"
toc="false"
numbered="true"
show-heading="true"
show-metadata="false"
expanded="true"
root="false"><fr:frontmatter><fr:anchor>481</fr:anchor><fr:taxon>Proof</fr:taxon><fr:addr>#200</fr:addr><fr:route>unstable-200.xml</fr:route><fr:parent>150-003B</fr:parent></fr:frontmatter><fr:mainmatter>
  By <fr:link
href="150-0038.xml"
type="local"
addr="150-0038">the definition</fr:link>, we must choose <fr:tex>a, b : \mathbb {N}</fr:tex> such that <fr:tex>n^2 + n + 3 \le  an^2 + b</fr:tex>.
  Let <fr:tex>a = 2</fr:tex> and <fr:tex>b = 3</fr:tex>; we have <fr:tex>n^2 + n + 3 \le  2n^2 + 3 = n^2 + n^2 + 3</fr:tex>, since <fr:tex>n^2 \le  n^2</fr:tex>, <fr:tex>n \le  n^2</fr:tex>, and <fr:tex>3 \le  3</fr:tex>.
</fr:mainmatter></fr:tree>
 
</fr:mainmatter></fr:tree></fr:backlinks><fr:references></fr:references></fr:backmatter></fr:tree>