Click or drag to resize

StringAlgorithmsLongestCommonSubsequence Method

Calculate the Longest Common Subsequence.

It differs from problems of finding common substrings: unlike substrings, subsequences are not required to occupy consecutive positions within the original sequences.

Examples
The following strings match, since the one fully contains the other in order
LongestCommonSubsequence("BLUB","aBcLeUgBh") = 4
LongestCommonSubsequence("aBcLeUgBh","BLUB") = 4
The following strings differ by one, since the final B is missing in the long string
LongestCommonSubsequence("BLUB","aBcLeUg") = 3
LongestCommonSubsequence("aBcLeUg","BLUB") = 3

Namespace:  DHI.Mike1D.Generic
Assembly:  DHI.Mike1D.Generic (in DHI.Mike1D.Generic.dll) Version: 19.0.0.0 (11.1.1.1111)
Syntax
public static int LongestCommonSubsequence(
	string s,
	string t
)

Parameters

s
Type: SystemString

[Missing <param name="s"/> documentation for "M:DHI.Mike1D.Generic.StringAlgorithms.LongestCommonSubsequence(System.String,System.String)"]

t
Type: SystemString

[Missing <param name="t"/> documentation for "M:DHI.Mike1D.Generic.StringAlgorithms.LongestCommonSubsequence(System.String,System.String)"]

Return Value

Type: Int32

[Missing <returns> documentation for "M:DHI.Mike1D.Generic.StringAlgorithms.LongestCommonSubsequence(System.String,System.String)"]

See Also