5

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: enter image description here

Can anybody help me understand and explain the image's method for finding the shift table?

keelar
  • 5,814
  • 7
  • 40
  • 79
J-H
  • 1,795
  • 6
  • 22
  • 41
  • 2
    Could you provide more background behind your question? More specifically, [what have you tried](http://whathaveyoutried.com) and do you know the text being searched for in this example? – Nondeterministic narwhal Jul 11 '13 at 23:22
  • no the text being searched is not given in my example. The task is to calculate the shifttable by using this method for the word anabanana. the picture i posted is the solution proposal.If there is any other simple method to calculate the shift table i would use this too. So my question is : "how to calculate the shifttable for the use with boyer and moore without using a computer with a simple method" thx – J-H Jul 12 '13 at 06:41
  • where you found that example? Give me a link and maybe I can help you. – Sayakiss Jul 12 '13 at 09:29
  • I didn't find the image on the internet. its from a presentationsheet of my university :/ but i found a similar example on http://www.worldwardiary.com/history/Boyer-Moore_string_searching_algorithm at the second half of the page. After reading it a few times i still don't get it how it is done. :( im totally confused. Any idea how that is working? – J-H Jul 12 '13 at 12:18

1 Answers1

3

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 pattern p[] depicted is 9. Each row below I name p_i[] where i is the index on the right

Further 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)

for i=1 to m do
    search in the rows below for a subpattern where p[m-i]<>p_j[m-1] (*)
    and p[m-i+1, ..., m-1]=p_j[m-i+1, ..., m-1]
    index j is your shift value for shift[i]
od  

(*) 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 possible j.

example of assorted steps

I hope this helps, albeit a bit late.

marc
  • 264
  • 1
  • 2
  • 17
  • Hi, although i passed already my exam this is a good and extensive explanation. Thank you very much for your effort. – J-H Oct 18 '13 at 10:04
  • 1
    I had to do this for an exam myself at that time and your question was the best information I could get aside from my lecture notes, which were not too understandable. This seems not to be an easily teachable algorithm. Indeed I have to thank you: Explaining it helped me fully understand this algo myself. That exam went very well. – marc Jun 09 '14 at 19:17