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.

Example

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

Definition

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

Parameters

s  String

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

t  String

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

Return Value

Int32

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

See Also