Levenshtein Distance

Description

Levenshtein distance (LD) is a measure of the similarity between two strings, and it is a minimum costs to transform a string to the other using deletions, insertions, or substitutions. This is really useful algorithm for comparing two strings.

Algorithm

As shown on the algorithm table, make a calculated distance table.

Next, initialize first row and column as 0 – (m or n).

Get minimum value of left one +1, upper one +1, and diagonally above and to the left + cost.

Example ( GUMBO & GAMBOL )

Step 7

final Levenshtein Distance is lower right hand corner of the matrix which is 2 in this case.