Rabin-Karp Algorithm
Rabin-Karp hashes the pattern and each window of the text. A rolling hash updates the window hash in constant time. Equal hashes still need a character check.
Costs
| Category | Algorithm |
| Difficulty | Hard |
| Average | O(n + m) |
| Worst, many hash matches | O(n × m) |
| Useful for | searching several patterns at once |
Questions
What is Rabin-Karp Algorithm?
Rabin-Karp hashes the pattern and each window of the text. A rolling hash updates the window hash in constant time. Equal hashes still need a character check.
Where do I practice it?
DSA Master keeps challenges and progress on the phone. This page is the idea and the costs.