Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Wu Mamber (String Algorithms 2007)
1. Approximate k-edit-distance Approximative ( k -distance) matching, now for edit distance Given string x = abbacbbbababacabbbba and pattern p = bbba find all “almost”-occurrences of p ind x x = a bba c bbba babacab b a bba 17 6 1
2. Edit distance The edit-distance between strings x and y is the minimal number of - insertions - deletions - substitutions needed to translate x into y d( abab,acc ) = 3: abab -> aba -> aca -> acc d( abab,aac ) = 2: abab -> aab -> aac
3. Calculating the edit-distance Basis cases: - string vs empty string: d (x,””) = d( ””,x) = | x | - two single characters: d(a,b) = 1 if a!=b 0 if a==b
4. Calculating the edit-distance Recursion: - two non-empty strings: d( x [1..i], y [1..j]) = d( x [1..i-1], y [1..j])+1 min d( x [1..i], y [1..j-1])+1 d( x [1..i-1], y [1..j-1])+d( x [i], y [j]) { i j i j i j
5. Dynamic programming algorithm Use table c[i,j] = d( x [1..i], y [1..j]) Initialize: c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j Main algorithm: for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { c[i-1,j] c[i,j-1] c[i-1,j-1] c[i,j]
6. Example a b a b c a 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) {
7. Example a b a b c a 0+0 1+1 1+1 0 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 2 3 4 5 6
8. Example a b a b c a 1+1 2+1 0+1 1 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6
9. Example a b a b c a 2+0 3+1 1+1 2 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 2 3 4 5 6
10. Example a b a b c a 3+0 4+1 2+1 3 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 2 3 4 5 6
11. Example a b a b c a 4+1 5+1 3+1 4 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 2 3 4 5 6
12. Example a b a b c a 5+1 6+1 4+1 5 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 2 3 4 5 6
13. Example a b a b c a 6+1 7+1 5+1 6 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 2 3 4 5 6
14. Example a b a b c a 7+1 8+1 6+1 7 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 3 4 5 6
15. Example a b a b c a 1+1 0+1 2+1 1 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 3 4 5 6
16. Example a b a b c a 0+0 1+1 1+1 0 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 0 3 4 5 6
17. Example a b a b c a 1+1 2+1 0+1 1 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 0 1 3 4 5 6
18. Example a b a b c a 2+1 3+1 1+1 2 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 0 1 2 3 4 5 6
19. Example a b a b c a 3+1 4+1 2+1 3 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 0 1 2 3 3 4 5 6
20. Example a b a b c a 4+0 5+1 3+1 4 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 0 1 2 3 4 3 4 5 6
21. Example a b a b c a 5+1 6+1 4+1 5 a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 0 1 2 3 4 5 3 4 5 6
22. Example a b a b c a a b a a c b c c c[0,0] = 0 for i=1..| x |: c[i,0] = i for j=1..| p |: c[0,j] = j for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) { 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 0 1 2 3 4 5 6 3 2 1 0 1 2 3 4 5 4 3 2 1 1 2 2 3 4 5 4 3 2 2 1 2 2 3 6 5 4 3 2 2 2 3 3
23. Dynamic programming algorithm After filling out c, d( x , y )=c[| x |,| y |] Time and space complexity: O(| x || y |)
24. Approximate pattern matching j=0 1 2 3 4 5 i= 0 1 2 3 4 5 6 7 8 9 10 11 12 13 c[i,j] = d( x [1..i], y [1..j]) j=0 1 2 3 4 5 i= 0 1 2 3 4 5 6 7 8 9 10 11 12 13 c[i,j] = min i' ≤ i d( x [i'..i], y [1..j]) j j i i i' Edit distance Edit distance pattern matching
25. Approximate pattern matching Use table c[i,j] = min i' ≤ i d( x [1..i], y [1..j]) Initialize: c[0,0] = 0 for i=1..| x |: c[i,0] = 0 for j=1..| p |: c[0,j] = j Main algorithm: for i=1..| x |: for j=1..| p |: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) {
26. Approximate pattern matching After filling out, in time and space O(| x || p |) all indices i, where c[i,| p |] ≤ k , correspond to one or more approximate matches. Some backtracking is needed to find the corresponding i' indices ... we can find one i' for each i in time O(| p |) per i , for a total time of O(| x || p |). (Theorem 10.1.1) (More complicated to get all matches...)
27. Wu-Manber We define a matrix s – the state of matching so far – by: s [ q , j ] = 0 iff d( x [ i-j+1 .. i ], p [1.. j ]) ≤ q for j =0..| p |, and q =0.. k i j
28. Wu-Manber As before, we use a pre-calculated bit-matrix: t [h,j] = 0 if p [j] == h 1 if p [j] != h with rows indexed by the alphabet and columns indexed by indices in p
29. Wu-Manber The recursion: c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d( x [i], y [j]) becomes: s i-1 [q-1, j] s i [q,j] = & s i [q-1,j-1] s i-1 [q-1,j-1] & ( s i-1 [q,j-1] | t [ x [i],j]) { {
30. Wu-Manber The expression: s i-1 [q-1, j] s i [q,j] = & s i [q-1,j-1] s i-1 [q-1,j-1] & ( s i-1 [q,j-1] | t [ x [i],j]) can be computed as: old = s s [0] = (old[0] >> 1) | t [ x [i]] // SHIFT-and-OR for q=1..k: s1 = old[q-1] // s1[j] = s i-1 [q-1, j] s2 = s [q-1] >> 1 // s2[j] = s i [q-1,j-1] s3 = s1 >> 1 // s3[j] = s i-1 [q-1,j-1] s4 = old[q] >> 1 // s4[j] = s i-1 [ q,j-1] s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) {
32. Example x = bbacbbbababacabbbba i=0 p = bbba 01234 s 0 [0]: 01111 s 0 [1]: 01111 s 0 [2]: 01111
33. Example x = b bacbbbababacabbbba i=1 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 = 00 111 | 0000 1 s 0 [1]: 01111 s 1 [1]: s 0 [2]: 01111 s 1 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = bb b a
34. Example x = b bacbbbababacabbbba i=1 01234 01234 s 0 [0]: 01111 s 1 [0]: 0 0 111 = 00 111 | 0000 1 s 0 [1]: 01111 s 1 [1]: s 0 [2]: 01111 s 1 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = bb b a 0 edit distance match
35. Example x = b bacbbbababacabbbba i=1 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 = 00 111 | 0000 1 s 0 [1]: 01111 s 1 [1]: s 0 [2]: 01111 s 1 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = bb b a Not 0 edit distance match
36. Example x = b bacbbbababacabbbba i=1 p = b bba 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 s 0 [1]: 01111 s 1 [1]: 0 00 11 = 0 1111 & 000 11 s 0 [2]: 01111 s 1 [2]: & 00 111 & ( 00 111 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b b ba p = bb b a p = bb b a
37. Example x = b bacbbbababacabbbba i=1 p = b bba 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 s 0 [1]: 01111 s 1 [1]: 0 00 11 = 0 1111 & 000 11 s 0 [2]: 01111 s 1 [2]: & 00 111 & ( 00 111 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b b ba p = bb b a p = bb b a 1 edit distance match
38. Example x = b bacbbbababacabbbba i=1 p = b bba 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 s 0 [1]: 01111 s 1 [1]: 0 00 11 = 0 1111 & 000 11 s 0 [2]: 01111 s 1 [2]: & 00 111 & ( 00 111 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b b ba p = bb b a p = bb b a Not 1 edit distance match
39. Example x = b bacbbbababacabbbba i=1 p = b bba 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 s 0 [1]: 01111 s 1 [1]: 000 11 s 0 [2]: 01111 s 1 [2]: 0000 1 = 0 1111 & 0000 1 & 00 111 & ( 00 111 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b b ba p = bb b a p = bb b a
40. Example x = b bacbbbababacabbbba i=1 p = b bba 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 s 0 [1]: 01111 s 1 [1]: 000 11 s 0 [2]: 01111 s 1 [2]: 0000 1 = 0 1111 & 0000 1 & 00 111 & ( 00 111 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b b ba p = bb b a p = bb b a 2 edit distance match
41. Example x = b bacbbbababacabbbba i=1 p = b bba 01234 01234 s 0 [0]: 01111 s 1 [0]: 00 111 s 0 [1]: 01111 s 1 [1]: 000 11 s 0 [2]: 01111 s 1 [2]: 0000 1 = 0 1111 & 0000 1 & 00 111 & ( 00 111 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b b ba p = bb b a p = bb b a Not 2 edit distance match
42. Example x = bb acbbbababacabbbba i=2 p = b bba 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 = 000 11 | 0000 1 s 1 [1]: 00011 s 2 [1]: s 1 [2]: 00001 s 2 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = bb ba p = b bb a p = b bb a
43. Example x = bb acbbbababacabbbba i=2 p = b bba 01234 01234 s 1 [0]: 00111 s 2 [0]: 0 00 11 = 000 11 | 0000 1 s 1 [1]: 00011 s 2 [1]: s 1 [2]: 00001 s 2 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = bb ba p = b bb a p = b bb a 0 edit distance match
44. Example x = bb acbbbababacabbbba i=2 p = b bba 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 = 000 11 | 0000 1 s 1 [1]: 00011 s 2 [1]: s 1 [2]: 00001 s 2 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = bb ba p = b bb a p = b bb a Not 0 edit distance match
45. Example x = bb acbbbababacabbbba i=2 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 s 1 [1]: 00011 s 2 [1]: 0000 1 = 00 111 & 0000 1 s 1 [2]: 00001 s 2 [2]: & 000 11 & ( 0000 1 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = bb ba p = b bb a p = b bb a
46. Example x = bb acbbbababacabbbba i=2 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 s 1 [1]: 00011 s 2 [1]: 0 000 1 = 00 111 & 0000 1 s 1 [2]: 00001 s 2 [2]: & 000 11 & ( 0000 1 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = bb ba p = b bb a p = b bb a 1 edit distance match
47. Example x = bb acbbbababacabbbba i=2 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 s 1 [1]: 00011 s 2 [1]: 0000 1 = 00 111 & 0000 1 s 1 [2]: 00001 s 2 [2]: & 000 11 & ( 0000 1 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = bb ba p = b bb a p = b bb a Not 1 edit distance match
48. Example x = bb acbbbababacabbbba i=2 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 s 1 [1]: 00011 s 2 [1]: 0000 1 s 1 [2]: 00001 s 2 [2]: 00000 = 000 11 & 00000 & 0000 1 & ( 00000 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = bb ba p = b bb a p = b bb a
49. Example x = bb acbbbababacabbbba i=2 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 s 1 [1]: 00011 s 2 [1]: 0000 1 s 1 [2]: 00001 s 2 [2]: 0 0000 = 000 11 & 00000 & 0000 1 & ( 00000 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = bb ba p = b bb a p = b bb a 2 edit distance match
50. Example x = bb acbbbababacabbbba i=2 01234 01234 s 1 [0]: 00111 s 2 [0]: 000 11 s 1 [1]: 00011 s 2 [1]: 0000 1 s 1 [2]: 00001 s 2 [2]: 0 000 0 = 000 11 & 00000 & 0000 1 & ( 00000 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = bb ba p = b bb a p = b bb a 2 edit distance match
51. Example x = bba cbbbababacabbbba i=3 01234 01234 s 2 [0]: 00011 s 3 [0]: 0 1111 = 0000 1 | 0 111 0 s 2 [1]: 00001 s 3 [1]: s 2 [2]: 00000 s 3 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = b bba
52. Example x = bba cbbbababacabbbba i=3 01234 01234 s 2 [0]: 00011 s 3 [0]: 0 1111 = 0000 1 | 0 111 0 s 2 [1]: 00001 s 3 [1]: s 2 [2]: 00000 s 3 [2]: old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = b bba Not 0 edit distance match
53. Example x = bba cbbbababacabbbba i=3 01234 01234 s 2 [0]: 00011 s 3 [0]: 0 1111 s 2 [1]: 00001 s 3 [1]: 00000 = 0000 1 & 00 111 s 2 [2]: 00000 s 3 [2]: & 00000 & ( 00000 | 0 111 0 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = b bba
54. Example x = bba cbbbababacabbbba i=3 01234 01234 s 2 [0]: 00011 s 3 [0]: 0 1111 s 2 [1]: 00001 s 3 [1]: 0 0000 = 0000 1 & 00 111 s 2 [2]: 00000 s 3 [2]: & 00000 & ( 00000 | 0 111 0 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = b bba 1 edit distance match
55. Example x = bba cbbbababacabbbba i=3 01234 01234 s 2 [0]: 00011 s 3 [0]: 0 1111 s 2 [1]: 00001 s 3 [1]: 00000 s 2 [2]: 00000 s 3 [2]: 00000 = 0000 1 & 00000 & 00000 & ( 00000 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = b bba
56. Example x = bba cbbbababacabbbba i=3 01234 01234 s 2 [0]: 00011 s 3 [0]: 0 1111 s 2 [1]: 00001 s 3 [1]: 00000 s 2 [2]: 00000 s 3 [2]: 0 0000 = 0000 1 & 00000 & 00000 & ( 00000 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = b bba 2 edit distance match
57. Example x = bba cbbbababacabbbba i=3 01234 01234 s 2 [0]: 00011 s 3 [0]: 0 1111 s 2 [1]: 00001 s 3 [1]: 00000 s 2 [2]: 00000 s 3 [2]: 0 000 0 = 0000 1 & 00000 & 00000 & ( 00000 | 0000 1 ) old = s s [0] = (old[0] >> 1) | t [ x [i]] for q=1..k: s1 = old[q-1] s2 = s [q-1] >> 1 s3 = s1 >> 1 s4 = old[q] >> 1 s [q] = s1 & s2 & s3 & (s4 | t [ x [i]]) p = b bba p = b b ba p = bb b a p = b bba 2 edit distance match