News for hackers. Stuff that matters.
Re:Why GNU grep is fast (2010) by yelnatz on Thursday November 28, 2013 @11:41AM (#6815231)
I'm actually more familiar with the KMP algorithm than BM. So I looked it up to see what the difference was:

The classic Boyer-Moore algorithm suffers from the phenomenon that it tends not to work so efficiently on small alphabets like DNA.

The skip distance tends to stop growing with the pattern length because substrings re-occur frequently.

By remembering more of what has already been matched, one can get larger skips through the text.

One can even arrange 'perfect memory' and thus look at each character at most once, whereas the Boyer-Moore algorithm, while linear, may inspect a character from the text multiple times.

1: http://stackoverflow.com/questions/12656160/what-are-the-mai...

Re:Why GNU grep is fast (2010) by ahelwer on Thursday November 28, 2013 @02:11PM (#6815965)
You would inspect characters multiple times only in a very naive implementation of Boyer-Moore. The Galil Rule[0] fixes this and is also required for proving linear worst-case runtime.

[0] https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_sea...

Re:Why GNU grep is fast (2010) by lubomir on Thursday November 28, 2013 @03:54PM (#6816398)
This page [1] nicely demonstrates differences between KMP and BM.

[1]: http://www.cs.utexas.edu/users/moore/best-ideas/string-searc...

Re:Why GNU grep is fast (2010) by mtdewcmu on Thursday November 28, 2013 @04:53PM (#6816651)
I have a book called Flexible Pattern Matching in Strings[1], which covers all the algorithms that might go into a modern, state-of-the-art grep, with practical advice on performance (N.B.: Boyer-Moore is no longer state-of-the-art). The publication year is 2002.

[1] http://www.dcc.uchile.cl/~gnavarro/FPMbook/

Re:Why GNU grep is fast (2010) by tetha on Thursday November 28, 2013 @04:56PM (#6816662)
Couldn't you speed up a small-alphabet search by considering pairs or triplets of characters so you have N^2 or N^3 glyphs instead of N characters (so, going from 4 characters to 16 cgaracters to 64 characters)?
Re:Why GNU grep is fast (2010) by mtdewcmu on Friday November 29, 2013 @10:53PM (#6822202)
I'm not sure exactly how your proposal might work, but, generally, the problem you would run into is that the group of characters can be shifted. So you'd end up having to compare every possible shift.