Edit Distance
Edit Distance
a
b
b
a
b
c
a
c
b
c
b
a
b
b
a
b
c
a
c
a
c
a
b
b
a
b
c
a
a
a
Edit Distance
S =�
T = ��ED(S,T) = 3�
a
b
b
a
c
c
b
a
a
c
c
b
c
a
subs
a
b
a
c
c
b
a
del
a
a
c
c
b
a
ins
a
a
c
c
b
c
a
Compute Edit Distance
Dynamic Programing for Edit Distance
S
T
i
j
ED[i,j] = ED( , )
Dynamic Programing for Edit Distance
S
T
i
j
Dynamic Programing for Edit Distance
S
T
i
j
Dynamic Programing for Edit Distance
S
T
i
j
Dynamic Programing for Edit Distance
S
T
i
j
Dynamic Programing for Edit Distance
S
T
i
j
Dynamic Programing for Edit Distance
S
T
i
j
Dynamic Programming for Edit Distance
Bounded Edit Distance
Landau-Vishkin Algorithm
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
i
Consider a diagonal in the ED dynamic programing table.
Landau-Vishkin Algorithm
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
0 1 2 3 4 5 6 7
-1
-2
-3
-4
-5
-6
-7
Landau-Vishkin Algorithm
Landau-Vishkin Algorithm
0 | 1 | 2 | | | | | |
1 | | | | | | | |
2 | | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
Landau-Vishkin Algorithm
0 | 1 | 2 | | | | | |
1 | | | | | | | |
2 | | | | | | | |
| | | | | | | |
| | | | 0? | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
Landau-Vishkin Algorithm
0
i
i
i-1
i-1
ED(i,i-1)+1 -> at least 1!
ED(i-1,i)+1 -> at least 1!
ED(i-1,i-1)+HD(S[i],T[i]) -> 0 iff ED[i-1,i-1] = 0 and S[i] = T[i]!
Landau-Vishkin Algorithm
0 | 1 | 2 | | | | | |
1 | 0 | | | | | | |
2 | | 0 | | | | | |
| | | 0 | | | | |
| | | | 0 | | | |
| | | | | 1 | | |
| | | | | | | |
| | | | | | | |
S
T
Landau-Vishkin Algorithm
0 | 1 | 2 | | | | | |
1 | 0 | | | | | | |
2 | | 0 | | | | | |
| | | 0 | | | | |
| | | | 0 | | | |
| | | | | 1 | | |
| | | | | | | |
| | | | | | | |
S
T
Landau-Vishkin Algorithm
0 | 1 | 2 | | | x | x+1 | |
1 | | | | | | | |
2 | | | | | | | |
| | | | | | | |
| | | | | | | |
x+1 | | | | | | | |
| | | | | | | |
| | | | | | | |
Landau-Vishkin Algorithm
0 | 1 | 2 | | | x | | |
1 | | | | | | | |
2 | | | | | | | |
| | | | | | | |
| | | | | | | |
x+1 | | | | | | | |
| | | | | | | |
| | | | | | | |
Landau-Vishkin Algorithm
x
i
i+x
i+x-1
i-1
ED(i+x,i-1)+1 -> at least x+2!
ED(i+x-1,i)+1 -> can be x if ED(i+x-1,i) = x-1!
ED(i+x-1,i-1)+HD(S[i+x],T[i]) -> is x iff ED[i+x-1,i-1] = x and S[i+x] = T[i]!
We already know the lowest cell in diagonal x-1 with value x-1!
Landau-Vishkin Algorithm
x
x-1
i
i+x
i+x-1
i-1
LV[x-1,x-1]
?
i+x+1
i+1
Landau-Vishkin Algorithm
x-1
x
x
x
S
x+1
j=LV[x-1,x-1]
j
j+x
j+x+1
j+1
Landau-Vishkin Algorithm
x-1
x
x
x
S
x+1
j=LV[x-1,x-1]
j
j+x
j+x+1
j+1
x
Landau-Vishkin Algorithm
Landau-Vishkin Algorithm
x
w
y
z
i
i+d
i+d-1
i-1
y=ED(i+d,i-1), y+1 -> relevant if y=x-1
z=ED(i+d-1,i), z+1 -> relevant if z = x-1
w =ED(i+d-1,i-1), +HD(S[i+d],T[i]) -> relevant if w=x-1
We know the lowest cell for every one of these!
Landau-Vishkin Algorithm
x-1
S
x
j2=LV[d-1,x-1]
j1 +1,
j=max(j2, )
j3+1
j+d
j+d+1
j+1
x-1
j3=LV[d+1,x-1]
x-1
j1=LV[d,x-1]
x
x
x
Landau-Vishkin Algorithm
x-1
S
x
j2=LV[d-1,x-1]
j1 +1,
j=max(j2, )
j3+1
j+d
j+d+1
j+1
x-1
j3=LV[d+1,x-1]
x-1
j1=LV[d,x-1]
x
x
x
x+1
Landau-Vishkin Algorithm
v
w
y
z
i
i+d
i+d-1
i-1
Landau-Vishkin Algorithm
Landau-Vishkin Algorithm