lcs
Longest (maximum) common subsequence
Contents
Syntax
- lcsLength = lcs(a, b)
- lcsLength = lcs(a, b, showPlot)
- [lcsLength, lcsPath, lcsStr, lcsTable] = lcs(...)
Description
lcsLength = lcs(a, b) returns the LCS (longest common subsequence) between two strings a and b.
- a: input string 1
- b: input string 2
lcsLength = lcs(a, b, 1) plots the path of LCS.
[lcsLength, lcsPath, lcsStr, lcsTable] = lcs(a, b) returns extra info:
- lcsPath: optimal path of dynamical programming through the LCS table
- lcsStr: LCS string
- lcsTable: LCS table for applying dynamic programming
Example
str1='elimination'; str2='religious'; showPlot=1; [lcsLength, lcsPath, lcsStr, lcsTable] = lcs(str1, str2, showPlot);
![](lcs_help_01.png)