5

Please help me to understand Boyer-Moore string search algorithm's "Good Suffix Shift"-Table.

What has happened when i==3?

There is no sub-string "_MAN" in the pattern. So the shift value should be 8 (as it was when i==1).

Why is it 6?

user366312
  • 16,949
  • 65
  • 235
  • 452

1 Answers1

6

There is no sub-string "_MAN", but the string does start with "AN", so if you shift over by 6 you could get a pattern that matches as follows

_ M A N _ _ _ _ _ _
_ _ A N P A N M A N
murgatroid99
  • 19,007
  • 10
  • 60
  • 95
  • So the calculation becomes recursive isn't it? That is searching a substring within a substring. – user366312 Jun 24 '11 at 19:47
  • This is what the preprocessing part of the algorithm does: because the string starts and ends with the same two letters, if you get a bad match then you can shift over by 6 characters and potentially have another match. – murgatroid99 Jun 24 '11 at 19:51