920 likes | 1.03k Views
Permuted Scaled Matching. Ayelet Butman Noa Lewenstein Ian Munro. Scale d matching. Input: Text T=t 1 ,…,t n Pattern P=p 1 ,…,p m Scaling: P [ i ] =p 1 …p 1 p 2 …p 2 … p m …p m Output: All text-locations j where i s.t. p [ i ] matches at j. . i. i. i. Scaled matching.
E N D
Permuted Scaled Matching AyeletButman Noa Lewenstein Ian Munro
Scaled matching Input: Text T=t1,…,tn Pattern P=p1,…,pm Scaling: P[i]=p1…p1p2…p2 … pm…pm Output: All text-locations j where is.t. p[i] matches at j. i i i
Scaled matching c b a a a c c a a a b b a a b a a b b b c c a c a b b
Permutation matching Input: Text T=t1,…,tn Pattern P=p1,…,pm Permutation (of pattern): pπ(1)pπ(2)…pπ(m) where π is a permutation on [m]. Output: All text-locations j where a pattern permutation occurs.
Permutation matching b c b a a b a a c b b a b b a a c b c a b b
Permutation matching b a b a c b a a c b b a b b a a c b c a b b
Permutation matching • Easy to solve in O(n) time (linear size alphabets). • The pattern matching version of Jumbled Indexing.
Scaled permutation matching • Match: First Permutation and then Scaling.
Scaled permutation matching c b a a c b b c a a a a a a b c c a b a b b a c a b b
Scaled permutation matching • Match: First Permutation and then Scaling. • B-Eres-Landau[04]: Scaled Permutation Matching in O(n) time. • Open: Can one do the reverse efficiently, i.e. scaling and then permutation. • Hard ? How can we solve? First - Naïve algorithm
Permuted scaled matching Input: Text T=t1,…,tn Pattern P=p1,…,pm Output: All text-locations j where exist permuted scaled matching
Permuted scaled matching c b a a a c c a a a b b a a b b a b b c a a c c a b b
Naïve algorithm P= c a a b T= c a b a a c b a c c a a b
Naïve algorithm P= c a a b k=1 T= c a b a a c b a c c a a b
Naïve algorithm P= c a a b k=2 T= c a b a a c b a c c a a b
Naïve algorithm • Construct a table R of size (n+1)×|Σ| such that R(i,j)=#σj(T[0, i]) for i ≥ 0 and R(−1, j) = 0. • For every 0 ≤ i < j ≤ n−1 such that j −i+ 1 = km for some natural number k ≥ 1 do: • Let r(l) =( R(j,l)−R(i−1,l))/#σl(P). • if r(l) = k for each l, 0 ≤ l ≤ |Σ| − 1, then announce that i is a k-scaled appearance.
Naïve algorithm P= c a a b T= c a b a a c b a c c a a b
Naïve algorithm T= c a b a a c b a c c a a b
Naïve algorithm T= c a b a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12
Naïve algorithm T= c a b a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a b c
Naïve algorithm T= c a b a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 b 0 c 0
Naïve algorithm T= c a b a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 b 0 0 c 0 1
Naïve algorithm T= c a b a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 b 0 0 0 c 0 1 1
Naïve algorithm T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 b 0 0 0 1 1 c 0 1 1 1
Naïve algorithm T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 b 0 0 0 1 1 1 c 0 1 1 1 1
Naïve algorithm T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 1 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 1 #a=2 #b=#c=1 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 1 #a=2 #b=#c=1 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 1 #a=2 #b=#c=1 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 1 #a=2 #b=#c=1 = = 1 = = 1 = = 1 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 1 #a=2 #b=#c=1 = = 1 = 0 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 2 #a=2 #b=#c=1 = = = 2 = = 2 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 2 #a=2 #b=#c=1 = = = 2 = = 2 T= c a b a a a c b a c c a a b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm P= c a a b K= 2 #a=2 #b=#c=1 T= c a b a a a c b a c c a a b = = = 2 = 2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 1 1 2 3 3 3 4 4 4 5 6 6 b 0 0 0 1 1 1 1 1 2 2 2 2 2 2 3 c 0 1 1 1 1 1 2 2 2 3 4 4 4 4
Naïve algorithm The running time is where .
Better? Properties • Mod-Equivalency: i and j are Mod-Equivalent if for every character σ (with frequency c in P): #σ in T[0,i] mod c = #σ in T[0,j] mod c • Equal-Quotients: i and j have equal-quotients for char’s a & b if:
Mod-equivalent • Mod-Equivalency: i and j are Mod-Equivalent if for every character σ (with frequency c in P): #σ in T[0,i] mod c = #σ in T[0,j] mod c
Mod-equivalent P= c a a b #a=2 #b=#c=1 T= c c b a a a c b a c c b c b -1 0 1 2 3 4 5 6 7. 8 9 10 11 12 a 0 0 0 0 1 2 2 2 3 3 3 3 3 3 b 0 0 0 1 1 1 1 1 2 2 2 2 3 3 4 c 0 1 2 2 2 2 3 3 3 4 5 5 6 6
Mod-equivalent P= c a a b #a=2 #b=#c=1 T= c c b a a a c b a c c b c b 3 11 a 1 3 b 1 3 c 2 6
Mod-equivalent P= c a a b #a=2 T= c c b a a a c b a c c b c b 3 11 a a 1 3 b 1 3 c 2 6
Mod-equivalent P= c a a b #a=2 T= c c b a a a c b a c c b c b 3 11 a a 1 3 b 1 3 c 2 6
Mod-equivalent P= c a a b #a=2 T= c c b a a a c b a c c b c b 3 11 a 1 3 b 1 3 c 2 6
Mod-equivalent P= c a a b #b=1 T= c c b a a a c b a c c b c b 3 11 a 1 3 b 1 3 c 2 6
Mod-equivalent P= c a a b #c=1 T= c c b a a a c b a c c b c b 3 11 a 1 3 b 1 3 c 2 6
Mod-equivalent P= c a a b T= c c b a a a c b a c c b c b 3 11 a 1 3 b 1 3 c 2 6
Mod-equivalent P= c a a b #a=2 T= c c b a a a c b a c c b c b -1 0 1 2 3 4 5 6 7 8 9 10 11 12 a 0 0 0 0 1 2 2 2 3 3 3 3 3 3 b 0 0 0 1 1 1 1 1 2 2 2 2 3 3 4 c 0 1 2 2 2 2 3 3 3 4 5 5 4 4
Mod-equivalent P= c a a b #a=2 T= c c b a a a c b a c c b c b 2 10 a 0 3 b 1 1 3 c 2 5
Mod-equivalent P= c a a b #a=2 T= c c b a a a c b a c c b c b 2 10 a 0 3 b 1 1 3 c 2 5