SlideShare a Scribd company logo
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...

More Related Content

Similar to Wu Mamber (String Algorithms 2007)

Approximate Matching (String Algorithms 2007)
Approximate Matching (String Algorithms 2007)Approximate Matching (String Algorithms 2007)
Approximate Matching (String Algorithms 2007)
mailund
 
cps170_bayes_nets.ppt
cps170_bayes_nets.pptcps170_bayes_nets.ppt
cps170_bayes_nets.ppt
FaizAbaas
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Shakil Ahmed
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
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
Chung Hua Universit
 
Ejercicios resueltos de analisis matematico 1
Ejercicios resueltos de analisis matematico 1Ejercicios resueltos de analisis matematico 1
Ejercicios resueltos de analisis matematico 1
tinardo
 
Topic
TopicTopic
Statistics assignment 7
Statistics assignment 7Statistics assignment 7
Statistics assignment 7
Ishaq Ahmed
 
Algebra 6
Algebra 6Algebra 6
Algebra 6
Mang Oha
 
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...
IJRTEMJOURNAL
 
Dynamic Programing_LCS.ppt
Dynamic Programing_LCS.pptDynamic Programing_LCS.ppt
Dynamic Programing_LCS.ppt
manasgaming4
 
ملزمة الرياضيات للصف السادس الاحيائي الفصل الاول
ملزمة الرياضيات للصف السادس الاحيائي الفصل الاولملزمة الرياضيات للصف السادس الاحيائي الفصل الاول
ملزمة الرياضيات للصف السادس الاحيائي الفصل الاول
anasKhalaf4
 
Quantum factorization.pdf
Quantum factorization.pdfQuantum factorization.pdf
Quantum factorization.pdf
ssuser8b461f
 
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022 ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
ملزمة الرياضيات للصف السادس التطبيقي الفصل الاول الاعداد المركبة 2022
anasKhalaf4
 
統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半統計的学習の基礎 4章 前半
統計的学習の基礎 4章 前半
Ken'ichi Matsui
 
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...
IRJET Journal
 
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
zuxigytix
 
PO_groupVI_Term assignment.pptx
PO_groupVI_Term assignment.pptxPO_groupVI_Term assignment.pptx
PO_groupVI_Term assignment.pptx
PATELPUNIT2
 

Similar to 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
 

More from mailund

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
mailund
 
Chapter 9 divide and conquer handouts
Chapter 9   divide and conquer handoutsChapter 9   divide and conquer handouts
Chapter 9 divide and conquer handouts
mailund
 
Chapter 9 divide and conquer
Chapter 9   divide and conquerChapter 9   divide and conquer
Chapter 9 divide and conquer
mailund
 
Chapter 7 recursion handouts with notes
Chapter 7   recursion handouts with notesChapter 7   recursion handouts with notes
Chapter 7 recursion handouts with notes
mailund
 
Chapter 7 recursion handouts
Chapter 7   recursion handoutsChapter 7   recursion handouts
Chapter 7 recursion handouts
mailund
 
Chapter 7 recursion
Chapter 7   recursionChapter 7   recursion
Chapter 7 recursion
mailund
 
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
mailund
 
Chapter 5 searching and sorting handouts
Chapter 5   searching and sorting handoutsChapter 5   searching and sorting handouts
Chapter 5 searching and sorting handouts
mailund
 
Chapter 5 searching and sorting
Chapter 5   searching and sortingChapter 5   searching and sorting
Chapter 5 searching and sorting
mailund
 
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)
mailund
 
Chapter 4 algorithmic efficiency handouts
Chapter 4   algorithmic efficiency handoutsChapter 4   algorithmic efficiency handouts
Chapter 4 algorithmic efficiency handouts
mailund
 
Chapter 4 algorithmic efficiency
Chapter 4   algorithmic efficiencyChapter 4   algorithmic efficiency
Chapter 4 algorithmic efficiency
mailund
 
Chapter 3 introduction to algorithms slides
Chapter 3 introduction to algorithms slidesChapter 3 introduction to algorithms slides
Chapter 3 introduction to algorithms slides
mailund
 
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)
mailund
 
Chapter 3 introduction to algorithms handouts
Chapter 3 introduction to algorithms handoutsChapter 3 introduction to algorithms handouts
Chapter 3 introduction to algorithms handouts
mailund
 
Ku 05 08 2009
Ku 05 08 2009Ku 05 08 2009
Ku 05 08 2009mailund
 
Association mapping using local genealogies
Association mapping using local genealogiesAssociation mapping using local genealogies
Association mapping using local genealogiesmailund
 
Neural Networks
Neural NetworksNeural Networks
Neural Networksmailund
 
Probability And Stats Intro
Probability And Stats IntroProbability And Stats Intro
Probability And Stats Intromailund
 
Probability And Stats Intro2
Probability And Stats Intro2Probability And Stats Intro2
Probability And Stats Intro2mailund
 

More from 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
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

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