Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C)
by Zed A. Shaw
Exercise 39. String Algorithms
In this exercise, I’m going to show you a supposedly faster string search algorithm, called binstr, and compare it to the one that exists in bstrlib.c. The documentation for binstr says that it uses a simple “brute force” string search to find the first instance. The one that I’ll implement will use the Boyer-Moore-Horspool (BMH) algorithm, which is supposed to be faster if you analyze the theoretical time. Assuming my implementation isn’t flawed, you’ll see that the practical time for BMH is much worse than the simple brute force of binstr.
The point of this exercise isn’t really to explain the algorithm, because it’s simple enough for you to read the “Boyer-Moore-Horspool algorithm” page on Wikipedia. The gist ...
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