You are on page 1of 9

Introduction to Formal Language, Fall 2016 8-Mar-2016

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

1. Show that (L∗ )∗ = L∗ for all languages.


Answer.
For all Σ,

(a) L∗ ⊆ (L∗ )∗ . The reason is because L∗ = {w1 , w2 , ...} and therefore {w1 , w2 , ...} ⊆
{w1 , w2 , ...}∗ .
(b) (L∗ )∗ ⊆ L∗ . For every w ∈ (L∗ )∗ , we can decompose it as w = w1 w2 . . . wn s.t.
each wi ∈ L∗ . Similarly, we can decompose wi = w1i w2i . . . wiNi where wiNi ∈ L.
Now we can represent w = w11 w21 . . . w1N1 w12 w22 . . . w2N2 , . . . , w1n w2n . . . wnNn
where wi,j ∈ L. So, w ∈ L∗ . Therefore, (L∗ )∗ ⊆ L∗ .

Finally, (a) and (b) implies (L∗ )∗ = L∗ .


2

2. Find grammars for Σ = {a, b} that generate the sets of

(a) all strings with exactly one a.


Answer.
S → BaB
B → bB|λ 2

(b) all strings with at least one a.


Answer.
S → BaB
B → aB|bB|λ 2

3. Let Σ = {a, b}. Find the grammar of L3 = {an+2 bn : n ≥ 1}.


Answer.
S → aAb
A → aAb|aa 2

1-1
4. Which of the strings 0001,01001,0000110 are accepted by the dfa in the following
figure?

Answer. 0001,01001 are acceptable. 2

5. For Σ = {a, b}, construct dfa’s that accept the sets consisting of all the strings with
exactly two a’s and more than two b’s.
Answer.

6. Give a dfa for language L = {ban : n ≥ 1, n 6= 5}.


Answer.

Figure 1: Question 6

7. Find a dfa for L = {w : na (w) mod 3 > 1}, where Σ = {a, b}.
Answer.
2

1-2
8. Consider the set of strings on {0, 1} defined by the requirement below. For each
construct an accepting dfa.

(a) All strings in which the leftmost two symbols and the rightmost two symbols are
identical.
Answer.

Figure 2: Question 8

1-3
9. Let L be the language accepted by the automaton in Figure 3. Find a dfa that accepts
L2 .

Figure 3: Dfa

Answer.

Figure 4: Question 9

10. In Figure 5, find δ ∗ (q0 , 1011) and δ ∗ (q1 , 01).

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

11. For the nfa in Figure 5, find δ ∗ (q0 , 1010) and δ ∗ (q1 , 00).
Answer.
δ ∗ (q0 , 1010) → {q0 , q2 }
δ ∗ (q1 , 00) → {} 2

1-4
12. Which of the strings 00, 01001, 10010,000, 0000 are accepted by the nfa in Figure 6?

Figure 6: Nfa
Answer.
All strings are acceptable. 2

13. What is the complement of the language accepted by the nfa in Figure 7?
Answer.

Figure 7: Nfa

We first find the dfa and compute the complement of dfa. As a result, the dfa accepts

Figure 8: Question 13

all strings s.t. na (w) > 1 and the complement accepts na (w) < 1. 2

1-5
14. Convert the nfa in Figure 9 into an equivalent dfa.

Figure 9: Nfa M
Answer.
Following the procedure of converting am nfa to a dfa, we have

δ ∗ (q, 0) 0 1
q0 {q0 , q1 , q2 } {q1 , q2 }
q1 {q0 , q1 , q2 } {q1 , q2 }
q2 {q2 } {q1 }

{q0 } ∈ F since λ ∈ L(M );


{q1 , q2 }, {q0 , q1 , q2 } ∈ F since q1 is a final state in M .
Thus, the result dfa is shown as follows.

Figure 10: Question 14

1-6
15. Give a simple verbal description of thc language accepted by the dfa in Figure 11.
Use this to find another dfa, equivalent to the given one, but with fewer states.

Figure 11: Nfa

Answer.
This dfa accepts binary strings of all 0’s and also accepts strings which contain only
one 1 at the end.

Figure 12: Question 15

1-7
16. Find minimal dfa for the Language L = {an b : n ≥ 0} ∪ {bn a : n ≥ 1}. If it’s possible,
prove that the result is minimal.
Answer. We first construct a nfa that accepts the language L. Then, we use the
algorithm described in Theorem 2.2 to convert the nfa to dfa. Finally, we follow the
steps in Theorem 2.3 to minimize the dfa.

Figure 13: Question 16, Corresponding nfa

Figure 14: Question 16, Corresponding dfa

1-8
Figure 15: Question 16, Minimized dfa. The labels indicate the previous index in Figure 14

17. Prove the following: If the states qa and qb are indistinguishable, and if qa and qc are
distinguishable, then qb and qc must be distinguishable.
Answer. Since qa and qc are distinguishable, ∃w ∈ Σ∗ s.t.
δ ∗ (qa , w) ∈ F
δ ∗ (qc , w) ∈
/F
We know that qa and qb are indistinguishable, we have:
δ ∗ (qa , w) ∈ F
δ ∗ (qb , w) ∈ F
This implies that qb and qc are distinguishable by w since δ ∗ (qb , w) ∈ F and δ ∗ (qc , w) ∈
/
F.
Similarly, we can show for other cases:
δ ∗ (qa , w) ∈
/F

δ (qc , w) ∈ F
and
δ ∗ (qa , w) ∈
/F

δ (qb , w) ∈ / F.
2

1-9

You might also like