seminum - Seminumerical String Matching CMSC 701 Something...

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

View Full Document Right Arrow Icon
Seminumerical String Matching CMSC 701
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
Rabin-Karp (Following CLR Chapter 34)
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 .
Background image of page 4
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(
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

seminum - Seminumerical String Matching CMSC 701 Something...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online