OhMyCalc

Levenshtein Distance Calculator

Calculate the edit distance between two strings and see the operations needed to transform one into the other.

How to Use the Levenshtein Distance Calculator

  1. Enter the first string in the First string field.
  2. Enter the second string in the Second string field.
  3. Click Calculate — the edit distance, similarity percentage, and operation list are displayed instantly.
  4. Expand the Distance matrix to see the full dynamic programming table used for the computation.

快速参考

kitten → sittingDistance: 3
Saturday → SundayDistance: 3
hello → helloDistance: 0 (identical)
abc → xyzDistance: 3 (all replaced)
cat → cartDistance: 1 (insert r)
book → backDistance: 2

使用场景

公式

The Levenshtein distance between two strings is the minimum number of single-character edits — insertions, deletions, or substitutions — required to transform one string into the other. It is computed using dynamic programming: a matrix of size (|s1|+1) × (|s2|+1) is filled where each cell represents the edit distance between prefixes of the two strings.

常见问题

What is Levenshtein distance?
Levenshtein distance (also called edit distance) is a metric for measuring how different two strings are. It counts the minimum number of single-character insertions, deletions, or substitutions needed to change one string into the other. A distance of 0 means the strings are identical; a higher distance means they are more different.
How is similarity percentage calculated from edit distance?
Similarity is derived from the Levenshtein distance using the formula: similarity = (1 − distance / max(len1, len2)) × 100%. For example, if two strings of length 7 and 8 have an edit distance of 3, the similarity is (1 − 3/8) × 100% = 62.5%.
What are common applications of Levenshtein distance?
Levenshtein distance is widely used in spell checkers to suggest corrections, in DNA sequence alignment for bioinformatics, in fuzzy string matching for search engines, in plagiarism detection tools, and in natural language processing for tasks such as named entity recognition and machine translation evaluation.