algo·visual

Edit Distance

Dynamic Programming
avgO(m·n)worstO(m·n)spaceO(m·n)
ε
S
I
T
T
I
N
G
ε
K
I
T
T
E
N

Cell [i][j] will hold the fewest edits that turn the first i letters of "KITTEN" into the first j letters of "SITTING"

1 / 54
String A6/14
String B7/14

How it works

Counts the fewest single-letter inserts, deletes and substitutions that turn one string into another (Levenshtein distance). Cell [i][j] holds the cost for the first i letters of a and the first j letters of b: matching letters cost nothing, otherwise pay 1 plus the cheapest neighbouring cell. Walking back from the corner spells out the edits.

Complexity

Best
O(m·n)
Average
O(m·n)
Worst
O(m·n)
Space
O(m·n)

Search algorithms

Jump to any algorithm or page