Tut-3 Solutions

You might also like

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

CS F351 Theory of Computation

Tutorial-3

Note: ∗ marked problems can be left to the students to try after the tutorial.

Problem 1 Design a DFA for the language, over Σ = {a, b}, such that all strings in the language contain

even number of a's and each a b.


is followed by at least one

Solution: Consider two sets of the given language:


A = {x ∈ Σ∗ | x contains even number of a's} and
B = {x ∈ Σ∗ | each a in x is followed by at least one b}
Note that the given language is the same as A ∩ B . The DFA's for A and B are given below:

Now we construct the DFA for the given language as discussed in the class.

Problem 2 Construct NFA for the following languages:

1. L1 = {x ∈ {0, 1}∗ | x contains the equal number of occurrences of 01 and 10}.


(∗) Also, construct a DFA for the same language.
Solution:

1
Figure 1: Solution to Problem 2.1.

2. (∗) L2 = {x ∈ {0, 1}∗ | x contains two 0s separated by a substring whose length is a multiple of 3}.

Solution:

Figure 2: Solution to Problem 2.2.

2
Problem 3 (∗) Say that string x is a prex of y if a string z such that y = xz and that x is a proper
prex of y if x ̸= y. Let A be a regular language.

Show that N OP REF IX(A) = {w ∈ A | no proper prex of w is a member of A} is also a regular


language.
Solution:
Let M = (Q, Σ, δ, q0 , F ) be an DFA such that L(M ) = A. We now construct M ′ = (Q′ , Σ, δ ′ , q0′ , F ′ ) such
that L(M ′ ) = N OP REF IX(A) where

1. Q′ = Q.
δ(r, a) if r ∈

/F
2. For r ∈ Q′ and a ∈ Σ dene δ ′ (r, a) =
∅ if r ∈ F
3. q0′ = q0 .
4. F ′ = F .

Problem 4 Construct an equivalent DFA for the following NFA's.

1. ({q0 , q1 , q2 , q3 }, {0, 1}, δ, q0 , {q3 }) where δ is Solution: The equivalent DFA is given be-
given in the below table. low. The states marked with ∗ are the nal
states.
δ 0 1 δ 0 1
→ q0 {q0 , q1 } {q0 } → {q0 } {q0 , q1 } {q0 }
q1 {q2 } {q2 } {q0 , q1 } {q0 , q1 , q2 } {q0 , q2 }
q2 {q3 } ∅ {q0 , q1 , q2 } {q0 , q1 , q2 , q3 } {q0 , q2 }
q3 {q3 } {q3 } {q0 , q2 } {q0 , q1 , q3 } {q0 }
∗{q0 , q1 , q2 , q3 } {q0 , q1 , q2 , q3 } {q0 , q2 , q3 }
∗{q0 , q1 , q3 } {q0 , q1 , q2 , q3 } {q0 , q2 , q3 }
∗{q0 , q2 , q3 } {q0 , q1 , q3 } {q0 , q3 }
∗{q0 , q3 } {q0 , q1 , q3 } {q0 , q3 }

2. (∗) ({q0 , q1 , q2 , q3 }, {0, 1}, δ, q0 , {q1 , q3 }) where Solution: The equivalent DFA is given be-
δ is given in the below table. low. The states marked with ∗ are the nal
states.
δ 0 1
δ 0 1
→ q0 {q1 , q3 } {q1 }
→ {q0 } {q1 , q3 } {q1 }
q1 {q2 } {q1 , q2 }
∗{q1 , q3 } {q2 } {q0 , q1 , q2 }
q2 {q3 } {q0 } ∗{q1 } {q2 } {q1 , q2 }
q3 ∅ {q0 } {q2 } {q3 } {q0 }
∗{q0 , q1 , q2 } {q1 , q2 , q3 } {q0 , q1 , q2 }
∗{q1 , q2 } {q2 , q3 } {q0 , q1 , q2 }
∗{q3 } ∅ {q0 }
∗{q1 , q2 , q3 } {q2 , q3 } {q0 , q1 , q2 }
∗{q2 , q3 } {q3 } {q0 }
∅ ∅ ∅

You might also like