This is documentation for Mathematica 7, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

LongestCommonSequence

LongestCommonSequence[s1, s2]
finds the longest sequence of contiguous or disjoint elements common to the strings or lists s1 and s2.
  • If there are several common subsequences of the same length, LongestCommonSequence returns the one that begins earliest in s1.
  • For strings, setting the option IgnoreCase->True makes LongestCommonSequence treat lowercase and uppercase letters as equivalent, and return the form of common sequence that occurs in s1.
Find the longest noncontiguous sequence common to two strings:
Find the longest noncontiguous sequence common to two strings:
In[1]:=
Click for copyable input
Out[1]=
Find the lengths of longest common sequences in random binary sequences of length 1000:
New in 7