← All Tools

🔀 Damerau-Levenshtein Distance

Edit distance that also counts adjacent transpositions — one op instead of two for the classic teh → the typo.

Distance
Similarity
|A|
|B|
Transpositions

Edit Script (optimal traceback)

    About

    The Damerau-Levenshtein distance is the minimum number of insertions, deletions, substitutions, and adjacent transpositions to turn one string into another. It counts ab → ba as one operation, matching how humans actually mistype. Standard Levenshtein counts the same swap as two (substitute + substitute).

    This tool uses the optimal string alignment variant (a.k.a. restricted DL): each substring may be edited only once, so CA → ABC is 3 rather than the true DL distance of 2. That variant is O(mn) time and space, exactly matching the DP recurrence shown in the matrix.

    Cell colouring: purple = cells on one optimal path; green = cells where a transposition was taken.