Code Implementation of Levenshtein Distance
In the previous article, I mentioned that when doing fuzzy matching, Levenshtein distance was selected as the reference value. At the time, I directly used the Python library to implement it, which did not run fast in actual use.
In recent days, I have stayed at home and took the time to write several implementations of Levenshtein Distance in Kotlin.
What is Levenshtein Distance
See wikipedia to get more information.
In information theory, linguistics and computer science, the 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 the Soviet mathematician 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. It is closely related to pairwise string alignments.
Implementation
Recursive
1 | class LevenshteinRecursiveUtils { |
Recursive With Memo
1 | class LevenshteinRecursiveWithMemoUtils { |
Dynamic Programming
1 | class LevenshteinDpUtils { |