Content deleted Content added
m →Rabin-Karp and multiple pattern search: Code-Layout |
→Rabin-Karp and multiple pattern search: improve wording, correct runtimes, remove "worst case" claim |
||
Line 57:
Rabin-Karp is inferior for single pattern searching to [[Knuth-Morris-Pratt algorithm]], [[Boyer-Moore string searching algorithm]] and other faster single pattern [[string searching algorithm]]s because of its slow worst case behavior. However, Rabin-Karp is an algorithm of choice for multiple pattern search.
That is, if we want to find any of a large number, say ''k'', fixed length patterns in a text, we can create a simple variant of Rabin-Karp that uses a [[hash table]] or any other [[set data structure]] to check whether the hash of a given string belongs to a set of hash values of patterns we are looking for:
'''function''' RabinKarpSet(''string'' s[1..n], ''set'' of ''string'' subs, m) {
Line 74:
Here we assume all the substrings have a fixed length ''m'', but this assumption can be eliminated. We simply compare the current hash value against the hash values of all the substrings simultaneously using a quick lookup in our set data structure, and then verify any match we find against all substrings with that hash value.
Other algorithms can search for a single pattern in
==References==
|