Homework 1 Solutions - National Chiao Tung...

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 * = {w 1 ,w 2 , ...} and therefore {w 1 ,w 2 , ...}⊆ {w 1 ,w 2 , ...} * . (b) (L * ) * L * . For every w (L * ) * , we can decompose it as w = w 1 w 2 ...w n s.t. each w i L * . Similarly, we can decompose w i = w 1i w 2i ...w iN i where w iN i L. Now we can represent w = w 11 w 21 ...w 1N 1 w 12 w 22 ...w 2N 2 ,...,w 1n w 2n ...w nNn where w i,j L. So, w L * . Therefore, (L * ) * L * . Finally, (a) and (b) implies (L * ) * = L * . 2. Find grammars for Σ = {a, b} that generate the sets of (a) all strings with exactly one a. Answer. S BaB B bB|λ (b) all strings with at least one a. Answer. S BaB B aB|bB|λ 3. Let Σ = {a, b}. Find the grammar of L 3 = {a n+2 b n : n 1}. Answer. S aAb A aAb|aa 1-1

Transcript of Homework 1 Solutions - National Chiao Tung...

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 = w1w2 . . . wn s.t.each wi ∈ L∗. Similarly, we can decompose wi = w1iw2i . . . wiNi where wiNi ∈ L.Now we can represent w = w11w21 . . . w1N1w12w22 . . . w2N2 , . . . , w1nw2n . . . 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 → BaBB → bB|λ 2

(b) all strings with at least one a.Answer.

S → BaBB → aB|bB|λ 2

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

S → aAbA→ aAb|aa 2

1-1

4. Which of the strings 0001,01001,0000110 are accepted by the dfa in the followingfigure?

Answer. 0001,01001 are acceptable. 2

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

2

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

Figure 1: Question 6

2

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 eachconstruct an accepting dfa.

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

Figure 2: Question 8

2

1-3

9. Let L be the language accepted by the automaton in Figure 3. Find a dfa that acceptsL2.

Figure 3: Dfa

Answer.

Figure 4: Question 9

2

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

2

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 onlyone 1 at the end.

Figure 12: Question 15

2

1-7

16. Find minimal dfa for the Language L = {anb : n ≥ 0}∪ {bna : 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 thealgorithm described in Theorem 2.2 to convert the nfa to dfa. Finally, we follow thesteps in Theorem 2.3 to minimize the dfa.

Figure 13: Question 16, Corresponding nfa

Figure 14: Question 16, Corresponding dfa

2

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 aredistinguishable, then qb and qc must be distinguishable.Answer. Since qa and qc are distinguishable, ∃w ∈ Σ∗ s.t.δ∗(qa, w) ∈ Fδ∗(qc, w) /∈ FWe know that qa and qb are indistinguishable, we have:δ∗(qa, w) ∈ Fδ∗(qb, w) ∈ FThis 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) ∈ Fandδ∗(qa, w) /∈ Fδ∗(qb, w) /∈ F .

2

1-9