Edit Distance Visualizer

Compare two strings with Levenshtein dynamic programming, inspect every DP cell, and backtrack one shortest edit script.

Source
6
Target
7
Distance
3
Step
1

String input

Step controls

Start with dp[0][0] = 0 for two empty prefixes.

DP table

Current operation: Start

Current Candidates Edit path
Source / target0sitting
00
k
i
t
t
e
n

Cell output

row = 0
col = 0
operation = Start
distance = 3
source_char = -
target_char = -

Edit script

1. substitute k -> s
2. keep i
3. keep t
4. keep t
5. substitute e -> i
6. keep n
7. insert g

What is an Edit Distance Visualizer?

An edit distance visualizer shows how many single-character edits are needed to transform one string into another. The standard Levenshtein distance allows insertion, deletion, and substitution.

This tool lets you enter two strings, fill the dynamic programming table cell by cell, and inspect the final edit script after backtracking from the bottom-right cell.

For the full algorithm set, browse the Data Structure Visualizers hub.

How to use this edit distance visualizer

  • Enter the source string.
  • Enter the target string.
  • Click Run Edit Distance to fill the table and show the final distance.
  • Step forward to inspect each deletion, insertion, substitution, or match decision.
  • Review the edit script to see one shortest transformation path.

Edit distance and dynamic programming

Edit distance is a useful dynamic programming example because every cell combines three smaller subproblems: delete from the source, insert into the source, or substitute one character for another.

If you want related string algorithms, compare it with the Longest Common Subsequence Visualizer, Z Algorithm Visualizer, KMP String Matching Visualizer, and Rabin Karp Visualizer.

Frequently Asked Questions

What operations count in Levenshtein distance?
Levenshtein distance counts insertions, deletions, and substitutions. Matching characters cost zero.
What does each DP table cell mean?
Cell dp[i][j] stores the minimum edits needed to transform the first i characters of the source into the first j characters of the target.
Why is the first row and column initialized?
The first column represents deleting source characters to reach an empty target, and the first row represents inserting target characters from an empty source.
What is the time complexity of edit distance?
The standard dynamic programming algorithm runs in O(mn) time and O(mn) space for strings of length m and n.

Related tools