Académique Documents
Professionnel Documents
Culture Documents
ID #:
This is a Close Book examination. Only an A4 cheating sheet belonging to you is acceptable.
You can write your answers in English or Chinese.
Maximum Score
Problem 1 20 20
Problem 2 5 5
Problem 3 25 25
Problem 4 15 15
Problem 5 10 10
Problem 6 10 15
Problem 7 5 10
Problem 7 10 10
Total 100 100
1
1. (20 pts) Mark by T(=True) or F(=False) each of the following statements. You don’t need
to prove it.
Question Answer
(1) T
(2) T
(3) F
(4) T
S1 = (S1 ∪ S2 ) − S2 .
Sol:
If x is in S1 and x is in S2 , then x is not in (S1 ∪ S2 ) − S2 . Because of this, a necessary and
sufficient condition is that the two sets are disjoint.
3. (25 pts) Please give the answer to each of the following questions. You do not need to show
how to derive the answers. Besides, there is no partial credit for each question.
(1) Give a simple description of the language generated by the grammar with productions,
where Σ = {a, b}?
S → AaAaAaA,
A → aA|bA|λ.
(2) Find a grammar for the language L = {w : na (w) = nb (w) + 1}, where Σ = {a, b}.
(3) Find a grammar for the language L = {w : an bn−3 : n ≥ 3}, where Σ = {a, b}.
(4) Give a dfa for the language L = {ab5 wb2 : w ∈ {a, b}∗ }, where Σ = {a, b}.
(5) Construct an nfa with three states that accepts the language {ab, abc}∗ .
Sol:
(1) the grammar can generate any string w ∈ {a, b}∗ as long as na (w) ≥ 3.
2
(2)
S → aS1 |S1 S,
S1 → S1 S1 ,
S1 → λ,
S1 → aS1 b,
S1 → bS1 a
(3)
S → aaaA,
A → aAb|λ
(4)
(5)
(1) (5 pts) Which of the following strings aabbb, aaa, aba, aabbaba, abbb are accepted by the
nfa? (Note: you must select all the acceptable strings to get the credits)
(2) (10 pts) Please convert it into an equivalent dfa.
Sol:
3
Figure 1: An nfa used in Problem 4.
q1
0 1 0, 1
0 0
1
q0 q2 q4
0 1
1
q3
4
0, 1 0
q0 q2
{q1, q3} 0
1
1
0, 1
q4
Figure 4: The dfa with minimized states for the dfa in Figure 3.
5. (10 pts) Minimize the states in the dfa depicted in the following diagram.
Sol:
6. (10 pts)
Sol:
8. (10 pts) Prove that, if the states qa and qb are indistinguishable, and if qa and qc are distin-
guishable, then qb and qc must be distinguishable.
Sol: By contradiction. Assume that qb and qc are indistinguishable. Since qa and qb are
indistinguishable and indistinguishability is an equivalence relation, qa and qc must be indis-
tinguishable.