Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Solutions To Sipser

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Introduction to the Theory of Computation Solutions

Ryan Dougherty
2
Contents

3
4 CONTENTS
Chapter 1

Solutions

5
6 CHAPTER 1. SOLUTIONS

1.1 Chapter 1
1.1 The following are the state diagrams of two DFAs, M1 and M2 . Answer the following questions about
each of these machines.
Solution: answered in the text.

1.2 Give the formal description of the machines M1 and M2 pictured in Exercise 1.1.
Solution: answered in the text.

1.3 The formal description of a DFA M is ({q1 , q2 , q3 , q4 , q5 }, {u, d}, δ, q3 , {q3 }), where δ is given by the
following table. Give the state diagram of this machine.

u d
q1 q1 q2
q2 q1 q3
q3 q2 q4
q4 q3 q5
q5 q4 q5

u d
d d d d
q1 q2 q3 q4 q5
Solution: u u u u

1.4 Each of the following languages is the intersection of two simpler languages. In each part, construct
DFAs for the simpler languages, then combine them using the construction discussed in footnote 3
(page 46) to give the state diagram of a DFA for the language given. In all parts, Σ = {a, b}.
Note: for simplicity, I omit the state diagrams.

a. Solution: The state set is Q = {qi,j : 0 ≤ i ≤ 3, 0 ≤ j ≤ 2}, with transition function:


• δ(qi,j , a) = qi+1,j for all 0 ≤ i ≤ 2, 0 ≤ j ≤ 2,
• δ(qi,j , b) = qi,j+1 for all 0 ≤ i ≤ 3, 0 ≤ j ≤ 1.
The start state is q0,0 , and the final state is q3,2 .
b. Solution: answered in the text.
c. Solution: the state set is Q = {qi,j : i ∈ {0, 1, 2, 3}, j ∈ {even, odd}}, with transition function:
• δ(qi,even , a) = qi,odd for all i,
• δ(qi,odd , a) = qi,even for all i,
• δ(qi,j , b) = qi+1,j for i ∈ {0, 1, 2}, j ∈ {even, odd},
• δ(q3,j , b) = q3,j for j ∈ {even, odd}.
d. Solution: answered in the text.
e. Solution: the state set is Q = {ij : i, j ∈ {0, 1, 2}}, with transition function in ??.
f. Solution: the state set is Q = {ij : i, j ∈ {0, 1}}, with transition function in ??.
g. Solution: the state set is Q = {ij : i, j ∈ {0, 1}}, with transition function in ??.

1.5 Each of the following languages is the complement of a simpler languages. In each part, construct
DFAs for the simpler language, then use it to give the state diagram of a DFA for the language given.
In all parts, Σ = {a, b}.
Note: for simplicity, I omit the state diagrams.

a. Solution: answered in the text.


1.1. CHAPTER 1 7

State ↓ Symbol → a b
00 (start) 10 21
01 11 22
02 12 22
10 (final) 10 11
11 (final) 11 12
12 12 12
20 20 21
21 21 22
22 22 22

Table 1.1: 1.4e state table.

State ↓ Symbol → a b
00 (start) 01 10
01 00 11
10 01 00
11 (final) 00 01

Table 1.2: 1.4f state table.

b. Solution: answered in the text.


1.6 Give state diagrams of NFAs with the specified number of states recognizing each of the following
languages. In all parts, the alphabet is {0, 1}.
a. Solution: answered in the text.
f. Solution: answered in the text.
1.7 Each of the following languages is the complement of a simpler language. In each part, construct a
DFA for the simpler language, then use it to give the state diagram of a DFA for the language given.
In all parts, Σ = {a, b}.
a. Solution: answered in the text.
b. Solution: answered in the text.
1.11 Prove that every NFA can be converted to an equivalent one that has a single accept state.
Solution: answered in the text.
1.20 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.
a. Solution: 2 members: ab, aa; 2 not members: ba, bab.
b. Solution: 2 members: ab, abab; 2 not members: b, ba.
c. Solution: 2 members: aa, bb; 2 not members: ba, ab.
d. Solution: 2 members: , aaa; 2 not members: b, bb.
e. Solution: 2 members: aba, aaba; 2 not members: b, bb.

State ↓ Symbol → a b
00 (start) 11 10
01 (final) 10 11
10 01 00
11 00 01

Table 1.3: 1.4g state table.


8 CHAPTER 1. SOLUTIONS

f. Solution: 2 members: aba, bab; 2 not members: a, b.


