Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. It is named after Vladimir Levenshtein, who considered this distance in 1965.
Levenshtein distance may also be referred to as edit distance, although that term may also denote a larger family of distance metrics.
Mathematically, the Levenshtein distance between two strings a,b (of length |a| and |b| respectively) is given by lev_a,b(|a|,|b|)
where
The Levenshtein distance between “kitten” and “sitting” is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits:
1) kitten → sitten (substitution of “s” for “k”)
2) sitten → sittin (substitution of “i” for “e”)
3) sittin → sitting (insertion of “g” at the end)
Python
1 | #-*- coding: utf-8 -*- |
Algorithm, Distance, Levenshtein — Apr 18, 2018
Made with ❤️ and ☀️ on Earth.