Algorithms – Dynamic Programming – Edit distance (Levenshtein)

code

I suggest to check out the following post first: http://badearobert.ro/2019/05/03/algorithms-dynamic-programming-longest-common-subsequence-lcs/

Edit distance refer to minimum number of moves to make two strings equal.

The Levenshtein distance is a string metric for measuring difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one word into the other.

Levenshtein distance may also be referred to as edit distance. It is closely related to pairwise string alignments.

Levenshtein distance are applicable in string matching, spell checking, etc.

Examples of edit distance:

  • kitten → sitten (substitution of “s” for “k”)
  • sitttin → sittin (deletion of “t“)
  • sittin → sitting (insertion of “g” at the end)

Let’s see the implementation of the algorithm.

And this is how the values are calculated, based on two strings:

References

Leave a comment

Your email address will not be published.