I have been trying to understand shift rules in Boyer–Moore string search algorithm but haven\'t understood them. I read here on wikipedia but that is too complex ! >
There's a good visualization here.
(EDIT: There's also a very good explanation with both examples and an example of how to implement the preprocessing steps here.)
General rules:
What I've just described is the "bad character" rule. The "good suffix" rule gives another option for shifting; whichever shifts farther is the one you should take. It's entirely possible to implement the algorithm without the good suffix rule, but it will be less efficient once the indices are built up.
The good-suffix rule requires that you also know where to find each multi-character substring of the pattern. When you hit a mismatch (checking, as always, from right to left), the good-suffix shift moves the pattern to a point where the letters that did already match will do so again. Alternatively, if the part that matched is unique in the pattern, you know you can skip all the way past it, because if it didn't match when lined up with the sole occurrence, it can't possibly match when lined up with any other part of the pattern.
For example, let's consider the following situation:
I have two options here:
and I should take whichever one lets me shift farther.
If you're still confused, try asking a more specific question; it's hard to be clear when we don't know where you're stuck.