Skip to content
uencoder

Edit Distance

Edit distance is the minimum number of single-character edit operations (insertion, deletion, substitution) required to transform one string into another; the Levenshtein distance is its most common form.

Purpose

Quantifies the degree of difference between strings, used for fuzzy matching and error correction.

Mechanism

General framework: define the allowed operation set and costs, then use dynamic programming to find the minimum total cost. Levenshtein allows insertion/deletion/substitution (each cost 1); Damerau-Levenshtein additionally allows transposition of adjacent characters; Hamming allows substitution only.

Use cases

  • Spelling correction
  • DNA sequence alignment
  • OCR error correction
  • Fuzzy deduplication

Examples

  • Input
    cat → cut
    Output
    1 (substituting a→u)

    Levenshtein

Common errors

Confusing different edit-distance variants
Make the operation set and costs explicit

Related terms

Related tools

References