Skip to main content

Rabin-Karp Algorithm

Learn Rabin-Karp Algorithm (Strings, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Rabin-Karp: Hashing for Pattern Matching Rabin-Karp finds a pattern in a text by comparing hashes of each candidate window instead of characters, sliding the window with a rolling hash in O(1) per step. Average case O(n + m); relies on verifying real matches with a direct comparison to rule out hash collisions.

More lessons in Strings