Approximate k-edit-distance

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

Longest Common Subsequence
DYNAMIC PROGRAMMING ALGORITHMS VINAY ABHISHEK MANCHIRAJU.
Dynamic Programming Nithya Tarek. Dynamic Programming Dynamic programming solves problems by combining the solutions to sub problems. Paradigms: Divide.
Space-for-Time Tradeoffs
Overview What is Dynamic Programming? A Sequence of 4 Steps
Inexact Matching of Strings General Problem –Input Strings S and T –Questions How distant is S from T? How similar is S to T? Solution Technique –Dynamic.
Dynamic Programming Optimization Problems Dynamic Programming Paradigm
Fussy Set Theory Definition A fuzzy subset A of a universe of discourse U is characterized by a membership function which associate with each element u.
Sequence Alignment Algorithms in Computational Biology Spring 2006 Edited by Itai Sharon Most slides have been created and edited by Nir Friedman, Dan.
Introduction to Bioinformatics Algorithms Dynamic Programming: Edit Distance.
Dynamic Programming Solving Optimization Problems.
Reminder -Structure of a genome Human 3x10 9 bp Genome: ~30,000 genes ~200,000 exons ~23 Mb coding ~15 Mb noncoding pre-mRNA transcription splicing translation.
Sequence Alignment Bioinformatics. Sequence Comparison Problem: Given two sequences S & T, are S and T similar? Need to establish some notion of similarity.
Distance Functions for Sequence Data and Time Series
Sequence Alignment Variations Computing alignments using only O(m) space rather than O(mn) space. Computing alignments with bounded difference Exclusion.
By Makinen, Navarro and Ukkonen. Abstract Let A and B be two run-length encoded strings of encoded lengths m’ and n’, respectively. we will show an O(m’n+n’m)
Multiple Sequence alignment Chitta Baral Arizona State University.
UNIVERSITY OF SOUTH CAROLINA College of Engineering & Information Technology Bioinformatics Algorithms and Data Structures Chapter 11: Core String Edits.
Class 2: Basic Sequence Alignment
1 Theory I Algorithm Design and Analysis (11 - Edit distance and approximate string matching) Prof. Dr. Th. Ottmann.
Space-Efficient Sequence Alignment Space-Efficient Sequence Alignment Bioinformatics 202 University of California, San Diego Lecture Notes No. 7 Dr. Pavel.
CSE 311 Foundations of Computing I Lecture 15 Recursive Definitions and Structural Induction Autumn 2011 CSE 3111.
Sequence Analysis CSC 487/687 Introduction to computing for Bioinformatics.
We want to calculate the score for the yellow box. The final score that we fill in the yellow box will be the SUM of two other scores, we’ll call them.
1 Approximate Algorithms (chap. 35) Motivation: –Many problems are NP-complete, so unlikely find efficient algorithms –Three ways to get around: If input.
Sequence Comparison Algorithms Ellen Walker Bioinformatics Hiram College.
Design and Analysis of Algorithms - Chapter 71 Space-time tradeoffs For many problems some extra space really pays off: b extra space in tables (breathing.
1 Sequence Alignment Input: two sequences over the same alphabet Output: an alignment of the two sequences Example: u GCGCATGGATTGAGCGA u TGCGCCATTGATGACCA.
Intro to Alignment Algorithms: Global and Local Intro to Alignment Algorithms: Global and Local Algorithmic Functions of Computational Biology Professor.
A * Search A* (pronounced "A star") is a best first, graph search algorithm that finds the least-cost path from a given initial node to one goal node out.
An Efficient Index Structure for String Databases Tamer Kahveci Ambuj K. Singh Presented By Atul Ugalmugale/Nikita Rasam 1.
Sequence Comparison I519 Introduction to Bioinformatics, Fall 2012.
Dynamic Programming & Memoization. When to use? Problem has a recursive formulation Solutions are “ordered” –Earlier vs. later recursions.
Dynamic Programming (Edit Distance). Edit Distance Input: – Two input strings S1 (of size n) and S2 (of size m) E.g., S1 = ATTTCTAGTGGGTAAA S2 = ATCTAGTTTAGGGATA.
= the matrix for T relative to the standard basis is a basis for R 2. B is the matrix for T relative to To find B, complete:
TU/e Algorithms (2IL15) – Lecture 4 1 DYNAMIC PROGRAMMING II
Core String Edits, Alignments, and Dynamic Programming.
Dynamic Programming for the Edit Distance Problem.
A Concurrent Matrix Transpose Algorithm Pourya Jafari.
CS502: Algorithms in Computational Biology
Text Search ~ k A R B n f u j ! k e
@#? Text Search g ~ A R B n f u j u q e ! 4 k ] { u "!"
Approximate Algorithms (chap. 35)
Bioinformatics: The pair-wise alignment problem
Distance Functions for Sequence Data and Time Series
Static Dictionaries Collection of items. Each item is a pair.
Fast Fourier Transform
Distance Functions for Sequence Data and Time Series
CSCE 411 Design and Analysis of Algorithms
Sequence Alignment Using Dynamic Programming
Sequence Alignment 11/24/2018.
Dynamic Programming 2 Neil Tang 4/22/2010
Computational Biology Lecture #6: Matching and Alignment
String matching.
Computational Biology Lecture #6: Matching and Alignment
Intro to Alignment Algorithms: Global and Local
Dynamic Programming Computation of Edit Distance
Cyclic string-to-string correction
Approximate Matching of Run-Length Compressed Strings
Lecture 8. Paradigm #6 Dynamic Programming
Dynamic Programming-- Longest Common Subsequence
Dynamic Programming 2 Neil Tang 4/22/2008
Bioinformatics Algorithms and Data Structures
2019/5/14 New Shift table Algorithm For Multiple Variable Length String Pattern Matching Author: Punit Kanuga Presenter: Yi-Hsien Wu Conference: 2015.
Linear space LCS algorithm
15-826: Multimedia Databases and Data Mining
Presentation transcript:

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 6 17 1 x=abbacbbbababacabbabba Character Mismatch Gap

Edit distance d(abab,acc) = 3: abab -> aba -> aca -> acc 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 { i j 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-1] c[i-1,j] c[i,j-1] c[i,j] {

{ Example c[0,0] = 0 for i=1..|x|: c[i,0] = i for j=1..|p|: c[0,j] = j c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d(x[i],y[j]) { a b a a c b c c 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 a b c

{ Example 0+0 1+1 1+1 0 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]) { a b a a c b c c 0+0 1+1 1+1 0 0 1 2 3 4 5 6 7 8 1 0 2 3 4 5 6 a b c

{ Example 1+1 2+1 0+1 1 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]) { a b a a c b c c 1+1 2+1 0+1 1 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 a b c

{ Example 2+0 3+1 1+1 2 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]) { a b a a c b c c 2+0 3+1 1+1 2 0 1 2 3 4 5 6 7 8 1 0 1 2 2 3 4 5 6 a b c

{ Example 3+0 4+1 2+1 3 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]) { a b a a c b c c 3+0 4+1 2+1 3 0 1 2 3 4 5 6 7 8 1 0 1 2 3 2 3 4 5 6 a b c

{ Example 4+1 5+1 3+1 4 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]) { a b a a c b c c 4+1 5+1 3+1 4 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 2 3 4 5 6 a b c

{ Example 5+1 6+1 4+1 5 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]) { a b a a c b c c 5+1 6+1 4+1 5 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 2 3 4 5 6 a b c

{ Example 6+1 7+1 5+1 6 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]) { a b a a c b c c 6+1 7+1 5+1 6 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 2 3 4 5 6 a b c

{ Example 7+1 8+1 6+1 7 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]) { a b a a c b c c 7+1 8+1 6+1 7 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 3 4 5 6 a b c

{ Example 1+1 0+1 2+1 1 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]) { a b a a c b c c 1+1 0+1 2+1 1 0 1 2 3 4 5 6 7 8 1 0 1 2 3 4 5 6 7 2 1 3 4 5 6 a b c

{ Example 0+0 1+1 1+1 0 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]) { a b a a c b c c 0+0 1+1 1+1 0 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 a b c

{ Example 1+1 2+1 0+1 1 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]) { a b a a c b c c 1+1 2+1 0+1 1 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 a b c

{ Example 2+1 3+1 1+1 2 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]) { a b a a c b c c 2+1 3+1 1+1 2 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 a b c

{ Example 3+1 4+1 2+1 3 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]) { a b a a c b c c 3+1 4+1 2+1 3 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 a b c

{ Example 4+0 5+1 3+1 4 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]) { a b a a c b c c 4+0 5+1 3+1 4 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 a b c

{ Example 5+1 6+1 4+1 5 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]) { a b a a c b c c 5+1 6+1 4+1 5 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 a b c

{ Example c[0,0] = 0 for i=1..|x|: c[i,0] = i for j=1..|p|: c[0,j] = j c[i-1,j] + 1 c[i,j] = min c[i,j-1] + 1 c[i-1,j-1] + d(x[i],y[j]) { a b a a c b c c 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 a b c

Dynamic programming algorithm After filling out c, d(x,y)=c[|x|,|y|] Time and space complexity: O(|x||y|)

Approximate pattern matching Edit distance pattern matching Edit distance c[i,j] = d(x[1..i],y[1..j]) c[i,j] = mini'≤i d(x[i'..i],y[1..j]) j=0 1 2 3 4 5 j=0 1 2 3 4 5 i= 1 2 3 4 5 6 7 8 9 10 11 12 13 i= 1 2 3 4 5 6 7 8 9 10 11 12 13 i' i i j j

Approximate pattern matching Use table c[i,j] = mini'≤id(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]) Makes it free to start at any index i' {

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: becomes: 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: si-1[q-1, j] si[q,j] = & si [q-1,j-1] si-1[q-1,j-1] & (si-1[q,j-1] | t[x[i],j]) { {

{ Wu-Manber The expression: can be computed as: si-1[q-1, j] si[q,j] = & si [q-1,j-1] si-1[q-1,j-1] & (si-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] = si-1[q-1, j] s2 = s[q-1] >> 1 // s2[j] = si [q-1,j-1] s3 = s1 >> 1 // s3[j] = si-1[q-1,j-1] s4 = old[q] >> 1 // s4[j] = si-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 p=bbba 01234 s0[0]: 01111 s0[1]: 01111 i=0 x=bbacbbbababacabbbba p=bbba 01234 s0[0]: 01111 s0[1]: 01111 s0[2]: 01111

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 = 00111 | 00001 s0[1]: 01111 s1[1]: s0[2]: 01111 s1[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 0 edit distance match i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 = 00111 | 00001 s0[1]: 01111 s1[1]: s0[2]: 01111 s1[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba Not 0 edit distance match i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 = 00111 | 00001 s0[1]: 01111 s1[1]: s0[2]: 01111 s1[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 s0[1]: 01111 s1[1]: 00011 = 01111 & 00011 s0[2]: 01111 s1[2]: & 00111 & (00111|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 1 edit distance match i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 s0[1]: 01111 s1[1]: 00011 = 01111 & 00011 s0[2]: 01111 s1[2]: & 00111 & (00111|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba Not 1 edit distance match i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 s0[1]: 01111 s1[1]: 00011 = 01111 & 00011 s0[2]: 01111 s1[2]: & 00111 & (00111|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 s0[1]: 01111 s1[1]: 00011 s0[2]: 01111 s1[2]: 00001 = 01111 & 00001 & 00111 & (00111|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 2 edit distance match i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 s0[1]: 01111 s1[1]: 00011 s0[2]: 01111 s1[2]: 00001 = 01111 & 00001 & 00111 & (00111|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba Not 2 edit distance match i=1 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s0[0]: 01111 s1[0]: 00111 s0[1]: 01111 s1[1]: 00011 s0[2]: 01111 s1[2]: 00001 = 01111 & 00001 & 00111 & (00111|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 = 00011 | 00001 s1[1]: 00011 s2[1]: s1[2]: 00001 s2[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 0 edit distance match i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 = 00011 | 00001 s1[1]: 00011 s2[1]: s1[2]: 00001 s2[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba Not 0 edit distance match i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 = 00011 | 00001 s1[1]: 00011 s2[1]: s1[2]: 00001 s2[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 s1[1]: 00011 s2[1]: 00001 = 00111 & 00001 s1[2]: 00001 s2[2]: & 00011 & (00001|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 1 edit distance match i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 s1[1]: 00011 s2[1]: 00001 = 00111 & 00001 s1[2]: 00001 s2[2]: & 00011 & (00001|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba Not 1 edit distance match i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 s1[1]: 00011 s2[1]: 00001 = 00111 & 00001 s1[2]: 00001 s2[2]: & 00011 & (00001|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 s1[1]: 00011 s2[1]: 00001 s1[2]: 00001 s2[2]: 00000 = 00011 & 00000 & 00001 & (00000|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 2 edit distance match i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s1[0]: 00111 s2[0]: 00011 s1[1]: 00011 s2[1]: 00001 s1[2]: 00001 s2[2]: 00000 = 00011 & 00000 & 00001 & (00000|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 2 edit distance match i=2 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 2-distance match 01234 01234 s1[0]: 00111 s2[0]: 00011 s1[1]: 00011 s2[1]: 00001 s1[2]: 00001 s2[2]: 00000 = 00011 & 00000 & 00001 & (00000|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=3 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s2[0]: 00011 s3[0]: 01111 = 00001 | 01110 s2[1]: 00001 s3[1]: s2[2]: 00000 s3[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba Not 0 edit distance match i=3 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s2[0]: 00011 s3[0]: 01111 = 00001 | 01110 s2[1]: 00001 s3[1]: s2[2]: 00000 s3[2]:

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=3 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s2[0]: 00011 s3[0]: 01111 s2[1]: 00001 s3[1]: 00000 = 00001 & 00111 s2[2]: 00000 s3[2]: & 00000 & (00000|01110)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba i=3 1 edit distance match x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s2[0]: 00011 s3[0]: 01111 s2[1]: 00001 s3[1]: 00000 = 00001 & 00111 s2[2]: 00000 s3[2]: & 00000 & (00000|01110)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba 01234 01234 i=3 x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s2[0]: 00011 s3[0]: 01111 s2[1]: 00001 s3[1]: 00000 s2[2]: 00000 s3[2]: 00000 = 00001 & 00000 & 00000 & (00000|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba i=3 2 edit distance match x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 01234 01234 s2[0]: 00011 s3[0]: 01111 s2[1]: 00001 s3[1]: 00000 s2[2]: 00000 s3[2]: 00000 = 00001 & 00000 & 00000 & (00000|00001)

Example x=bbacbbbababacabbbba p=bbba p=bbba p=bbba p=bbba i=3 2 edit distance match x=bbacbbbababacabbbba p=bbba 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=bbba p=bbba p=bbba 2-distance match 01234 01234 s2[0]: 00011 s3[0]: 01111 s2[1]: 00001 s3[1]: 00000 s2[2]: 00000 s3[2]: 00000 = 00001 & 00000 & 00000 & (00000|00001)

Exercise: Complete the example...