StringSearching - String Search Boyer-Moore Algorithm...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
String Search Boyer-Moore Algorithm Pattern matching algorithm useful for non-repetitive sequences from large alphabets. Relies on a last function to determine by how much to shift. Letters are checked right-to-left. Demo: http://www.prism.gatech.edu/~jgirata3/boyermoore Pattern: RACECAR The last function is calculated by associating each letter with a number. The letters in the string receive the value of the right-most position of that letter. Letters not in the string receive a value of -1. So: R A C E C A R 0 1 2 3 4 5 6 Gives a last function: R: 6 A: 5 C: 4 E: 3 Everything else: -1 When searching through text, you start from right to left, and continue until a mismatch occurs. If a mismatch occurs, you move the string to the right by length(pattern) - last[‘letter that caused mismatch’] - 1 spaces. If you reach the end of the string without a mismatch, you return the found position of the string in the text. An example: Text: CACECARR ACDFGHIJKL RACECAR Pattern: RACECAR CACECARR ACDFGHIJKL RACECAR RACECAR
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Mismatch occurs between ‘C’ and ‘R’ so length(‘RACECAR’) = 7 last[‘C’] = 4 shift amount: 7 - 4 - 1 = 2 CACECARR ACDFGHIJKL RACECAR RACECAR Shift: 7 -(-1) - 1 = 7 CACECARR ACDFGHIJKL RACECAR RACECAR Shift: 7 -(-1) -1 = 7
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern