Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Longest Common Subsequence Question

by Anonymous Monk
on Nov 19, 2007 at 04:35 UTC ( [id://651583]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Longest Common Subsequence Question
in thread Longest Common Subsequence Question

with S1=aa1bbb and S2=aa2bbb the longest common subsequence between them still would be aabbb and the longest common subsequence between aabbb and aa would still be aa. This is the longest common subsequence, not the longest common substring.
  • Comment on Re^4: Longest Common Subsequence Question

Replies are listed 'Best First'.
Re^5: Longest Common Subsequence Question
by ikegami (Patriarch) on Nov 19, 2007 at 04:41 UTC
    oh, it doesn't have to be contiguous? Then yeah, your method would work.

    Update: Pardon the disaster that was my participation in this thread.

      No, it wouldn't; it is just harder to come up with the counter example. The one that pops into my mind is due to the fact that an algorithm that claims to find "the longest common subsequence" will actually find "one of the maximal common subsequences" and you may have needed to find some other one:

      axbc abxc a1b2c

      If the first run picks "axc" then you are doomed. If you get lucky and it picks "abc", then you win.

      But I strongly suspect that you don't even need to rely on that quirk. Indeed, I now see that it is easy to extend the above example:

      axybc abxyc a1b2c

      The solution is "abc" but you will first pick "axyc" and so won't include "b" in the final "answer".

      - tye        

      Humm Makes me think...:)

      Actually mathematical subsequences are defined as maps on a subset of N and have "holes"; for example consider u(2n) versus u(n). Still in the case of finite sequences (especially in the context of char strings) it seems *contiguous* would be a fair (even natural) requisite.

      Looking at some implementations seems to indicate that the contiguous case is considered as the common useful case:

      % steph@ape (/home/stephan/w/tp) % % perl -MString::LCSS -le 'print scalar String::LCSS::lcss(qw[xaxbcxdx + aybycyydy])' % steph@ape (/home/stephan/w/tp) % % perl -MString::LCSS -le 'print scalar String::LCSS::lcss(qw[xabcdxxx +xxx yyyabcdyyyyy])' abcd

      I get the same with the recent String::LCSS_XS

      % steph@ape (/home/stephan/w/tp) % % perl -MString::LCSS_XS -le 'print scalar String::LCSS_XS::lcss(qw[xa +bcdxxxxxx yyyabcdyyyyy])' abcd
      cheers --stephan

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-23 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found