Вы находитесь на странице: 1из 6

Introduction to Formal Language, Fall 2017 14-Mar-2017

Homework 1 Solutions
Instructor: Prof. Wen-Guey Tzeng Scribe: Amir Rezapour

1. How many substrings aab are in wwR w, where w = aabbab?


Answer. aabbabbabbaaaabbab. 2

2. Let L = {ab, aa, baa}. Which of the following strings are in L∗ : abaabaaabaa,
aaaabaaaa, baaaaabaaaab, baaaaabaa? Which strings are in L4 ?
Answer.
aa aab aa aa , baa aa ab aa 2

3. For Σ = {a, b}, construct dfa’s that accept the sets consisting of all the strings with
at least two a’s.
Answer.

4. Give a dfa for language L = {ab4 wb2 : w ∈ {a, b}∗ }.


Answer.

1-1
5. Find a dfa for L = {w : (na (w) − nb (w)) mod 3 = 0}, where Σ = {a, b}. Answer.

c = (Q, Σ, δ, q0 , Q − F ) are two dfa’s, then


6. Show that if M = (Q, Σ, δ, q0 , F ) and M
L(M ) = L(M
c).
Answer.
L(M ) = {w ∈ Σ∗ : δ ∗ (q0 , w) ∈ F }
L(M ) = {w ∈ Σ∗ : δ ∗ (q0 , w) ∈
/ F } = {w ∈ Σ∗ : δ ∗ (q0 , w) ∈ Q − F } = L(M
c). 2

7. Construct a dfa for all strings on {0, 1} of length five or more in which the third
symbol from the right end is different from the leftmost symbol.
Answer.

1-2
8. Let L be the language accepted by the automaton in Figure 1. Find a dfa that accepts
the language L2 − L.

Figure 1: Dfa
Answer.

Figure 2: Question 8

9. In Figure 3, find δ ∗ (q0 , 1011) and δ ∗ (q1 , 01).

Figure 3: Nfa
Answer.
δ ∗ (q0 , 1011) → {q2 }
δ ∗ (q1 , 01) → {q1 }
2

10. Design an nfa with no more than five states for the set {ababn : n ≥ 0}∪{aban : n ≥ 0}.
Answer.
2

1-3
Figure 4: Nfa

11. Find an nfa with no more than three states that accepts the language L = {an : n ≥
1} ∪ {bm ak : m ≥ 0, k ≥ 0}.
Answer.

Figure 5: Nfa

12. Convert the nfa defined by

δ(q0 , a) = {q0 , q1 }
δ(q1 , b) = {q1 , q2 }
(1)
δ(q2 , a) = {q2 }
δ(q0 , λ) = {q2 }

with initial state q0 and the final state q2 into an equivalent dfa.
Answer.

13. Prove that for every nfa with an arbitrary number of final states there is an equivalent
nfa with only one final state. Can we make a similar claim for dfa’s?
Answer. We can create one final state qf inal and connect nfa’s final states to the
qf inal and set them to non-final state.
Since λ transition doesn’t exist in dfa, therefore we cannot always find the correspond-
ing dfa with only one final state. 2

1-4
14. Show that if L is regular, so is LR .
Answer.
Informally, the following procedure shows that we can always construct a finite ac-
cepter MLR that accepts LR for a given finite accepter ML that accepts L.

(a) Reverse all transitions in ML .


(b) Add a new initial stare qs and generate λ-transitions from qs to each of the final
states in ML .
(c) Turn all final states of ML into normal states of MLR and turn the initial states
of ML into a final state of MLR .

Formally, let ML = (QL , Σ, δL , q0 , FL ) be an NFA that accepts L. The NFA MLR below
accepts LR .

(a) MLR = (QL ∪ qs , Σ, δLR , qs, q0) and qs ∈


/ QL .
(b) δL (qi , a) = qj ←→ δLR (qj , a) = qi for all a ∈ Σ and qi , qj ∈ QL .
(c) δLR (qs , λ) = q for all q ∈ FL .

From (b), if w ∈ L(ML ), δL (q0 , w) = qj ∈ FL ←→ δL (qj , w) = q0 . From (c),


δLR (qs , λ) = qj for all qj ∈ FL . Thus, we have that for all w ∈ L(ML ), wR ∈ L(MLR ).
2

15. From a language L, we create a new language, choplef t(L), by removing the leftmost
symbol of every string in L. Specifically,

choplef t(L) = {w : vw ∈ L, with|v| = 1}. (2)

Show that if L is regular, then choplef t(L) is also regular.


Answer.
If L is regular, then there exist a dfa D that accepts L. Construct an nfa that simulates
D. Create a new start state qstart and link it to all states that D’s start state link to
with a λ transition. This nfa accepts choplef t(L), therefore choplef t(L) is regular.
Formally, let ML = (QL , Σ, δL , q0 , FL ) be an dfa that accepts L. The NFA Mchoplef t(L)
below accepts choplef t(L).

(a) Mchoplef t(L) = (QL ∪ qstart , Σ, δL , S, FL ) and qstart ∈


/ QL .
(b) δL (qi , a) = qj ←→ δL (qstart , λ) = qj for all a ∈ Σ and qi ∈ S.

From (b), Mchoplef t(L) accepts choplef t(L) = {w : vw ∈ L, with|v| = 1}. 2

16. Minimize the number of the states in the following dfa.


Answer.
2

1-5
1-6

Вам также может понравиться