$./edit-distance
# algorithm
1EditDistance(s1, s2)
2begin
3 dp[i][0]i; dp[0][j]j
4 for i1 to m, j1 to n do
5 if s1[i] == s2[j]
6 dp[i][j]dp[i-1][j-1]
7 else
8 dp[i][j]1 + min(dp[i][j-1], // ins
9 dp[i-1][j], // del
10 dp[i-1][j-1])// rep
11 return dp[m][n]
12end
# strings
s1:
HORSE
s2:
ROS
# dp table
εROS
ε0000
H0000
O0000
R0000
S0000
E0000
# operation
Initializing...
# legend
Match (free)
Insert (+1)
Delete (+1)
Replace (+1)
Optimal path
# current action
click "run" to begin...