CMPSCI 401: Theory of Computation
First Midterm Exam, Spring 2010
David Mix Barrington
22 February 2010
Directions:
- Answer the problems on the exam pages.
- There are seven problems
for 125 total points plus 10 extra credit.
Actual scale was A=115, C=75.
- If you need extra space use the back of a page.
- No books, notes, calculators, or collaboration.
- The first four questions are true/false, with five points for the correct
boolean answer and up to five for a correct justification of your answer --
a proof, counterexample, quotation from the book or from lecture, etc. -- note
that there is no reason not to guess if you don't know.
Q1: 10 points
Q2: 10 points
Q3: 10 points
Q4: 10 points
Q5: 35+10 points
Q6: 20 points (note the exam paper said "30" here)
Q7: 30 points
Total: 125+10 points
Several questions refer to the following PDA called P. P has state set
{q0, q, f}, start state q0, final state set {f}, input
alphabet {a, b}, and stack alphabet {$, c}. It has six transitions:
(q0, ε, ε; q, $),
(q, a, ε; q, c),
(q, b, ε; q, c),
(q, a, c; q, ε),
(q, b, c; q, ε), and
(q, ε, $; f, ε). (Remember that a transition (p, a, b; q, c)
means that the machine may go from state p to state q reading a from the input,
popping b, and then pushing c.)
The grammar G is defined to have rules S --> SS,
S --> aSa, S --> aSb, S --> bSa, S --> bSb, and S --> ε. It
was on the test paper but I only noticed in February 2011 that is was
not
defined here. (DAMB)
- Question 1 (10):
True or false with justification:
There exists a string of odd length (with an odd number of letters) in L(P).
- Question 2 (10):
True or false with justification:
Every string of even length is in L(P).
- Question 3 (10):
True or false with justification:
Let L be a regular language, the language of some DFA with k states. Then if
w is any string in L with length at least k, there exist strings x, y, and z
such that w = xyz and such that every string in L is of the form xyi
for some number i. (Clarification during test: The last phrase means
∀s:(s ∈ L) → ∃i: s = xyiz rather than
∃i:∀s: (s ∈ L) → s = xyiz.)
- Question 4 (10):
True or false with justification:
The languages L(P) and L(G) are equal.
- Question 5 (35+10):
The grammar G is defined before Question 1 above.
- (a,5) Give a parse tree showing that the string aabbab is in L(G).
- (b,5) Show that for any non-negative integer n, the string
anbnanbn is in L(G).
- (c,10) Is the language
{anbnanbn: n ≥ 0} a
context-free language? Prove your answer.
- (d,10) Describe either a top-down parser or a bottom-up parser for G
(and indicate which you are doing).
- (e,5) Is L(G) a regular language? Prove your answer.
- (f,10XC) Let G' be the grammar obtained from G by deleting
the two rules S → aSb and S → bSa. Is L(G') a regular language?
Prove your answer.
- Question 6 (20):
Let N1 and N2 be any two NFA's with k states each.
Remember not to make any assumptions other than that they are NFA's with
k states.
- (a,10) Describe an NFA N3 such that
L(N3) = L(N1) ∪ L(N2). How many states
does your N3 have?
- (b,10) Describe an NFA N4 such that
L(N4) = L(N1) ∩ L(N2). How many states
does your N4 have?
- Question 7 (30):
Let M be an NFA with state set {1, 2, 3, 4}, start state 1, final state
set {4}, and the transitions (1,b,2), (1,a,3), (1,a,4), (2,b,3), (2,b,4), and
(3,b,4). (Remember that the transition (p,a,q), for example, means that the
NFA can go from state p to state q while reading an a.) In Sipser's notation
for NFA's, we have that δ(1,a) = {3,4}, δ(1,b) = {2},
δ(2,b) = {3,4}, δ(3,b) = {4}, and for all other states p and letters
c, δ(p,c) = ∅.
- (a,10) Give a regular expression denoting the language L(M). If you
use the GNFA construction, note that M already satisfies the conditions to be
a GNFA.
- (b,10) Using the subset construction or otherwise, find a DFA D such
that L(D) = L(M).
- (c,10) Show that your DFA D is minimal, or otherwise find a DFA for
L(M) that has the minimum number of states needed to decide that language.
Last modified 13 February 2011