30 September 2010 Ima Sample 0123456789

CSE 355
Fall 2010 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 1 of 6
30 September 2010
NAME
Ima Sample
ASU ID
0123456789
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
[15]
Question 2
[10]
Question 3
[8]
Question 4
[12]
Question 5
[5]
Total
[50]
Bonus question [1 mark]: What is the language ∅*?
It is {λ}.
Grades out of 50 are: 10 11 11 12 14 15 16 16 17 18 19 20 22 23 23 25 25 25 26 26 27 27 29 30
31 32 34 35 36 36 36 37 37 38 40 43 43 44 44
CSE 355
Fall 2010 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 2 of 6
Question 1. [15 marks total]
Consider the language L over {a,b} in which every b is immediately
two consecutive a’s.
preceded by at least
(a) [5 marks] Give an NFA-λ for L.
(Q,Σ,δ,q0,F) with Q ={q0,q1,q2}; Σ = {a,b}, F = {q0,q1,q2}, and δ defined by δ(q0,a) =
{q0,q1}, δ(q1,a) = {q2}, and δ(q2,b) = {q0}
(b) [5 marks] Using the algorithm developed in class, from the NFA-λ, form a regular
expression for L. (Describe briefly the steps that you follow.)
I make the machine above have only one accept state by adding a new state q3 with transitions
δ(q0,λ) = {q3}, δ(q1,λ) = {q3}, δ(q2,λ) = {q3}, and then change the accepting states to F =
{q3}. Then I use the algorithm from class to remove states q1 and q2 to get (a ∪ aab)*
(c) [5 marks] Using the algorithm developed in class, convert this NFA-λ to a DFA. Show a
state diagram of the DFA. (Describe briefly the steps that you follow.)
I use the NFA-λ from the (a) part. I am too lazy to draw a state diagram on these solutions, but
instead give the states and transitions for the DFA as a table:
State
{q0} – start state
{q0,q1}
{q0,q1,q2}
∅
Transition on a
{q0,q1}
{q0,q1,q2}
{q0,q1,q2}
∅
Transition on b
∅
∅
{q0}
∅
The first three are accepting but ∅ is not.
Because I named the states of the DFA as the algorithm does, the method that I used is clear.
Question 2. [10 marks total]
(a) [3 marks] Give a formal definition of an NFA-λ.
It is a 5-tuple (Q,Σ,δ,q0,F) where Q is a finite set of states, q0 ∈ Q is the start state, F ⊆ Q is the
set of accepting states, Σ is a finite input alphabet, and δ is a function from Q × (Σ ∪{λ}) to the
powerset of Q.
(b) [3 marks] Give a recursive definition of the λ-closure of a state in an NFA-λ.
Base: q is in the λ-closure of q.
Recursive: If r is in the λ-closure of q and s ∈ δ(r, λ) then s is in the λ-closure of q.
CSE 355
Fall 2010 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 3 of 6
Closure: All states in the λ-closure of q can be obtained from the base step by a finite number of
applications of the recursive step.
(c) [4 marks] Give the λ-closure for each state in the NFA-λ shown.
λ-closure(q0) = {q0,q1,q2,q3}
λ-closure(q1) = {q1,q2,q3}
λ-closure(q2) = {q1,q2,q3}
λ-closure(q3) = {q1,q2,q3}
λ-closure(q4) = {q4}
Question 3 [8 marks] A string of parentheses (i.e. `(` and `)`) is dominating if every prefix
contains at least as many left parentheses as right parentheses. Let L be the language of
dominating strings over {(,)}*.
Is L regular? Answer yes or no (1 mark), and then show that your answer is correct (7 marks).
No!
Comments: This language L does not have all ( before all ), and does not need to have the same
number of ( and ). Statements that we have to remember the number of ( are intuitively correct
but are not relevant to showing the result.
Suppose that L were regular. Then there is a constant n so that when z is in L and |z| is at least n,
there is a way to write z = uvw with |uv| ≤ n, |v| > 0, and uviw ∈ L for all i ≥ 0. I get to choose z,
so I choose z = (n)n, noting that z is in L. Now because |uv| ≤ n, the only possibility is that for
some p and q, we have u = (p and v = (q with q > 0. Then uviw = (n+(i-1)q)n . (If I take i>0 there is
no contradiction.) Choose i=0. Then uv0w = (n-q)n . But this is not in L, a contradiction. So L
cannot be regular.
CSE 355
Fall 2010 - Colbourn
Theory of Computing
Midterm # 1
ID: ___________
Page 4 of 6
Question 4 [12 marks]
(a) [5 marks] Build a DFA to accept the language of strings over {a,b} that contain at least
one a and at least one b, and in which the first and last symbols are the same.
State
q0 – start state
q1
q2
q3 – accepting
q4
q5
q6 – accepting
Transition on a
q1
q1
q2
q3
q5
q5
q5
Transition on b
q4
q2
q2
q2
q4
q6
q6
(b) [7 marks] Let L be the language of strings over {a,b} that contain at least as many a’s as
b’s, and in which the first and last symbols are the same. Show that L is not regular.
If L were regular, there would be a constant n so that for every string z in L, there is a way to
write z = uvw with |uv| ≤ n, |v| > 0, and uviw ∈ L for all i ≥ 0. I get to choose z, so I choose
bnan+1b, which is in L. Then because |uv| ≤ n, we have u = bp and v = uq for q>0, and then uviw
= bn+(i-1)qan+1b. But this is not in L when i>1 because q>0 and so we would have more b’s than
a’s. This contradicts the hypothesis that L is regular, so we conclude that L is not regular.
Question 5 [5 marks]
Suppose that L and L’ are two regular languages.
(a) Show that the complement of L is regular. (Do not use other closure properties in
showing this.)
L is regular so L is accepted by a DFA (Q,Σ,δ,q0,F). Then (Q,Σ,δ,q0,Q-F) accepts the
complement of L.
(b) Show that L ∩ L’ is regular. (You can use other closure properties in showing this if it
helps.)
(Note: L’ is not the complement! See page 9 of the text.)
Because L and L’ are regular, their complements are also regular by the (a) part (or by the known
closure property, since we’re allowed to use them here). Form the union of the two
complements, and complement this union – by DeMorgan’s Law, this is equal to L ∩ L’.
Because we also have closure of regular languages under union, L ∩ L’ is therefore regular.