I failed the whole evening to calculate a simple shift table for the search term "anabanana" for use in the Boyer and Moore pattern matching algorithm.
I found the following example without any explanations:
Can anybody help me understand and explain the image's method for finding the shift table?
I think I understand what is done here, so i'll try and explain.
The line "Wort" is the pattern you are analysing, there is (in my opinion) no need to consider the row "Text" above. Instead assume an additional row containing the zero-based position of the char within your pattern from left to right. The length
m
of the patternp[]
depicted is 9. Each row below I namep_i[]
where i is the index on the rightFurther explanation is based on 2:
In the lower rows beneath the pattern mark all characters matching the character in the pattern above. (Done here by crossing out)
(*) Note: When the shifted pattern
p_j
got shifted too far right, there will be empty chars to compare. In this case, you can always assume==
or<>
as needed. Always use the minimum of all possiblej
.I hope this helps, albeit a bit late.