{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

seminum

# seminum - Seminumerical String Matching CMSC 701 Something...

This preview shows pages 1–6. Sign up to view the full content.

Seminumerical String Matching CMSC 701

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Something completely different... Semi-numerical string matching: Instead of focusing on comparing characters, think of string as a sequence of bits or numbers and use arithmetic operations to search for patterns. Two algorithms: Rabin-Karp Shift-And Both tend to be better for short patterns.
Rabin-Karp (Following CLR Chapter 34)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Characters as digits Assume = {0,...,9} Then a string can be thought of as the decimal representation of a number: In general, if | | = d , a string represents a number in base d. Let p = the number represented by query P. Let t s = the number represented by the | P | digits of T that start at position s . 427328 P occurs at position s of T p = t s .
t s = 10 ( t s -1 - 10 m -1 T [ s-1 ] ) + T [ s + m-1 ] Computing p and t s Use Horner’s rule to compute p in time O(| P |= m ): p = P [ m ] + 10( P [ m -1] + 10(P[ m -2] + ... + 10(P[2] + 10P[1])...) 427328 = ( 8 +10( 2 +10( 3 +10( 7 +10( 2 + 10 × 4 ))))) “Left shift” by 1 digit Example: remove high- order digit add next digit of T as the low- order digit t 0

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}