Sei sulla pagina 1di 3

CSE 355

Fall 2015 - Colbourn

Theory of Computing
Midterm Examination # 1 Solutions

NAME
ASU ID

ID: ___________
Page 1 of 5

05 October 2015
Ima Sample

You have 50 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]

Total

[40]

Bonus question [1 mark]: What is the language *? It is .

Question 1. [10 marks]


(a) [5 marks] Let L {a,b}* be the language containing all strings in which the number of
substrings equal to ab is the same as the number of substrings equal to ba. Is L regular?
Justify your answer carefully. (Recall that a substring of w contains consecutive symbols
of w.)
(This is part of question 5 from Homework 2.) Yes, L is regular. Indeed w is a member of L if
and only if L starts with a and ends with a, starts with b and ends with b, or is empty. L is
described by the regular expression a b a(ab)*a b(ab)*b.
(b) [5 marks] Let L {a,b}* be the language containing all strings in which the number of
subsequences equal to ab is the same as the number of subsequences equal to ba. Is L
regular? Justify your answer carefully. (Recall that a subsequence of w contains symbols
that appear in the same order in w, not necessarily consecutively.)
L is not regular. To show this, assume to the contrary that L is regular and let p be its pumping
length. Consider the string w = apbpap. Then |w| = 3p > p, and w is in L because it has p2
occurrences of the subsequence ab and p2 occurrences of the subsequence ba. If we write w =
xyz with |xy| p and |y| > 0, then y consists only of as from the first block of as. Say y = ah.
Then xy2z = ap+hbpap which contains p2+hp occurrences of the subsequence ab and p2
occurrences of the subsequence ba, so because h and p are both positive, xy2z is not in L. This
contradicts the pumping lemma, so L is not regular.
Question 2. [10 marks total]
Let R be the regular expression 1*(001 1)*(11 00). Call its language L.
(a) [6 marks] Using regular expression R and the methods described in class, give an NFA
for L. (Describe briefly the steps that you follow.)
For single characters, make an NFA with a start state and a final state with a single transition
from start to final labeled with that character.
For concatenation of two regular expressions R and R, make NFAs M and M for them. Add transitions from each final state of M to the start state of M. Make all final states of M non-final.
The new start state is the start state of M.
For union of two regular expressions R and R, make NFAs M and M for them. Add a new start
stare and -transitions from the new start state to the start states of M and M.
For Kleene star of a regular expression R, make an NFA M for R. Add a new start state and -

CSE 355
Fall 2015 - Colbourn

Theory of Computing
Midterm Examination # 1 Solutions

ID: ___________
Page 2 of 5

transitions from the new start state to the start state of M. Add -transitions from each final state
of M to the new start state. Make all final states of M non-final, and make the new start state be
final.
Using our results about GNFAs, we can often simplify. For example, if the only transition
leaving a state is an -transition, and the state is not final, we can easily remove it. It is ok to
simplify as long as the justification is clear and correct.
You should show at least some of the transition diagrams obtained.
(b) [4 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.)
For example, S T | W; T 1U; U S; W A | H; A B | D; B 1C; C W; D 0E;
E 0F; F 1G; G W; H J; J K | N; K 0L; L 0M; N 1P; P 1Q. I have just
turned each transition of the NFA into a rule, assuming the start state of the NFA is S and the
final states are M and Q.
Question 3 [10 marks] Consider the NFA with start state q0, final state q3,. and transition function
0
1
State Symbol

q0
{q
q
}
{q

0, 1
3}
q1
{q2}

q2
{q2}
{q2}

q3
{q2}
{q3}

Call the language that it recognizes L.


(a) [5 marks] Using the methods described in class, produce a DFA that recognizes L.
Explain your method.
I compute the subsets of states that can be reached by following a transition on a single letter
followed by any number of -transitions.
0
1
State Symbol
{q0, q3} start, final
{q2}
{q0, q1, q3}
{q0, q1, q3} final
{q2}
{q0, q1, q3}
{q2}
{q2}
{q2}
(b) [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 start with the DFA, renaming the states as A, B, C, and convert it to a GNFA by adding a new
start state and final state. Here is the first GNFA
From State To State Start A B C Final
Start

A
1
0

B
1
0

C
01
Final
I process state C and remove it. (There is no way to leave C so it just gets deleted.)
From State To State Start A B Final
Start

A
1

CSE 355
Fall 2015 - Colbourn

Theory of Computing
Midterm Examination # 1 Solutions

B
Final

ID: ___________
Page 3 of 5

I process state A and remove it.


From State To State Start B Final
Start
1

B
1

Final
I process state A and remove it.
From State To State Start Final
Start
11*
Final
So the regular expression is 11*.
Question 4 [10 marks] The DFA M has start state q0, final state q0, and transition function
0
1
State Symbol
q0
q0
q1
q1
q1
q0
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.
0
1
State Symbol
00 start
01
12
01
00
10
02 final
01
11
10
11
02
11
10
00
12
11
01
(b) [5 marks] Give a regular expression that describes infinitely many strings that are in L
but not in L. (You do not need to describe all, just an infinite number.)
The language of all strings in L but not in L is given by the DFA
0
1
State Symbol
00 start
01
12
01
00
10
02
01
11
10
11
02
11
10
00
12 final
11
01
Check out 1(101)*. This infinite set of strings is accepted.

Potrebbero piacerti anche