Name Asu Id: CSE 355 Theory of Computing ID: - Spring 2012 - Colbourn Midterm # 1 Page 1 of 7 16 February 2012
Name Asu Id: CSE 355 Theory of Computing ID: - Spring 2012 - Colbourn Midterm # 1 Page 1 of 7 16 February 2012
Name Asu Id: CSE 355 Theory of Computing ID: - Spring 2012 - Colbourn Midterm # 1 Page 1 of 7 16 February 2012
Theory of Computing
Midterm # 1
ID: ___________
Page 1 of 7
16 February 2012
IMA SAMPLE
NAME
ASU ID
[13]
Question 2
[10]
Question 3
[8]
Question 4
[9]
Question 5
[10]
Total
[50]
Bonus question [1 mark]: What is the language *? It is {} (Note that * = .)
CSE 355
Spring 2012 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 2 of 7
I make every variable a state, and make the start state be the start variable and the final states be
every variable X for which X . Every production X aY makes a transition from X to Y
labeled a.
So I get an NFA with states Q={S,A,B,C,M,N,P}, start state S, final states {A,P}, = {0,1}, and
transition function defined by (S,0) = {A,M}, (A,0) = {A}, (A,1) = {B}, (B,0) = {C}, (C,0)
= {A}, (M,1) = {N}, (N,1) = {P}, (P,0) = {M}, (P,1) = {P}. When (X,a) is not defined
here, it is .
(It is probably easier to draw a transition graph, and most people did.)
(b) [5 marks] Using your answer to (a) and the algorithms developed in class, give a DFA for
L. (Describe briefly the steps that you follow.)
My DFA has states corresponding to sets of states of the NFA from the (a) part. For each set of
states that I encounter and each symbol in , I make a transition to the set of all states that the
NFA can get to by reading the specified symbol. I start with the state {S}. I determine whether a
state is final according to whether its set contains a final state of the NFA.
State of DFA
Transition on 0 to state
Transition on 1 to state
{S}
{A,M}
{A,M} final!
{A} final!
{B,N}
{B}
{C}
{P} final!
{M}
{N}
{A}
{A}
{C}
{C}
{A}
{M}
{B,N}
{B}
{P}
{P}
{N}
{P}
(c) [5 marks] Using your answer to (a) and the algorithms developed in class, give a regular
expression for L. (Describe briefly the steps that you follow.)
First I modify the NFA from (a) by giving it a single final state F. To do this, I add transitions
(A,) = {F} and (P,) = {F}; make F a final state; and make A and P non-final. Now I
repeatedly eliminate a non-start, non-final state by figuring out all the ways to enter and leave it
and making a transition labeled with the corresponding regular expression.
To start, eliminate B and the two transitions involving it, and add the transition (A,10) = {C}.
Then eliminate C, and replace the transition (A,0) = {A} by (A,0+100) = {A}.
Then eliminate N and the two transitions involving it, and add the transition (M,11) = {P}.
Then eliminate M and the three transitions involving it, add (S,011) ={P}, and replace (P,1) =
{P} by (P,1+011) = {P}.
Finally eliminate A and P to get a two-state NFA with (S,0(0+100)* + 011(1+011)*) = {F}.
Now read out the regular expression, 0(0+100)* + 011(1+011)*.
There are many reduction orders, and the answer can look different.
CSE 355
Spring 2012 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 3 of 7
CSE 355
Spring 2012 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 4 of 7
It is not enough to just say that one cannot make an NFA or DFA.
Question 4 [9 marks]
(a) [2 marks] Build a DFA to accept the language of strings over {a,b} that start and end
with an a.
I allow the case that there is only one letter, and then the first and the last letters are the
same.
State
Transition on input a to
Transition on input b to
q0 start state
q1
qdead
qdead
qdead
qdead
q1 final state
q1
q2
q2
q1
q2
(b) [7 marks] Let L be the language of strings over {a,b} that start and end with an a and
contain at least as many as as bs. Is L regular? Answer yes or no, and show that your
answer is correct.
No! The easiest is to use pumping, but let me use a different argument. Suppose to the contrary
that there is a DFA for L with start state q0 and transition function . Lets define an infinite
sequence of states by qi+1 = (qi,a) for all i 0. By the pigeonhole principle, there must be an i
and j with i < j for which qi = qj.
Because ajb j+1a is in L, it follows that *(qj, b j+1a) is a final state.
But qi = qj so *(qi, b j+1a) is a final state, and hence aib j+1a is in L.
This is a contradiction because i < j.
(Arguments that just say not enough memory, while true, are not convincing at all. Arguments
that presume that the numbers of as and bs are the same are not correct.)
CSE 355
Spring 2012 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 5 of 7