Part III: SOME NOVEL APPLICATIONS OF HASHING

CHAPTER 16

Karp-Rabin String Searching

16.1 OVERVIEW

Let y = (y0, y1, ···, yn−1) be string of characters of length |y equal to n from an alphabet x1D49C_EuclidMathOne_10n_000100.

A basic string search problem P is

Given: a string x = (x0, x1, ···, xm−1) of m characters from the alphabet x1D49C_EuclidMathOne_10n_000100

Determine: whether x is a substring of y = (y0, y1, ···, yn−1).

When x is (resp. is not) a substring of y, we write xy (resp. x x2288_MathematicalPi-Four_10n_000100 y). In the first case, extensions of the search problem P include the following:

P1. Find the first/last occurrence of x in y; the first/last index a such that xi = yi+a for 0 ≤ i < m, or

P2. The set of all occurrences of x in y.

Algorithm #1 below solves P by making m bit-comparisons of x in each of the nm possible substrings y[i,i+m) ≡ (yi, yi+1, ···, yi+m−1) for i = 0, 1, ···, nm.

Algorithm #1: P
for i = 0 to nm do
Set INDi = 1
for j = 0 to m − 1 do
c16ue001

An extensive literature including the paper by Knuth et al. [Knuth, Morris and Pratt 1977]. The performance issues include the solution’s running time (number of comparisons and arithmetic operations) and ...

Get Hashing in Computer Science: Fifty Years of Slicing and Dicing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.