Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Theory of Computing
Midterm Examination Solutions
ID: ___________
Page 1 of 6
29 October 2014
Ima
Sample
NAME
1234567890
ASU ID
You have one hour and 15 minutes to complete the exam. Do not open the exam until instructed to do so. No notes, texts,
computers, calculators, or communication devices are permitted. Write all answers on the examination paper itself. BUDGET
YOUR TIME WELL! SHOW ALL WORK!
Question 1
[10]
Question 2
[10]
Question 3
[10]
Question 4
[10]
Question 5
[10]
Total
[50]
I also do one more simplification: If a state q is not a final state, not the start state, has no transition to
itself, and either every incoming transition has label or every outgoing transition has label , then if we
rip this state out (using the GNFA reduction), the result is an NFA.
In this case the resulting NFA has no transitions.
CSE 355
Fall 2014 - Colbourn
State Symbol
S - start
A
B
C
D
E - final
Theory of Computing
Midterm Examination Solutions
B
B
D
1
A,S,C,E
ID: ___________
Page 2 of 6
(b)
[5 marks] Using your NFA, give a regular grammar that generates L. (For the purposes of
this question, in a regular grammar we are permitted to have rules of the form A bC, A b, A C,
and A , where A and C are variables and b is a terminal.)
From the table above:
S 1A | 1S | 1C | 1E
A 0B
B 0B | 1S
C 0D
D 1E
E
(because E is a final state)
Question 3 [10 marks] Consider the NFA with start state q0, final state q3,. and transition function
0
1
State Symbol
q0
{q0, q1}
{ q3}
q1
{q2}
q2
{q2}
{q2}
q3
{q3}
{ q2}
{ q2}
{ q2}
[5 marks] Using either the original NFA, or the DFA you produced in the (a) part, use the methods
described in class to produce a regular expression for L.
I am going to use the original NFA. First I need to turn it into a GNFA, which I do by adding a new
start state S and final state F:
0
1
State Symbol
S
{q
0}
q0
{q0, q1}
{ q3}
q1
{q2}
CSE 355
Fall 2014 - Colbourn
Theory of Computing
Midterm Examination Solutions
ID: ___________
Page 3 of 6
q2
{q2}
{q2}
q3
{q3}
{F}
Rip q2 simply deletes it because it has no outgoing transition. Then rip q1 deletes it because it has no
outgoing transition. Then rip q3 changes the entry for state q0 to state F to 1*. Then rip q0 changes the
entry for state S to state F to 0*1*. And this is the regular expression for L: 0*1*.
Question 4 [10 marks] The DFA M has start state q0, final state q2, and transition function
0
1
State Symbol
q0
q0
q2
q1
q2
q1
q2
q0
q1
Let L be the language recognized by M.
The DFA M has start state q0, final state q2, and transition function
0
1
State Symbol
q0
q1
q2
q1
q0
q0
q2
q1
q1
Let L be the language recognized by M.
(a) [5 marks] Using the methods developed in class, produce a DFA for L L.
I use the product construction, writing ij to represent state i of M and j of M.
00
01
02
10
11
12
20
21
22
State
Symbol
0
01
00
01
21
20
21
01
00
01
1
22
20
21
12
10
11
12
10
11
Final state is 22 (start state is 00).
(b) [5 marks] Show that there are
infinitely many strings in L but not in L,
(00)*01
infinitely many strings in L but not in L,
(00)*011
infinitely many strings in both L and L,
(00)*1
infinitely many strings in neither L nor L
(00)*11
To get these, use the DFA table in the (a) part. Note that 00 carries both machines from their start state
back to their start state, so you can add (00)* at the beginning of any string without changing the
outcome. Now 1 ends in state 22, 01 in state 20, 011 in state 12, and 11 in state 11.
Question 5 [10 marks] Let L be a language. For each string w in L, let |w| be the number of symbols in
w (or the length of w). Define a language N(L) 1* so that 1s N(L) if and only if there is a string w
L with |w| = s.
(a) [7 marks] Show that N(L) is regular whenever L is regular.
(L may not even have a 1 in its alphabet!) (A subset of a regular language need not be regular! Consider
that 0n1n 0*1*.) (You cannot use pumping to show that a language is regular!)
L is regular so it has a DFA (Q,,,q0,F). Ill make an NFA for N(L), (Q,{1},,q0,F) it has the same
states, same start state, same final states as the DFA. For every state q define (q,1) = {(q,a) : a in }.
Then my NFA accepts 1s exactly when there is any string of length s in L.
(b) [3 marks] Show that N(L) can be regular even when L is not regular.
Let L be the language of as and bs in which every string has at least as many as as bs. Then (as seen
in class) L is not regular. But N(L) = 1*, which is regular.