Suppose we are given two strings
and
. We want to devise a function
that tells us how close the two strings are. A reasonable measurement would be to measure how many "edits" operations have to be made to one string in order to change it to the other. There are three possible "edit" operations:
Substitution: Replacing a single character from so that it matches costs . If and . Then .
Insertion: Inserting a single character also costs . Ie, If and , then .
Deletion: Deleting a single character also costs . Ie. If and then .
Given and , compute .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This is called the edit distance or the Levenshtein Distance .
Algorithms for solving this problem are explained here .
Python code: