From what I can see from Robert Sedgewick's Algorithms in C, a mergesort algorithm becomes significantly more complex - possibly affecting the stability of the sort, something which is a valued property of a mergesort - when it is modified to do an in-place sort, removing the requirement of extra space proportional to the number of records.

If the the extra space is a problem, something like a heapsort may be an alternative.
Both mergesort and heapsort algorithms generally have N log N runtimes.

Cheers.

BazB

Update: BTW, I recommend the aforementioned book if you're interested in an easy to understand, but complete, reference to algorithms.
I've not looked at O'Reilly's Mastering Algorithms with Perl , however I believe it is also a great textbook.

I've only used a basic mergesort, so have no personal experience with more complex implementations.


In reply to Re: mergesort scratch space question by BazB
in thread mergesort scratch space question by nothingmuch

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.