Vous êtes sur la page 1sur 11

Mike & Ike

Chapter 3 Exercises
Last Updated: 2018/07/24, at 22:01:17, EST, USA
Foobanana (the real one)

No I’m not posting the LATEX code; write up your own solutions, you bum ,
3.1 How might we recognize that a process in Nature computes a function not computable
by a Turing machine?
Solution: If the computational model we form from that process is able to simulate
the Turing machine model, but the Turing machine model is not able to simulate
the model we’ve constructed, then the process will be able to compute functions not
computable on the Turing machine model of computation.

3.2 Show that single-tape Turing machines can each be given a number from the list
1, 2, 3, ... in such a way that the number uniquely specifies the corresponding machine.
We call this number the Turing number of the corresponding Turing machine.
Solution: The program of a Turing machine is the part which identifies that ma-
chine, and so we will work towards uniquely encoding the program. Suppose we have
a Turing machine, which has states qs , q1 , ..., qm , qh , and symbols −1, 0, +1, b, B. Then,
we will map these symbols and states to numbers following the table below (we’ll refer
to this map as φ). Note that this map is injective.

Input Output
qs 1
qh 2
B 3
−1 4
0 5
+1 6
b 7
qi i+7

Next, we will take each line of the program and send it to a number by taking the
first five “available” primes and exponentiating each prime by its respective encoded
number of the respective symbol. Since that sentence was pretty terrible, let’s do a
small example.
Take the program hqs , B, qh , B, 0i. This program will get mapped to the number
2φ(qs ) 3φ(B) 5φ(qh ) 7φ(B) 11φ(0) = 21 33 52 73 115 . If we had a second line to this program,
we would have taken the next five primes, 13, 17, 19, 23, 29, done this process with the
second line of the program, and then multiplied the two numbers together to get one
x for that two-line program.
We can see that this encoding is unique: suppose we have two numbers a, b, which

1
represent programs and are such that a = b. Then, they have the same prime factor-
izations, and so the same powers on all their primes. So, as φ is injective we have that
all symbols in each respective line of the programs mapping to a and b are the same,
and thus they are the same program, and so the same Turing machine is represented
by both a and b.

3.3 Describe a Turing machine which takes a binary number x as input, and outputs the
bits of x in reverse order.
Solution: We will use a two-tape Turing machine for this problem, where the input
will be the number x on the first string followed by all blanks, and the second string will
start all blank, as this will be where the solution will be when the process is complete.

1 hqs , B, B, q1 , B, B, +1, 0i;


2 hq1 , 0, B, q1 , 0, B, +1, 0i; // move down first tape
3 hq1 , 1, B, q1 , 1, B, +1, 0i;
4 hq1 , b, B, q2 , b, B, −1, +1i; // end of number, prepare to copy
5 hq2 , 1, b, q2 , 1, 1, −1, +1i; // copy the digits
6 hq2 , 0, b, q2 , 0, 0, −1, +1i;
7 hq1 , B, b, qh , B, b, 0, 0i; // end of number

3.4 Describe a Turing machine to add two binary numbers x and y modulo 2. The numbers
are input on the Turing machine tape in binary, in the form x, followed by a single
blank, followed by a y. If one number is not as long as the other then you may assume
that it has been padded with leading 0s to make the two numbers the same length.
Solution: We will use a three-tape Turing machine for this problem, where the
input will be the number x on the first string followed by all blanks, the number y
on the second string followed by all blanks, and the third string will start all blank,
as this will be where the sum will be when the process is complete. We are of course
assuming that the smaller of the two is padded with zeros so that x and y are of the
same length.

