LongestCommonSubsequence

LongestCommonSubsequence[s1,s2]

finds the longest contiguous subsequence of elements common to the strings, biomolecular sequences 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  (3)

Find the longest contiguous subsequence common to two strings:

Find the longest contiguous subsequence common to two lists:

Find the longest contiguous subsequence common to two biomolecular sequences:

Applications  (1)

Longest contiguous DNA subsequence of two genes:

Neat Examples  (1)

Lengths of the longest common subsequences in random binary sequences of length 1000:

Wolfram Research (2008), LongestCommonSubsequence, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSubsequence.html (updated 2020).

Text

Wolfram Research (2008), LongestCommonSubsequence, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSubsequence.html (updated 2020).

CMS

Wolfram Language. 2008. "LongestCommonSubsequence." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/LongestCommonSubsequence.html.

APA

Wolfram Language. (2008). LongestCommonSubsequence. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LongestCommonSubsequence.html

BibTeX

@misc{reference.wolfram_2024_longestcommonsubsequence, author="Wolfram Research", title="{LongestCommonSubsequence}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/LongestCommonSubsequence.html}", note=[Accessed: 22-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_longestcommonsubsequence, organization={Wolfram Research}, title={LongestCommonSubsequence}, year={2020}, url={https://reference.wolfram.com/language/ref/LongestCommonSubsequence.html}, note=[Accessed: 22-December-2024 ]}