This is more like an algorithm, efficiency,storage and design question. I have N arrays and each array may have 0 to N elements. All elements are numbered from 1 to N. I like to find efficient way to do following: Given the element, I like to find top K other elements which makes maximum pair with the given element in any array.

example:

2 4 5 7 8 10 
1 2 5 6 7 9 
2 6 7 8 9 10 
1 3 5 10 
1 3 4 5 6 8 9 
1 2 4 6 
1 2 4 5 7 10 
1 3 4 6 7 8 9 
and if element is '1' and k=3 (Top 3 elements) I will have (6,5,4) as the answer. ie.. (1,6), (1,5) and (1,4) occur most times (incidently 4 times all) as a pair then any other pair, given 1 as one of the element.

For the shorter numbers of arrays I don't have any porblem producing the result. So I am looking an efficient way to handle this for the larger numbers ie.. million arrays. For large arrays, I am ready to reduce the number of elmenets in each array to let's say 20.

Thanks,
artist.


In reply to Best Pairs by artist

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.