Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Maybe this will be fast enough for you. Maybe you need to be a bit more specific with your spec. This will not scale very well. The 27 element data set consumes 120 loops in the generation phase and 34 in the output phase for a total of 154. It is roughly O(n^2) but it is quite data dependent.

I wrote Algorithm::LCSS which is based on Algorithm::Diff and may be a better option depending on the real task. The problem with that approach is that it is a one to one comparison not many to many which is what you seem to want.

my @a = ( [2,5,10,5,12,6,21,5,10,12,23], [5,6,11,10,5,10,6,21,5,1,9], [6,5,10,15,21] ); my $m = 2; my $n = 2; my %h; for my $ref (@a) { for my $i ( 0 .. (@$ref-$n) ) { for my $j ( ($i+$n-1) .. @$ref-1 ) { $h{ join ',', (@$ref)[$i..$j] }++; } } } for my $seq( sort { $h{$b}<=>$h{$a} } keys %h ) { print "$h{$seq}: $seq\n" if $h{$seq} >= $m; } __DATA__ 4: 5,10 2: 6,21,5 2: 10,5 2: 6,21 2: 21,5

cheers

tachyon


In reply to Re: Seeking algorithm for finding common continous sub-patterns by tachyon
in thread Seeking algorithm for finding common continous sub-patterns by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-18 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found