We present randomized algorithms to solve the following string-matching problem and some of its generalizations: Given a string X of length n (the pattern) and a string Y (the text), find the first occurrence of X as a consecutive block within Y. The algorithms represent strings of length n by much shorter strings called fingerprints, and achieve their efficiency by manipulating fingerprints instead of longer strings. The algorithms require a constant number of storage locations, and essentially run in real time. They are conceptually simple and easy to implement. The method readily generalizes to higher-dimensional patternmatching problems. Text-processing systems must allow their users to search for a given character string within a body of text. Database systems must be capable of searching for records with stated values in specified fields. Such problems are instances of the following string-matching problem: For a specified set ((X(i), Y(i))) of pairs of strings, determine, if possible, an r such that X(r) = Y(r). Usually the set is specified not by explicit enumeration of the pairs, but rather by a rule for computing the pairs (X(i), Y(i)) from some given data. We present a randomized algorithm to solve this problem. The algorithm associates with each string X a fingerprint I#@' ) which is much shorter than the string itself. The search for a match then compares short fingerprints instead of long strings. The algorithm selects thejngerprint function & at random from a family of easy-to-compute functions. No matter which input ((X(i), Y(i))) is presented, the algorithm is unlikely to produce a false match, in which two fingerprints agree even though the original strings do not. The most widely studied pattern-matching problem is the following: Given a pattern X of length n and a text Y of length m 2 n, find the first occurrence of X as a consecutive substring of Y. Several linear time algorithms have been given for this problem. have found a realtime algorithm using a constant number of registers. Our method, based on fingerprint functions, runs essentially in real time; the exact meaning of this statement is spelled out in Theorem 4. It requires a constant number of registers and needs a substring of length n of the text in main memory. One version, described by Algorithm 3, runs strictly in real time but allows a provably minuscule probability of error. produce the same theoretical time bounds as the deterministic algorithms and require a competitive or A considerable advantage of our algorithms is that they
One of the first algorithms was the Karp-Rabin algorithm REF which was used for string matching problems and it is based on modular arithmetic for hashing.
Efficient randomized pattern-matching algorithms
IBM J. Res. Dev.
IBM J. Res. Dev.
Computer Science