July 2015
Intermediate to advanced
380 pages
10h 15m
English
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 ...