Solution to CS 390 Test
July 23, 2003
1. Find a regular expression for each of the following languages over the alphabet {0, 1}:
(a) The language of all strings containing exactly two 1's.
Ans: 0*10*10*
(b) The language of all strings that do not end in 01. [10 each]
Ans: (0 + 1)*(0 + 11) + 1*
2. For the language represented by the regular expression (0*1 + 01*)*,
answer the following questions:
(a) Find a string of the shortest length.
Ans:
(b) Find a string of length 4.
Ans: Any string of 0's and 1's of length 4.
(c) Simplify the regular expression.
Ans: (0 + 1)*
(d) Describe the language in English as simply as possible. [5 each]
Ans: The set of all strings of 0's and 1' including
.
3. Prove that
|ax| = |xa|
by structural (general) induction,
where a is an arbitrary symbol in the alphabet {0, 1}, x is an arbitrary string
over the alphabet and |w| denotes the length of the string w.
Note that |w| is defined recursively as follows:
Basis Clause: || = 0
Inductive Clause: |ax| = |x| + 1 for any string x and a symbol a. [20]
Proof:
Basis Step: x = .
Since |ax| = |x| = |x| = |xa|,
|ax| = |xa|.
Inductive Step: Assume that |ax| = |xa| for an arbitrary string x.
We show that for an arbitrart symbol b of the alphabet, |abx| = |bxa|.
By the definition of |w|, |abx| = |bx| + 1 = |x| + 1 + 1.
Also by the definition of |w|, |bxa| = |xa| + 1.
Since by the induction hypothesis |ax| = |xa|, |bxa| = |xa| + 1 = |ax| + 1
= |x| + 1 + 1.
Hence |abx| = |bxa|.
4 (a) Find an FA
that recognizes the same language as the following NFA and list the accepting states of the FA.
Note that { } below denotes the empty set. [20]
State
|
a
|
b
|
0
|
{1, 2}
|
{ 2 }
|
1
|
{ 3 }
|
{2, 3}
|
2
|
{ 3 }
|
{ }
|
3
|
{ 1 }
|
{ 1 }
|
The initial state is state 0 and the accepting state is state 1.
Ans:
State
|
a
|
b
|
State
|
a
|
b
|
{ 0 }
|
{1, 2}
|
{ 2 }
|
{ 1 }
|
{ 3 }
|
{2, 3}
|
{1, 2}
|
{ 3 }
|
{2, 3}
|
{1, 3}
|
{1, 3}
|
{1, 2, 3}
|
{ 2 }
|
{ 3 }
|
{ }
|
{1, 2, 3}
|
{1, 3}
|
{1, 2, 3}
|
{ 3 }
|
{ 1 }
|
{ 1 }
|
{ }
|
{ }
|
{ }
|
{2, 3}
|
{ 1, 3 }
|
{ 1 }
|
|
|
|
The accepting states are { 1 }, {1, 2}, {1, 3}, {1, 2, 3}.
(b) Find *(0, abb), where is the transition function of the NFA. [5]
Ans: { 1 }.
5. Prove that for an arbitrary string x over the alphabet {a, b}, (xr)r = x, where
xr denotes the reversal of string x.
Note that wr for a string w is defined recursively as follows:
Basis Clause: r =
Inductive Clause: For any arbitrary string x and symbol a, (ax)r = xra. [15]
Proof:
Basis Step: x = .
Since r = ,
(r)r = r
= .
Hence (xr)r = x for x = .
Inductive Step: Assume that (xr)r = x for an arbitrary string x.
We show that for an arbitrary symbol a, ((ax)r)r = ax .
Since by the definition of the reversal (ax)r = xra,
((ax)r)r = (xra)r.
Since (xy)r = yrxr for arbitrary strings x and y,
(xra)r = a((x)r)r
(You can also use (wa)r = awr here).
Since (xr)r = x by the induction hypothesis, a((x)r)r = ax.
Hence ((ax)r)r = ax .