CS321 Theory of Computation Midterm, Fall 2014

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

CS321

Theory of Computation
Midterm, Fall 2014
Name:

1. (a) [5pt] Draw a DFA M with alphabet Σ = {a, b} such that

L(M ) = {ava : v ∈ Σ∗ }.

(b) [5pt] Draw an NFA N that accepts the following language.


L(N ) = {a}∗ ∪ {a}{b}∗ ∪ {ab}{c}∗

So for example aaaaa, abbbbb, abccc are in L(N ), but aba, aab,
and abcb are not in L(N ).

(c) [5pt] Draw a DFA or NFA M with alphabet Σ = {a, b} such that
L(M ) = {w : w ∈ Σ∗ , na (w) mod 2 = 0}.
2. (a) [5pt] Write a regular expression r such that
L(r) = {w : w = am bn , m + n is even}
.
r = (aa)*(bb)* + a(aa)*b(bb)*

(b) [5pt] Write a regular expression r such that


L(r) = {uv : u ∈ {a, b}∗ , v ∈ {a, b}∗ , na (u) is even , na (v) is even}.

r = (b*ab*ab*)*

This is just the language of all strings with an even number of


a's.

(c) [5pt] Prove that every finite language is regular.

Assume that L={w1,w2,...,w_n} is a finite language containing n


strings.

Consider the regular expression:

r = w1 + w2 + ... + w_n

From the definition of REs we have that

L(r) = {w1,w2,...,w_n} = L

This shows that L is regular since it has an RE.

A similar argument can be made using NFAs.


3. (a) [5pt] Prove that regular languages are closed under the concate-
nation operation.
Let L1 and L2 be two regular languages. We want to show that
L1L2 is also regular.

Let r1 and r2 be two REs such that L1 = L(r1) and L2=L(r2).

Now consider a new RE r = r1r2.


Based on the definitions associated with REs we know that:

L(r)=L(r1)L(r2)=L1L2.

This shows that r is an RE for L1L2 and hence that L1L2 is regular.

(b) [5pt] Let REPLACE be an operation on languages such that


REPLACE(L) is a new language that is identical to L, except
that each ‘a’ in a string is replaced with ‘cc’.
For example, if L = {a, ab, aabb, bbb} then REPLACE(L) = {cc, ccb, ccccbb, bbb}.
Show that the set of regular languages is closed under the RE-
PLACE operation. (If you don’t understand the operation then
please ask the instructor.)

Assume that L is a regular language. We want to show that REPLACE(L) is


also regular.

Let r be an RE such that L=L(r).

Construct an RE r' by starting with r and then replacing each 'a' in r with 'cc'.

It is clear that L(r') = REPLACE(L). This is because r' will insert a 'cc' in a string
exactly when r would have inserted an 'a' in a string.

A similar argument could be made by starting with an NFA N such that L=L(N).

Now create a new NFA N' that starts with N but replaces any arc labeled by an
'a' with two consecutive arcs, each labeled by a 'c'. The picture below illustrates
the process for one transition, noting that q' is a new state that is introduced into
N'.

It should be clear that L(N') = REPLACE(L) since whenever N would have


required reading in an 'a', N' will require reading in 2 c's instead.
4. (a) [5pt] Let DFAL be the set of languages accepted by DFAs and
NFAL be the set of languages accepted by NFAs. Is it true that
DFAL ⊆ NFAL ? Give a brief argument in support of your answer.

We need to show that for any DFA M there is an NFA N


such that L(M)=L(N).

This is true because DFAs are special cases of NFAs. That


is, DFAs must satisfy conditions that general NFAs do not.
So every DFA is in fact an NFA.

(b) [5pt] Use the procedure taught in class or the book to convert the
following NFA to an equivalent DFA.

Start q0 λ q1 b q2 b q3

b b a

q4 q5
5. (a) [5pt] Consider the following NFA N .

a b
Start q0 q1 q2
b

b a a

b
q3

Draw an equivalent generalized transition graph that results by


removing q3 from N .

(b) [5pt] Consider the following generalized transition graph G.


ba∗
(a + b)
Start q0 q1
b∗ a
bb
Using the pattern taught in class and the book, write a regular
expression that is equivalent to the generalized transition graph
G.

(ba*)*(a+b)(bb + b*a(ba*)*(a+b))*

You might also like