1 / 13

Witness Tables

Witness Tables. Tsvi Kopelowitz Modified by Orgad Keller. Patten Matching. Input: A (large) text and a (smaller) pattern . Output: All locations where pattern matches text, i.e. all locations where

raquel
Download Presentation

Witness Tables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Witness Tables Tsvi Kopelowitz Modified by Orgad Keller

  2. Patten Matching • Input: A (large) text and a (smaller) pattern . • Output: All locations where pattern matches text, i.e. all locations where • In the lecture you will see an algorithm using a Witness Table.

  3. Witness Tables • A witness table is an array W of size m • W[i]= • * if p1p2…pm-i+1= pipi+1…pm • k if p1p2…pk-i= pipi+1…pk-1 and pk pk-i+1 • Example:

  4. Example: P: * 7 8 3 8 6 5 2 W:

  5. Another Example

  6. Construction • Naïve: O(m2) • Idea: when calculating W[i], use W[1]…W[i-1] • Let W[k] be the maximum of {W[2], W[3],…,W[i-1]} • What is W[k] for i=5? i=10? i=12? i=18? • What is k for i=5? i=10? i=12? i=18?

  7. A Few Notes • W[1] isn’t interesting. • If i>1, and W[i]=*, then we can treat W[i] as being m+1.

  8. Construction • So we compared alignment 1 and alignment k, but we will also want to compare alignments k and i. We already compared these. We want to compare these. W[k] i i-k Also already compared these. k-1 i-k i-1

  9. Three (+1) Cases • Case 0 (?): i>W[k] • Compare from i. W[k] i k-1 i-1

  10. Three Cases • Case 1: W[i-k+1]+k-1<W[k] • We found the first mismatch. • W[i]=W[i-k+1]+k-1 iff W[i-k+1]+k-1<W[k] W[i] W[i-k+1] W[k] i W[i-k+1]+k-1 i-k k-1 i-k i-1

  11. Three Cases • Case 2: W[i-k+1]+k-1>W[k] • W[i]=W[k]! W[i-k+1] W[k] i i-k k-1 i-1

  12. ? ? = Three Cases We have already “scanned” the pattern till W[k] • Case 3: W[i-k+1]+k-1=W[k] • If W[i-k+1]+k-1=W[k] compare from W[k] • Total of O(m) construction time. W[k] W[i] W[i-k+1] i i-k ? k-1 i-1 ?

  13. Example: k W[i-k+1]+k-1=W[5-4+1]+4-1=W[2]+3=5<6 W[i-k+1]+k-1=W[6-4+1]+4-1=W[3]+3=6=6=W[k] W:

More Related