2
1 hqs , B, B, B, q1 , B, B, B, +1, +1, +1i;
2 hq1 , 0, 0, b, 0, 0, b, +1, +1, 0i; // 2-5 move down first and second tapes
3 hq1 , 0, 1, b, 0, 1, b, +1, +1, 0i;
4 hq1 , 1, 0, b, 1, 0, b, +1, +1, 0i;
5 hq1 , 1, 1, b, 1, 1, b, +1, +1, 0i;
6 hq1 , b, b, b, q2 , b, b, b, 0, 0, +1i; // prepare for possible final carry
7 hq2 , b, b, b, q2 , b, b, b, −1, −1, −1i; // move to end of numbers to start addition
8 hq2 , 0, 0, b, q2 , 0, 0, 0, −1, −1, −1i; // 8-11 are easy adds (no carry needed)
9 hq2 , 0, 1, b, q2 , 0, 1, 1, −1, −1, −1i;
10 hq2 , 1, 0, b, q2 , 1, 0, 1, −1, −1, −1i;
11 hq2 , 0, 0, 1, q2 , 0, 0, 1, −1, −1, −1i;
/* 12-19 contain four pairs, each of which describes a small
subroutine for performing a carry operation */
12 hq2 , 1, 1, b, q3 , 1, 1, 0, 0, 0, −1i; // carry pair 1
13 hq3 , 1, 1, b, q2 , 1, 1, 1, −1, −1, 0i;
14 hq2 , 0, 1, 1, q3 , 0, 1, 0, 0, 0, −1i; // carry pair 2
15 hq3 , 0, 1, b, q2 , 0, 1, 1, −1, −1, 0i;
16 hq2 , 1, 0, 1, q3 , 1, 0, 0, 0, 0, −1i; // carry pair 3
17 hq3 , 1, 0, b, q2 , 1, 0, 1, −1, −1, 0i;
18 hq2 , 1, 1, 1, q3 , 1, 1, 0, 0, 0, −1i; // carry pair 4
19 hq3 , 1, 1, b, q2 , 1, 1, 1, −1, −1, 0i;
20 hq2 , B, B, b, qh , B, B, 0, 0, 0, 0i; // fill in zero if no final carry
21 hq2 , B, B, 1, qh , B, B, 1, 0, 0, 0, i;

3.5 Show that given a Turing machine M there is no algorithm to determine whether M
halts when the input to the machine is a blank tape
Solution: UNFINISHED WORK

3.6 Suppose we number the probabilistic Turing machines using a scheme similar to that
found in Exercise 3.2 and define the probabilistic halting function hp (x) to be 1 if
machine x halts on input of x with probability at least 1/2 and 0 if machine x halts on
input of x with probability less than 1/2. Show that there is no probabilistic Turing
machine which can output hp (x) with probability of correctness strictly greater than
1/2 for all x.
Solution: UNFINISHED WORK

3.7 Suppose a black box is made available to us which takes a non-negative integer x as
input, and then outputs the value of h(x), where h(·) is the halting function defined
in Box 3.2 on page 130. This type of black box is sometimes known as an oracle for
the halting problem. Suppose we have a regular Turing machine which is augmented
by the power to call the oracle. One way of accomplishing this is to use a two-tape
Turing machine, and add an extra program instruction to the Turing machine which

3
results in the oracle being called, and the value of h(x) being printed on the second
tape, where x is the current contents of the second tape. It is clear that this model
for computation is more powerful than the conventional Turing machine model, since
it can be used to compute the halting function. Is the halting problem for this model
of computation undecidable? That is, can a Turing machine aided by an oracle for the
halting problem decide whether a program for the Turing machine with oracle will halt
on a particular input?
Solution: UNFINISHED WORK

4
3.8 Show that the N AN D gate can be used to simulate the AN D, XOR, and N OT gates,
provided wires, ancilla bits and F AN OU T are available.
Solution: For the following problems, note that if we have multiple places where a
variable like x is input, we are using the F AN OU T operation. With this, we may see
that the rest of the logical operators can be constructed with N AN D gates as:

x
¬(x ∧ x) = ¬x
x
1
x
y
¬((¬(x ∧ y)) ∧ (¬(x ∧ y))) = (x ∧ y) ∨ (x ∧ y) = x ∧ y
x
y
1

x
x
¬((¬(x ∧ x)) ∧ (¬(y ∧ y))) = x ∨ y
y
y
1

x
y
(x ∨ y) ∧ ¬(x ∧ y)(= x XOR y)
x
y
1

