LongestCommonSubsequence

LongestCommonSubsequence[s1,s2]

finds the longest contiguous subsequence of elements common to the strings or lists s1 and s2.

Details and Options

  • If there are several common subsequences of the same length, LongestCommonSubsequence returns the one that appears earliest in s1.
  • For strings, setting the option IgnoreCase->True makes LongestCommonSubsequence treat lowercase and uppercase letters as equivalent, and return the form of common subsequence that occurs in s1.

Examples

open allclose all

Basic Examples  (1)

Find the longest contiguous subsequence common to two strings:

In[1]:=
Click for copyable input
Out[1]=

Find the longest contiguous subsequence common to two lists:

In[2]:=
Click for copyable input
Out[2]=

Applications  (1)

Neat Examples  (1)

See Also

LongestCommonSequence  SequenceAlignment  NeedlemanWunschSimilarity  Longest  Subsequences

Introduced in 2008
(7.0)