Levenshtein questions

In the Levenshtein Distance algorithm , what does this line do?

    d[i][j] = Minimum (d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1] + cost);

Although it gets the minimum of all these values, why is the value added to the end, and why do we have + 1 at the end of each array indexer (the first two parameters)?

+3
source share
3 answers

Here is the formula:

alt text

m(a,b) = if a==b then 0 else 1

The line with "min" is the recursive formula itself, the rest are the non-recursive cases that the recursion leads to.

Your string uses "caching" the results in an array. Try to look at it as:

 d(i, j) = Minimum (d(i-1, j)+1, d(i, j-1)+1, d(i-1, j-1) + cost);

costis m(a,b), and it is zero, if a==bone in the other case

+2
source

From the article:

                (
                  d[i-1, j] + 1,  // deletion
                  d[i, j-1] + 1,  // insertion
                  d[i-1, j-1] + 1 // substitution
                )

- ( ) . "" , . "" 1, "" 1 "" .

+1

, : , . , , , .

, . > 0 , , ,

0

Source: https://habr.com/ru/post/1727386/


All Articles