0% found this document useful (0 votes)
26 views3 pages

Bad Character Rule

The document discusses the Boyer-Moore string matching algorithm and provides an example of how it works compared to the naive algorithm. It shows how the Boyer-Moore algorithm reduces the number of character comparisons needed to find a match by leveraging information about the suffix of the pattern. It also presents examples of operator precedence and associativity in expressions.

Uploaded by

bishoy akmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Bad Character Rule

The document discusses the Boyer-Moore string matching algorithm and provides an example of how it works compared to the naive algorithm. It shows how the Boyer-Moore algorithm reduces the number of character comparisons needed to find a match by leveraging information about the suffix of the pattern. It also presents examples of operator precedence and associativity in expressions.

Uploaded by

bishoy akmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy