Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, so the graph displays a measurement of the cost of inserting <code>n</code> elements into your tree, where the x axis is how many elements we've inserted, and the y axis is the total time.</p> <p>Let's call the function that totals the time it takes to insert n elements into the tree <code>f(n)</code>.</p> <p>Then we can get a rough idea of what <code>f</code> might look like:</p> <pre><code>f(1) &lt; k*log(1) for some constant k. f(2) &lt; k*log(1) + k*log(2) for some constant k ... f(n) &lt; k * [log(1) + log(2) + ... + log(n)] for some constant k. </code></pre> <p>Due to how logs work, we can collapse <code>log(1) + ... + log(n)</code>:</p> <pre><code>f(n) &lt; k * [log(1*2*3*...*n)] for some constant k f(n) &lt; k * log(n!) for some constant k </code></pre> <p>We can take a look at Wikipedia to see a <a href="http://en.wikipedia.org/wiki/Factorial#Rate_of_growth_and_approximations_for_large_n" rel="nofollow">graph</a> of what <code>log(n!)</code> looks like. Take a look at the graph in the article. Should look pretty familiar to you. :)</p> <p>That is, I think you've done this by accident:</p> <pre><code>for n in (5000, 50000, 500000): startTime = ... ## .. make a fresh tree ## insert n elements into the tree stopTime = ... ## record the tuple (n, stopTime - startTime) for plotting </code></pre> <p>and plotted total time to construct the tree of size n, rather than the individual cost of inserting one element into a tree of size n:</p> <pre><code>for n in range(50000): startTime = ... ## insert an element into the tree stopTime = ... ## record the tuple (n, stopTime - startTime) for plotting </code></pre> <hr> <p>Chris Taylor notes in the comments that if you plot <code>f(n)/n</code>, you'll see a log graph. That's because a fairly tight approximation to <code>log(n!)</code> is <code>n*log(n)</code> (see the Wikipedia page). So we can go back to our bound:</p> <pre><code>f(n) &lt; k * log(n!) for some constant k </code></pre> <p>and get:</p> <pre><code>f(n) &lt; k * n * log(n) for some constant k </code></pre> <p>And now it's should be easier to see that if you divide <code>f(n)</code> by <code>n</code>, your graph will be bounded above by the shape of a logarithm.</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