This is both off-topic, and about as airey-fairey a question as I've ever asked.

You have two (equal length, though that may be irrelevant), sorted buffers of data, call them numbers for simplicity, and you have to merge them. In-place; though a small (say 10%) extra buffer could be used if it would help.

For reasons nothing to do with the merge, before performing it, you have to make (individually) a sequential pass of both buffers. Why, irrelevant to this question.

Is there anything that you could do during that pass, that would some how inform you in a way that would make the subsequent merge more efficient?

For example: although the passes over the two buffers only need to be done individually for their own requirement; is there anything that could be learned by running those passes in lock-step?

Ie. instead of: for i ( 0 .. n ) f( a[i] ); for i ( 0 .. n ) f'( b[i] ); we might do:

for i ( 0 .. n ) { f( a[i] ); // the required stuff for a[] f'( b[i] ); // the required stuff for b[] g( a[i], b[i] ); // and whilst we have them, do something to, or a +ccumulate some statistic, that might help the subsequent merge. }

Alternatively, there would be negligible cost and might be some benefit in doing:

f( a[0] ); f'( b[0] ); for i ( 1 .. n ) { f( a[i] ); f'( a[i] ); g( a[i], a[i-1] ); g'( b[i], b[i-1] ); }

I know it is a nebulous question, so please don't bother telling me that; but, if just reading it triggers some idea; no matter how incomplete, please do.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to [OT] A measure of 'sortedness'? by BrowserUk

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.