• Please give details of your answer. A direct answer without explanation is not counted.
• Your answers must be in English.
• Please carefully read problem statements.
• During the exam you are not allowed to borrow others’ class notes.
• Try to work on easier questions first.
Problem 1 (5 pts)
Give the formal definition of the following NFA.
q1
start q2 q3 q4
0,1
1 0,1, 0,1,
Answer
The formal definition of the NFA is (Q, Σ, δ, q1, F ), where
• Q = {q1, q2, q3, q4},
• Σ = {0, 1},
• δ is given as
0 1
q1 {q1} {q1, q2} ∅ q2 {q3} {q3} {q3} q3 {q4} {q4} {q4}
q4 ∅ ∅ ∅
,
• q1 is the start state, and
• F = {q4}.
Common Mistakes
• Σ 6= {0, 1, }
• start state is q1 (not {q1}).
• elements in δ should be sets (not states).
Problem 2 (20 pts)
Use the procedure in section 1.2 of the textbook to convert the NFA in Problem 1 to DFA.
Simplify the obtained DFA to have only 4 states. (You need to first draw ALL possible states and then eliminate unnecessary states.)
Answer
∅
q2
q3 q4
q12
q13
q23 q24
q34 q123
q124 q234
q14 q134
q1234
q1
start
0,1
0 1
0,1
0,1 0,1
0
1
0 1
0 1
0,1 0,1 0,1 0
1 0
1 1
0
0,1 0
1
the simplified diagram:
q14
q134
q1234
q1
start 0
1 0
1 1
0
0
1
Problem 3 (20 pts)
Is the following language regular?
L = {ambn| m = kn, where k is positive integer } Explain your answer clearly.
Answer
No. Assume L is regular. By pumping lemma, there is a positive integer p ≥ 1 such that for all s ∈ L and |s| ≥ p, s = xyz satisfies the following conditions:
• |y| ≥ 1,
• |xy| ≤ p, and
• for all i ≥ 0, xyiz ∈ L.
Let s = apbp. Because p = 1p, s ∈ L. For i = 0, xy0z = a(p−|y|)bp, then p − |y| < kp for any positive integer k. We have proved xy0z /∈ L and got a contradiction, so the language L is not regular.
Common Mistakes
• Some of you choose s = a2pbp. However, for i = 0, |y| = p, xy0z = a2p−|y|bp = apbp ∈ L.
• When you choose a string s, you cannot sepcify x, y, or z there. For example, you cannot choose s to be x = , y = ap, z = bp and say that xy0z /∈ L.
Problem 4 (20 pts)
Is the following language regular?
L = {ambn | m + n is prime}
Explain your answer clearly.
Answer
No. Assume L is regular. By pumping lemma, there is a positive integer p ≥ 1 such that for all s ∈ L and |s| ≥ p, s = xyz satisfies the following conditions:
• |y| ≥ 1,
• |xy| ≤ p, and
• for all i ≥ 0, xyiz ∈ L.
Let s = apbq, where q is the smallest positive integer so that p + q is prime. Choose y = at for t ≥ 1, then xyiz = ap−t+itbq = ap+(i−1)tbq. Select i = p + q + 1, xyp+q+1z = ap+(p+q)tbq, then (p + (p + q)t) + q = (p + q)(t + 1) is not prime. We have proved xyp+q+1z /∈ L and got a contradiction. L is not regular.
Problem 5 (25 pts)
Consider the following language
A = {}, where the alphabet Σ = {0}.
1. Give a 1-state NFA to recognize this language (diagram and formal definition).
2. Give a 2-state NFA to recognize this language (diagram and formal definition).
3. Convert the 2-state NFA to DFA using the procedure in section 1.2 of the textbook. (You need to first draw ALL possible states and then simplify it to a 2-state DFA.)
4. Convert the DFA to GNFA and follow the procedure in section 1.3 of the textbook to obtain the corresponding regular expression.
5. Consider the DFA of subproblem 3. Is the 2-state DFA unique? Why? If you use 3 states to recognize the language, is there an unique DFA? Why?
Answer
1.
q1 start
The formal definition of the NFA is (Q, Σ, δ, q1, F ), where
• Q = {q1},
• Σ = {0},
• δ is given as
0 q1 ∅ ∅
,
• q1 is the start state, and
• F = {q1}.
2.
q1
start q2
0 0
The formal definition of the NFA is (Q, Σ, δ, q1, F ), where
• Q = {q1, q2},
• Σ = {0},
0 q1 {q2} ∅ q2 {q2} ∅
,
• q1 is the start state, and
• F = {q1}.
3.
q1
start q2 q12 q∅
0 0
0
0
the simplified diagram:
q1
start q2
0 0
4.
• add qs and qa:
qs
start q1
qa
q2
0 0
• remove q2:
qs
start q1
qa
• remove q1:
qs
start qa
The regular expression is .
5.
Yes. The DFA must accept at first state. For the alphabet Σ = {0}, it requires another state for transition. The 2-state DFA is unique.
No. The one more state can offer another state for transition or be unconnected.
q1
start q2 q3
0
0 0
q1
start 0 q2 q3
0
0
q1
start q2 q3
0 0
0
The 3-state DFA is not unique.
Problem 6 (10 pts)
Give a counterexample to show that the following construction fails to prove the closure of the class of regular languages under the star operation. Let N1 = (Q1, Σ, δ1, q1, F1) recognize A1, where Σ = {0, 1}. Construct N = (Q1, Σ, δ, q1, F ) as follows. N is supposed to recognize A∗1.
• The states of N are the states of N1.
• F = {q1} ∪ F1.
The accept states F are the old accept states plus its start state.
• Define δ so that for any q ∈ Q and any a ∈ Σ ∪ {},
δ(q, a) =
(δ1(q, a) q /∈ F1 or a 6= δ1(q, a) ∪ {q1} q ∈ F1 and a = .
The counterexample must be a NFA diagram with the smallest number of states, and explain your counterexample clearly.
Answer
Here is a counterexample: A1 = ∅ and N1 =
q1 start
0
Then N =
q1 start
0
N accepts 0, but 0 /∈ A∗1. Therefore, N does not recognize A∗1.
Common Mistakes
• One state is enough.
• Your NFA should recognize your langauge.