Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I've posted code here that seems to be about 7000 times faster than BrowserUk's solution

  1. The results I posted were those for finding all the LCSs for all pairings. If I only search for the single longest LCS, and make the same minimum match assumption as you:
    [ 8:05:03.68] P:\test>484593-3 -MIN=128 bioman.dat Best match len:1271 between string 0:82 & string 2:82 15 trials of bioman.dat ( 5.443s total), 362.894ms/trial

    Which means your still 500+ X faster, but it allows me to save face (a little :).

  2. You're making an assumption in your code that you cannot make for a general solution, that of a minimum match length of 128, and produce no output if you set it too high.

    Whilst your comments say that this can be adjusted to a lower power of 2, when I tried this, I got strangely 'almost correct' values for both length and offset. I tracked this down to ...

  3. Your algorithm only produces the correct output if the input strings are an exact multiple of the minimum size specified.

    To demonstrate, I trimmed 1 character from the front of each line in biomain's data and ran your code with $subStrSize = 128 and got:

    P:\test>gf bioman2.dat Completed in 0.009606 Best match: >string 1 - >string 3 . 1273 characters starting at 80 an +d 80.

    Note that the length has increased by 2 when it should be the same, and both offsets have reduced by 2 when they should have reduced by 1?

    I also tried setting $subStrSize = 1, as thought that might correct the problem, but apart from running much more slowly, it still produced the same, slightly wrong output:

    [ 7:49:55.56] P:\test>gf bioman2.dat Completed in 76.466764 Best match: >string 1 - >string 3 . 1273 characters starting at 80 an +d 80.

All that said, your algorithm is blazingly fast and the anomolies can probably be corrected.

If so, or if bioman only needs the single LCS, and can live with specifying a minimum match and arranging for his input data to always be a multiple of that minimum size, it blow's what I have into dust.

At least, until I can adapt my code to use elements of your search technique :). Nice++


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^2: 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":



  • 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 romping around the Monastery: (7)
As of 2024-03-28 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found