Slightly off topic, albeit a question. Please excuse.
I have contempated the idea of merge sorting in place, with a smaller scratch size (1 - N/2):
The array to be sorted is in memory. When it is split, the root index and length of the recursed slice is passed on.
After having gone down to a stage where bubble/insertion sorts are used, or when slices lengthed 1 element are merged, the merge should (in my opinion) go as follows:
The next elements of the two slices to be merged are known.
Merging of the elemnts is performed normally, except that when writing, if the position where the next element to be written (over slice 1, then slice 2) is the position of the current position of slice 1 then two elements are pushed to a FIFO structure.
When merging, if the FIFO structure has any elements pending, they are merged with slice 2. Otherwise the next element of slice 1 is merged with slice 2.
When the writing index reaches the next elem of slice two then the two slices are merged and we return from the recursion.
My question is why hasn't such a scheme been implemented before? I always see documentation of sorts saying that mergesort's main setback is the scratch size it needs - and yet most say that quicksorts disadvantages can be taken care of by tweaking - hence i figured i'm missing something... Could someone tell me what that is?
Thanks in advance
-nuffin
zz zZ Z Z #!perl
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.