http://qs321.pair.com?node_id=651584


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

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.

  • Comment on Re^5: Longest Common Subsequence Question

Replies are listed 'Best First'.
Re^6: Longest Common Subsequence Question (no)
by tye (Sage) on Nov 19, 2007 at 05:49 UTC

    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        

Re^6: Longest Common Subsequence Question
by sgt (Deacon) on Nov 19, 2007 at 14:06 UTC

    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