The thing that really slowed my code down was detecting multiple, equal-length LCS within the same pairing. Eg. In this dataset:

>string1 AAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTT >string2 AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT

my program detects and reports both the As at the beginning and the Ts at the end:

P:\test>484593-4 duptest.dat 000:001 L[017] (0 0)'AAAAAAAAAAAAAAAAA' (47 47)'TTTTTTTTTTTTTTTTT' 1 trial of duptest.dat ( 1.210ms total), 1.210ms/trial

Where your program will only report the first of the two equal LCSs:

P:\test>gf -MIN=16 duptest.gf Completed in 0.000209 Best match: >string1 - >string2. 17 characters starting at 0 and 0. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 AAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAA

Also, if the equal LCSs appear in different relative positions within the pairing, which is reported depends upon which appears first within the first string of the pairing:

P:\test>type duptest.gf >string1 TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA >string2 AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT P:\test>gf -MIN=16 duptest.gf Completed in 0.00021 Best match: >string1 - >string2. 17 characters starting at 0 and 47. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA TTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT ...............................................TTTTTTTTTTTTTTTTT P:\test>type duptest.gf >string1 AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT >string2 TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA P:\test>gf -MIN=16 duptest.gf Completed in 0.000209 Best match: >string1 - >string2. 17 characters starting at 0 and 47. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 AAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAA TTTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAA ...............................................AAAAAAAAAAAAAAAAA

I cannot see how you could adapt your code to handle that without loosing it's performance?


This may be just a bug-report rather than a fundemental problem, but I modified the above dataset by deleting one of the As from the start of each line and adding two T's (keeping the length to 64) at the end, making the Ts the LCS for the pair.

Ignoring the reporting anomolies, your code still detects the As as the LCS unless I drop the minimum length right down to 2?

P:\test>gf -MIN=16 duptest.gf Completed in 0.000207 Best match: >string1 - >string2. 17 characters starting at 0 and 0. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAC AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAG P:\test>gf -MIN=8 duptest.gf Completed in 0.000296 Best match: >string1 - >string2. 17 characters starting at 0 and 0. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAC AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAG P:\test>gf -MIN=4 duptest.gf Completed in 0.000611 Best match: >string1 - >string2. 17 characters starting at 0 and 0. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAC AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAG P:\test>gf -MIN=2 duptest.gf Completed in 0.000909 Best match: >string1 - >string2. 19 characters starting at 44 and 44. 123456789 123456789 123456789 123456789 123456789 123456789 123456789 AAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTT ............................................CCTTTTTTTTTTTTTTTTT AAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTT ............................................GGTTTTTTTTTTTTTTTTT

Indeed, as it stands, your code always favours a shorter match in the first string over a longer match in the second unless the minimum match is set to a value less than or equal to the difference between the matches.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re^4: Search for identical substrings by BrowserUk
in thread Search for identical substrings by bioMan

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.