Document 13085766

advertisement
TDDB29
Övningsuppgifter i formella språk oh automatateori
Sammanställt av Jonas Wallgren
2007
Här följer de problem (med (partiella) lösningar) som giks igenom på lektionen oh som
inte nns i kursmaterialet.
Problems
2.4
For eah of the following languages, onstrut a DFA that aepts the language.
a) L1 = {x ∈ {0, 1}∗ | x
b) L2 = {x ∈
{0, 1}∗
| x = (01)n , n ≥ 0}
) L3 = {x ∈ {0, 1}∗ |
2.6 b)
ends in 00}
every 0 is immediately followed by 1}
Given the NFA in gure 1, onstrut an equivalent DFA.
0
q1
ǫ
q2
1
q3
q4
ǫ
start
q0
ǫ
ǫ
ǫ
ǫ
q5
q6
ǫ
ǫ
ǫ
q7
0
1
q9
Figure 1: M8
1
q8
ǫ
q10
3.3
Construt an NFA whih aepts the language dened by the regular expression 10 +
(0 + 11)0∗ 1.
6.1
Find CFG's for the following regular expressions:
a) 00(1 + 0)∗ 1
b) 101(101)∗ 010(010)∗
) (11 + 010)∗ 11(00 + 11)∗
Solutions
2.4 a)
An example of a DFA M15 suh that L(M15 ) = L1 is given in gure 2.
1
start
0
q0
q1
1
1
0
q2
0
Figure 2: M15
b)
An example of a DFA M16 suh that L(M16 ) = L2 is given in gure 3.
start
0
q0
q1
1
1
0
q2
0, 1
Figure 3: M16
)
An example of a DFA M17 suh that L(M17 ) = L4 is given in gure 4.
The subset onstrution results in an DFA with reahable states {q0 , q1 , q3 , q5 , q6 , q7 , q10 },
{q2 , q9 , q10 }, {q4 , q10 }, ∅, {q6 , q7 , q8 , q10 }, {q9 }. The initial state is {q0 , q1 , q3 , q5 , q6 , q7 , q10 }.
The nal states are those ontaining q10 .
2.6) b
3.3
By deomposing the regular expression syntatially aording to the reursive denition
of regular expressions, an NFA an be onstruted systematially in a bottom-up fashion
2
1
0
start
q0
q1
0
q2
1
0, 1
Figure 4: M17
by suessively joining NFA:s orresponding to subexpressions aording to the regular
operator (*, onatenation, +) in question. The resulting NFA is shown in gure 5.
q1
ǫ
start
1
q2
ǫ
q0
q3
ǫ
q5
0
0
ǫ
q18
q6
ǫ
q11
ǫ
q4
ǫ
q7
1
ǫ
q8
q12
ǫ
ǫ
ǫ
q9
1
q10
ǫ
q14
Figure 5: M23
6.1
a)
S → 00A1
A → ǫ | 0A | 1A
b)
S → 101A010B
A → ǫ | 101A
B → ǫ | 010B
)
S → A11B
A → ǫ | 11A | 010A
B → ǫ | 00B | 11B
ǫ
q13
3
ǫ
0
q15
q16
1
q17
Download