g. Solution: 2 members: b, ab; 2 not members: ba, bb.
h. Solution: 2 members: a, ba; 2 not members: ab, b.
1.23 Let B be any language over the alphabet Σ. Prove that B = B + iff BB ⊆ B.
Solution: answered in the text.
1.29 Use the pumping lemma to show that the following languages are not regular.
a. Solution: answered in the text.
b. Solution: A2 = {www | w ∈ {a, b}∗ }. Suppose that A2 were regular, and let p be the constant for
A2 as given by the pumping lemma. Then, let s = ap bap bap b ∈ A2 . Therefore, we can decompose s
as xyz, where |xy| ≤ p, |y| > 0, and xy i z ∈ A2 for ∀i ∈ N. Since |xy| ≤ p, x, y consist entirely of a’s;
therefore, we can write x = ac , y = ad , and z = ap−c−d bap bap b, where c ≥ 0, d > 0, p − c − d ≥ 0.
For the third condition, choose i = 2: w = xy 2 z = ac a2d ap−c−d bap bap b = ap+d bap bap b. Since
d > 0, w ∈/ A2 : therefore, we have a contradiction, and A2 is not regular.
c. Solution: answered in the text.
1.31 For any string w = w1 w2 · · · wn , the reverse of w, written wR , is the string w in reverse order,
wn · · · w2 w1 . For any language A, let AR = {wR |w ∈ A}. Show that if A is regular, so is AR .
Solution: For any regular language A, let M = (Q, Σ, δ, q0 , F ) be the DFA recognizing A. We need
to construct an NFA/DFA N such that L(N ) = AR . Let N = (Q0 , Σ, δ 0 , q00 , {q0 }), where q00 ∈ / Q and
Q0 = Q ∪ {q00 }. Define δ 0 as: δ 0 (q00 , ) = F , and δ 0 (q00 , a) = ∅, ∀a ∈ Σ. Also, ∀(q, a) ∈ Q × Σ, δ 0 (q, a) =
{q 0 |δ(q 0 , a) = q}.
Another way to approach this problem is an informal explanation: we reverse all of the transitions of
M , and set the accept state of N to be M ’s start state. Also, introduce a new state q00 as N ’s start
state, which goes to every accept state in M by an -transition.
1.39 The construction in Theorem 1.54 shows that every GNFA is equivalent to a GNFA with only two
states. We can show that an opposite phenomenon occurs for DFAs. Prove that for every k > 1, a
language Ak ⊆ {0, 1}∗ exists that is recognized by a DFA with k states but not by one with only k − 1
states.
Solution: let Lk = {0i | i ≥ k − 1}. This language consists of strings of length ≥ k − 1. Therefore, no
DFA of k − 1 states can recognize this language, but certainly one of k states can.
1.40 Recall that string x is a prefix of string y if a string z exists where xz = y, and that x is a proper
prefix of y if in addition x 6= y. In each of the following parts, we define an operation on a language
A. Show that the class of regular languages is closed under that operation.
a. Solution: answered in the text.
1.42 For languages A and B, let the shuffle of A and B be the language {w | w = a1 b1 ...ak bk , where
a1 ...ak ∈ A and b1 ...bk ∈ B, each ai , bi ∈ Σ∗ }. Show that the class of regular languages is closed under
shuffle.
Solution: Let DA = (QA , Σ, δA , qA , FA and DB = (QB , Σ, δB , qB , FB be the DFAs recognize A and
B, respectively. We will design a DFA D = (Q, Σ, δ, q0 , F ) such that it recognizes the shuffle of A and
B as follows:
• Q = QA × QB × {A, B}.
• q0 = (qA , qB , A).
• F = FA × FB × {A}.
• For δ:
– δ((x, y, A), a) = (δA (x, a), y, B).
– δ((x, y, B), b) = (x, δB (y, b), A).
1.1. CHAPTER 1 9

1.44 Let B and C be languages over Σ = {0, 1}. Define

1
B←
− C = {w ∈ B| for some y ∈ C, strings w and y contain equal numbers of 1s}.

1
Show that the class of regular languages is closed under the ←
− operation.
Solution: answered in the text.
1.45 Let A/B = {w|wx ∈ A for some x ∈ B}. Show that if A is regular and B is any language, then A/B
is regular.
Solution: Let M = (Q, Σ, δ, q0 , F ) be a DFA such that L(M ) = A, and Σ is the union of the alphabets
of A and B. Let Fr = {q ∈ Q|∃x ∈ B such that M can reach a final state when having read x, starting
at q}. Therefore, L(M ) = A/B.
1.48 Let Σ = {0, 1} and let

D = {w|w contains an equal number of occurrences of the substrings 01 and 10}.

Thus 101 ∈ D because 101 contains a single 01 and a single 10, but 1010 ∈ / D because 1010 contains
two 10s and one 01. Show that D is a regular language.
Solution: D is just precisely described by the regular expression (1+ 0∗ 1+ )∗ ∪ (0+ 1∗ 0+ )∗
1.50 Read the informal definition of the finite state transducer given in Exercise 1.24. Prove that no FST
can output wR for every input w if the input and output alphabets are {0, 1}.
Solution: answered in the text.
1.52 Myhill-Nerode theorem. Refer to Problem 1.51. Let L be a language and let X be a set of strings.
Say that X is pairwise distinguishable by L if every two distinct strings in X are distinguishable
by L. Define the index of L to be the maximum number of elements in any set that is pairwise
distinguishable by L. The index of L may be finite or infinite.
Solution: answered in the text.
1.53 Let Σ = {0, 1, +, =} and ADD = { x = y + z | x, y, z are binary integers, and x is the sum of y and
z}. Show that ADD is not regular.
Solution: Assume that ADD is regular. Therefore, there exists a pumping length p ∈ Z such that the
three conditions of the Pumping Lemma are satisfied. Choose w as 1p = 0p + 1p . Clearly, w ∈ ADD.
By the conditions of the Pumping Lemma, we can partition w = xyz such that |xy| ≤ p, |y| > 0, and
xy i z ∈ ADD for ∀i ∈ N. By the first and second conditions of the Pumping Lemma, x and y consist
entirely of 1s, i.e. x = 1a , y = 1b , z = 1p−a−b = 0p + 1p for a ≥ 0, b > 0. By the third condition,
xy i z ∈ ADD for ∀i ∈ N. Choose i = 2: xy 2 z = 1a 12b 1p−a−b = 0p + 1p = 1p+b = 0p + 1p . However,
this string is not in ADD, because this implies p + b = p, but b > 0, a contradiction. Therefore, ADD
is not regular.
1.55 The pumping lemma says that every regular language has a pumping length p, such that every string
in the language can be pumped if it has length p or more. If p is a pumping length for language A, so
is any length p0 ≥ p. The minimum pumping length for A is the smallest p that is a pumping length
for A. For example, if A = 01∗ , the minimum pumping length is 2. The reason is that the string s = 0
is in A and has length 1 yet s cannot be pumped; but any string in A of length 2 or more contains
a 1 and hence can be pumped by dividing it so that x = 0, y = 1, and z is the rest. For each of the
following languages, give the minimum pumping length and justify your answer.
a. 0001∗
Solution: answered in the text.
b. 0∗ 1∗
Solution: answered in the text.
c. 001 ∪ 0∗ 1∗
Solution: We cannot pump 001, so the minimum pumping length is 4.
10 CHAPTER 1. SOLUTIONS

d. 0∗ 1+ 0+ 1∗ ∪ 10∗ 1
Solution: answered in the text.
e. (01)∗
Solution: We cannot pump , so the minimum pumping length is 1 (if we wanted to be construc-
tive, the answer would be 2, since there is no string of length 1 here).
g. 1∗ 01∗ 01∗
Solution: We cannot pump 00, but we can for 100, so the minimum pumping length is 3.

1.58 If A is any language, let A 13 − 31 be the set of all strings in A with their middle thirds removed so that

A 13 − 31 = {xz | for some y, |x| = |y| = |z| and xyz ∈ A}.

Show that if A is regular, then A 31 − 31 is not necessarily regular.


Solution: Let A = {0∗ #1∗ }, which is regular. Therefore, A 13 − 31 ∩ {0∗ 1∗ } = {0n 1n | n ≥ 0} is
also regular since regular languages are closed under intersection, and {0∗ 1∗ } is a regular language.
However, the resulting language is not regular, so therefore A 13 − 31 is not necessarily regular when A is.

1.63 (a) Let A be an infinite regular language. Prove that A can be split into two infinite disjoint regular
subsets.
Solution: since A is infinite and regular, then the conditions of the Pumping Lemma for Regular
Languages hold, i.e., that there is a p ≥ 0 such that for all w ∈ A, we can partition w into w = xyz
that satisfy those 3 conditions. Consider A0 = {xy 2i z | i ≥ 0}, and A00 = L ∩ A0 . These are the
desired languages because they partition A and are infinite.
(b) Let B and D be two languages. Write B b D if B ⊆ D and D contains infinitely many strings
that are not in B. Show that if B and D are two regular languages where B b D, then we can
find a regular language C where B b C b D.
Solution: Let L = D ∩ B; L is regular by the closure operations, and is infinite. By the Pumping
Lemma for Regular Languages, there is a w ∈ L such that w = xyz such that |y| > 0, and for all
i ≥ 0, xy i z ∈ L. Let C = B ∪ {xy i z ∈ L | i is even}. Call the second language L0 . We can see
that C is regular. Since L0 ∩ B is infinite, we have B b C. By a similar analysis, we have C b D.

1.70 We define the avoids operation for languages A and B to be

A avoids B = {w | w ∈ A and w doesn’t contain any string in B as a substring}.

Prove that the class of regular languages is closed under the avoids operation.
Solution: The idea is to find a regular language that has strings in B as a substring, and remove
from A this language. Therefore, define Lsubstr = Σ∗ BΣ∗ . Clearly, Lsubstr is regular because it is
the concatenation of 2 regular languages. Since regular languages are closed under complement and
intersection, then A \ Lsubstr = A ∩ Lsubstr is also regular. But these are precisely the strings that are
in A that are not in Lsubstr , which is what we want.

1.72 Let M1 and M2 be DFAs that has k1 and k2 states, respectively, and then let U = L(M1 ) ∪ L(M2 ).

a. Show that if U 6= ∅, then U contains some string s, where |s| < max(k1 , k2 ).
Solution: Consider a DFA D = (Q, Σ, δ, q0 , F ) such that L(D) 6= ∅. Therefore, if the final state is
reachable, transitioning from D’s start state to a final state requires at most |Q| − |F | transitions.
Since U 6= ∅, then either L(M1 ) 6= ∅ or L(M2 ) 6= ∅ (or both). We have the following cases:
1. L(M1 ) = ∅, L(M2 ) 6= ∅. This implies that M1 has no reachable accept states, and M2 has
at least one reachable accept state. Also, U = L(M2 ). From our observation above, if M2
accepts a string s, then |s| ≤ k2 − |F2 | < k2 ≤ max(k1 , k2 ) where F2 is the set of accept states
of M2 . Therefore, s ∈ L(M2 ) = U .
2. L(M1 ) 6= ∅, L(M2 ) = ∅. This is equivalent to Case 1.
1.1. CHAPTER 1 11

3. L(M1 ), L(M2 ) 6= ∅. Therefore, M1 and M2 have at least one reachable accept state. Let s1
be the string of minimal length accepted by M1 , and s2 for M2 . Let s ∈ U be such that
|s| = min(|s1 |, |s2 |). We have the following 2 cases:
3.1. |s1 | =
6 |s2 |. This implies |s| = min(|s1 |, |s2 |) < max(|s1 |, |s2 |). There are two possibilities.
If max(|s1 |, |s2 |) = |s1 |, then |s| = |s2 | < |s1 | < k1 ≤ max(k1 , k2 ). Therefore, we are done.
The same conclusion is reached if we consider when max(|s1 |, |s2 |) = |s2 |.
3.2. |s1 | = |s2 . This implies |s| = min(|s1 |, |s2 |) = max(|s1 |, |s2 |). From our observation above,
we have that |s| = min(|s1 |, |s2 |) = max(|s1 |, |s2 |) = |s1 | < k1 ≤ max(k1 , k2 ). Therefore,
we are done.
b. Show that if U 6= Σ∗ , then U excludes some string s, where |S| < k1 k2 .
Solution: Let D = (Q, Σ, δ, q0 , F ) be a DFA such that L(D) = U = L(M1 ) ∪ L(M2 ). Suppose
(to the contrary) that all strings s ∈ U are such that |s| < k1 k2 . Also, suppose there exists a
non-accepting state q ∈ Q. Therefore, there cannot exist a sequence of states q1 , · · · , qk1 k2 in D
such that running D on s would have q in this sequence:
1. q1 = q0 .
2. δ(qi , x) = qi+1 for 1 ≤ i ≤ k1 k2 − 1 and for all x ∈ Σ.
6 qk for j 6= k.
3. qj =
If q were in this sequence, then q would be an accepting state. However, this implies that D has
k1 k2 + 1 distinct states, and D has only k1 k2 states, a contradiction. Therefore, either q is not
reachable from q0 , or q does not exist.

Since q is an arbitrary non-accepting state of D, the only states reachable from q0 are accepting
states. Now, we prove by induction that all strings of length ≥ k1 k2 are accepted by D.

Basis step: from above, D accepts any string of length k1 k2 − 1 < k1 k2 . Let s ∈ Σ∗ such
that |s| = k1 k2 − 1. Therefore, δ ∗ (q0 , s) must result in an accepting state. Let r be this state.
Therefore, δ(q, w) for all w ∈ Σ must result in an accepting state, since all reachable states from
q0 are accepting states. Therefore, D must accept any string s ∈ Σ∗ such that |s| = k1 k2 .

Inductive Hypothesis: assume that D accepts any string s ∈ Σ∗ such that |s| = k1 k2 + n for
some n ∈ N.

Inductive Step: By the IH, δ ∗ (q0 , s) must result in an accepting state for all s ∈ Σ∗ such that
|s| = k1 k2 + n for some n ∈ N. Let the accept state be r. For all w ∈ Σ, δ(q, w) results in an
accepting state. It follows that D accepts all s ∈ Σ∗ such that |s| = k1 k2 + n + 1. Now, we showed
that D accepts all s ∈ Σ∗ such that |s| ≥ k1 k2 . From earlier, we showed that D accepts all t ∈ Σ∗
such that |t| < k1 k2 .

Therefore, L(D) = U = Σ∗ . However, this is a contradiction to our assumption. Therefore,


U excludes some string s where |s| < k1 k2 .
12 CHAPTER 1. SOLUTIONS

1.2 Chapter 2
2.3 Answer each part for the following context-free grammar G.

R → XRX|S
S → aT b|bT a
T → XT X|X|
X → a|b

Solution: answered in the text.


2.7 Give informal English descriptions of PDAs for the languages in Exercise 2.6.
Solution: answered in the text.
2.8 Show that the string the girl touches the boy with the flower has two different leftmost deriva-
tions in grammar G2 on page 103. Describe in English the two different meanings of this sentence.
Solution: answered in the text.
2.9 Give a context-free grammar that generates the language

A = {ai bj ck | i = j or j = k where i, j, k ≥ 0}

Is your grammar ambiguous? Why or why not?


Solution: construct a CFG G = (S, A, B, C, D}, {a, b, c}, R, S) with the rules:

S → BC | AD
B → aBb | 
C → cC | 
A → aA | 
D → bDc | 

Yes it is ambiguous. Choose the word abc. The two derivations are:
(a) S → BC → aBbC → abC → abcC → abc,
(b) S → AD → aAD → aD → abDc → abc.
2.18 a. Let C be a context-free language and R be a regular language. Prove that the language C ∩ R is
context free.
Solution: answered in the text.
b. Let A = {w | w ∈ {a, b, c}∗ and w contains equal numbers of a?s, b?s, and c’s}. Use part (a) to
show that A is not a CFL.
Solution: answered in the text.
2.24 Let E = {ai bj |i 6= j and 2i 6= j}. Show that E is a context-free language.
Solution: This is a partition of 3 languages: L1 , L2 , L3 (i.e., it is their union). They are defined as
follows:
• L1 = {ai bj |i > j},
• L2 = {ai bj |i < j and 2i > j},
• L3 = {ai bj |2i < j}.
It suffices to show that L1 , L2 , L3 are all context-free languages. They are due to the following gram-
mars:
L1 :
1.2. CHAPTER 2 13

• S → aSb|aA,
• A → aA|
L2 :
• S → aAb,
• A → aAb|aAbb|abb.
L3 :
• S → aSbb|Ab,
• A → Ab|

2.30 Use the pumping lemma to show that the following languages are not context free.
b. Solution: answered in the text.
c. Solution: answered in the text.
2.38 Refer to Problem 1.41 for the definition of the perfect shuffle operation. Show that the class of context-
free languages is not closed under perfect shuffle.
Solution: answered in the text.
2.52 Show that every DCFG generates a prefix-free language.
Solution: answered in the text.
14 CHAPTER 1. SOLUTIONS

1.3 Chapter 3
3.1 This exercise concerns TM M2 , whose description and state diagram appear in Example 3.7. In each
of the parts, give the sequence of configurations that M2 enters when started on the indicated input
string.

a. 0. Solution: q1 0 → tq2 t → ttqaccept .


b. 00. Solution: answered in the text.
c. 000. Solution: q1 000 → tq2 00 → txq3 0 → tx0q4 t → tx0tqreject .
d. 000000. Solution: q1 000000 → tq2 00000 → txq3 0000t → tx0q4 000 → tx0xq3 00 → tx0x0q4 0 →
tx0x0xq3 t → tx0x0q5 xt → tx0xq5 0xt → tx0q5 x0xt → txq5 0x0xt → tq5 x0x0xt →
q5 tx0x0xt → tq2 x0x0xt → txq2 0x0xt → txxq3 x0xt → txxxq3 0xt → txxx0q4 xt →
txxx0xq4 t → txxx0xtqreject .

3.2 This exercise concerns TM M1 , whose description and state diagram appear in Example 3.9. In each
of the parts, give the sequence of configurations that M1 enters when started on the indicated input
string.

a. 11. Solution: answered in the text.


b. 1#1. Solution: q1 1#1 → xq3 #1 → x#q5 1 → xq6 #x → q7 x#x → xq1 #x → x#q8 x →
x#q8 t → x#xtqaccept t.
c. 1##1. Solution: q1 1##1 → xq3 ##1 → x#q5 #1 → x##qreject 1.
d. 10#11. Solution: q1 10#11 → xq3 0#11 → x0q3 #11 → x0#q5 11 → x0q6 #x1 → xq7 0#x1 →
q7 x0#x1 → xq1 0#x1 → xxq2 #x1 → xx#q4 x1 → xx#xq4 1 → xx#x1qreject t.
e. 10#10. Solution: q1 10#10 → xq3 0#10 → x0q3 #10 → x0#q5 10 → x0q6 #x0 → xq7 0#x0 →
q7 x0#x0 → xq1 0#x0 → xxq2 #x0 → xx#q4 x0 → xx#xq4 0 → xx#q6 xx → xxq6 #xx →
xq7 x#xx → xq7 x#xx → xxq1 #xx → xx#q8 xx → xx#xq8 x → xx#xxq8 t → xx#xxtqaccept t.

3.3 Modify the proof of Theorem 3.16 to obtain Corollary 3.19, showing that a language is decidable iff
some nondeterministic Turing machine decides it. (You may assume the following theorem about trees.
If every node in a tree has finitely many children and every branch of the tree has finitely many nodes,
the tree itself has finitely many nodes.)
Solution: answered in the text.

3.5 Examine the formal definition of a Turing machine to answer the following questions, and explain your
reasoning.
Solution: answered in the text.

3.6 In Theorem 3.21, we showed that a language is Turing-recognizable iff some enumerator enumerates it.
Why didn?t we use the following simpler algorithm for the forward direction of the proof? As before,
s1 , s2 , · · · is a list of all strings in Σ∗ .
E = “Ignore the input.

(a) Repeat the following for i = 1, 2, 3, · · · .


(b) Run M on si .
(c) If it accepts, print out si.”

Solution: The second step might run forever, and therefore E may not move onto the next string.

3.7 Explain why the following is not a description of a legitimate Turing machine.
Mbad = “On input hpi, a polynomial over variables x1 , · · · , xk :

(a) Try all possible settings of x1 , · · · , xk to integer values.


(b) Evaluate p on all of these settings.
1.3. CHAPTER 3 15

(c) If any of these settings evaluates to 0, accept; otherwise, reject.”


Solution: it’s not a valid description because the machine will never halt, and the first step alone will
take infinite time.
3.10 Say that a write-once Turing machine is a single-tape TM that can alter each tape square at
most once (including the input portion of the tape). Show that this variant Turing machine model is
equivalent to the ordinary Turing machine model. (Hint: As a first step, consider the case whereby
the Turing machine may alter each tape square at most twice. Use lots of tape.)
Solution: answered in the text.
3.11 A Turing machine with doubly infinite tape is similar to an ordinary Turing machine, but its
tape is infinite to the left as well as to the right. The tape is initially filled with blanks except for the
portion that contains the input. Computation is defined as usual except that the head never encounters
an end to the tape as it moves leftward. Show that this type of Turing machine recognizes the class of
Turing-recognizable languages.
Solution: we simulate a doubly-infinite TM with an ordinary one with 2 tapes (which is equivalent
to single-tape TMs). The first tape starts with the input string, and the second is blank. Cut the
doubly-infinite tape into 2 parts, at the start of the input string, and these two parts are the same as
the two tapes.
3.12 A Turing machine with left reset is similar to an ordinary Turing machine, but the transition
function has the form
δ : Q × Γ → Q × Γ × {R, RESET}
If δ(q, a) = (r, b, RESET), when the machine is in state q reading an a, the machine?s head jumps to
the left-hand end of the tape after it writes b on the tape and enters state r. Note that these machines
do not have the usual ability to move the head one symbol left. Show that Turing machines with left
reset recognize the class of Turing-recognizable languages.
Solution: Let M be a TM. We will construct a TM with left-reset L as follows:
L = “On input w:
(a) If q is a halting (i.e., accept or reject) state, go to step d. Otherwise, execute Steps b or c
depending on whether the current transition is right or left.
(b) If the current transition is right:
i. For the current tape symbol s, and for δ(q, a) = (q 0 , b, R), replace the a with a b and then
RESET.
ii. Scan right for a marked symbol - if there are none, RESET and mark the first symbol. Then,
move the head to the right, change L’s state to q 0 , and go back to step a. If there is a marked
symbol, move the tape head right.
iii. Mark the symbol under the tape head, move right, and change L’s state to be q 0 . Then, go
back to step a.
(c) If the current transition is left:
i. If δ(q, a) = (q 0 , b, L), replace the a with b and then RESET.
ii. If the first symbol is marked, remove the mark, and then RESET. Also, change L’s state to
be q 0 and go back to step a.
iii. Scan right for a marked symbol - if there are none, reject w. Otherwise, if one is found,
RESET and mark the first symbol.
iv. If the next symbol is marked, unmark it and RESET. Also, move right and change L’s state
to be q 0 , and go back to step a.
v. If the second symbol is not marked:
A. RESET, move right to the first marked cell, and unmark it and move right again.
B. Mark the current tape cell and move right again.
C. If the current tape cell is unmarked, go back to A. Otherwise, unmark it and RESET.
16 CHAPTER 1. SOLUTIONS

D. Move right to the first marked cell. Move right and change L’s state to q 0 and go back to
step a.
(d) If q 0 is an accept state, then accept w; otherwise, reject w.”
3.15 Show that the collection of decidable languages is closed under the operation of

a. union. Solution: answered in the text.


3.16 Show that the collection of Turing-recognizable languages is closed under the operation of
a. union. Solution: answered in the text.
3.18 Show that a language is decidable iff some enumerator enumerates the language in the standard string
order.
Solution: let the language be L. If L is decidable, then we can just generate strings in lexicographic
order, and test if each is in L, thus generating an enumerator that prints in standard string order. If
we have such an enumerator E:
(a) If L is finite, then just hardwire each of the strings in L in E.
(b) If L is infinite, then on an input w, run E to print all strings in standard string order until a
string lexicographically after w appears; if w has appeared, accept; otherwise, reject.
3.22 Let A be the language containing only the single string s, where s = 0 if life never will be found
on Mars, and s = 1 if life will be found on Mars someday. Is A decidable? Why or why not? For
the purposes of this problem, assume that the question of whether life will be found on Mars has an
unambiguous YES or NO answer.
Solution: answered in the text.
1.4. CHAPTER 4 17

1.4 Chapter 4
4.2 Consider the problem of determining whether a DFA and a regular expression are equivalent. Express
this problem as a language and show that it is decidable.
Solution: We formulate the problem EQDF A,REX = {〈A, R〉 | A is a DFA, R is a regular expression,
and L(A) = L(R)}. We will design a TM T that decides EQDF A,REX :
T = “On input 〈A, R〉 where A is a DFA, R is a regular expression:

1. Use Theorem 1.54 to convert R into an equivalent DFA B. Therefore, L(B) = L(R).
2. Run EQDF A on input 〈A, B〉. Output what EQDF A outputs.”

Since EQDF A is decidable, and the conversion from regular expressions to DFAs takes finite time,
EQDF A,REX is decidable.

4.3 Let ALLDF A = {〈A〉 | A is a DFA and L(A) = Σ∗ }. Show that ALLDF A is decidable.
Solution: We will design a TM T that decides ALLDF A :
T = “On input 〈A〉 where A is a DFA:

1. Construct a DFA B such that L(B) = L(A).


2. Run EDF A on input 〈B〉. Output what EDF A outputs.”

Since EDF A is decidable, ALLDF A is decidable.

4.4 Let ACF G = {〈G〉 | G is a CFG that generates .}. Show that ACF G is decidable.
Solution: We will design a TM T that decides ACF G :
T = “On input 〈G〉 where G is a CFG:

1. Convert G into an equivalent CFG C = (V, Σ, R, S) in Chomsky Normal Form.


2. Accept 〈G〉 if C includes the rule S → , reject 〈G〉 otherwise.”

Since converting a CFG into CNF is decidable, ACF G is decidable.

4.7 Let B be the set of all infinite sequences over {0, 1}. Shat that B is uncountable using a proof by
diagonalization.
Solution: Suppose (by contradiction) that B is countable. Therefore, there exists a bijection f
between B and N. For ∀n ∈ N, let f (n) = sn1 ...snk , where snk is the kth bit in the nth sequence of B
for ∀k ∈ N. Define t = t1 t2 ... be an infinite sequence over {0, 1} such that tk = |skk − 1| for ∀k ∈ N.
Therefore, t ∈ B by construction. We can see that @x ∈ {0, 1} such that x = |1 − x|. Therefore, for
∀k ∈ N, tk 6= |skk − 1|. This implies that in at least 1 bit, t is different than all other sequences in B
because of t’s construction, which involves all other sequences in B. This implies for ∀n ∈ N, f (n) 6= t,
a contradiction. Therefore, B is uncountable.

4.10 Let IN F IN IT EDF A = {〈M 〉 | M is a DFA and L(M ) is an infinite language}. Show that IN F IN IT EDF A
is decidable.
Solution: answered in the text.

4.11 Let IN F IN IT EP DA = {〈M 〉 | M is a PDA and L(M ) is an infinite language}. Show that IN F IN IT EP DA
is decidable.
Solution: We will design a TM T that decides IN F IN IT EP DA :
T = “On input 〈M 〉 where M is a PDA:

1. Construct an equivalent CFG G from M .


2. Convert G into an equivalent CFG C = (V, Σ, R, S) in Chomsky Normal Form.
+
3. Accept 〈M 〉 if there exists a derivation A =
⇒ uAv for some u, v ∈ Σ∗ . Otherwise, reject 〈M 〉.

Since all of the algorithms in this machine are decidable, IN F IN IT EP DA is decidable.


18 CHAPTER 1. SOLUTIONS

4.12 Let A = {〈M 〉 | M is a DFA that doesn’t accept any string containing an odd number of 1s}. Show
that A is decidable.
Solution: answered in the text.

4.13 Let A = {〈R, S〉 | R and S are regular expressions and L(R) ⊆ L(S)}. Show that A is decidable.
Solution: We will design a TM T that decides A:
T = “On input 〈R, S〉 where R and S are regular expressions:

1. Construct a DFA B such that L(B) = L(S) ∩ L(R).


2. Run EDF A on input 〈B〉. Output what EDF A outputs.”

Since EDF A is decidable, A is decidable. This construction is correct because L(R) ⊆ L(S) ⇔ L(S) ∩
L(R) = ∅.

4.14 Let Σ = {0, 1}. Show that the problem of determining whether a CFG generates some string in 1∗ is
decidable. In other words, show that

{〈G〉 | G is a CFG over {0, 1} and 1∗ ∩ L(G) 6= ∅}

is a decidable language.
Solution: answered in the text.

4.15 Show that the problem of determining whether a CFG generates all strings in 1* is decidable. In other
words, show that {〈G〉 | G is a CFG over {0, 1} and 1∗ ⊂ L(G)} is a decidable language.
Solution: Let f be a computable function. Construct a decider D:
D = “On input 〈G〉 where G is a CFG:

1. Convert G into an equivalent CFG C in Chomsky Normal Form.


2. Let p be the pumping length of C.
3. Repeat 0 ≤ i ≤ p + p!:
a. Check whether 1i ∈ L(C).
b. If not, reject 〈G〉.
4. Accept 〈G〉.

We can check 1i ∈ L(C) using the Cocke-Younger-Kasami (CYK) algorithm for CFGs, which has a
running time of Θ(n3 |G|). Therefore, the loop has a running time of Θ(pn3 |G|). Since Steps 1, 2, 3,
and 4 take finite time, this language is decidable.

4.23 Say that an NFA is ambiguous if it accepts some string along two different computation branches. Let
AM BIGN F A = {〈N 〉 | N is an ambiguous NFA}. Show that AM BIGN F A is decidable. (Suggestion:
One elegant way to solve this problem is to construct a suitable DFA and then run EDF A on it.)
Solution: answered in the text.

4.24 A useless state in a pushdown automaton is never entered on any input string. Consider the problem
of determining whether a pushdown automaton has any useless states. Formulate this problem as a
language and show that it is decidable.
Solution: Let UP DA = {〈P 〉 | P is a PDA that has useless states}. We will design a TM T that
decides UP DA . First, we will define the problem EP DA = {〈P 〉 | P is a PDA and L(P ) = ∅}. We now
show that EP DA is decidable with a decider D:
D = “On input 〈P 〉 where P is a PDA:

1. Convert P into an equivalent CFG G.


2. Run ECF G on input 〈G〉. Output what ECF G outputs.”

This language is decidable because all steps in its construction take finite time, and ECF G is a decider.
T = “On input 〈P 〉 where P = (Q, Σ, Γ, δ, q0 , Z, F ) is a PDA:
1.4. CHAPTER 4 19

1. For ∀q ∈ Q:
a. Modify P such that F = {q}.
b. Run EP DA on input 〈P 〉. If EP DA accepts, accept 〈P 〉.
2. Reject 〈P 〉.”
Since EP DA is decidable, UP DA is decidable.
4.25 Let BALDF A = {〈M 〉 | M is a DFA that accepts some string containing an equal number of 0s and
1s}. Show that BALDF A is decidable. (Hint: Theorems about CFLs are helpful here.)
Solution: answered in the text.
20 CHAPTER 1. SOLUTIONS

1.5 Chapter 5
5.5 Show that AT M is not mapping reducible to ET M . In other words, show that no computable function
reduces AT M to ET M . (Hint: Use a proof by contradiction, and facts you already know about AT M
and ET M .)
Solution: answered in the text.

5.6 Show that ≤m is a transitive relation.


Solution: answered in the text.

5.7 Show that if A is Turing-recognizable and A ≤m A, then A is decidable.


Solution: answered in the text.

5.8 In the proof of Theorem 5.15, we modified the Turing machine M so that it never tries to move its
head off the left-hand end of the tape. Suppose that we did not make this modification to M . Modify
the PCP construction to handle this case.
Solution: answered in the text.

5.10 Consider the problem of determining whether a two-tape Turing machine ever writes a nonblank symbol
on its second tape when it is run on input w. Formulate this problem as a language and show that it
is undecidable.
Solution: answered in the text.

5.11 Consider the problem of determining whether a two-tape Turing machine ever writes a nonblank symbol
on its second tape during the course of its computation on any input string. Formulate this problem
as a language and show that it is undecidable.
Solution: answered in the text.

5.13 A useless state in a Turing machine is one that is never entered on any input string. Consider the
problem of determining whether a Turing machine has any useless states. Formulate this problem as
a language and show that it is undecidable.
Solution: Let U SELESST M = {〈M, q〉 | q is a useless state in M }. Suppose that U SELESST M was
decidable, and let U be its decider. We will construct a decider E for ET M :
E = “On input 〈M 〉 where M is a TM:

1. Run U on 〈M, qaccept 〉, where qaccept is M ’s accept state.


2. Output what U outputs.

Since ET M is undecidable, U SELESST M is also undecidable.

5.17 Show that the Post Correspondence Problem is decidable over the unary alphabet Σ = {1}.
Solution: Since Σ = {1}, there is only a difference in the number of 1s on the top of each domino
compared to the bottom. We will construct a decider D that decides PCP for a unary alphabet:
D = “On input a collection of dominos:

1. If any domino has the same number of 1s on the top and bottom, accept.
2. If all dominos have more 1s on the top than the bottom, or more 1s on the bottom than the top,
reject.
3. Let d1 be one domino with c1 more 1s on the top than the bottom, and d2 be another domino
with c2 more 1s on the bottom than the top.
4. Choose c2 of the d1 domino, and c1 of the d2 domino.

Step 4 guarantees a match. Let d1 have t1 1s on the top, and t1 − c1 1s on the bottom. Let d2 have t2
1s on the top and t2 + c2 . Choosing c2 of the d1 domino and c1 of the d2 domino yields c2 × t1 + c1 × t2
1s on the top, and c2 × (t1 − c1 ) + c1 × (t2 + c2 ) = c2 × t1 + c1 × t2 1s on the bottom, which is a match.
1.5. CHAPTER 5 21

5.24 Let J = {w| either w = 0x for some x ∈ AT M , or w = 1y for some y ∈ AT M }. Show that neither J
nor J is Turing-recognizable.
Solution: let L1 = {hM, xi|M is a TM and M does not accept x}. We can see AT M ≤m L1 . We
show L1 ≤m J with the following reduction: on input w, output 1w. We have that w ∈ L1 if and only
if 1w ∈ J, showing J is not Turing-recognizable. We now show AT M ≤m J, done by the following
reduction: on input w, output 0w. We have w ∈ AT M if and only if 0w ∈ J, showing that J is not
Turing-recognizable.

5.25 Give an example of an undecidable language B, where B ≤m B.


Solution: Any Turing-recognizable but not co-Turing-recognizable language works (or vice versa),
such as AT M .

5.26 Define a two-headed finite automaton (2DFA) to be a deterministic finite automaton that has two
read-only, bidirectional heads that start at the left-hand end of the input tape and can be independently
controlled to move in either direction. The tape of a 2DFA is finite and is just large enough to contain
the input plus two additional blank tape cells, one on the left-hand end and one on the right-hand end,
that serve as delimiters. A 2DFA accepts its input by entering a special accept state. For example, a
2DFA can recognize the language {an bn cn |n ≥ 0}.

a. Let A2DF A = {hM, xi|M is a 2DFA and M accepts x}. Show that A2DF A is decidable.
Solution: since the input tape is only finitely long, there are only finitely many different config-
urations that the 2DFA can be in: if it has |Q| states with input w of length |w| (counting the
delimiters), the number of configurations is |Q| × |w|2 . We can decide A2DF A with a TM T as
follows:
T = “On input hM, xi where M is a 2DFA and x is a string, and M has states Q:
i. Simulate M on x for |Q| × |x|2 steps.
ii. If M halts within |Q| × |x|2 steps, then accept x; otherwise, reject x.”
b. Let E2DF A = {hM i|M is a 2DFA and L(M ) = ∅}. Show that E2DF A is not decidable
Solution: we show E2DF A ≤m AT M . Given hM i and w, we can create a 2DFA that accepts all
accepting computation histories for M on w, and rejects all other strings. Then we just test if
the language is empty. The proof goes the same way as did for ELBA .

5.28 Rice’s theorem. Let P be any nontrivial property of the language of a Turing machine. Prove that
the problem of determining whether a given Turing machine’s language has property P is undecidable.
In more formal terms, let P be a language consisting of Turing machine descriptions where P fulfills
two conditions. First, P is nontrivial–it contains some, but not all, TM descriptions. Second, P is a
property of the TM’s language–whenever L(M1 ) = L(M2 ), we have 〈M1 〉 ∈ P iff 〈M2 〉 ∈ P . Here, M1
and M2 are any TMs. Prove that P is an undecidable language.
Solution: answered in the text.

5.29 Show that both conditions in Problem 5.28 are necessary for proving that P is undecidable.
Solution: If the property P is trivial, then one of the following is true:

1. All TM descriptions are in the language (if p includes all TMs)


2. The language is empty.

For 1, we just build a TM that accepts if M is a valid TM description. In the latter case, we build a
TM that rejects all strings. If P is a property of the machine rather than the language, it is possible
for the language to be decidable.

5.30 Use Rice’s theorem, which appears in Problem 5.28, to prove the undecidability of each of the following
languages.

a. IN F IN IT ET M = {〈M 〉 | M is a TM and L(M ) is an infinite language}.


Solution: answered in the text.
22 CHAPTER 1. SOLUTIONS

b. {〈M 〉 | M is a TM and 1011 ∈ L(M )}.


Solution: Let P be this language. We can clearly see P is a language of descriptions of TMs.
It is non-trivial because some TMs contain the string 1011 in their language, and others do not.
Also, it only depends on the language. If two TMs recognize the same language, either both have
their descriptions in P , or neither do. Therefore, we can apply Rice’s theorem and conclude that
P is undecidable.
c. ALLT M = {〈M 〉 | M is a TM and L(M ) = Σ∗ }.
Solution: ALLT M is non-trivial because some TMs accept Σ∗ and others do not. Also, it only
depends on the language. If two TMs recognize Σ∗ , then the descriptions of both are in ALLT M
or neither are. Therefore, we can apply Rice’s theorem and conclude that ALLT M is undecidable.
1.6. CHAPTER 6 23

1.6 Chapter 6
6.6 Describe two different Turing machines, M and N , where M outputs 〈N 〉 and N outputs 〈M 〉, when
started on any input.
Solution: Construct M as follows:
M = “On input w:
1. Obtain 〈M 〉 by the recursion theorem.
2. Compute q(〈M 〉), and write the result to the tape.
3. Halt.”
Now let N = q(〈M 〉). The computation in Step 2 writes 〈q(〈M 〉)〉 = 〈N 〉. N writes 〈M 〉 to the tape,
so the construction of M and N is correct.
6.9 Use the recursion theorem to give an alternative proof of Rice?s theorem in Problem 5.28.
Solution: answered in the text.
6.10 Give a model of the sentence φeq = ∀x[R1 (x, x)] ∧ ∀x, y[R1 (x, y) ↔ R1 (y, x)] ∧ ∀x, y, z[(R1 (x, y) ∧
R1 (y, z)) → R1 (x, z)].
Solution: answered in the text.
6.12 Let (N, <) be the model with universe N and the “less than” relation. Show that Th(N, <) is decidable.
Solution: answered in the text.
6.13 For each m > 1 let Zm = {0, 1, 2, · · · , m − 1}, and let Fm = (Zm , +, ×) be the model whose universe
is Zm and that has relations corresponding to the + and × relations computed modulo m. Show that
for each m, the theory Th(Fm ) is decidable.
Solution: we are given a formula φ = Q1 x1 · · · Qk xk ψ(x1 , · · · , xn ) (assuming the Qi are quantifiers,
and ψ has no quantifiers). We iteratively define I` for 0 ≤ ` ≤ n:
• In (x1 , · · · , xn ) = ψ(x1 , · · · , xn ),
Wm−1
• I`−1 (x1 , · · · , x`−1 ) = i=0 Ii (x1 , · · · , x`−1 , i) if Q` is ∃,
Vm−1
• I`−1 (x1 , · · · , x`−1 ) = i=0 Ii (x1 , · · · , x`−1 , i) if Q` is ∀.
We then output the value of I0 . By an induction argument, we correctly calculate the truth value of
φ. Therefore, Th(Fm ) is decidable.
6.23 Show that the function K(x) is not a computable function.
Solution: Suppose that K(x) were computable. We now construct a TM Z:
Z = “On any input:
1. Obtain 〈Z〉 by the recursion theorem.
2. Compute d = K(〈Z〉).
3. Enumerate strings x ∈ Σ∗ in any order until K(x) > d.
4. Output x.”
This a contradiction since we are outputting a value of K(x) that is greater than the own Turing
Machine’s value. Therefore, K(x) is not computable.
6.24 Show that the set of incompressible strings is undecidable.
Solution: Since the set of incompressible strings is an infinite set, this reduces to 6.25.
6.25 Show that the set of incompressible strings contains no infinite subset that is Turing-recognizable.
Solution: Suppose that such a subset were Turing-recognizable, and let E be the enumerator, since
Turing-enumerable languages are exactly the Turing-recognizable ones. We now construct a TM Y :
Y = “On any input:
1. Obtain 〈Y 〉 by the recursion theorem.
24 CHAPTER 1. SOLUTIONS

2. Run E until it outputs a string x with |x| > |〈Y 〉|.


3. Output x.”

This a contradiction - therefore, no infinite subset of the set of incompressible strings is Turing-
recognizable.
6.27 Let S = {〈M 〉 | M is a TM and L(M ) = {〈M 〉}}. Show that neither S nor S is Turing-recognizable.
Solution: We will show that AT M ≤m S and AT M ≤m S, implying that neither S nor S is Turing-
recognizable. For AT M ≤m S, given 〈M, w〉 ∈ AT M , construct a TM T that, on input x, rejects if x 6=
〈T 〉 and simulates M on w otherwise. Therefore, L(T ) = {〈T 〉} if M accepts w, and ∅ otherwise.
For AT M ≤m S, change T ’s construction to be “accepts” instead of “rejects”.
1.7. CHAPTER 7 25

1.7 Chapter 7
7.1 Answer each part TRUE or FALSE.

c. Solution: answered in the text.


d. Solution: answered in the text.

7.2 Answer each part TRUE or FALSE.

c. Solution: answered in the text.


d. Solution: answered in the text.

7.15 Show that P is closed under the star operation. (Hint: Use dynamic programming. On input
y = y1 · · · yn for yi ∈ Σ, build a table indicating for each i ≤ j whether the substring yi · · · yj ∈ A∗ for
any A ∈ P.)
Solution: Let M be a TM that decides A in polynomial time. We construct a TM T to decide A∗ in
polynomial time:

T = “On input w ∈ Σ∗ :

1. Let |w| = n ∈ N.
2. If n = 0, accept w.
3. Construct an n × n table B, initializing all elements to 0.
4. For 1 ≤ i ≤ n do:
a. If wi ∈ A, set B(i, i) = 1.
5. For 2 ≤ j ≤ n do:
a. For 1 ≤ k ≤ n − j + 1 do:
i. Set m ← j + k − 1.
ii. If wk · · · wm ∈ A, set B(k, k) = 1.
iii. For k ≤ p ≤ m − 1 do:
1. If B(k, p) = B(p, m) = 1, set B(k, m) = 1.
6. Output if B(1, n) = 1.”

7.16 Show that NP is closed under the star operation.


Solution: answered in the text.

7.20 We generally believe that PATH is not NP-complete. Explain the reason behind this belief. Show that
proving PATH is not NP-complete would prove P 6= NP.
Solution: We can prove the converse: if P = NP, then PATH is NP-complete. We will do two things
(in assuming P = NP): show that PATH is NP-hard, and because PATH ∈ NP, PATH is NP-complete.
We will do this by showing SAT ≤p P AT H.
Since P = NP, there is a decider S for SAT that runs in time O(nk ) for some k ∈ N. We construct a
TM T that computes the reduction:

T = “On input 〈φ〉 where φ is a SAT formula:

1. Run S on input 〈φ〉. If S accepts 〈φ〉, the construct a graph G = (V, E) such that s, t ∈ V, (s, t) ∈
E.
2. If S rejects 〈φ〉, construct a graph G = (V, E) such that V = {s, t}, E = ∅.
3. Output 〈G, s, t〉.”

Since this reduction takes polynomial time, then P = NP implies PATH is NP-complete.
26 CHAPTER 1. SOLUTIONS

7.22 Let DOU BLE-SAT = {〈φ〉 | φ has at least two satisfying assignments}. Show that DOU BLE-SAT
is NP-complete.
Solution: We will reduce 3SAT to this problem. Given φ as a 3SAT formula, all we need to do is to
introduce a new variable x, and create a new formula φ0 as follows:

φ0 = φ ∧ (x ∨ x)

We show that φ ∈ 3SAT if and only if φ0 ∈ DOU BLE-SAT . If φ ∈ 3SAT , then there is one satisfying
assignment - for φ0 there are two since we can set x = 0, 1 and still have φ0 be true. If φ is unsatisfiable,
then clearly φ0 is also unsatisfiable. Therefore, we are done.
m
7.23 Let HALF -CLIQU E = {〈G〉 | G is an undirected graph having a complete subgraph with at least 2
nodes, where m is the number of nodes in G}. Show that HALF -CLIQU E is NP-complete.
Solution: answered in the text.
7.33 In the following solitaire game, you are given an m × m board. On each of its m2 positions lies either
a blue stone, a red stone, or nothing at all. You play by removing stones from the board until each
column contains only stones of a single color and each row contains at least one stone. You win if you
achieve this objective. Winning may or may not be possible, depending upon the initial configuration.
Let SOLIT AIRE = {〈G〉 | G is a winnable game configuration}. Prove that SOLIT AIRE is NP-
complete.
Solution: answered in the text.
7.38 Show that if P = NP, a polynomial time algorithm exists that produces a satisfying assignment when
given a satisfiable Boolean formula. (Note: The algorithm you are asked to provide computes a
function; but NP contains languages, not functions. The P = NP assumption implies that SAT is in
P, so testing satisfiability is solvable in polynomial time. But the assumption doesn?t say how this test
is done, and the test may not reveal satisfying assignments. You must show that you can find them
anyway. Hint: Use the satisfiability tester repeatedly to find the assignment bit-by-bit.)
Solution: The assumption of P = NP implies SAT ∈ P with polynomial-time TM M . We will
construct a polynomial-time TM B that outputs, given φ an assignment if one exists:
B = “On input boolean formula φ over variables x1 , · · · , xk :
(a) Run M on φ. If M rejects, reject φ. Otherwise, continue.
(b) For 1 ≤ i ≤ k:
i. Let φ0 be φ but with the variable xi hard-coded to 0.
ii. Run M on φ0 . If M accepts, overwrite all instances of xi in φ to be 0; otherwise, overwrite
all instances of xi in φ to be 1.
B runs in polynomial time because setting the xi takes O(|φ|) time for each xi . Since there are O(|φ|)
variables, and calling M takes polynomial time by assumption, B ∈ P. The logic is correct because the
first step checks whether φ is satisfiable or not - when we use the for loop, we know that an assignment
exists. If setting xi to be 0 makes M reject φ, then the setting of xi must be 1.
7.40 Show that if P = NP, a polynomial time algorithm exists that takes an undirected graph as input and
finds a largest clique contained in that graph. (See the note in Problem 7.38.)
Solution: answered in the text.
7.49 Let f : N → N be any function where f (n) = o(n log n). Show that T IM E(f (n)) contains only the
regular languages.
Solution: We define a crossing sequence (abbreviated “C.S.”) for a TM M as the sequence of states
that M enters at a given tape cell during computation on an input. We will prove two things, which
is sufficient to prove that T IM E(f (n)) contains only the regular languages:
1. A deterministic, single-tape TM with C.S.’s of bounded length decides a regular language.
2. A deterministic, single-tape TM with C.S.’s of unbounded length cannot run in o(n log n) time.
1.7. CHAPTER 7 27

For the first part, let M be a deterministic, single-tape TM, and consider M running on some input.
If all of M ’s C.S.’s on these inputs have length ≤ k, we can construct an NFA N that simulates M ,
because N only needs enough states to record the current C.S. plus a start state. N then guesses
the sequence of C.S.’s that would occur if M processed the input string further, and also checks that
adjacent C.S.’s are consistent (somewhat like a “computation history”). Without loss of generality,
assume that we modify M so that it accepts at the right-most end of the input. Also, N ’s accept
states correspond to C.S.’s that contain M ’s accept state and that match with M ’s computation on
the blank portion of the tape (initially) after the input string. Therefore, a deterministic, single-tape
TM with C.S.’s of bounded length decides a regular language.
For the second part, we will prove by contradiction. Suppose (to the contrary) that we have a deter-
ministic, single-tape TM M that runs in o(n log n) time and has C.S.’s of unbounded length. We can
easily see that M runs in time bn log(n), for all n ≥ n0 for some constant n0 (also note that all inputs
are of length n). We can also see that for all possible inputs, at least half of the C.S.’s must have length
≤ 2b log(n), as not to exceed M’s running time. Define these C.S.’s as the short crossing sequences
(abbreviated “S.C.S.”). If M has |Q| states, the number of distinct C.S.’s of length p is |Q|p . If we
choose b to be small enough, it is possible to force repetition among the S.C.S.’s because |Q|2b log(n) is
much less than n2 . For ∀k ∈ N, consider inputs that have a C.S. of length ≥ k and that are of length
n0 or more. Let w be the shortest such string, and let i be the position in w such that the longest C.S.
occurs. We can see that 3 positions (p1 , p2 , p3 ) must exist that have exactly the same C.S.’s. Remove
either the substring p1 through p2 − 1 or p2 through p3 − 1 from w such that position i is not removed.
We can also see that M runs on the modified string exactly the same way as it originally did on w, but
now except for the removed portion, because positions of w with exactly the same C.S.’s were overlaid.
Therefore, there exists a C.S. of length ≥ k in this modified input. However, we originally selected w
to be the shortest string which has a C.S. of length ≥ k, a contradiction. Therefore, a deterministic,
single-tape TM with C.S’s of unbounded length cannot run in o(n log n) time.
This is quite strange, as all regular languages are in T IM E(n), and there are not any in T IM E(f (n))∩
T IM E(n) where f (n) ∈ o(n log n). However, according to (http://arxiv.org/pdf/1307.3648.pdf),
any TM running in time f (n) ∈ o(n log n) actually runs in linear time.
28 CHAPTER 1. SOLUTIONS

1.8 Chapter 8
8.6 Show that any PSPACE-hard language is also NP-hard.
Solution: by definition of PSPACE-hardness for a language L, for all A ∈ PSPACE, A ≤P L. Since
SAT ∈ NP, SAT ∈ PSPACE because NP ⊆ PSPACE. Therefore, SAT ≤P L. Since SAT is NP-complete,
it is NP-hard. Therefore since SAT ≤P L, L is NP-hard (by transitivity of ≤P ).
1.9. CHAPTER 9 29

1.9 Chapter 9
30 CHAPTER 1. SOLUTIONS

1.10 Chapter 10
10.19 Show that if NP ⊆ BPP, then NP = RP.
Solution: Since RP ⊆ NP, we only need to show NP ⊆ RP. So assume NP ⊆ BPP. Therefore,
SAT ∈ BPP, and since it is NP-complete, we only need to show it is in RP.
Let M be a probabilistic poly-time TM that accepts SAT with error at most 13 .

You might also like