BrowserUk,
For reasons I don't want to go into, I don't currently have the ability run or test any code so these are ideas you would have to implement yourself:

Idea 1:
Use a modified merge algorithm to efficiently copy all values into a single sorted array. In doing so, create a parallel hash that knows which array the value came from. Walking the sorted array to find spans of 4 should be straight forward. I believe this is a refinement jbert's idea.

Idea 2:
This is more memory friendlier but will likely be slower. Use a binary search with a modified merge algorithm. You will need to keep track track of your position in each array. This will keep track of a moving end point of your binary search as well as allow you to walk your arrays as a merge algorithm would. Find the lowest value using the current positions, do a binary search over each array looking for the next value. I think you can work out from here the rest of the details.

Minor wording update.

Cheers - L~R


In reply to Re: Searching parallel arrays. by Limbic~Region
in thread Searching parallel arrays. 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.