Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The math being done here is as follows. When you say O(n(n + n<sup>2</sup>)), that's equivalent to saying O(n<sup>2</sup> + n<sup>3</sup>) by simply distributing the n throughout the product.</p> <p>The reason that O(n<sup>2</sup> + n<sup>3</sup>) = O(n<sup>3</sup>) follows from the formal definition of big-O notation, which is as follows:</p> <blockquote> <p>A function f(n) = O(g(n)) iff there exists constants n<sub>0</sub> and c such that for any n &ge; n<sub>0</sub>, |f(n)| &le; c|g(n)|.</p> </blockquote> <p>Informally, this says that as n gets arbitrary large, f(n) is bounded from above by a constant multiple of g(n).</p> <p>To formally prove that n<sup>2</sup> + n<sup>3</sup> is O(n<sup>3</sup>), consider any n &ge; 1. Then we have that</p> <blockquote> <p>n<sup>2</sup> + n<sup>3</sup> &le; n<sup>3</sup> + n<sup>3</sup> = 2n<sup>3</sup></p> </blockquote> <p>So we have that n<sup>2</sup> + n<sup>3</sup> = O(n<sup>3</sup>), with n<sub>0</sub> = 1 and c = 2. Consequently, we have that </p> <blockquote> <p>O(n(n + n<sup>2</sup>)) = O(n<sup>2</sup> + n<sup>3</sup>) = O(n<sup>3</sup>).</p> </blockquote> <p>To be truly formal about this, we would need to show that if f(n) = O(g(n)) and g(n) = O(h(n)), then f(n) = O(h(n)). Let's walk through a proof of this. If f(n) = O(g(n)), there are constants n<sub>0</sub> and c such that for n &ge; n<sub>0</sub>, |f(n)| &le; c|g(n)|. Similarly, since g(n) = O(h(n)), there are constants n'<sub>0</sub>, c' such that for n &ge; n'<sub>0</sub>, g(n) &le; c'|h(n)|. So this means that for any n &ge; max(c, c'), we have that</p> <blockquote> <p>|f(n)| &le; c|g(n)| &le; c|c'h(n)| = c x c' |h(n)|</p> </blockquote> <p>And so f(n) = O(h(n)).</p> <p>To be a bit more precise - in the case of the algorithm described here, the authors are saying that the runtime is &Theta;(n<sup>3</sup>), which is a stronger result than saying that the runtime is O(n<sup>3</sup>). &Theta; notation indicates a tight asymptotic bound, meaning that the runtime grows at the same rate as n<sup>3</sup>, not just that it is bounded from above by some multiple of n<sup>3</sup>. To prove this, you would also need to show that n<sup>3</sup> is O(n<sup>2</sup> + n<sup>3</sup>). I'll leave this as an exercise to the reader. :-)</p> <p>More generally, if you have <em>any</em> polynomial of order k, that polynomial is O(n<sup>k</sup>) using a similar argument. To see this, let P(n) = &sum;<sub>i=0</sub><sup>k</sup>(a<sub>i</sub>n<sup>i</sup>). Then, for any n &ge; 1, we have that</p> <p>&sum;<sub>i=0</sub><sup>k</sup>(a<sub>i</sub>n<sup>i</sup>) &le; &sum;<sub>i=0</sub><sup>k</sup>(a<sub>i</sub>n<sup>k</sup>) = (&sum;<sub>i=0</sub><sup>k</sup>(a<sub>i</sub>))n<sup>k</sup></p> <p>so P(n) = O(n<sup>k</sup>).</p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload