Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > String Manipulation > Sequence Alignment & Comparison >

LongestCommonSubsequence

LongestCommonSubsequence[s1, s2]
finds the longest contiguous subsequence of elements common to the strings or lists s1 and s2.
  • 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.
Find the longest contiguous subsequence common to two strings:
Find the longest contiguous subsequence common to two strings:
In[1]:=
Click for copyable input
Out[1]=
Longest contiguous DNA subsequence of two genes:
Lengths of the longest common subsequences in random binary sequences of length 1000:
New in 7
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team