Professional Documents
Culture Documents
Bad Character Rule
Bad Character Rule
Bad Character Rule
t=ABBABBCACCABABACBCCABAB
p=ABAB
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)
Problem 1.3:
----------------
a)
+ 6, left
- 6, left
* 7, left
/ 7, left
^ 8, right
$ 0, right
&& 3, right
|| 2, right
b)
example of those operators are: ==, /=, <, <=, >, >=
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.