Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
The maths you are doing here are plain wrong!

O expressions only show how an algorithm performance scales depending on the size of the data. They can't be manipulated as regular math expressions, and so O(NlogN) / O(N) != logN .

Undoing the tipical simplifications performed to get to the O expression, we can obtain a valid expression for the number of operations required by an algorithm. For instance, for an O(NlogN) algorithm as perl built-in sort, the number of operations should be something like A*NlogN + B*N + C (where A, B and C are unknown constants).

For an O(N) algorithm the number of operations is usually B'*N + C'. But when sorting using the ST the cost of the algorithm is still O(NlogN), you can not ignore the sort step, even if it is implemented in fast C. So the real number of operations is A'*NlogN + B'*N + C', though A' is much smaller than A.

Considering all this, the resulting relative performance between both algorithms is (A*NlogN + B*N + C)/(A'NlogN + B'*N + C)

It's very different from the logN value you were using and that's why the benchmark results don't mach your expectations.


In reply to Re: Wasting time thinking about wasted time by salva
in thread Wasting time thinking about wasted time by brian_d_foy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (10)
    As of 2014-11-28 05:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (193 votes), past polls