(From memory!)

Your algorithm is O(N^2) but mine is O(N)

True enough, but which N?

I don't think your code comes close to answering the question. Your treating all the strings in each array as a single concatenated string. I'm not, and I don't believe that's what the OP wants.

Using your algorithm on my test data produces this:

#! perl -slw use strict; use Data::Dumper; my $site1 = 'abcdecdefgefghi'; my $site2 = 'zyxwvxwvutvutrs'; # brute force my (%hash, $loops); for my $base1( split //, $site1 ) { for my $base2( split //, $site2 ) { $hash{"${base1}_$base2"}++; $loops++; } } print Dumper \%hash; __DATA__ $VAR1 = { 'f_r' => 2, 'c_s' => 2, 'd_w' => 4, 'c_z' => 2, 'e_r' => 3, 'i_v' => 3, 'g_w' => 4, 'h_x' => 2, 'f_t' => 4, 'i_r' => 1, 'h_r' => 1, 'h_w' => 2, 'c_u' => 4, 'a_y' => 1, 'd_s' => 2, 'i_u' => 2, 'c_v' => 6, 'c_y' => 2, 'b_s' => 1, 'a_t' => 2, 'h_t' => 2, 'b_z' => 1, 'i_z' => 1, 'f_s' => 2, 'i_x' => 2, 'h_u' => 2, 'c_w' => 4, 'a_x' => 2, 'g_x' => 4, 'a_r' => 1, 'b_w' => 2, 'e_u' => 6, 'a_u' => 2, 'e_v' => 9, 'b_x' => 2, 'i_t' => 2, 'a_z' => 1, 'd_v' => 6, 'b_r' => 1, 'c_t' => 4, 'g_s' => 2, 'b_u' => 2, 'i_w' => 2, 'd_t' => 4, 'i_s' => 1, 'a_v' => 3, 'f_w' => 4, 'h_v' => 3, 'g_y' => 2, 'h_s' => 1, 'a_s' => 1, 'g_r' => 2, 'c_x' => 4, 'f_x' => 4, 'd_z' => 2, 'd_u' => 4, 'g_t' => 4, 'g_u' => 4, 'h_z' => 1, 'f_y' => 2, 'g_z' => 2, 'c_r' => 2, 'b_t' => 2, 'b_y' => 1, 'd_y' => 2, 'e_s' => 3, 'b_v' => 3, 'i_y' => 1, 'e_y' => 3, 'e_x' => 6, 'f_u' => 4, 'g_v' => 6, 'd_r' => 2, 'f_v' => 6, 'h_y' => 1, 'e_w' => 6, 'a_w' => 2, 'e_z' => 3, 'f_z' => 2, 'd_x' => 4, 'e_t' => 6 };

Which is solving a totally different problem to the one I belive the OP wants to solve.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re^2: Comparing two arrays and counting pairwise comparisons by BrowserUk
in thread Comparing two arrays and counting pairwise comparisons by replicant4

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.