Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Search for identical substrings

by GrandFather (Saint)
on Aug 21, 2005 at 09:06 UTC ( [id://485506]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Search for identical substrings
in thread Search for identical substrings

Actually the code does generate all the LCS's. I used to print those out. If you are interested you can add back the line by copying the print for best match, pasting it after the line $localBest = expandMatch (@$localBest); and replacing $bestMatch with $localBest. The run time remains about the same :).

I noticed the anomolies, but was so excited by the run rate that I sort of forgot about them and posted the code. The problem will be in the expandMatch sub which does a binary search to extend the match at each end to the full extent of the matched run. It's probably trivial to fix and I'll have a look and update the posted code when I find the bug.

The minimum match length is where the "blazingly fast" bit comes from. Although it still seems to be pretty fast even for small match lengths.

This turned out so much faster than anything else that I couldn't quite believe it! I'm pleased that you have reproduced my results (bugs included).


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^4: Search for identical substrings
by BrowserUk (Patriarch) on Aug 21, 2005 at 23:18 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://485506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-20 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found