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…

How Manacher mirrors palindrome radii

Short answer: Manacher’s algorithm finds every palindromic substring’s radius, and in particular the longest one, in O(n) time. It transforms the string so odd and even lengths share one code path, then fills a radius array. A window around the rightmost palindrome found so far mirrors radii across its…