Question 1 (6 points) Give a regular expression for the language L1

advertisement
Question 1 (6 points)
Give a regular expression for the language L1 ⊆ {0, 1}∗ :
L1 = {w | w does not contain the substring 101}
1
Question 2 (3 + 4 = 7 points)
1. In each of the following cases, find a regular expression R that satisfies the
equation.
(a) L(R) = L(R∗ )
R=
(b) L(R) = L(aR ∪ b)
R=
(c) L(aR) = L(bR)
R=
2. For each of the following statements, where R1 and R2 are regular expressions,
indicate whether it is true (T) or false (F) by circling the appropriate letter.
(a) L((R1∗ )∗ ) = L(R1∗ )
(T
F)
(T
F)
(c) L(R1∗ (R1 ∪ R2 )∗ ) = L((R1 ∪ R2 )∗ )
(T
F)
(d) L((R1 ∪ R2 )∗ ) = L((R1∗ R2∗ )∗ )
(T
F)
∗
(b) L((R1 R2 ) ) =
L(R1∗ R2∗ )
2
Question 3 (6 points)
Draw the state diagram of an NFA that recognizes the language L3 :
L3 = {wxw R |w, x ∈ {a, b}+ }
3
Question 4 (4 + 3 = 7 points)
Consider the context-free grammar G4 = ({S, T, U}, {0, 1}, R, S), where R is defined
by the following rules.
S
T
U
−→
−→
−→
T U | 00U
0A | 0
1
1. Show that G4 is ambiguous by giving a string in L(G4 ) and drawing two different
parse trees for it.
2. Give an unambiguous grammar which is equivalent to G4 .
4
Question 5 (10 points)
Following the algorithm you leaned in class, draw the state diagram of a PDA which
is equivalent to the grammar G4 of Question 4.
5
Question 6 (4 + 2 = 6 points)
Consider the following CFG G6 .
S
A
T
−→ AT A
−→ aAbA | aAcA | bAaA | cAaA | T | ε
−→ bT | cT | b | c
1. Of the following strings, circle only those in L(G6 ).
(a) ε
(b) ababca
(c) abcca
(d) bcca
2. Give a simple verbal description of L(G6 ).
6
Question 7 (9 points)
Draw the state diagram of a pushdown automaton that recognizes the language L7
over the alphabet {a, b}:
L7 = {w | na (w) = nb (w) + 1}
where ns (w) is the number of occurrences of the symbol s ∈ {a, b} in the string w.
7
8
9
Download