vaibhawraj / Levenshtein-Sequence-Python

List all possible Levenshtein (i.e., edit) sequences from one string to another with optimal number of inserts/deletes/replaces.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backtracking goes over the first character

BobbyL2k opened this issue · comments

Your code breaks when computing the distance for the input "01" and "10"

This is because the backtrackSequence goes backward by comparing StringA[i-1] == StringB[j-1] without a boundary check.

The fix is bellow

if(i-1 >= 0 and j-1 >= 0 and StringA[i-1] == StringB[j-1]):
        paths = backtrackSequence(matrix,StringA,StringB,i-1,j-1)
        return paths

Thanks Anuruth for the correction.