Sei sulla pagina 1di 3

CSE 355

Fall 2014 - Colbourn

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]

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


Question 1. [10 marks]
(a)
[5 marks] Let L be the language with alphabet {0,1} containing all strings in which the
number of occurrences of 01 is the same as the number of occurrences of 10. Is L regular? Justify your
answer carefully.
L is regular. Strings in L are precisely those that satisfy one of the following: the string is empty, or it
starts with 0 and ends with 0, or it starts with 1 and ends with 1.
So L = 0 1 0(01)*0 1(01)*1.
A justification. When scanning left to right every time we change symbols from 0 to 1 we see a 01 and
every time we change symbols from 1 to 0 we see a 10. These alternate. So if we start with a 01 we
must end with a 10 (and vice versa). This is the condition given above.
(b)
[5 marks] Let L be the language with alphabet {0,1} containing all strings in which the
number of occurrences of 00 is the same as the number of occurrences of 11. Is L regular? Justify your
answer carefully.
L is not regular. Suppose to the contrary that it is, and let p be its pumping length. Consider the string
0p1p; it has p-1 occurrences of 00 and p-1 of 11 so it is in L. And it has length p. So we must be able
to write it as xyz with |xy| at most p, and y not empty. Because the first p symbols are 0s, y only
contains 0s, so let y = 0a (and x = 0b and z = 0p-a-b1p). Then xy2z has p-1+a occurrences of 00 and p-1 of
11, so it is not in L. This is a contradiction. So L is not regular.
Question 2. [10 marks total] Let R be the regular expression (100*1 1)*(1 101). Call its language L.
(a)
[5 marks] Using regular expression R and the methods described in class, give an NFA for
L. (Describe briefly the steps that you follow.)
I use the methods from class for union, concatenation and Kleene star. Specifically, say I have built NFAs
(Q,,,q0,F) for language L and (Q,,,q0,F) for language L.
I build one for LL by adding an epsilon transition from every state in F to the state q0, making F the final states
and q0 the start state of the merged machine.
I build one for LL by adding a new start state q0 and an epsilon transition from q0 to the states q0 and q0,
making FF the final states and q0 the start state.
I build one for L* by adding a new state q0 and adding an epsilon transition from every state in F to the state q0
and an epsilon transition from q0 to q0, making q0 the only final state and q0 the start state.
(You dont need to write all these words pictures would do.)

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}

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 use the powerset method, figuring out what set of states I can reach on reading an input
character followed by as many transitions as I want.
0
1
State Symbol
{q0, q3}
{q0, q1, q3}
{q3}
{q0, q1, q3}
{q0, q1, q2, q3}
{q3}
{q0, q1, q2, q3}
{q0, q1, q2, q3}
{ q2, q3}
{ q2, q3}
{q3}
{ q2, q3}
{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.

Potrebbero piacerti anche