AA-VIZ
/
Rabin-Karp
Interactive visualizations for Chapter 1 of the Advanced Algorithms notes
Rabin-Karp — Rolling Hash Search
Step through the Rabin-Karp algorithm. At each window position, the fingerprint (hash mod q) of the current window is compared against the pattern’s fingerprint:
- Orange window = no hash match → skip instantly
- Purple window = hash hit → must verify character-by-character
- Green window = verified true match
- Red window = spurious hit (hash matched but characters differ)
Try small values of q (e.g. 3, 5) to see spurious hits in action.
Effect of q on Spurious Hits
The bar chart below compares four values of q on the same input. Small q → many spurious hits (red bars). Large prime q → almost none.