WOLFRAM

finds the longest contiguous subsequence of elements common to the strings, biomolecular sequences or lists s1 and s2 and returns their positions {pos1,pos2} in s1 and s2.

Details and Options

  • For lists si, Take[si,posi] returns the longest common subsequence. For strings si, StringTake[si,posi] returns the longest common contiguous substring.
  • If there are several common subsequences of the same length, LongestCommonSubsequencePositions returns the position of the one that appears earliest in s1.
  • For strings, setting the option IgnoreCase->True makes LongestCommonSubsequencePositions treat lowercase and uppercase letters as equivalent, and returns the form of common subsequence that occurs in s1.

Examples

open allclose all

Basic Examples  (3)Summary of the most common use cases

Find the longest contiguous subsequence common to two strings:

Out[1]=1

Find the longest contiguous subsequence common to two lists:

Out[1]=1

Find the longest contiguous subsequence common to two biomolecular sequences:

Out[1]=1

Scope  (2)Survey of the scope of standard use cases

Act on two strings:

Out[1]=1

Act on two lists of expressions:

Out[1]=1

Options  (1)Common values & functionality for each option

IgnoreCase  (1)

By default, LongestCommonSubsequencePositions distinguishes lower and upper case:

Out[1]=1

Ignore case:

Out[2]=2

Applications  (1)Sample problems that can be solved with this function

Longest contiguous DNA subsequence of two genes:

Out[1]=1

Properties & Relations  (1)Properties of the function, and connections to other functions

Take two strings:

Find the positions of the longest common sequence of characters:

Out[2]=2

The corresponding strings coincide:

Out[3]=3

LongestCommonSubsequence returns those strings joined:

Out[4]=4
Wolfram Research (2015), LongestCommonSubsequencePositions, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html.
Wolfram Research (2015), LongestCommonSubsequencePositions, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html.

Text

Wolfram Research (2015), LongestCommonSubsequencePositions, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html.

Wolfram Research (2015), LongestCommonSubsequencePositions, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html.

CMS

Wolfram Language. 2015. "LongestCommonSubsequencePositions." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html.

Wolfram Language. 2015. "LongestCommonSubsequencePositions." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html.

APA

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

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

BibTeX

@misc{reference.wolfram_2025_longestcommonsubsequencepositions, author="Wolfram Research", title="{LongestCommonSubsequencePositions}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html}", note=[Accessed: 09-July-2025 ]}

@misc{reference.wolfram_2025_longestcommonsubsequencepositions, author="Wolfram Research", title="{LongestCommonSubsequencePositions}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html}", note=[Accessed: 09-July-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_longestcommonsubsequencepositions, organization={Wolfram Research}, title={LongestCommonSubsequencePositions}, year={2015}, url={https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html}, note=[Accessed: 09-July-2025 ]}

@online{reference.wolfram_2025_longestcommonsubsequencepositions, organization={Wolfram Research}, title={LongestCommonSubsequencePositions}, year={2015}, url={https://reference.wolfram.com/language/ref/LongestCommonSubsequencePositions.html}, note=[Accessed: 09-July-2025 ]}