Lecture 5 - BM Flashcards

1
Q

What does BM stand for?

A

Boyer Moore (algorithm)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does BM perform compared to KMP and brute force?

A

It is almost always faster than both.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Are all characters in the text checked at BM?

A

No, most are skipped.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In what direction is the string scanned?

A

right to left (reverse of the other 2 methods)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is used to decide the next comparison?

A

the text character involved in the mismatch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Does BM include any preprocessing?

A

Yes, we need to record the position of the last occurrence of each character c in the alphabet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

While preprocessing what happens if a certain alpha character doesn’t xist in the string?

A

-1 is entered

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How big is our BM array?

A

big enough to fit the whole alphabet and other character, the array is indexed by the ascii value (128)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What version of BM will we look at in this course?

A

Boyer Moore Horspool algorithm , it is the simplified version of BM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How big is the ASCII character set?

A

128 chars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens upon a mismatch in BM?

A

We have to slide s along to align last occurance with the mismatched character. If s moves in the incorrect direction we instead move s once position to the right. If occurance doesn’t exist we slide string -> align with the next on the left

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How many mismatch cases is there in Bm?

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is case 1 in BM?

A

There is a mismatch and last occurence exists to the left (yet to check ). In this case:

  • slide string to match last occurence with current i (this means i + (m-1) - last occurence index)
  • j becomes m-1 (last character of the string as we essentially restart search from right to left)
  • sp becomes sp + j - last occurence (the amount pattern has been shifted)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is case 2 in BM?

A

There is a mismatch and last occurence exists to the right (been checked). In this case:

“we move string along by one place to the right and restart from the end”

  • the new value of i is i + (m-1) - (j-1)
  • the new value of j is m-1
  • sp becomes sp+1 (as shifted by 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is case 3 in BM?

A

When there is a mismatch and the character doesn’t appear.

  • i = i + m, shift by the length of the whole string
  • j = m-1 (end of string - absolute restart)
  • sp = sp + j + 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where to see all cases?

A

check slide 182

16
Q

Why can’t last occurrence equal to our char at j?

A

Since there is a mismatch between char in text and char in string , so this can’t be equal to char at j.

17
Q

What is the complexity of BM?

A

O(mn)

18
Q

Why is the complexity O(mn)?

A

As we need at most m char comparisons at every n - (m+1) positions in text (never retract)

19
Q

Is there a better version than O(mn)?

A

Yes, a linear one O(m+n), but we do not go over this in the course.