5
3.9 Prove that f (n) is O(g(n)) if and only if g(n) is Ω(f (n)). Deduce that f (n) is Θ(g(n))
if and only if g(n) is Θ(f (n)).
Solution: Let f (n) be O(g(n)), so by definition there exists some c > 0 and n0 ∈ N
such that for all n ≥ n0 we have that f (n) ≤ cg(n). Then we have that for all n ≥ n0
that 1c f (n) ≤ g(n), and so with c0 = 1c > 0 we satisfy the definition for g(n) ∈ Ω(f (n)).
Now suppose that g(n) is Ω(f (n)), and so there exist c > 0 and n0 ∈ N such that for
all n ≥ n0 we have that cf (n) ≤ g(n). Then, for all n ≥ n0 , f (n) ≤ 1c g(n), and so with
c0 = 1c > 0 we satisfy the definition for f (c) ∈ O(g(n)). Therefore, we have shown that
f (n) ∈ O(g(n)) if and only if g(v) ∈ Ω(f (n)).
Now lastly suppose that f (n) ∈ Θ(g(n)). By definition, this means that f (n) ∈ O(g(n))
and f (n) ∈ Ω(g(n)). By applying our above theorem, we find that this holds if and
only if g(n) ∈ Ω(f (n)) and g(n) ∈ O(f (n)) respectively, and since both of these hold we
find again by definition that g(n) ∈ Θ(f (n)). Thus we have shown that f (n) ∈ Θ(g(n))
if and only if g(n) ∈ Θ(f (n)).

3.10 Suppose g(n) is a polynomial of degree k. Show that g(n) is O(nl ) for any l ≥ k.
Solution: Let g(n) = ak nk + ... + a0 . To show that g(n) ∈ O(nk ), we need to find
k
a c > 0 and n0 ∈ N such that for all n ≥ n0 we have that g(n) ≤ cnk . Let c = |ai |.
P
i=0
Then, for any n ≥ 1 = n0 we see that ai ni ≤ |ai |ni , where 0 ≤ i ≤ k. Thus we can see
that
k
X Xk k
X
i i k
g(n) = ai n ≤ |ai |n ≤ n |ai | = cnk
i=0 i=0 i=0

