In the typical dynamic Levenshtein distance algorithm, to compute the value of cell d[i][j]
, where i
and j
are the row and column numbers, respectively, we take the minimum of d[i-1][j-1]+0/1
, d[i-1][j]+1
and d[i][j-1]+1
. However, it seems to me that the minimum of d[i-1][j-1]+0/1
and d[i-1][j]+1
is always going to be d[i-1][j-1]+0/1
, in which case including d[i-1][j]+1
in the computation seems redundant. Is it ever the case that d[i-1][j-1]+0/1
> d[i-1][j]+1
in the Levenshtein distance algorithm, and if not, wouldn't it be more efficient to omit this comparison?
EDIT: Sorry for the under-researched question; any standard run of the algorithm shows instances where d[i-1][j-1]+0/1
> d[i-1][j]+1
:
A
+-+-+
|0|1|
+-+-+
A|1|0|
+-+-+
(consider the second row).