214 review 1 - university of windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf ·...

23
214 Review 1 U Windsor January 31, 2017

Upload: others

Post on 05-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

214 Review 1

U Windsor

January 31, 2017

Page 2: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Given a grammar that contains the following production rule,where A is a nonterminal and a and b are terminals:

A→ aAa|abba (1)

According to Chomsky hierarchy, the grammar is in which level?

Page 3: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Given the following rules of a grammar, where A and B arenon-terminals, a and b are terminals, and A is the start symbol:

A→ aB|bB (2)

B → a|b (3)

write the corresponding regular expression

A tricky question

Given the following grammar, what is the language beingrecognized?

A→ aB|bB (4)

B → aB|bB (5)

is there a corresponding regular expression?

Page 4: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

is the following true?

I

(0|1)∗ = ((1|0)∗)∗

I

(01) ∗ 0 = 0(10)∗

Page 5: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

is the following true?

I

(0|1)∗ = ((1|0)∗)∗

I

(01) ∗ 0 = 0(10)∗

Page 6: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

I Given the regular expression (ab)*. Write the correspondingregular grammar. Note that you will not get any marks if thegrammar is not regular.

I Some incorrect answers

A→ abA|ε

A→ BA|εB → ab

I

Page 7: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

I Given the regular expression (ab)*. Write the correspondingregular grammar. Note that you will not get any marks if thegrammar is not regular.

I Some incorrect answers

A→ abA|ε

A→ BA|εB → ab

I

Page 8: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

I Given the regular expression (ab)*. Write the correspondingregular grammar. Note that you will not get any marks if thegrammar is not regular.

I Some incorrect answers

A→ abA|ε

A→ BA|εB → ab

I

Page 9: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write a regular expression

I for language over the alphabet 0, 1 in which all the stringscontain at least two 0’s.

I

(0|1) ∗ 0(0|1) ∗ 0(0|1)∗ (6)

I for email addresses

I for quoted string

I for identifiers in Assignment one

Page 10: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write a regular expression

I for language over the alphabet 0, 1 in which all the stringscontain at least two 0’s.

I

(0|1) ∗ 0(0|1) ∗ 0(0|1)∗ (6)

I for email addresses

I for quoted string

I for identifiers in Assignment one

Page 11: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write a regular expression

I for language over the alphabet 0, 1 in which all the stringscontain at least two 0’s.

I

(0|1) ∗ 0(0|1) ∗ 0(0|1)∗ (6)

I for email addresses

I for quoted string

I for identifiers in Assignment one

Page 12: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write a regular expression

I for language over the alphabet 0, 1 in which all the stringscontain at least two 0’s.

I

(0|1) ∗ 0(0|1) ∗ 0(0|1)∗ (6)

I for email addresses

I for quoted string

I for identifiers in Assignment one

Page 13: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write a regular expression

I for language over the alphabet 0, 1 in which all the stringscontain at least two 0’s.

I

(0|1) ∗ 0(0|1) ∗ 0(0|1)∗ (6)

I for email addresses

I for quoted string

I for identifiers in Assignment one

Page 14: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

I Write one advantage of NFA over DFA

I Write one advantage of DFA over NFA

Page 15: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

I Write one advantage of NFA over DFA

I Write one advantage of DFA over NFA

Page 16: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Find the shortest string that is not in the language represented bythe regular expression a*(ab)*b*.

ba

Page 17: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Find the shortest string that is not in the language represented bythe regular expression a*(ab)*b*. ba

Page 18: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write a context free grammar for the strings that consist of equalnumber of a’s followed by equal number of b’s.

A→ ab

A→ aAb

Page 19: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write a context free grammar for the strings that consist of equalnumber of a’s followed by equal number of b’s.

A→ ab

A→ aAb

Page 20: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write the corresponding regular expression

S1

S2

b

a

Page 21: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write the corresponding regular expression

S1

S2 S3

a

b

a

b

c

Page 22: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write the regular expressions you used in A12.java

Write A12.java.

Page 23: 214 Review 1 - University of Windsorjlu.myweb.cs.uwindsor.ca/214/214review1_2017.pdf · 2017-01-31 · Given the following rules of a grammar, where A and B are non-terminals, a and

Write the regular expressions you used in A12.javaWrite A12.java.