Bad Character Rule

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Problem 1.

1: boyer moore bad character rule:


-----------------------------------------------------------

t=ABBABBCACCABABACBCCABAB
p=ABAB

Starting alignment using naive string search algorithm:

A)

ABBABBCACCABABACBCCABAB
ABAb Abab
Abab Abab
Abab ABAB // matched string found!!
ABAb
Abab
Abab
Abab
ABab

- 11 alignments
- 19 character comparison

Boyer-Moor Algorithm:
-----------------------------

B)

ABBABBCACCABABACBCCABAB
abaB
ABAB
abaB
abaB
ABAB

- 5 Alignments
- 11 character comparison

C)

ABBABBCACCABABACBCCABAB
abaB
ABAB // AB is a good suffix, skip 1 alignment
abaB
abaB
abaB
abaB
abaB
aBAB // AB is a good suffix, skip 1 alignment
ABAB //
- 8 Alignments
- 17 character comparison

D)

ABBABBCACCABABACBCCABAB
abaB // (i) no match ( bad character )
ABAB // (ii) Suffix rule skip 1 alignment
abaB // (iii) no such suffix, skip until the end of the pattern.
abaB // (i) no match ( bad character )
aBAB // (ii) Suffix rule skip 1 alignment
ABAB // matched string found

- 6 Alignments
- 14 character comparison

Problem 1.2:
----------------
a)

(-) ((*) (5) (((+) 5 ((*)(2) ((+)4 3))))) ((( (+) ((*)5 10) 3)))

b)

gcd (42 `div` 2) ( 30`mod`16)

Problem 1.3:
----------------
a)

precedence levels and the associativity :

+ 6, left
- 6, left
* 7, left
/ 7, left
^ 8, right
$ 0, right
&& 3, right
|| 2, right

b)

example of those operators are: ==, /=, <, <=, >, >=

so if for example we had an expression saying that


a == true && b == false

here the equality operator doesn't determine the associativity of the expression but the
AND logical operator determines it so the expression will be executed from the right to left because
the AND operator is right-associative.

You might also like