Thus we have shown that g(n) ∈ O(nk ). Since n ≥ 1 we know that for ` ≥ k that
n` ≥ nk , and thus the same c gives g(n) ≤ cn` , and thus we have shown that for any
` ≥ k that g(n) ∈ O(n` ).

3.11 Show that log n is O(nk ) for any k > 0.


Solution: Remember that z = log n is the number such that ez = n. As ez > n
for n > 1, we know that ez = n requires that z < n, and so for n ≥ 1 we find that
log n < n. Applying this, we see that for any k > 0 that log nk < nk for n > 1, or
equivalently that log n < cnk for c = k1 and n > 1. Thus we have shown that for k > 0
that log n ∈ O(nk ).

3.12 Show that nk is O(n log n) for any k, but that n log n is never O(nk ).
Solution: Since the range of log over R+ is R, we know that for some n∗ ∈ R+
that log n∗ = k. We will take dn∗ e = n0 , and then nk < nlog n for n > n0 , and so
nk ∈ O(nlog n ).
Now, suppose for the sake of contradiction that nlog n ∈ O(nk ); then there would exist
some c > 0 and n0 ∈ N such that for n ≥ n0 , we would have that nlog n ≤ cnk .
log n
Over this same range of n we would have that n nk ≤ c. However, we can see that

6
log n
lim n k = ∞, as we get a constant on the bottom and increasing function in n after
n→∞ n
applying L’Hopitals rule k times, a contradiction with the statement that this ratio is
bounded by c. Thus it must be the case that nlog n 6∈ O(nk ).

3.13 Show that an is Ω(n log n) for any a > 1, but that n log n is never Ω(an ).

Solution: We know from exercise 3.11
√ that log n ∈ O( n). Thus, there exists some
c0 > 0 and n0 ∈ N such that log n ≤ c0 n for n ≥ n0 . So, (log n)2 ≤ c20 n, and as log n
is increasing and has range R over R+ , there exists some x such that c20 = log xa ,
a
2

take this x and call it c. So, we have that (log n) ≤ n log c , and with algebra we
have that cnlog n ≤ an for all n ≥ n0 . Thus we have shown that an ∈ Ω(nlog n ), or (by
Exercise 3.9) that nlog n ∈ O(an ).
Now, suppose for the sake of contradiction that an ∈ O(nlog n ). Then there would exist
an
some c > 0 and n0 ∈ N such that an ≤ cnlog n for n ≥ n0 , or equivalently nlog n ≤ c for

such a range of n. However, we find that


an
lim = lim an n− log n = lim exp(log(a)n − log2 (n)) = ∞
n→∞ nlog n n→∞ n→∞

(Yes, I know that my calculus is lacking some rigor, but the idea is there.) Thus, we
have that an 6∈ O(nlog n ), and thus nlog n 6∈ Ω(an ).

3.14 Suppose e(n) is O(f (n)) and g(n) is O(h(n)). Show that e(n)g(n) is O(f (n)h(n)).
Solution: Let e(n) ∈ O(f (n)) and g(n) ∈ O(h(n)). So, there exist constants
c1 , c2 > 0 and constants n1 , n2 ∈ N such that for all n ≥ n1 , it is the case that
e(n) ≤ c1 f (n), and for all n ≥ n2 , it is the case that g(n) ≤ c2 h(n). Then, as
these are all positive quantities, we find that for all n ≥ max{n1 , n2 } = n0 , that
e(n)g(n) ≤ c(f (n)h(n)), where c = c1 c2 . Thus we have shown by definition that
e(n)g(n) ∈ O(f (n)h(n)).

3.15 Suppose an n element list is sorted by applying some sequence of compare-and-swap


operations to the list. There are n! possible initial orderings of the list. Show that after
k of the compare-and-swap operations have been applied, at most 2k of the possible
initial orderings will have been sorted into the correct order. Conclude that Ω(n log n)
compare-and-swap operations are required to sort all possible initial orderings into the
correct order.
Solution: UNFINISHED WORK

3.16 Show that there exist Boolean functions on n inputs which require at least 2n / log n
logic gates to compute.
Solution: UNFINISHED WORK

3.17 Prove that a polynomial-time algorithm for finding the factors of a number m exists if
and only if the factoring decision problem is in P.

7
Solution: First suppose there exists a polynomial time algorithm to find the prime
factors of a number m. Use this algorithm to generate all factors of m; there must be
no more than m of them (this is just some upper bound), and so it would subsequently
take no more than m comparisons to determine if any of them are less than some given
`, which is given in the posing of the F ACT ORIN G problem. In this way we would
have that F ACT ORIN G is in P.
Now suppose that F ACT ORIN G is in P. Take ` = m, and we will construct a
polynomial time algorithm for finding the factors of m, shown below. This algorithm
factors m in polynomial time, since the while loop can’t run more than m times, and
we know that the F ACT ORIN G decision is polynomial.

Input: m
1 while m > 1 do
2 if F ACT ORIN G(m) is “yes” then
3 m ←− m/`;
4 Store ` somewhere (for constructing factorization);
5 end
6 end

3.18 Prove that if coNP 6= NP then P 6= NP.


Solution: UNFINISHED WORK

3.19 The REACHABILIT Y problem is to determine whether there is a path between two
specified vertices in a graph. Show that REACHABILIT Y can be solved using O(n)
operations if the graph has n vertices. Use the solution to REACHABILIT Y to show
that it is possible to decide whether a graph is connected in O(n2 ) operations.
Solution: UNFINISHED WORK

3.20 Prove Euler’s theorem. In particular, if each vertex has an even number of incident
edges, give a constructive procedure for finding an Euler cycle.
Solution: UNFINISHED WORK

3.21 Show that if a language L1 is reducible to the language L2 and the language L2 is
reducible to L3 then the language L1 is reducible to the language L3 .
Solution: Take languages L1 , L2 , L3 . We know that as L1 reduces to L2 that there
exists some Turing machine T1 such that giving T1 input x results in R1 (x) ∈ L2 if and
only if x ∈ L1 , and similarly there exists some Turing machine T2 such that giving T2
input y results in R2 (y) ∈ L3 if and only if y ∈ L2 . These two machines have states
qs , q1 , ..., qm , qh and ps , p1 , ..., p` , ph respectively. We construct a new Turing machine T
by taking all the states of both T1 , t2 as the states of T and relabeling both qh and ps
as some state p0 . Let the program of T be all lines from both T1 and T2 , keeping in

8
mind this relabeling resulting in state p0 and applying this to all necessary program
lines. Therein, we have constructed a machine which, given input x yields an output
R2 (R1 (x)) which is such that R2 (R1 (x)) ∈ L3 if and only if x ∈ L1 , and so by definition
we have that L1 reduces to L3 .
3.22 Suppose L is complete for a complexity class, and L0 is another language in the com-
plexity class such that L reduces to L0 . Show that L0 is complete for the complexity
class.
Solution: If L is complete, then we have by definition that every language K in our
class reduces to L. If L reduces to L0 , then by Exercise 3.21 we know that K reduces
to L0 . As this holds for all K in the given class, we have by definition of complete that
L0 is also complete with respect to the given complexity class.
3.23 Show that SAT is NP-complete by first showing that SAT is in NP, and then showing
that CSAT reduces to SAT .
Solution: UNFINISHED WORK
3.24 Suppose φ is a Boolean formula in conjunctive normal form, in which each clause
contains only two literals.
(a) Construct a (directed) graph G(φ) with directed edges in the following way: the
vertices of G correspond to variables xj and their negations ¬xj in φ. There is a
(directed) edge (α, β) in G if and only if the clause (¬α ∨ β) or the clause (β ∨ ¬α)
is present in φ. Show that φ is not satisfiable if and only if there exists a variable
x such that there are paths from x to ¬x and from ¬x to x in G(φ).
(b) Show that given a directed graph G containing n vertices it is possible to determine
whether two vertices v1 and v2 are connected in polynomial time.
(c) Find an efficient algorithm to solve 2SAT .
Solution: UNFINISHED WORK
3.25 The complexity class EXP (for exponential time) contains all decision problems which
k
may be decided by a Turing machine running in exponential time, that is time O(2n ),
where k is any constant. Prove that PSPACE ⊆ EXP.
Solution: UNFINISHED WORK
3.26 The complexity class L (for logarithmic space) contains all decision problems which
may be decided by a Turing machine running in logarithmic space, that is, in space
O(log(n)). More precisely, the class L is defined using a two-tape Turing machine.
The first tape contains the problem instance, of size n, and is a read-only tape, in the
sense that only program lines which don’t change the contents of the first tape are
allowed. The second tape is a working tape which initially contains only blanks. The
logarithmic space requirement is imposed on the second, working tape only. Show that
L ⊆ P.

9
Solution: UNFINISHED WORK
3.27 Let G = (V, E) be an undirected graph. Prove that the following algorithm finds a
vertex cover for G that is within a factor two of being a minimal vertex cover:

1 VC =∅
2 E0 = E
3 while E 0 6= ∅ do
4 let (α, β) be any edge of E 0
5 V C = V C ∪ {α, β}
6 remove from E 0 every edge incident on α or β
7 end
8 return V C.

Solution: UNFINISHED WORK


3.28 Suppose k is a fixed constant, 1/2 < k ≤ 1. Suppose L is a language such that there
exists a Turing machine M with the property that whenever x ∈ L, M accepts x with
probability at least k, and whenever x 6∈ L, M rejects x with probability at least k.
Show that L ∈ BPP.
Solution: UNFINISHED WORK
3.29 Show that applying two consecutive Fredkin gates gives the same outputs as inputs.
Solution: Assume we have a pair of Fredkin gates with inputs a, b, c which go to
states a0 , b0 , c0 after one gate is applied, and then a00 , b00 , c00 after the second gate is
applied. We break this into two cases. In the case where c = 0, then c00 = c0 = 0, and
from these we see that a00 = a0 = a and b00 = b0 = b. In the second case, when c = 1,
we have that c00 = c0 = 1 as well. Then, we again get what we wish, since a00 = b0 = a
and b00 = a0 = b, and thus the Fredkin gate is its own inverse.
3.30 Verify that the billiard ball computer in Figure 3.14 computes the Fredkin gate.
Solution: I’m not sure how to type up a complete solution to this; however, the
key to seeing the effect is to first imagine just the a and b balls going through the
obstacles, and see that they will go to a0 and b0 respectively. Then add in the c ball
and see that the a and b switch which they go to, while the c ball will continue on to
c0 . Then you can more easily imagine any other pairings of these.
3.31 Construct a reversible circuit which, when two bits x and y are input, outputs (x, y, c, x⊕
y), where c is the carry bit when x and y are added.
Solution: Note that we can take inputs x and y and perform F AN OU T and
CROSSOV ER operations on them and some ancilla bits until we get the input con-
figuration shown below (I was too lazy to fully work this out). Then, the following
circuit does what we desire.

10
x x

y y

0 c

y x⊕y
1
3.32 What is the smallest number of Fredkin gates needed to simulate a Toffoli gate? What
is the smallest number of Toffoli gates needed to simulate a Fredkin gate?
Solution: Consider the following two circuits given. I don’t have particularly good
arguments as to why these are the minimum number of gates needed.

a a0

c c0

b b0
1
Figure 1: Toffoli from Fredkin

a a

b b ⊕ ac ⊕ ab

c c ⊕ ab ⊕ ac
1
Figure 2: Fredkin from Toffoli

11

Vous aimerez peut-être aussi