How Rabin-Karp rolls a hash across the text

Short answer: Rabin-Karp hashes the pattern and every window of the text. A polynomial rolling hash updates the next window in constant time: subtract the outgoing character, multiply by the radix, and add the incoming character, all modulo a prime. Equal hashes are candidates and must be verified character…