Uploaded by U W

midterm1-sol

advertisement
CSE303 Midterm 1 Solutions
1. (20 Pts) Design an NFA (non-deterministic finite automata) to accept the set of strings of 0’s and 1’s
that either
(a) end in 010 and have 011 somewhere preceding, or
(b) end in 101 and have 100 somewhere preceding
Solution:
0,1
0
0,1
>
q1
1
1
q2
0
q3
1
q4
0
q5
q6
q0
1
q7
q8
0
q9
0
q10
1
q11
0
1
q13
0,1
2. (15 Pts) Transform the following NFA (note that stands for null-string) into an equivalent DFA
(deterministic finite automata)
q
b
a
r
a
b
> s
t
b
Solution:
b
{t}
a,b
a
{0}
a
a
b
b
{r,t}
{s}
a
^
{q,r,t}
a
b
b
{s,t}
3. (10 Pts) What is the language accepted by the following finite state automata?
3
a
> 1
a
b
2
b
1
b
4
a
5
Solution: a(bb + bba)∗ ba or ab(bb + bab)∗ a
4. (15 Pts) Let Σ = {a, b}. Write regular expression for the language L consisting of all strings in Σ∗
with exactly one occurrence of the substring aaa.
Solution: (b + ab + aab)∗ aaa(baa + ba + b)∗
5. (20 Pts) Construct DFA to accept L = {w ∈ {a, b}∗ | w has an odd number of a’s and an even
number of b’s}. Your construction must be direct, without using NFA.
Solution:
Odd #of a
Even #of b
b
a
a
>
b
Even #of a
Odd #of a
Even #of b
Odd #of b
b
a
a
b
Even #of a
Odd #of b
6. (20 Pts)
(a) Let Σ be a finite alphabet. Prove or disprove that the set Σ∗ of all finite length words (using
letters from Σ) is countable.
Solution:
If Σ is a finite alphabet, the set Σ∗ of all words using
S∞letters from Σ is countably infinite. Note
that Σ is nonempty by definition. Recall that Σ∗ = k=0 Σk where each Σk is finite. Thus Σ∗ is
a countable union of countable sets, and hence Σ∗ itself is countable since the union of countably
many countable sets is countable (Homework 2, Question 3).
(b) Let Σ be an infinite alphabet. Prove or disprove that the set Σ∗ of all finite length words (using
letters from Σ) is countable.
Solution:
For each k ∈ P, the set Σk of all words of length k is in one-to-one correspondence with the product
set Σk = Σ × Σ × . . . × Σ (k times). In fact, the correspondence maps each word a1 a2 . . . ak to the
k-tuple (a1 , a2 , . . . , ak ). So each set Σk is countable
S∞ by Homework 2, Question 4. The 1-element
set Σ0 = {} is countable too. Hence Σ∗ = k=0 Σk is countable since the union of countably
many countable sets is countable (Homework 2, Question 3).
2
Download