Hard

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

CategoryAlgorithm
DifficultyHard
AverageO(n + m)
Worst, many hash matchesO(n × m)
Useful forsearching 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.