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 ...
Get Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.