Levenshtein distance

(code by Claude, guidance by Georgios Evangelidis)

The Levenshtein distance is the cheapest way to turn one word into another using single-letter insertions, deletions and substitutions. Cell D[i][j] holds the distance between the first i letters of the source and the first j letters of the target. Each cell is computed from three neighbours, and the answer ends up in the bottom-right corner.

Operation costs
Try:
  • From the diagonal: match or substitute
  • From above: delete
  • From the left: insert
  • Traceback path

Click any filled cell to see how it was computed. Use the controls to step through the current phase. When you choose the path yourself, click the neighbour you think the current value came from. Keyboard: ← → step, Space play, Home End jump.

Alignment

Edit script