Levenshtein Distance or edit distance between two strings is the number of single character edits to be made to convert one string to another. The edit can be an insertion, deletion or substitution.
Eg: Levenshtein distance between 'Choose' and 'Shoes' is 3.
- Substitute 'C' with 'S'
- Substitute 2nd 'o' with 'e'
- Delete 's'
C h o o s e
S h o o s e
S h o e s e
S h o e s _
The Damerau–Levenshtein Distance is also an edit distance between two strings but it includes one more edit operation viz transposition.
Eg: Damerau–Levenshtein distance 'Reign' and 'Field' is 4
- Substitute 'R' with 'F'
- Transpose 'i' and 'e'
- Substitute 'g' with 'l'
- Substitute 'n' with 'd'
R e i g n
F e i g n
F i e g n
F i e l n
F i e l d
Levenshtein distance between 'Reign' and 'Field' is 5.
No comments:
Post a Comment