SlideShare une entreprise Scribd logo
1  sur  58
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
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
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
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
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]
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]) {
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Dynamic programming algorithm After filling out c, d( x , y )=c[| x |,| y |] Time and space complexity: O(| x || y |)
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
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]) {
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...)
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
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
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]) { {
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]]) {
Wu-Manber Special case: -Initial matrix:  s [q] = 01 | p | Match when  s [k,| p |] == 0
Example x = bbacbbbababacabbbba i=0 p = bbba 01234 s 0 [0]: 01111 s 0 [1]: 01111 s 0 [2]: 01111
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Exercise: Complete the example...

Contenu connexe

Tendances

Phương pháp nhánh cận
Phương pháp nhánh cậnPhương pháp nhánh cận
Phương pháp nhánh cận
Diên Vĩ
 
Matroids
MatroidsMatroids
Matroids
totycro
 
Algorithmes d'approximation
Algorithmes d'approximationAlgorithmes d'approximation
Algorithmes d'approximation
mohamed_SAYARI
 
Les algorithmes d'arithmetique
Les algorithmes d'arithmetiqueLes algorithmes d'arithmetique
Les algorithmes d'arithmetique
mohamed_SAYARI
 

Tendances (20)

Introduction à Python
Introduction à PythonIntroduction à Python
Introduction à Python
 
Cours tic complet
Cours tic completCours tic complet
Cours tic complet
 
TENSOR DECOMPOSITION WITH PYTHON
TENSOR DECOMPOSITION WITH PYTHONTENSOR DECOMPOSITION WITH PYTHON
TENSOR DECOMPOSITION WITH PYTHON
 
ZK Study Club: Sumcheck Arguments and Their Applications
ZK Study Club: Sumcheck Arguments and Their ApplicationsZK Study Club: Sumcheck Arguments and Their Applications
ZK Study Club: Sumcheck Arguments and Their Applications
 
EXPOSE SUR L’ALGORITHME DU TRI À BULLES (BUBBLE SORT).
EXPOSE SUR L’ALGORITHME DU TRI À BULLES (BUBBLE SORT).EXPOSE SUR L’ALGORITHME DU TRI À BULLES (BUBBLE SORT).
EXPOSE SUR L’ALGORITHME DU TRI À BULLES (BUBBLE SORT).
 
Quy Hoach Dong
Quy Hoach DongQuy Hoach Dong
Quy Hoach Dong
 
Phương pháp nhánh cận
Phương pháp nhánh cậnPhương pháp nhánh cận
Phương pháp nhánh cận
 
Matroids
MatroidsMatroids
Matroids
 
Algorithmes d'approximation
Algorithmes d'approximationAlgorithmes d'approximation
Algorithmes d'approximation
 
Take advantage of C++ from Python
Take advantage of C++ from PythonTake advantage of C++ from Python
Take advantage of C++ from Python
 
Q4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVAQ4.11: Getting Started in LAVA
Q4.11: Getting Started in LAVA
 
Formation python
Formation pythonFormation python
Formation python
 
Benharratharijtp4 arbre de décision
Benharratharijtp4 arbre de décisionBenharratharijtp4 arbre de décision
Benharratharijtp4 arbre de décision
 
Giáo trình Phân tích và thiết kế giải thuật - CHAP 5
Giáo trình Phân tích và thiết kế giải thuật - CHAP 5Giáo trình Phân tích và thiết kế giải thuật - CHAP 5
Giáo trình Phân tích và thiết kế giải thuật - CHAP 5
 
Bai toan du lich
Bai toan du lichBai toan du lich
Bai toan du lich
 
Les algorithmes de tri
Les algorithmes de triLes algorithmes de tri
Les algorithmes de tri
 
Introduction to Bayesian Inference
Introduction to Bayesian InferenceIntroduction to Bayesian Inference
Introduction to Bayesian Inference
 
How to break SAML if I have paws?
How to break SAML if I have paws?How to break SAML if I have paws?
How to break SAML if I have paws?
 
Les algorithmes d'arithmetique
Les algorithmes d'arithmetiqueLes algorithmes d'arithmetique
Les algorithmes d'arithmetique
 
Théorie de l'information
Théorie de l'informationThéorie de l'information
Théorie de l'information
 

Similaire à Wu Mamber (String Algorithms 2007)

Quantum factorization.pdf
Quantum factorization.pdfQuantum factorization.pdf
Quantum factorization.pdf
ssuser8b461f
 

Similaire à Wu Mamber (String Algorithms 2007) (20)

Approximate Matching (String Algorithms 2007)
Approximate Matching (String Algorithms 2007)Approximate Matching (String Algorithms 2007)
Approximate Matching (String Algorithms 2007)
 
cps170_bayes_nets.ppt
cps170_bayes_nets.pptcps170_bayes_nets.ppt
cps170_bayes_nets.ppt
 
Lec38
Lec38Lec38
Lec38
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
A Course in Fuzzy Systems and Control Matlab Chapter Three
A Course in Fuzzy Systems and Control Matlab Chapter ThreeA Course in Fuzzy Systems and Control Matlab Chapter Three
A Course in Fuzzy Systems and Control Matlab Chapter Three
 
Cs262 2006 lecture6
Cs262 2006 lecture6Cs262 2006 lecture6
Cs262 2006 lecture6
 
Ejercicios resueltos de analisis matematico 1
Ejercicios resueltos de analisis matematico 1Ejercicios resueltos de analisis matematico 1
Ejercicios resueltos de analisis matematico 1
 
Topic
TopicTopic
Topic
 
Statistics assignment 7
Statistics assignment 7Statistics assignment 7
Statistics assignment 7
 
Algebra 6
Algebra 6Algebra 6
Algebra 6
 
Existence of positive solutions for fractional q-difference equations involvi...
Existence of positive solutions for fractional q-difference equations involvi...Existence of positive solutions for fractional q-difference equations involvi...
Existence of positive solutions for fractional q-difference equations involvi...
 
Dynamic Programing_LCS.ppt
Dynamic Programing_LCS.pptDynamic Programing_LCS.ppt
Dynamic Programing_LCS.ppt
 
ملزمة الرياضيات للصف السادس الاحيائي الفصل الاول
ملزمة الرياضيات للصف السادس الاحيائي الفصل الاولملزمة الرياضيات للصف السادس الاحيائي الفصل الاول
ملزمة الرياضيات للصف السادس الاحيائي الفصل الاول
 
Quantum factorization.pdf
Quantum factorization.pdfQuantum factorization.pdf
Quantum factorization.pdf
 
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
 
統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半
 
IRJET- On Greatest Common Divisor and its Application for a Geometrical S...
IRJET-  	  On Greatest Common Divisor and its Application for a Geometrical S...IRJET-  	  On Greatest Common Divisor and its Application for a Geometrical S...
IRJET- On Greatest Common Divisor and its Application for a Geometrical S...
 
Elementary Linear Algebra 5th Edition Larson Solutions Manual
Elementary Linear Algebra 5th Edition Larson Solutions ManualElementary Linear Algebra 5th Edition Larson Solutions Manual
Elementary Linear Algebra 5th Edition Larson Solutions Manual
 
PO_groupVI_Term assignment.pptx
PO_groupVI_Term assignment.pptxPO_groupVI_Term assignment.pptx
PO_groupVI_Term assignment.pptx
 

Plus de mailund

Ku 05 08 2009
Ku 05 08 2009Ku 05 08 2009
Ku 05 08 2009
mailund
 
Association mapping using local genealogies
Association mapping using local genealogiesAssociation mapping using local genealogies
Association mapping using local genealogies
mailund
 
Neural Networks
Neural NetworksNeural Networks
Neural Networks
mailund
 
Probability And Stats Intro
Probability And Stats IntroProbability And Stats Intro
Probability And Stats Intro
mailund
 
Probability And Stats Intro2
Probability And Stats Intro2Probability And Stats Intro2
Probability And Stats Intro2
mailund
 

Plus de mailund (20)

Chapter 9 divide and conquer handouts with notes
Chapter 9   divide and conquer handouts with notesChapter 9   divide and conquer handouts with notes
Chapter 9 divide and conquer handouts with notes
 
Chapter 9 divide and conquer handouts
Chapter 9   divide and conquer handoutsChapter 9   divide and conquer handouts
Chapter 9 divide and conquer handouts
 
Chapter 9 divide and conquer
Chapter 9   divide and conquerChapter 9   divide and conquer
Chapter 9 divide and conquer
 
Chapter 7 recursion handouts with notes
Chapter 7   recursion handouts with notesChapter 7   recursion handouts with notes
Chapter 7 recursion handouts with notes
 
Chapter 7 recursion handouts
Chapter 7   recursion handoutsChapter 7   recursion handouts
Chapter 7 recursion handouts
 
Chapter 7 recursion
Chapter 7   recursionChapter 7   recursion
Chapter 7 recursion
 
Chapter 5 searching and sorting handouts with notes
Chapter 5   searching and sorting handouts with notesChapter 5   searching and sorting handouts with notes
Chapter 5 searching and sorting handouts with notes
 
Chapter 5 searching and sorting handouts
Chapter 5   searching and sorting handoutsChapter 5   searching and sorting handouts
Chapter 5 searching and sorting handouts
 
Chapter 5 searching and sorting
Chapter 5   searching and sortingChapter 5   searching and sorting
Chapter 5 searching and sorting
 
Chapter 4 algorithmic efficiency handouts (with notes)
Chapter 4   algorithmic efficiency handouts (with notes)Chapter 4   algorithmic efficiency handouts (with notes)
Chapter 4 algorithmic efficiency handouts (with notes)
 
Chapter 4 algorithmic efficiency handouts
Chapter 4   algorithmic efficiency handoutsChapter 4   algorithmic efficiency handouts
Chapter 4 algorithmic efficiency handouts
 
Chapter 4 algorithmic efficiency
Chapter 4   algorithmic efficiencyChapter 4   algorithmic efficiency
Chapter 4 algorithmic efficiency
 
Chapter 3 introduction to algorithms slides
Chapter 3 introduction to algorithms slidesChapter 3 introduction to algorithms slides
Chapter 3 introduction to algorithms slides
 
Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)Chapter 3 introduction to algorithms handouts (with notes)
Chapter 3 introduction to algorithms handouts (with notes)
 
Chapter 3 introduction to algorithms handouts
Chapter 3 introduction to algorithms handoutsChapter 3 introduction to algorithms handouts
Chapter 3 introduction to algorithms handouts
 
Ku 05 08 2009
Ku 05 08 2009Ku 05 08 2009
Ku 05 08 2009
 
Association mapping using local genealogies
Association mapping using local genealogiesAssociation mapping using local genealogies
Association mapping using local genealogies
 
Neural Networks
Neural NetworksNeural Networks
Neural Networks
 
Probability And Stats Intro
Probability And Stats IntroProbability And Stats Intro
Probability And Stats Intro
 
Probability And Stats Intro2
Probability And Stats Intro2Probability And Stats Intro2
Probability And Stats Intro2
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
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]]) {
  • 31. Wu-Manber Special case: -Initial matrix: s [q] = 01 | p | Match when s [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 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