Enter two strings and instantly calculate their edit distance — how many single-character insertions, deletions, or substitutions it takes to transform one into the other. Visualize the full DP matrix, trace the edit path, and run batch comparisons. Everything runs in your browser with no server, no sign-up, no tracking.
Enter one pair per line, separated by a comma: word1,word2
What Is Levenshtein Distance?
The Levenshtein distance (also called edit distance) between two strings is the minimum number of single-character edits — insertions, deletions, and substitutions — needed to transform one string into the other.
The classic example: transforming “kitten” into “sitting” requires 3 operations, so their Levenshtein distance is 3.
| Operation | Example | Cost |
|---|---|---|
| Substitution | k → s (kitten → sitten) | 1 |
| Substitution | e → i (sitten → sittin) | 1 |
| Insertion | sittin → sitting | 1 |
Similarity % is computed as (1 − distance / max(len_a, len_b)) × 100.
How the DP Algorithm Works
The calculator builds an (m+1) × (n+1) matrix where m and n are the lengths of the two strings. Each cell dp[i][j] stores the minimum edit distance between the first i characters of string A and the first j characters of string B. The recurrence is:
- If
A[i] == B[j]:dp[i][j] = dp[i-1][j-1](no cost) - Otherwise:
dp[i][j] = 1 + min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1])(substitute, delete, insert)
Tracing back through the matrix from dp[m][n] reveals the specific sequence of operations shown in the step-by-step breakdown.
Common Use Cases
| Application | How edit distance helps |
|---|---|
| Spell checking | Find the closest dictionary word |
| DNA sequencing | Measure genetic sequence similarity |
| Fuzzy search | Rank search results by closeness |
| Plagiarism detection | Detect near-duplicate passages |
| Record linkage | Merge duplicate database entries |
| Autocorrect | Suggest the most likely intended word |
| NLP / ML | Feature for text similarity models |
Tips
- Case-sensitive toggle — By default, comparison is case-insensitive. Enable case-sensitivity when comparing code identifiers or passwords.
- DP matrix — Enable “Show DP matrix” to see the full dynamic programming table with the optimal path highlighted. Limited to strings of 20 characters or fewer for readability.
- Batch mode — Paste a list of
word1,word2pairs to compare many strings at once — handy for evaluating fuzzy-match thresholds. - Swap — Swap the two inputs instantly; Levenshtein distance is symmetric (
d(A,B) == d(B,A)).
Compare full text blocks line by line → Text Diff Checker
Count words, characters, and sentences → Word Counter
