Wu Mamber (String Algorithms 2007)

download Wu  Mamber (String Algorithms 2007)

If you can't read please download the document

description

The Wu Manber approximate matching algorithm

Transcript of Wu Mamber (String Algorithms 2007)

  • 1. Approximate k-edit-distance Approximative ( k -distance) matching, now for edit distance Given stringx = abbacbbbababacabbbbaandpatternp = bbbafind all almost-occurrences ofpindx x = a bba c bbba babacab b a bba 17 6 1

2. Edit distance Theedit-distancebetween stringsxandyisthe minimal number of - insertions - deletions - substitutions needed to translatexintoy 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 mind( 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 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j Main algorithm: fori=1..| x |: forj=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 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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+01+1 1+10 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 10 2 3 4 5 6 8. Example a b a b c a 1+12+1 0+11 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 9. Example a b a b c a 2+03+1 1+12 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 1012 2 3 4 5 6 10. Example a b a b c a 3+04+1 2+13 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 23 2 3 4 5 6 11. Example a b a b c a 4+15+1 3+14 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 34 2 3 4 5 6 12. Example a b a b c a 5+16+1 4+15 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 45 2 3 4 5 6 13. Example a b a b c a 6+17+1 5+16 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 56 2 3 4 5 6 14. Example a b a b c a 7+18+1 6+17 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 67 2 3 4 5 6 15. Example a b a b c a 1+10+1 2+11 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 21 3 4 5 6 16. Example a b a b c a 0+01+1 1+10 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 210 3 4 5 6 17. Example a b a b c a 1+12+1 0+11 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 21 01 3 4 5 6 18. Example a b a b c a 2+13+1 1+12 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 21 0 12 3 4 5 6 19. Example a b a b c a 3+14+1 2+13 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 21 0 1 23 3 4 5 6 20. Example a b a b c a 4+05+1 3+14 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 21 0 1 2 34 3 4 5 6 21. Example a b a b c a 5+16+1 4+15 a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 21 0 1 2 3 45 3 4 5 6 22. Example a b a b c a a b a a c b c c c[0,0] = 0 fori=1..| x |: c[i,0] = i forj=1..| p |: c[0,j] = j fori=1..| x |: forj=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 101 2 3 4 5 6 7 21 0 1 2 3 4 56 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 33 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' id( 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 fori=1..| x |: c[i,0] =0 forj=1..| p |: c[0,j] = j Main algorithm: fori=1..| x |: forj=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 indicesi,where c[i,| p |] k , correspond to one or more approximate matches. Some backtracking is needed to find the correspondingi'indices ... we can find onei'for eachiin time O(| p |) peri , for a total time of O(| x || p |). (Theorem 10.1.1) (More complicated to get all matches...) 27. Wu-Manber We define amatrix s the state of matching so far by: s [ q , j ] = 0iffd( x [ i-j+1 .. i ], p [1.. j ]) q forj =0..| p |, andq =0.. k i j 28. Wu-Manber As before, we use apre-calculated bit-matrix: t [h,j] = 0ifp [j] == h 1ifp [j] != h with rows indexed by the alphabet and columns indexed by indices inp 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 Theexpression: 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 forq=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]]) { 31. Wu-Manber Special case: -Initial matrix:s [q] = 01 | p | Match whens [k,| p |] == 0 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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 0123401234 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]] forq=1..k: s1 = old[q-1]s2 =s [q-1] >> 1s3 = s1 >> 1s4 = old[q] >> 1s [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 58. Exercise: Complete the example...