1 / 23

A simple fast hybrid pattern-matching algorithm

A simple fast hybrid pattern-matching algorithm. Authors : Frantisek Franek, Christopher G. Jennings , W. F. Smyth Publisher : Journal of Discrete Algorithms 2007 Present: Chung-Chan Wu Date: December 11, 2007. Department of Computer Science and Information Engineering

gordy
Download Presentation

A simple fast hybrid pattern-matching algorithm

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. A simple fast hybrid pattern-matching algorithm Authors: Frantisek Franek, Christopher G. Jennings , W. F. Smyth Publisher: Journal of Discrete Algorithms 2007 Present: Chung-Chan Wu Date:December 11, 2007 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C.

  2. Outline • Introduction • Algorithm Description • KMP (Knuth-Morris-Pratt) • Boyer-Moore • Sunday shift • The Hybrid Algorithm (FJS) • Extension • Experimental Results • Conclusions

  3. Introduction • This contribution resides in these categories: • In an effort to reduce processing time, we propose a mixture of Sunday’s variant of BM with KMP. • Our goal is to combine the best/average case advantages of Sunday’s algorithm (BMS) with the worst case guarantees of KMP • According to the experiments we have conducted, our new algorithm (FJS) is among the fastest in practice for the computation of all occurrences of a pattern p = p[1..m] in a text string x = x[1..n] on an alphabet Σ of size k.

  4. KMP (Knuth-Morris-Pratt) • Main Feature • Perform the comparisons from left to right • Space and time complexity:O(m) • Searching phase: O(m+n) • A pre-compute table called pi-table to compare backward. • The π value will avoid another immediate mismatch • the character of the prefix in the pattern must be different from the character comparing presently. • The best worst case running time in software algorithm.

  5. KMP (Knuth-Morris-Pratt) Input string: pattern:

  6. Boyer-Moore • Main Feature • Performs the comparisons from right to left • Preprocessing phase:O(m+δ) in Space and time complexity • Searching phase: O(mn) • A pre-compute table called delta_1 and delta_2. • Perform well in best / average case.

  7. If char is known not occur in pattern, then we know we need not consider the possibility of an occurrence of the pattern. BM - Observation 1 b does not occur in the pattern, use δ1 Input string: b u pattern: a u bad-character shift contains no b k m

  8. If the rightmost occurrence of char in pattern is δ1 characters from the right end of pattern, then we know we can slide pattern down δ1 positions without checking for matches. contains no b b BM - Observation 2 b occurs in the pattern, use δ1 Input string: b u pattern: a u bad-character shift k m

  9. The good-suffix shift consists in aligning the segment y[i+j+1 … j+m-1] = x[i+1 … m-1] with its rightmost occurrence in x that is preceded by a character different from x[i]. ~a u BM - Observation 3(a) u reoccurs in pattern preceded byc ≠ a, use δ2 Input string: b u pattern: a u good-suffix shift k m

  10. If there exists no such a segment, the shift consists in aligning the longest suffix v of y[i+j+1 … j+m-1] with a matching prefix of x. v BM - Observation 3(b) Only a suffixv of ureoccurs in pattern, use δ2 Input string: b u pattern: a u v good-suffix shift k m

  11. Boyer-Moore Example Input string: pattern:

  12. e e e x x x a a a m m m p p p l l l e e e Sunday Shift Boyer Moore Input string: prefix b p pattern: Sunday Shift s Input string: prefix b p pattern:

  13. i i’ pat pat j FJS Algorithm • Definitions • Search p = p[1..m] in x = x[1..n] • by shifting p from left to right along x. • position j = 1 of p is aligned with a position i ∈ 1..n − m + 1 in x • partial match: if a mismatch occurs at j >1, we say that a partial match has been determined with p[1..j − 1]. • i’ = i + m - j Input string: pattern: m

  14. FJS Algorithm • Strategy • Whenever no partial match of p with x[i..i + m − 1] has been found, • Sunday shifts are performed to determine the next position i’ at which x[ i’ ] = p[m]. When such an i has been found, KMP matching is then performed on p[1..m− 1] and x[i −m+ 1..i − 1]. • If a partial match of p with x has been found, KMP matching is continued on p[1..m]. • once a suitable i’ has been found, the first half of FJS just performs KMP matching in a different order: • position m of p is compared first, followed by 1, 2, . . . , m − 1

  15. FJS Algorithm • Pre-processing • Sunday’s arrayΔ = Δ[1..k], computable in O(m + k)time. • KMP arrayβ’ = β’[1..m+1], computable in O(m)time.

  16. FJS Algorithm Input string: pattern:

  17. Extension • The alphabet-based preprocessing arrays of BM-type algorithms are their most useful feature, but they can be a source of trouble as well. • The ASCII alphabet: • Text were usually of 8 bits or less. • The processing time can be regardless. • The natural language text: • Wide characters • DNA data: {A, T, C, G} is mapping into {00, 01, 10, 11}, the alphabets of size varying by powers of 2 from 2 to 64. • An example DNA : ACTG • The preprocessing time is a bottleneck.

  18. Environment

  19. Experiment – Frequency These patterns occur 3,366,899 times

  20. Experiment – Pattern Length

  21. Experiment – Alphabet Size

  22. Experiment – Pathological Cases

  23. Conclusion • We have tested FJS against four high-profile competitors (BMH, BMS, RC, TBM) over a range of contexts: • pattern frequency (C1), pattern length (C2), alphabet size (C3), and pathological cases (C4). • FJS was uniformly superior to its competitors, with an up to 10% advantage over BMS and RC • For FJS the pathological cases (C4) are those in which the KMP part is forced to execute on prefixes of patterns where KMP provides no advantage • we presented a hybrid exact pattern-matching algorithm, FJS, which combines the benefits of KMP and BMS. It requires O(m + k) time and space for preprocessing

More Related