Test 1 Solutions

CS 360 Introduction to the Theory of Computing
Test 1 Solutions
1. The following four questions are yes/no questions. In each case, answer “yes” or “no,” and
give a short argument in support of your answer.
(a) Suppose Σ is an alphabet and A ⊆ Σ∗ is a nonempty language satisfying A = AA. Is it
necessarily the case that ε ∈ A?
Solution. Yes. Let
n = min |w| : w ∈ A ,
which is the minimum length of a string in A. This is a well-defined quantity because
A is non-empty. For any string w ∈ A with |w| = n, it is possible to write w = uv for
u, v ∈ A by virtue of the fact that A = AA. This implies
n = |w| = |u| + |v| ≥ 2n.
Because n is a nonnegative integer, we conclude from the fact that n ≥ 2n that n = 0,
which implies that ε ∈ A.
(b) Suppose Σ is any alphabet and A ⊆ Σ∗ is any infinite language. Must there exist a
nonregular language B ⊆ Σ∗ with B ⊆ A?
Solution. Yes. Because A is infinite, there are uncountably many subsets B ⊆ A. As
there are only countably many regular languages over the alphabet Σ, there must exist
a nonregular language B ⊆ A.
(c) Let us say that a string x is obtained from a string w by deleting symbols if it is possible
to remove zero or more symbols from w so that just the string x remains. For example,
the following strings can all be obtained from 0110 by deleting symbols:
ε, 0, 1, 00, 01, 10, 11, 010, 011, 110, and 0110.
Suppose Σ = {0, 1}, A ⊆ Σ∗ is a regular language, and
there exists a string w ∈ A such that x
∗
B= x∈Σ :
.
is obtained from w by deleting symbols
Is it necessarily the case that B is regular?
Solution. Yes. Given a DFA M = ( Q, Σ, δ, q0 , F ) for A, we may obtain an NFA for B
by simply adding one ε-transition to M corresponding to each of its transitions. More
formally, we may take N = ( Q, Σ, η, q0 , F ), where η is defined by
η (q, σ ) = {δ(q, σ )}
η (q, ε) = {δ(q, τ ) : τ ∈ Σ}
for all q ∈ Q and σ ∈ Σ. It holds that L( N ) = B and therefore B is regular.
(d) [2 points] Suppose N is an NFA with n states and alphabet Σ = {0}, and N accepts
every string w ∈ Σ∗ with |w| ≤ n. Is it necessarily the case that L( N ) = Σ∗ ?
Solution. No. For example, the following NFA has 8 states, it accepts every string
w ∈ Σ∗ with |w| ≤ 11, but rejects w = 012 .
q1
0
q2
0
q3
0
q6
ε
0
q0
ε
q4
0
q5
0
q7
0
2. Let Σ = {0, 1} and suppose that A ⊆ Σ∗ is an arbitrarily chosen regular language. Define
three new languages as follows:
B = {w ∈ Σ∗ : there exists a string u ∈ Σ∗ such that uw ∈ A},
C = {w ∈ Σ∗ : there exists a string v ∈ Σ∗ such that wv ∈ A},
D = {w ∈ Σ∗ : there exist strings u, v ∈ Σ∗ such that uwv ∈ A}.
In words, the language B contains every string that is a suffix of a string in A, the language
C contains every string that is a prefix of a string in A, and the language D contains every
string that is a substring of a string in A.
For this problem you will be asked to prove that B, C, and D are all regular languages.
You are free to prove these facts however you choose, but it may help you to make use of
the following observations in your proof (which you do not need to restate as part of your
answer).
Because A is regular, there must exist a DFA M = ( Q, Σ, δ, q0 , F ) such that L( M) = A. Some
of the states in Q are reachable from the start state q0 , by following zero or more transitions
specified by the transition function δ. We may call this set R, so that
R = q ∈ Q : there exists w ∈ Σ∗ such that δ∗ (q0 , w) = q .
Also, from some of the states in Q, it is possible to reach an accept state of M, by following
zero or more transitions specified by the transition function δ. We may call this set P, so that
P = q ∈ Q : there exist w ∈ Σ∗ and r ∈ F such that δ∗ (q, w) = r .
For example, suppose M happened to be the DFA specified by this state diagram:
2
0
0
1
q0
1
q1
q2
1
1
0
1
q3
q4
0, 1
0
0
q5
In this case, the set R of reachable states is R = {q0 , q1 , q2 , q3 } while the set P of states from
which it is possible to reach an accepting state of M is P = {q0 , q1 , q2 , q4 , q5 }.
(Keep in mind that this is just an example—you cannot assume that A is recognized by this
particular DFA.)
(a) Prove that B is regular.
Solution. Define an NFA NB = ( Q ∪ {r0 }, Σ, η, r0 , F ), where the transition function η is
defined as
η (r0 , ε) = R,
η (q, σ) = {δ(q, σ)}
(for each q ∈ Q and σ ∈ Σ),
and η takes the value ∅ in all other cases. In words, we define NB from M by adding a
new start state r0 , along with ε-transitions from r0 to every reachable state in M. It holds
that L( NB ) = B, and therefore B is regular.
(b) Prove that C is regular.
Solution. Define a DFA MC = ( Q, Σ, δ, q0 , P). In words, MC is the same as M except
that its accept states are all of the states in M from which it is possible to reach an accept
state of M. It holds that L( MC ) = C, and therefore C is regular.
(c) Prove that D is regular.
Solution. We may obtain an NFA ND for D by combining the ideas from the two previous answers. Specifically, take MD = ( Q ∪ {r0 }, Σ, η, r0 , P), for η defined precisely as in
part (a). It holds that L( ND ) = D and therefore D is regular.
3
3. Let Σ = {0, 1}, and define a language
E = {u0v : u, v ∈ Σ∗ and |u| = |v|}.
In words, E is the language of all binary strings of odd length whose middle symbol is 0.
Prove that E is not regular.
In case you are inclined to use the pumping lemma when solving this problem, here it is:
Pumping lemma. For every alphabet Σ and every regular language A ⊆ Σ∗ , there exists a
pumping length p ≥ 1 for A that satisfies the following property. For every string w ∈ A
with |w| ≥ p, it is possible to write w = xyz for strings x, y, z ∈ Σ∗ such that
(a) y 6= ε,
(b) | xy| ≤ p, and
(c) xyi z ∈ A for every i ∈ N.
Solution: Assume toward contradiction that E is regular. By the pumping lemma, there
exists a pumping length p ≥ 1 for E with the property described above. Let w = 1 p 01 p .
Given that w ∈ E and |w| = 2p + 1 ≥ p, there must exist strings x, y, z ∈ Σ∗ such that
w = xyz, and for which the above three items (a), (b), and (c) are satisfied (for E in place of
A for item (c)). As y 6= ε and | xy| ≤ p, we conclude that y = 1k for some choice of an integer
k with k ≥ 1. As xyi z ∈ E for every i ≥ 0, we conclude that
1 p+k 01 p = xy2 z ∈ E.
However, the string 1 p+k 01 p is not contained in E, as the only 0 in this string is not in the
middle position (because k ≥ 1). We have therefore derived a contradiction, and thus E is
not regular.
4