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

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I saw a Perl implementation on this forum to determine the longest common subsequence among M strings. Let assume there are three strings S1, S2, and S3. Would the common subsequence be found by determining the common subsequence between S1 and S2 (let's call it R12), then take this result and find the common subsequence between it (R12) and S3. Will this work or under what condition will this method fail? Any thought?

Replies are listed 'Best First'.
Re: Longest Common Subsequence Question
by ikegami (Patriarch) on Nov 19, 2007 at 03:57 UTC

    Your method would fail for

    S1 = aabbb S2 = aabbb S3 = aa

    The answer is "aa", but your method will try to find the LCS("bbb", "aa") and will fail to find a result.

    Update: Oops, I meant

    S1 = aa1bbb S2 = aa2bbb S3 = aa
      I thought the longest common subsequence between S1 and S2 in this case is aabbb.
      And then the longest common subsequence between this result aabbb and S3 (aa) is aa. Am I missing something?

        Oops, I meant

        S1 = aa1bbb S2 = aa2bbb S3 = aa
Re: Longest Common Subsequence Question
by Limbic~Region (Chancellor) on Nov 20, 2007 at 00:35 UTC