StringTools
EditDistance
compute the edit distance between two strings
Calling Sequence
Parameters
Description
Examples
EditDistance( s, t )
s
-
Maple string
t
The EditDistance(s,t) command returns an integer measure of the distance between the two strings s and t.
The edit distance between two strings s and t, is defined to be the difference between the sum of their lengths and twice the length of the longest common subsequence of s and t. If strings s and t have respective lengths m and n, then the edit distance is defined to be m+n−2⁢length⁡LongestCommonSubSequence⁡s,t. It is related to the Levenshtein metric, which is sometimes also called the edit distance.
For a different notion of the distance between two strings, see StringTools[HammingDistance] and StringTools[Levenshtein].
All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
useStringToolsinEditDistance⁡Mathematics,Mathematischeend use
4
with⁡StringTools:
EditDistance⁡abc,abd
2
EditDistance⁡abc,abcd
1
EditDistance⁡Elisabeth,Elyse
6
EditDistance⁡Connor,Constance
7
Since it is a metric, the edit distance satisfies the triangle inequality.
s≔Random⁡1000,lower:
t≔Random⁡1000,lower:
u≔Random⁡1000,lower:
EditDistance⁡s,t
1352
EditDistance⁡s,u+EditDistance⁡u,t
2746
See Also
string
StringTools[Levenshtein]
Download Help Document