hw3sol1.20
Short Description
Download hw3sol1.20...
Description
University of Central Florida School of Computer Science COT 4210
Fall 2004
Prof. Rene Peralta Homework 3 Solutions (by TA Robert Lee)
1.11. Give a counterexample to show that the following construction fails to prove Theorem 1.24, the closure of the class of regular languages under the star operation. Let N1 = (Q1 , Σ, δ1 , q1 , F1 ) recognize A1 . Construct N = (Q1 , Σ, δ, q1 , F ) as follows. N is supposed to recognize A∗1 . a. The states of N are the states of N1 . b. The start state of N is the same as the start state of N1 . c. F = {q1 } ∪ F1 . The accept states F are the old accept states plus its start state. d. Define δ so that for any q ∈ Q and any a ∈ Σ² , (
δ(q, a) =
δ1 (q, a) q 6∈ F1 or a 6= ² δ1 (q, a) ∪ {q1 } q ∈ F1 and a = ².
Solution See Figure 1.11.1 on the next page for a picture of this formal construction. The primary difference between this construction and the one in Theorem 1.24 is that the original start state becomes an accept state. To create a counterexample, we want to consider a language that does not already accept in its start state. Choose the language A1 = 1(01)∗ . Language A1 is recognized by NFA N1 : N1 = ({q1 , q2 }, {0, 1}, δ1 , q1 , {q2 }), where δ1 is given by δ1 q1 q2
0 ∅ {q1 }
1 {q2 } ∅
² ∅ ∅
Using the procedure given in this problem, construct the NFA N to recognize A∗1 : N = ({q1 , q2 }, {0, 1}, δ, q1 , {q1 , q2 }), where δ is given by δ1 q1 q2
0 ∅ {q1 }
1 {q2 } ∅
² ∅ {q1 }
Both NFA N1 and NFA N are shown in Figure 1.11.2 on the next page. Notice that the constructed machine N accepts the string 10, which is not in the language A∗1 = (1(01)∗ )∗ . Thus N1 is a valid counterexample to prove that this construction does not work.
N1
N ε
ε
Fig. 1.11.1. The proposed construction to prove the closure of the regular languages under the star operation.
N1
N ε
0 q1
q2 1
q1
0 1
Fig. 1.11.2. The counterexample to show why this construction doesn't work. NFA N1 accepts 1(01)*, but NFA N accepts 10, which is not in (1(01)*)*.
q2
1.12 Use the construction given in Theorem 1.19 to convert the following two nondeterministic finite automata to equivalent deterministic finite automata. Solution a. This NFA is ({1, 2}, {a, b}, δN F A , 1, {1}), where δN F A is given by δN F A
a
b
²
1
{1, 2}
{2}
∅
2
∅
{1}
∅
Using the construction in Theorem 1.19, the constructed DFA is (P({1, 2}), {a, b}, δDF A , {1}, {{1}, {1, 2}}), where δDF A is given by δDF A
a
b
∅
∅
∅
{1}
{1, 2}
{2}
{2}
∅
{1}
{1, 2}
{1, 2}
{1, 2}
(See the figure on the page after part b.)
b. This NFA is ({1, 2, 3}, {a, b}, δN F A , 1, {2}), where δN F A is given by δN F A
a
b
²
1
{3}
∅
{2}
2
{1}
∅
∅
3
{2} {2, 3}
∅
Using the construction in Theorem 1.19, the constructed DFA is (P({1, 2, 3}), {a, b}, δDF A , {1, 2}, {{2}, {1, 2}, {2, 3}, {1, 2, 3}}), where δDF A is given by δDF A
a
b
∅
∅
∅
{1}
{3}
∅
{2}
{1, 2}
∅
{3}
{2}
{2, 3}
{1, 2}
{1, 2, 3}
∅
{1, 3}
{2, 3}
{2, 3}
{2, 3}
{1, 2}
{2, 3}
{1, 2, 3}
{1, 2, 3}
{2, 3}
(See the figure on the following page.)
Equivalent DFA
1.12a. Original NFA
a
1 a, b
b
b
1.12b. Original NFA a 2
ε
a, b
a
3
b
Equivalent DFA
a
{1}
{3}
b
a
b b
{2,3}
a
b
a a, b
{2}
b a
q{}5
{1,2,3}
a, b b
{1,2}
a
{1,3}
q4 {1,2}
a, b
{}
a, b
b {2}
2
1
a
{1}
a
1.13
Give regular expressions generating the languages of Exercise 1.4.
Solution
One way to approach this problem is to start with the DFAs you have already drawn
(in HW2) to answer Exercise 1.4. A regular expression can be derived by following each accepting path, that is, each path from the start state to an accept state, and writing a regular subexpression for each path. After all paths have been considered, take the union of the regular subexpressions to obtain the final regular expression. Because the alphabet Σ = {0, 1} for each of these languages, we will write Σ as shorthand for (0 ∪ 1). a. {w | w begins with a 1 and ends with a 0} = 1Σ∗ 0. b. {w | w contains at least three 1s} = Σ∗ 1Σ∗ 1Σ∗ 1Σ∗ . c. {w | w contains the substring 0101} = Σ∗ 0101Σ∗ . d. {w | w has length at least 3 and its third symbol is a 0} = ΣΣ0Σ∗ . e. {w | w starts with 0 and has odd length, or starts with 1 and has even length} = (0∪1Σ)(ΣΣ)∗ . f. {w | w doesn’t contain the substring 110} = 0∗ (10)∗ 0∗ ∪ 0∗ 1(00∗ 1)∗ ∪ 0∗ 1(00∗ 1)∗ 11∗ . g. {w | the length of w is at most 5} = ² ∪ Σ ∪ ΣΣ ∪ ΣΣΣ ∪ ΣΣΣΣ ∪ ΣΣΣΣΣ. h. {w | w is any string except 11 and 111} = ² ∪ 1 ∪ 0Σ∗ ∪ 10Σ∗ ∪ 110Σ∗ ∪ 111ΣΣ∗ . i. {w | every odd position of w is a 1} = (1Σ)∗ ∪ 1(Σ1)∗ . j. {w | w contains at least two 0s and at most one 1} = 000∗ ∪ 000∗ 10∗ ∪ 0100∗ ∪ 1000∗ . k. {², 0} = ² ∪ 0. l. {w | w contains an even number of 0s, or exactly two 1s} = 1∗ ∪ (1∗ 01∗ 01∗ )∗ ∪ 0∗ 10∗ 10∗ . m. The empty set is generated by ∅. n. The language containing all strings except the empty string is generated by ΣΣ∗ .
1.14a. (0 U 1)*000(0 U 1)* 0
1
0
q4
1
q4
ε
0U1
0
ε 1
q4
ε
(0 U 1)* ε
ε
0
ε 1
q4 ε
0
000
q4
ε
0
q4
ε
0
q4
(0 U 1)*000(0 U 1)* ε ε
ε
ε
ε
0 ε
ε 1
ε
ε
0
ε 1
q4 ε
ε
q4 ε
0
q4
ε
0
q4
ε
ε 0
q4
1.14b. (((00)*(11)) U 01)* 0
1
00
0
q4
1
q4
0
q4
ε
0
q4
1
q4
ε
1
q4
0
q4
ε
1
q4
q4
ε
0
q4
ε
0
11
01
ε
(00)*
ε
0
ε
0
q4
ε
(00)*(11)
q4 ε
ε 1
((00)*(11)) U 01
0
ε
q4
ε
q4
1
1
q4
1
q4
q4
ε
ε ε
ε
0
ε
q4
0
q4 ε
ε 1
q4
(((00)*(11)) U 01)* 0
ε
ε
q4
ε
1
q4
ε q4
ε
ε ε
ε
0
q4
ε
0
q4 ε
ε 1
q4
ε
1
q4 ε
1.14c. θ* θ
θ*
q4
ε
1.15 For each of the following languages, give two strings that are members and two strings that are not members—a total of four strings for each part. Assume the alphabet Σ = {a, b} in all parts. Solution a. a∗ b∗ . Members: ², a. Non-members: ba, aba. b. a(ba)∗ b. Members: ab, abab. Non-members: ², aa. c. a∗ ∪ b∗ . Members: ², a. Non-members: ab, ba. d. (aaa)∗ . Members: ², aaa. Non-members: a, aa. e. Σ∗ aΣ∗ bΣ∗ aΣ∗ . Members: aba, aaba. Non-members: ², a. f. aba ∪ bab. Members: aba, bab. Non-members: ², a. g. (² ∪ a)b. Members: b, ab. Non-members: ², a. h. (a ∪ ba ∪ bb)Σ∗ . Members: a, ba. Non-members: ², b.
1.16a.
a
1 b
b
a
2
S
ε
b
b A
S
ε
ε
2
a
1
a U ba*b
ba* A
S (a U ba*b)*ba* A
a
1
1.16b. a, b
1
b
a
a
2
1
ε
b
S
aUb
a
A
3
ε
ε
S
b
ε
S ε
aUb
b
(a U b)a*b
a
2
b U (a(a U b)) 3 aUε A
(b U (a(a U b)))a*b
3 aUε A
S
ε U ((a U b)a*b((b U (a(a U b)))a*b)*(a U ε))
A
a
2 b 3
View more...
Comments