Handling Long Needles
Armed with our new, shiny implementation of the Rabin-Karp algorithm, we’re ready to tackle substring search for an alphabet of any size. This could include uppercase letters, lowercase letters, the numbers 0 through 9, punctuation marks, and various other characters. For our discussion, though, we’ll continue to use the 26 lowercase letters of the English alphabet.
But there’s a problem.
In our example, we had used a pretty short needle. After all, "cafe" only contains four characters. But it’s not uncommon to search for longer needles. If we’re searching a document for plagiarism, for example, we might use an entire sentence as a needle.
Now, say that our needle is the 28-character word "antidisestablishmentarianism" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access