Overview
Rabin-Karp hashes the pattern and each same-length text window, then verifies characters when hashes match.
Searches for a pattern by comparing rolling hash values.
Compact metadata for implementation and discovery.
Rabin-Karp hashes the pattern and each same-length text window, then verifies characters when hashes match.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n + m)
Average
O(n + m)
Worst
O(nm)
Space
O(1)
hash_next = (base * (hash - old * base^(m - 1)) + new) mod primeUpdates the window hash after dropping one character and adding another.
Show a fixed-size text window moving while its hash updates.
Hash collisions require a character check before reporting a match.
What each reference supports for this entry.
String algorithms reference for Rabin-Karp's pattern matching, suffix indexing, alignment, or sequence-processing mechanism.
Open sourceTextbook support for Rabin-Karp's algorithm family, complexity framing, and standard implementation concepts.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Rabin-Karp uses rolling hashes rather than prefix automata.
Rabin-Karp uses rolling hashes for exact pattern search, while MinHash uses hashes for approximate set similarity.