Sie sind auf Seite 1von 196

PREFACE

This STUDENTS' SOLUTIONS MANUAL to accompany Discrete Mathematics:


An Introduction to Concepts, Methods, and Applications contains complete worked-out
solutions to all the odd-numbered exercises in the text, except for the exploratory exer-
cises. The solutions we give here are not the only ways to solve these problems, and in
many cases alternative approaches-Qr even other correct answers-are possible. In some
cases we have tried to point out potential pitfalls as well as give a correct solution.

As was pointed out in the preface to the student in the text, you must use this
solutions manual with great care. Do not even consider looking at the solution (or even
the answer) to an exercise until you have spent a great deal of time grappling with
it-understanding what is being asked, working through some examples (if relevant) to
see what is going on, probably trying several approaches (the first n - 1 of which may
be unsuccessful), letting the problem sit for a while before coming back to it, perhaps
discussing it with fellow students. You should only look at the solutions presented here
after you have written out your complete solution. For other problem-solving hints and
an explanation of what is expected in a solution to a problem, please review the preface
of the text.

lowe a great deal of thanks and appreciation to my colleague Jon Froemke for his
advice and assistance in the preparation of this manual. Jon worked out all the exercises
independently as a gauge on the appropriateness of the exercises and as a check on the
accuracy of these solutions. I thank Lucy Hebard, the ancillary manager at Macmillan,
for her help in preparing this manual, and the mathematics editor, Robert Pirtle, for his
valuable suggestions. I also thank Suzanne and Pamela for putting up with my many
hours away from the joys that they bring.

J.W.G.
CONTENTS

PREFACE III

Solutions to Exercises in Chapter 1 LOGIC 1


1.1 PropMitiong 1
1.2 Logical Quantifiers 7
1.3 Proofs 10
1.4 Boolean Functions 12

Solutions to Exercises in Chapter 2 SETS 16


2.1 Basic Definitions in Set Theory 16
2.2 Sets with Structure 18
2.3 Operations on Sets 20

Solutions to Exercises in Chapter 3 FUNCTIONS AND RELATIONS 26


3.1 Functions 26
3.2 Functions in the Abstract 29
3.3 Relations 33
3.4 Order Relations and Equivalence Relations 38

Solutions to Exercises in Chapter 4 ALGORITHMS 44


4.1 The Idea of an Algorithm 44
4.2 Pseudocode Description of Algorithms 48
4.3 Efficiency of Algorithms 54
4.4 Intractable and Unsolvable Problems 57
4.5 Algorithms for Arithmetic and Algebra 58

Solutions to Exercises in Chapter 5 INDUCTION AND RECURSION 62


5.1 Recursive Definitions 62
5.2 Recursive Algorithms 66
5.3 Proof by Mathematical Induction 70

Solutions to Exercises in Chapter 6 ELEMENTARY COUNTING


TECHNIQUES 77
6.1 Fundamental Principles of Counting 77
6.2 Permutations and Combinations 80
___ J..~.L': __ _ 0')
Solutions to Exercises in Chapter 7 ADDITIONAL TOPICS IN
COMBINATORlCS 92
7.1 Combinatorial Identities 92
7.2 Modeling Combinatorial Problems
with Recurrence Relations 96
7.3 Solving Recurrence Relations 101
7.4 The Inclusion-Exclusion Principle 107
7.5 Generating Functions 111

Solutions to Exercises in Chapter 8 GRAPHS

S.1 BasiC Deflnitions in Graph Theory 120


8.2 Travelino ThrouOh a Graph 130
8.3 Graph Representation and Graph Isomorphism 136
8.4 Planarity of Graphs 143
B.~ Coloring of Graphs 150

Solutions to Exercises in Chapter 9 TREES 157


9.1 Basic Definitions for Trees 157
9.2 Spanning Trees 164
9.3 Tree Traversal 171
9.4 Further Applications of Binary Trees 177
9.5 Game Trees 182

Solutions to Exercises in Chapter 10 GRAPHS AND DIGRAPHS WITH


ADDITIONAL STRUCTURE 191
10.1 Shortest Paths and Longest Paths 191
10.2 Minimum Spanning Trees 196
10.3 Flows 199
Section 1.1 Propositions 1

CHAPTER 1
LOGIC
SECTION 1.1 Propositions
1. (a) yes (b) yes (c) no (it is a command) (d) yes (e) yes
(f) yes (g) yes (h) no (it is a question) (i) yes
(j) no (it is a noun phrase) (k) yes (I) yes

3. (b) F (f) T (2 is even) (i) T (in fact he was over 6 feet tall) (k) T

5. (a) Paris is not the capital of Spain.


(b) 4 < 7 or 13 is prime.
(c) If 4 < 7, then both 13 is prime and Paris is the capital of Spain.
(d) 4 I. 7 or 13 is not prime.
(e) It is not the case that both 4 < 7 and 13 is prime.
(f) Either 4 < 7 implies that 13 is prime, or 13 is prime implies that Paris is the capital
of Spain.
(g) Q 1\ R: 13 is prime and Paris is the capital of Spain.
(h) P: 41. 7
(i) Q V R: Either 13 is prime or Paris is not the capital of Spain.

7. In each case the final column of T's shows that the proposition is a tautology.
(a) P Q P-Q PI\(P-Q) {PI\(P-Q)} -Q
T T T T T
T F F F T
F T T F T
F F T F T

(b) P Q P-Q P QVP (P-Q) ..... (QvJ5)


T T T F T T
T F F F F T
F T T T T T
F F T T T T
Chapter 1 LOGIC

(c) P Q P PAP (P A P) -+ Q
T T F F T
T F F F T
F T T F T
F F T F T

9. (a) T if :I:= 2; F if = 3 :I:

(d) T if p = 17; F if p = 18
(e) F if = 2 and y = 1; never
:I: T since the right-hand side is always greater than the
left-hand side
(g) F if He = Ronald Reagan; never T since that candidate was actually a "she"
(1) T if N = 11; F if N = 10

11. (a) F-+T is T (b) TAT is F (c) TVF is F


(d) (TVF)A(TAF) is F (e) T-+T is T (f) T-+T is T
(g) T -+ T is T (h) T ..... T is T (i) F -+ T is T

13. If P is false, then :I: ::; 2, which implies that :I: < 7; this makes Q true. Therefore it
is impossible to have both P and Q false. The other six possibilities are all actually
possible. If :I: = 5 or :I: = 6, then P and Q are true, and R is true in the first case, false
= =
in the second. Similarly, if :r 11 or :r 12, then P is true and Q is false; and if :r 1 =
or :r = 2, then P is false and Q is true.

15. (a) neither (the implication is T if and only if P is F)


(b) tautology (T -+ T is T, and F -+ F is T)
(c) tautology (if P A Q is T, then P and Q are both T, so P V Q is T)
(d) neither (the proposition is F if P is T and Q is F; it is T if P is F)
(e) contradiction (if P is T, then -,(P V Q) is F; therefore P A -,(P V Q) is always F)
(f) neither (the proposition is F if P is F and Q is T; it is T if P is T)
(g) neither (the proposition is F if P and Q have the same truth value; it is T if P and
Q have opposite truth values)
(h) neither (the proposition is F if P and Q have opposite truth values; it is T if P
and Q have the same truth value)

17. If Q is F, then Q A (P V R) is F. However (Q A P) V R is T in this case as long as R


is F.
Section 1.1 Propositions 3

19. We present this proof with a truth table.


P Q P-Q P P-Q (P - Q) A (P - Q)
T T T F T T
T F F F T F
F T T T T T
F F T T F F

Observe that the second column has a T whenever the last column has aT. Thus
(P - Q)A(P - Q) ==> Q. In fact, these two columns are identical, so (P - Q)A(P-
Q) {::=> Q. In everyday terms, we are saying: "If Q is true when P holds, and if Q is
true when P does not hold, then Q is true."

21. This is a tautology. We will prove it using Theorems 1 and 3. (This fact can also be
proved by using truth tables.) First, using various parts of Theorem 1 we have
P - (Q - R) {::=> P - (Q v R) (implication)
{::=> P v (Q v R) (implication)
o (PVQ)V R) (associative law)
{::=> P AQVR (DeMorgan's law).
Thus by Theorem 3b, (P - (Q - R» +-+ (P A Q V R) is a tautology.

23. (a) Let S be the proposition that you may swim here, let L be the proposition that you
are less than six years old, and let P be the proposition that your parent is present. The
lifeguard said S - (L A P) and then (L A P) - S.
(b) As we see from the following truth table, in every case in which S - (L A P) is true,
(L A P) - S is also true. However, in the third and fifth lines of the table, (L A P) - S
is true, but S - (L A P) is false.
L P S LAP S - (L A P) LAP (LAP) - S
T T T T T F T
T T F T T F T
T F T F F F T
T F F F T F T
F T T F F F T
F T F F T F T
F F T F F T F
F F F F T T T

(c) She should have said: "If you're not less than six years old 0 r your parent isn't present,
then you may not swim in the pool." This is (L V P) - S. By the contrapositive law,
this is logically equivalent to S - LV P, which is in turn equivalent to S - (L A P) by
DeMorgan's law and the double negative law.
4 Chapter 1 LOGIC

25. (a) P is always true. It says the same thing as "If x and yare both positive, then x· y
is positive."
(b) For x . y to be positive, it is sufficient that x and y both be positive.
(c) For x . y to be positive, it is necessary that x and y both be positive. For x and y
both to be positive, it is sufficient that x· y be positive.
(d) The converse is false if, for example, x = =
y -1, since in this case it is not true
that x and yare both positive, but it is true that x . y is positive.

=
27. (a) First 42548 + 3 14182~, so 42548 is not divisible by 3; and 4 + 2 + 5 + 4 + 8 23 =
is not divisible by 3. The proposition holds: F +-+ F is T. Similarly, 121551+ 3 = 40517,
so 121551 is divisible by 3; and 1 + 2 + 1 + 5 + 5 + 1 = 15 is also divisible by 3. Again
the proposition holds: T +-+ T is T.
(b) A necessary and sufficient condition for a natural number to be divisible by 3 is that
the sum of its digits be divisible by 3.

29. (a) The following table shows that Q (in column 2) is true whenever P A (P -+ Q) (in
column 4) is true, namely in line 1.
P Q PA(P-+Q)
T T T T
T F F F
F T T F
F F T F

(b) The following table shows that PVQ (in column 3) is true whenever P (in column 1)
is true, namely in lines 1 and 2.
P Q PVQ
T T T
T F T
F T T
F F F

(c) The following table shows that P (in column 1) is true whenever P AQ (in column 3)
is true, namely in line 1.
P Q PAQ
T T T
T F F
F T F
F F F

(d) The following table shows that P (in column 1) is true whenever P -+ P (in column 3)
is true, namely in line 1. In fact, these two propositions are logically equivalent.
Section 1.1 Propositions 5

P
T F T
F T F

(e) The following table shows that P (in column 1) is true whenever P - F (in column 3)
is true, namely in line 1. In fact, these two propositions are logically equivalent.
P
T F T
F T F

(f) Since F is never true, it holds vacuously that P is true whenever F is true.
(g) Since T is always true, it holds trivially that T is true whenever P is true.
(h) The following table shows that P --> R (in column 7) is true whenever (P -->

Q) A (Q - R) (in column 6) is true, namely in lines 1, 5, 7, and 8.


P Q R P-Q Q-R (P-Q)A(Q-R) P-R
T T T T T T T
T T F T F F F
T F T F T F T
T F F F T F F
F T T T T T T
F T F T F F T
F F T T T T T
F F F T T T T

31. Only (d) and (e) are logical equivalences; the truth tables shown in the solution to Exer-
cise 29 show that in these two parts (and only in these two parts) the columns in question
are identical.

33. (a) We need to have either that P is true and Q is false, or that P is false and Q is
true. The most straightforward way to assert this is (P A Q) V (P A Q).
(b) We simply assert the conjunction of the negations of P and Q: P A Q.
(c) This time we want to assert that either P is false or Q is false; in symbols, P V Q.

35. P <==> Q means that every assignment of truth values to the propositional variables in
P and Q results in the same truth value for P and for Q. By the definition of +-+, this
occurs if and only if P +-+ Q is always true, that is, P +-+ Q is a tautology.
6 Chapter 1 LOGIC

37. (a) (PAQ)VRj PVQA(TAQ)


(b) If we make these replacements twice, then each of A, V, T, and F returns to what
it was originally.
(c) We show that (P A Q) V (P A Q) ¢:::::::> P by the following argument using Theorem l.
(P A Q) V (P A Q) ~ P A (Q V Q) (distributive law)
~ PAT (complement law)
~ P (identity law)
Dualizing this argument shows that the dual propositions are logically equivalent.
(PVQ)A(PVQ) ~ PV(QAQ) (distributive law)
~ P VF (complement law)
~ P (identity law)

39. (a) The obvious thing to try first, since there is only one propositional variable here,
is PiP. This works, since it follows immediately from the truth table definition that
P1P~P.

(b) Note from the given truth table that "nand," as its name suggests, is "not and"
(the negation of the conjunction). By DeMorgan's law, P V Q is the negation of the
conjunction of P and Q-in other words, it is the nand of P and Q. Combining this
observation with our result from part (a), we obtain P V Q ¢:::::::> (P 1 P) 1 (Q 1 Q).
(c) By the double negative law (and our observation in part (b) that nand is the negation
of conjunction), we know that we want the negation of P 1 Q. But from part (a), this
means P A Q ~ (P 1 Q) i (P 1 Q).

41. (a) The discussion of disjunctive normal form in Section 1.4 provides a solution (it follows
the hint given here).
(b) Any use of V in a proposition involving V, A, and - can be replaced by substituting
P A Q whenever we see an expression of the form P V Q. This follows from parts (h)
and (i) of Theorem 1. Repeated applications of this substitution, from the inside of
the expression outward, eliminates all uses of V. Thus {A, -} is complete. The dual
reasoning (see Exercise 37) applies to eliminating A, so {V, -} is also complete.
(c) We know that {V, -} is comp lete by part (b). From Exercise 39 we can replace each
occurrence of P by P 1 P, one at a time, working from the inside out. This results in
a proposition using only V and i. Then by replacing each occurrence of P V Q (one at
a time, from the inside out) with (P 1 P) 1 (Q 1 Q), we obtain a logically equivalent
expression involving only 1. A dual argument applies to 1.
(d) P -+ Q ~ P V Q ~ (P i P) V Q ~ [(P 1 P)t (P 1 P)J j(Q i Q)
(e) P -+ Q ~ P V Q ~ (P 1 P) V Q ~ [(P ! P) ! QJ ! [(P ! P) 1 QJ
Logical Quantifiers 7
Section 1.2

SECTION 1.2 Logical Quantifiers


1. (a) 'r/x: (x 2 > 4 +-+ (x> 2 V x < -2»)
(b) 3x:x = x 2
(c) 'r/x>1:3y:(y > x 1\ Y < 2x)
(d) 3x:'r/y: y2 >X

3. (a) There exists an x such that for every y, x +y = y.


(b) For every x there exists a y such that x + y = y.
(c) For every x and for every y, x +y = y.
(d) There exist x and y such that x - y = y.
(e) There exists an x such that for every y, x - y = y.
(f) For every x there exists a y such that x - y = y.

5. (a) There exist a and b, both greater than 1, whose product is x (i.e., x is composite).
(b) For every x there exists a y such that x < y2.
(c) For every x there exists a y such that either x = 3y or x = 3y + 1 or x = 3y + 2.
(d) For every x, if x < 2, then x 2 < 4.
(e) For every x, if x 2 < 4, then x < 2.
(f) There exists an x such that x < 5 implies x < 3.
(g) There exists an x such that x 2 - 2x - 120 = o.
(h) For every x, x 2 > a.

7. (a) 3x:3y:(x f:: yI\M(Diana,x) 1\ M(Diana,y) 1\ F(Charles,x) 1\ F(Charles,y»


(b) Assuming that we are interested in their joint offspring, we can express this with the
unique existential quantifier symbol: 3!x: (M(Suzanne, x) 1\ F(Jerry, x».
(c) 3x: (M(x, Pam) 1\ F(Sam, x»
(d) 3x:3y:3z:(M(x,y) 1\ M(x,z) 1\ F(y,Pam) 1\ F(z,Conrad»
(e) 3x:'r/y: (M(x, y) 1\ F(x, y»

9. (a) 3n: 100 = 5 . n


(b) ...,3n: 1000 = 8· n
(c) 'r/x: (3y:x = 6· y) +-+ 3y:x = 2· y)
(d) Note that this does not say, "Not every multiple of 3 is even." It says something
= =
stronger; in symbols, 'r/x: (3y: x 3· y) ...... ...,3y: x 2 . y).
(e) 3x:'r/y:x-y·y
8
Chapter 1 LOGIC

11. (a) T (100 = 5 . 20)


(b) F (1000 = 8 . 125)
(e) F (4 is a multiple of 2 but not a multiple of 6)
(d) F (6 is a multiple of 3 that is even)
(e) T (look at 2 or -25)

13. (a) neither (it depends on x)


(b) T (take y = Ixl + 1)
(e) T (divide x by 3 and ignore the remainder to obtain y)
(d) F (take x = -3)
(e) T (if x 2 < 4, then -2 < x < 2)
(1) T (take x = 7)
(g) T (take x = 12)
(h) neither (it depends on a)

15. (a) 100 is not a multiple of 5.


(b) 1000 is a multiple of 8.
(c) Some multiple of 6 is not a multiple of 2, or some multiple of 2 is not a multiple of
6.
(d) Some multiple of 3 is even.
(e) Every number has a square root.

17. ( a) Some perfect square is not less than 500.


(b) Every perfect square is not less than 500.
(e) Some perfect square is less than 500.
(d) Every perfect square is less than 500.
(e) Some perfect square is less than 500.
(1) Every perfect square is less than 500.

19. (a) F (12 ::j: 2)


(b) F (4 2 ::j: 2)
(e) T (3 2 = 9)
(d) F (y'6 is not an integer; there is no positive integer solution to x 2 = 6)
(e) T (take y = 36)
(1) T (take x = 36; note that it is the position of x in the symbol P( 6, x) and not the
fact that it is the letter x that is relevant)
(g) T (for each x. take 11 = x2 )
Section 1.2 Logical Quantifiers 9

(h) F (if = 6, no such x exists)


y
(i) F (no matter what y is, look at x = y+ 1 j there are no real solutions to (y+ 1)2 = y)

21. (a) 7921 > 1/\ ...,3,1:: 3y: (7921 = x·y /\ x > 1/\ Y > 1). This is false, since 7921 = 89·89.
(b) Vx: [(3y:x = y2) -> (x ~ 1 V 3a:3b:(x = a·b /\ a > 1/\ b > 1»)]. This is true. If x
is a perfect square, then either x = 0 or x = 1, or else x factors as y. y, with y > 1. In
the latter case, we let a =y and b =y in the second part of the proposition.

23. (a) P(I,I) /\ P(I,2) /\ P(2, 1) /\ P(2,2)


(~) P(1,1) V P(1,2) V P(2, 1) V P(2,2)
(c) (P(I,1) V P(I,2») /\ (P(2,1) V P(2,2»)
(d) (P(I, 1) /\ P(I,2») V (P(2, 1) /\ P(2,2»)

25. Most people would probably interpret this to mean Vx:3y:3t:L(x,y,t).

27. (a) We need to say that x and y are not the same, but x and y have the same parents:
x::fi y /\ 3m: 31: (C(x, m, I) /\ C(y, m, I)) .
(b) We need to make up existentially quantified variables for y's mother (p), father (q),
and paternal grandmother (r) in order to express this: 3p: 3q: 3r: (C(y, p, q) /\C(q, r, x») .
(c) There are four ways in which x might have a grandchild, and we rule out each of them.
In the following proposition, p is the (nonexistent) grandchild, q and r are its parents,
and s is x's spouse: ...,3p:3q:3r:3s: [C(p,q,r) /\ (C(q,x,s) V C(q,s,x) V C(r,x,s) V
C(r,s,x»)] .
(d) Here we need to assert the existence of y's parents (m and I), one of whom is a sibling
of x: 3m:31:3a:3b: [(C(y,m,1) /\ C(x,a,b) /\ C(m,a,b) /\ m::fi x) V (C(y,m,1) /\
C(x,a,b) /\ C(f,a,b) /\ l::fi x)].

29. (a) These are equivalent. Both state that P and Q are always true, no matter what
value x has.
(b) These are not equivalent. For example, let P(x) be "x is odd," and let Q(x) be
"x is even." Then Vx: (P V Q) is true, but neither Vx: P nor Vx: Q is true.
(c) These are not equivalent. The same counterexample as in part (b) applies. The point
is that the x's for the second proposition could be different.
(d) These are equivalent. Both state that there is some x for which either P or Q is
true.
(e) These are not equivalent. Again, the same counterexample as in part (b) applies.
(1) These are not equivalent. For example, let P(x) be x = 3, and let Q(x) be x::fi x.
Then the first proposition is true, but the second is false.
10 Chapter 1 LOGIC

31. (a) Vn>2:Vx:Vy:Vz: (xn + yn ::j: zn)


(b) positive integers x, y, z, and n, with n > 2, such that xn + yn = zn

33. The quantified proposition has no free variables, so it cannot mean that x = 0 (a state-
ment about z). The proposition means that every number has an additive identity
(possibly depending on the number). One can say that for every y, the one and only x
that makes z + y =
y is z o.=
35. We need to assert the existence of an z that makes P true and the fact that any y that
makes P true is in fact this x. In symbols we have 3x: [P(z) A Vy: (P(y) -+ y = z)].

37. This is false, since 412 - 41 + 41 = 412 is not prime.

39. (a) "If: Va: (J is continuous at a ...... "1(>0: 38>0:Vx: (Ix - al < 8 -+ If(x) - f(a)1 < ())
(b) Vx:Vp: (x is a quadratic residue modulo p ...... 3y: 3m: z - y2 = pm)
(c) Vf:Va:Vb>a: [(J is continuous on [a,b] A f is differentiable on (a,b) A f(a) = 0 A
-+ 3c: (a < c < b A f' (c) = 0)]
f (b) = 0)
(d) Vp:Vq: (p::j: q -+ 3!1: (p is on I A q is on I))

SECTION 1.3 Proofs


1. Let 2n be the given even number. Then (2n)2 = 4n 2 = 2{2n 2 ). Since this is 2 times
some number, it is even.

3. (a) The product of two odd numbers is odd. Proof: Let 2n + 1 and 2m + 1 be the
numbers. Their product is (2n+ 1)(2m+ 1) = 4nm+2n+2m+ 1 = 2(2nm+ n+m) + 1,
which is odd by definition.
(b) The product of two even numbers is even. Proof: Let 2n and 2m be the numbers.
Their product is (2n)(2m) = 2(2nm), which is even by definition.
(c) The product of an even number and an odd number is even. Proof: Let 2n and
2m + 1 be the numbers. Their product is (2n )(2m + 1) = 2(2nm + n), which is even by
definition.

5. (a) Let z = 6n be the given number. Then x = (3· 2)n = 3(2n) , so x is a multiple of 3.
(b) This is false. Look at 9, for example; it is a multiple of 3 but not a multiple of 6.
(c) We give an indirect proof, by proving the equivalent proposition, "If z is a multiple
of 6, then x is a multiple of 2." Let z = 6n be the given number. Then z = (2. 3)n =
2(3n), so z is a multiple of 2.
Section 1.3 Proofs 11

7. Let Xl, X2, ..• , Xn be the real numbers, and let A be their average. This means that
A = (Xl + X2 + ... + xn)/n. If the statement is not true, then Xi > A for all i. If we
add the inequalities Xi > A for i = 1, 2, ... , n, we obtain Xl + X2 + ... + Xn > nA, or
(Xl + X2 + ... + xn)/n > A, a contradiction to the definition of A. Thus the statement
is true.

9. (a) This "proof' starts by assuming what we are trying to prove. We wanted to prove
P _ Q, but the given argument shows Q _ P. In fact the proposition is false; n = 4
provides a counterexample.
(b) One case has been omitted: n might be an even number not divisible by 4, such
as 6. In this case, n 2 - 1 will be odd (for example, 62 - 1 = 35), not a multiple of 4.
Thus the proposition is false.
(c) This "proof" has things backward. Looking at p = 17 would only tell us something
about the twinliness of 76 if 17 were a factor of 76, but 17 + 2 were not. Nevertheless
the proposition is true. For a valid proof, we can consider p = 19. Then p is a prime
factor of 76, but p + 2 = 21 is not. Hence 76 is not twinly. (Numbers such as 64 and
5·7·9 = 315 are twinly, though.)
(d) The "proof' erroneously assumes that there is some b such that P( a, b) holds. In
fact the proposition is false. Let P(x, y) be the proposition X =I X 1\ Y =I y, which is
always false (the quantifiers r~nge over the natural numbers, say). Then the two axioms
are both vacuously true, but 'Va: pea, a) is false.

11. (a) By the hypothesis we have a = sb and b = tc for some integers sand t. Thus
a = s(tc) = (st)e, which shows that a is a multiple of e.
(b) Since 6083824773 = 13 ·467986521, the statement is true.
(c) We can write n 2 + n as n(n + 1). There are two cases to consider. If n is even,
then by Exercise 3, n(n + 1) is even. Otherwise n is odd, so n + 1 is even, and again by
Exercise 3, n(n + 1) is even.

13. (a) Let 2n+ 1 and 2m+ 1 be the given odd numbers. Then the difference of their squares
is (2n + 1)2 - (2m + 1)2 =
4n 2 + 4n + 1 - (4m 2 + 4m + 1) =
4(n 2 + n - m 2 - m), a
multiple of 4.
(b) Again, let 2n + 1 and 2m + 1 be the given odd numbers. Then the sum of their
= =
squares is (2n+ 1)2+(2m+ 1)2 4n2+4n+ 1+(4m2+4m+ 1) 4(n2+n+m2+m)+2.
Clearly the remainder when dividing this by 4 is 2; therefore it is not a multiple of 4.

15. Let X < Y be the two distinct real numbers. Let z = (x+y)/2. We claim that X < z < y.
(For the first inequality, add X to both sides of x < y and divide by 2; for the second,
add y to both sides of x < y and divide by 2.) Thus z is the desired number strictly
between x and y.
12 Chapter 1 LOGIC

17. Suppose that 5V2 were rational. Since 1/5 is also rational, the product (1/5) . (5V2) =
.../2 would be rational, contradicting Theorem 5. Therefore 5V2 is not rational. (To see
that the product of two rational numbers is rational, recall first that a rational number is
any number of the form xly, where x is an integer and y is a positive integer. Let alb
and cld be two rational numbers, where a and b are integers and c and d are positive
integers. Their product is (ab)/(cd). Since ab is an integer, and cd is a positive integer,
the product is again a rational number.)

19. We mimic the proof of Theorem 5. First we need an analogue of Theorem 4: If n 2 is a


multiple of 3, then n is a multiple of 3. (Proof: If n were not a multiple of 3, then we
could write n as 3k + 1 or 3k + 2 for some integer k. In either case, n 2 would be of
the form 3m + 1 and hence not a multiple of 3.) Now suppose that v'3 = alb in lowest
= =
terms. Then a 2 3b 2 . Therefore a 2 is a multiple of 3, so a is as well, say a 3n. Then
we have 9n 2 3b 2 , or 3n 2 b2 . This implies that b2 , and hence b, is a multiple of 3.
= =
This has now contradicted our assumption that alb was in lowest terms. Hence v'3 is
irrational.

21. There exist irrational numbers rand s such that r8 is rational. Our proof is noncon-
structive. Look at .../2../2. If this is rational, then we are finished-take r = s = .../2.
Otherwise, let r = ~ and s = V2. Then r' = (~).../2 = V2../2..../2 = 2 is rational.

23. Let x and y be positive real numbers. We want to show that ..;xy ~ (x + y)/2, with
equality holding if and only if x = eNow clearly (..;x - .[Y)2 ~ 0, with equality if and
only if x = y. But this is equivalent to ..;x2 - 2..;x.[Y + .[Y2 ~ 0, i.e., x + y ~ 2..;x'[y,
or, as desired, ..;xy ~ (x + y)/2.

25. Among five consecutive positive integers, exactly one will be divisible by 5. Hence the
product N is a multiple of 5. Similarly, the product is a multiple of 3, since at least
one of any three consecutive integers must be divisible by 3. So far, then, we have
established that the prime factorization of N must contain a 3 and a 5. Now among the
five consecutive numbers there are at least 2 consecutive even ones, say 2a and 2a + 2.
Their product is 2a(2a + 2) = 4a(a + 1). By Exercise l1c, a(a + 1) is even, so 4a(a + 1)
is divisible by 4·2 = 8. Thus the prime factorization of N contains at least 23 . Putting
this all together, we see that N is divisible by 23 ·3 ·5 = 120. Note that we cannot do
better than this, since 1· 2 . 3 . 4 . 5 = 120.

SECTION 1.4 Boolean Functions


1. (a) f(l, 1, 1) = 1· 1·1 + 1 . (1 + 1) + n:-r = 1·0·1 + 1 . 1 + I = 0 + 1 + 0 = 1
(b) 1(0,1,0) = 0 . 1·0 + O· (1 + 0) + 0 + 1 = 0·0·0 + 0·1 + 1= 0 + 0 + 0 = 0
Section 1.4 Boolean Functions 13

3. The following table shows that equality holds in all four cases: The first and fourth
columns are identical.
z y z+y z(z + y)
o 0 o o
o I I o
I 0 I I
I I I I

5. This circuit is the sum (the last OR gate) of two products (the two AND gates), whose
inputs are the original inputs and their complements (because of the inverters). Thus the
Boolean expression is z y + x y .

7. (a) The motion will pass if all three people vote for it or if two of them vote for it and
one votes against. We write down a minterm for each of these cases and take their sum:
zyz+zyz+zyz+xyz.
(b) A motion passes if and only if (at least) two of the members vote in the affirmative.
Thus we can represent the condition as z y + z z + y z .

9. (a) The idea is to apply DeMorgan's law to break up zy into pieces that we can then
work with by applying the distributive law.
z . xy = z . (x + y) (DeMorgan's law)
= z . X + z .Y (distributive law)
= 0 + z .Y (complement law)
= zy (identity law)

(b) This is exactly dual to part (a). It seems less natural to distributive addition over
multiplication, but in Boolean algebra it is equally valid.
x + x + y = x + (xy) (DeMorgan's law)
= (x + x)· (z + y) (distributive law)
= 1 . (x + y) (complement law)
= x + y (identity law)
(c) If we think to "factor out" the z, the rest is easy.
x+xy=x·1+xy (identity law)
= x(1 + y) (distributive law)
= x(y+ 1) (commutative law)
= x.I (dominance law)
=x (identity law)
14 Chapter 1 LOGIC

(d) This is dual to part (c). Again, it is less natural, but the prooffor part (c) dualizes.
An alternative approach is to expand the left-hand side, replace x· x by x, and then use
the result of part (c) directly.
x(x + y) = (x + O)(x + y) (identity law)
=x+O·y (distributive law)
=x + y . 0 (commutative law)
=x + 0 (dominance law)
= x (identity law)

11. (a) We just invert the output of the AND gate.

X--)+I
y--+)I
xy

(b) By DeMorgan's law, xy = x + y. For the circuit, we feed the two inverted inputs to
an OR gate.

(c) x+y = x(y +y) +y(x + x) = xy +xy+yx + yx = xy + xy+xy

13. (a) x y + xy = x(y + y) = X· 1= x


(b) x y + x y + x y + xy = x(y + y) + x(y + y) = x . 1 + x . 1 = x + X = 1
(c) xyz+xyz+xyz+xyz = x(yz+yz)+x(yz+yz) = (x+x)(yz+yz)
1· (yz+ yz) = yz+ yz
(d) xyz+xyz+xyz= x(yz+yz+yz), which can be written x(yz) or x(y+z)

15. (a) xyz = ¥ + Y+ ~ = x + y + z = x(y + y)(z + z) + (x + x)y(z + z) + (x + x)(y + y)z =


x y z + x yz + xy z + xyz + xy z + xyz + xy z (after canceling repeated terms)
(b) (x + yz)(x+yz) = (xyz)(x+y+z) = xyzx+xyzy+xyzz = O+xyz+xyz = xyz
(c) (x + y)(y + z)x = (x y + x z + y + y z)x = 0 + 0 + xy + xy z = xy(z + z) + xy z =
xyz+xyz
Boolean Functions 15
Section 1.4

17. Since this expression has three terms, we use an OR gate with three inputs.

19. (a) If 2: = 1 and Y = 0, then 2:Y = 1 but zy = o.


(b) If 2: = 1 and Y = 0, then x + Y = 0 but z + y = 1.
21. (a) For each case in which f( al, a2, ... , an) = 0, we write down a sum Yl + Y2 + ... + Yn
that will be 0 only in this case; we do so by letting Yi = Xi if ai = 0, and Yi = Xi if
ai = 1. Then we take the product of all such sums. This expression will have the value
o if and only if f(al,a2, ... ,an) = O.
(b) The motion fails in four cases, for each of which we form a sum. It fails if x = Y =
z = 0; this gives the sum 2: + Y + z. It fails if 2: = =
Y 0 and z =1; this gives the
sum 2: + Y + z. Similarly we obtain the sums x + y + z and z + Y + z. We take the
product of these sums to obtain the conjunctive normal form for the desired function:
(2: + Y + z)(2: + Y + z)(2: + y + z)(z + Y + z). This expression has the value 0 if and only
if the motion fails. Therefore it has the value 1 if and only if the motion passes.
(c) Form the disjunction normal form of the complement of the desired function (i.e.,
write down all the mil1terms that are missing from the given disjunctive normal form
expression), complement it, and then apply DeMorgan's law in two stages (and the dou-
ble complement law if necessary), pushing the complementation operation inside. The
outermost + operations thereby become . operations, and the innermost . operations
become + operations. For example, for majority voting in a committee of three we have

2: Y z + x Y z + x yz + 2: Y z = (2:Yz)(zyz)(zyz)(zyz)
= (z+ y+¥)(¥ +y+ ~(¥ + y +z)(¥ + y+ ~
= (z + Y + z)(2: + y + z)(x + Y + z)(2: + Y + z).
16
Chapter 2 SETS

CHAPTER 2
SETS
SECTION 2.1 Basic Definitions in Set Theory
1. {Ronald Reagan, Jimmy Carter, {25, 4,48}, {{4}, 0, {1,2}, N, Z}}

3. (a) no (not a set) (b) yes (c) yes


(d) yes (e) no (not proper) (f) no

5. (a) {-99, -98, ... , -1, 0, 1,2, ... , 99}


(b) {I, 2, ... ,67,68,70,71,72, ... , 100}
(c) to, 1,4, 9, 16, 25, ... }

7. {red, blue}, {red, green}, {red, yellow}, {blue, green}, {blue, yellow}, {green, yellow}

9. (a) F (the left-hand side has two elements; the right-hand side has three elements)
(b) F (the left-hand side has two elements; the right-hand side has one element)
(c) T (both sets contain the three numbers 1, 2, and 3)

11. (a) We know that A ~ B if and only if 'v'x:(x E A -+ x E B). Thus


A <l B -<===> -Nx: (x E A -+ x E B)
-<===> 3x: -,(x E A -+ x E B)
-<===> 3x: (x E A 1\ x rt. B) .
The last equivalence follows from part (k) of Theorem 1 in Section 1.1.
(b) 0 f/; A -<===> 3x: (x E 0 1\ x rt. A) This is clearly false, since there is no x such that
x E 0.

13. (a) {x I x E N 1\ x < 100 1\ -,3mEN:x = 10m}


(b) {1/x 3 I x E N 1\ x> O}
(c) {n(n + 1) I n E N 1\ 1 :::; n :::; 99} = {I. 2, 2·3, 3·4,4·5, ... ,99· 100}
(d) {x I 3mEZ: x = 3m}
(e) {6n + 1 In E Z}
Section 2.1 Basic Definitions ill Set Theory 17

15. {Henry VIII, {2,I5}, {25,4}, {1l,I7}}

17. We are given that A ~ Band B ~ C, and we want to show that A ~ C, i.e., that
"Ix: (x E A -+ x E C). So let x be an arbitrary element of A. Since A ~ B, it follows
that x E B. Then siilce B ~ C, we conclude that x E C, as desired.

19. (a) Let A = =


{0}. Then peA) {0, {0}}, so A ~ peA) (the one element of A is also in
peA) ).
(b) Let A = {I}. Then peA) = {0, {I}}, so A rz. peA) (the one element of A is not an
element of P(A)).
(c) Let A = {I} and B = {I, {I}}. Then A is an element of B, and the one element of
A is an element of B (so A ~ B).

21. Given A ~ B, we must show that peA) ~ PCB), i.e., that VC:(C ~ A -+ C ~ B).
Suppose that C is an arbitrary subset of A. We must show that C ~ B. But this follows
directly from Exercise 17.

=
23. 101 0, IP(0)1 20 = =
1, IP(P(0))1 21 = =
2, IP(P(P(0)))1 22 = = 4,
IP(P(P(P(0)))) 1 24= =16, IP(P(P(P(P(0))))) 1 2 16 65536 = =
25. By the observation made before Theorem 1, we know that A = 0 +-+ (A ~ 01\ 0 ~ A). By
Theorem 1, we know that 0 ~ A is always true. Since P 1\ T {=::} P for any proposition P,
we conclude that A = 0 +-+ A ~ 0.

27. (a) We can list the set of even positive integers as {2, 4, 6, 8, ... }. In other words, by
letting n E N correspond to 2n + 2 in the set of even positive integers, we have set up a
one-to-one correspondence between these two sets.
(b) This set is finite, hence countable. (Indeed, there are, by most estimates, fewer than
10 100 atoms in the entire universe.)
(c) We can list this set as {O, ~, -~, 1, -1, I~, -I~, 2, -2, 2~, -2~, ... }.

29. (a) VA:VB: 3C:Vx: (x E C ..... (x =A V x = B))


(b) 3S:Vx:x E S
(c) VA:3P:VC: (C E P +-+ "Ix: (x E C -+ x E A))

31. First we show that it is possible to list all the positive rational numbers expressed in
lowest terms as r1, r2, r3, .... \Ve order them as follows: first all the positive rational
numbers in lowest terms, the sum of whose numerator and denominator is 2; then those
for which the sum is 3; then those for which the sum is 4, and so on; and within each
group, we order by increasing numerator. Thus the list is ~, t,
~, f, f, :t,
~, ~, t,
!, i, i, ~, ~, ~, ~, and so on. Finally, we list all the rational numbers in the order 0,
rl, -rl, r2, -r2, ....
18 Chapter 2 SETS

33. (a) All real numbers between 0 and 1 can be written as infinite decimals. To avoid
ambiguity in notation, since any finite decimal between 0 and 1 can be written in two
ways (either ending with a string of all O's or ending with a string of all 9's), we arbitrarily
declare that we will use no representations ending with a string of all 9's.
(b) Assume that the set of real numbers between 0 and 1 is countable, and can therefore
be labeled as rl, r2, r3, ... (it is clearly infinite). Let d jj be the jth digit in the decimal
for rj. For example, if rl = 1/7 = .142857142857 ... , then d I4 = 8.
(c) Define a number 7' = O.d l d2 d3 ••• as follows. If djj # 4, then dj = 4; if djj = 4, then
dj = 5. Note that dj # dii for all i, so that r is not in the list. On the other hand,
r represents a real number and does not end in a string of 9's, so r must be in the list.
This contradiction shows that our assumption that the set of real numbers between 0
and 1 is countable was wrong. Therefore this set is uncountable.
(d) The set of real numbers between 0 and 1 is a subset of the set of all real numbers.
If the latter were countable, the former would also have to be countable, and we just
showed that this is not the case.

35. (a) w + 2 = {O, 1, 2, ... , w, w + I}; w + 3 = {O, 1,2, ... , w, w + 1, w + 2}


(b) w ·2= {O, 1, 2, ... , w, w + 1, w + 2, ... }
(c) w 2 = {O, 1,2, ... , w, w + 1, w + 2, ... , W· 2, w ·2+ 1, w ·2+ 2, ... , w ·3, w ·3+ 1,
w ·3+ 2, ... , ... }; w 2 + 1 = {O, 1,2, ... , w, w + 1, w + 2, ... , w ·2, w ·2+ 1, w ·2+ 2,
••• , W· 3, w ·3+ 1, w ·3+ 2, ... , ... , w 2 }

SECTION 2.2 Sets with Structure


1. (a) {(I, 1), (1,3), (2,1), (2,3)}
(b) {(a,a,a), (a,a,b), (a,b,a), (a,b,b), (b,a,a), (b,a,b), (b,b,a), (b,b,b)}
(c) {(I,5), (2,5), (3,5), (4,5)}
(d) {(I,4,5), (2,4,5), (3,4,5)}
(e) 0

3. rolloverrover = r(oll)(ove)rr(ove)r = uwvuuvu

5. The initial su bstrings are ..\, 7', 7'0, rol, and roll. The other substrings are 0, 01, oll,
1, and ll.
;s

19
Section 2.2 Sets with Structure

7. It is straightforward to calculate the entries of these matrices. For example, the (4, 2)th
entry for part (b) is 0 because 2 is not a multiple of 4; and the (2,4)th entry for part (c)
is the substring of papa extending from the second letter to the fourth, namely apa.
(c)
~ ~ ~]
(
~ ~
(a) (b)

o 0 100
o 0 010
o 0 001

9. (a) 5 + 8 + 11 + 14 = 38
(b) 22° + 221 + 22~ + 223 = 21 + 22 + 24 + 28 = 2 + 4 + 16 + 256 = 278
( c) 7 + 7 + ... + 7 = 700
(d) 22 + 32 + 52 + 72 + 112 = 208
(e) 1+1+2+2+3+3=12

11. Let (a,e) E A x C. Then a E A and e E C. Since A ~ Band C ~ D, we know that


a E Band e E D. Hence (a, c) E B x D, as desired.

13. If A = B, then we have the identity A x A = A x A. Conversely, suppose that A f. B.


Then there is an element in one of the sets but not in the other; without loss of generality,
assume that it is an element a
that is in A but not in B. Since B f. 0, we can also
find an element bE B. Then (a,b) E A x B, but (a,b) fj. B x A since a fj. B. Thus
AxBf.BxA.

15. 00001111, 00010111, 00011011, 00011101, 00100111, 00101011, 00101101, 00110011,


00110101, 01000111, 01001011, 01001101, 01010011, 01010101

17. {(0,0,3), (0,3,0), (3,0,0), (0,1,2), (0,2,1), (1,0,2), (1,2,0), (2,0,1), (2,1,0), (1,1,1)}

[~ -~
(b) (c) 0 1
19. (a) 0 3
2 0]
1 -1
~ 4~l
-3
o
[o
0 o 7
3 o 0 [
1 0
1../2
1 0 4 0 v'8v'5

21. (a) An open set is determined by its endpoints, which can be any real numbers (as long
as the left endpoint is less than the right endpoint). Thus the set is { {x I a < x < b} I
a < b } , indexed by pairs of real numbers (a, b) with a < b.
(b) {last name of x Ix is a person in the United States}
(c) The sets listed here are the multiples of 1, 2, 3, and so on. The set of multiples of
n is the set of all numbers of the form mn, where mEN. Thus the set is { { mn I m E
I
N} n E N /I. n f. O} , indexed by the positive integers.
---------- ..............
20
Chapter 2 SETS

23. Let An be the set of prime divisors of the natural number n. Then {An I n = 5, 10, 20}
is different from {An I n = 5, 10} as indexed sets (the first has an indexing set with
three elements, the second has an indexing set with two elements). But as sets, both are
simply {{5}, {2, 5}}.

25. (a) 1·2 + 1 ·3 + 2·3 = 11


(b) 1· 1 + 1 . 2 + 1 . 3 + 2 . 1 + 2 . 2 + 2 . 3 + 3 . 1 + 3 . 2 + 3 . 3 = 36

21. (a) (T(n) = L d


din
15d<n
n

(b) trace(A) = La;;, where A = (aij) is an n by n matrix


;=1

29. (a) 1·2·3·4·5·6·7 = 5040


(b) 46·45·44···2·1·0 = 0 (no arithmetic is needed because of the final factor)
(e) (1·1)(2.1 + 2·2)(3·1 + 3 ·2+ 3·3) = 108
(d) (1·1) + «2 ·1)(2·2» + «3·1)(3·2)(3·3» = 171

31. (a) yes (n corresponds to 2n; the key point is that 2(n + m)
"
= 2n + 2m)
(b) no (Z has a multiplicative identity, but E does not)
(e) no (addition is commutative but subtraction is not)

33. A palindrome is any string of the form Ul U2 ... U n - l Un Un-I . .. U2Ul , where n ~ 1 and
each U; E U, or of the form Ul U2 ... U n - l UnU n Un-I . .. U2Ul, where n ~ 0 and each
Uj E U.

SECTION 2.3 Operations on Sets


1. (a) 0 (b) {3,9} (c) U (d) {2, 3, 4, 6,8,9, lO}
(e) {I, 2, 4, 5, 7, 8, to} (f) {I, 5, 7} (g) {2, 3, 4, 8, 9, lO}

3. (a) MnC (b) JlfnC (c) M-C=MnC=MUC


(d) An C n Al = (A n JIf) - C (e) AnMnC= AUMnC = C- (AUM)

5. If z E A n B, then z E A and z E B. In particular, z E A, so z E A V z E B. Thus


zEAUB.

1. (a) {I} and {2, 3} (b) {4} and {O, 5, 6, 7, ... } (e) {2, 3} and {O, 3, 4, 5, ... }
Section 2.3 Operations on Sets 21

9. The symmetric difference of A and B, according to Exercise 15, equals the difference
(A U B) - (A n B). By Exercise 5, An B ~ Au B. Therefore A EB B = AU B if and
only if An B = 0. In other words, the symmetric difference equals the difference if and
only if the sets are disjoint.

11. The proof is dual to the proof given in the text for the first half of Theorem 2. We can
give it more succinctly in symbols.

iEI iEI

= {x I-.(x E U Ai) }
iEI

= { x 1 -.(3iEI: x E Ai) }
= {x 1 ViEI: x ~ Ai }
= { x 1 'ViEI: x E As }

= nAi
iEI

13. {{O, I}, {2,3}, {4,5}, ... }

15. The idea in this proof is to tear the definition apart to obtain a complete logical description
of when an element is in A EB B, then to use logic to rewrite that description so that it
matches the definition of (A U B) - (A n B).
A EB B = { x I (x E A 1\ x ~ B) V (x E B 1\ x ~ A) }
= { x 1 (x E A V x E B) 1\ (x E A V x ~ A)
1\ (x ~ B V x E B) 1\ (x ~ B V x ~ A) }
(this follows from part (c) of Theorem 1 in Section 1.1)
= { x 1 (x E A V x E B) 1\ T 1\ T 1\ (x E B V x E A) }
= { x 1 (x E A V x E B) 1\ x E B 1\ x E A}
={xIXEAUBl\x~AnB}
= (A U B) - (A n B)

17. (a) The double-hatched region is An (B EB C).


22 Chapter 2 SETS

A _B
(b) The entire hatched region is (A - B) U (C - A).

(c) In the picture on the left we have shaded A with horizontal hatching and B (J) C with
vertical hatching. The symmetric difference of these two sets is therefore the region which
is hatched but not double-hatched. It is redrawn, simply shaded, in the Venn diagram on
the right.

A B A

19. (a). (A n B U C) U (B n C n A) = (A n B n C) U (A n B n C)
(b) (A n B) U (A n C) U (B n C)
(c) (AUBUC)-(AnB)-(AnC)-(BnC) = (A-B-C)U(B-A-C)U(C-A-B)
(d) (B-A)U(AnCnB)
Operations on Sets 23
Section 2.3

21. (a) Suppose that x E Au B. Then x E A or x E B. In either case, x E B U A. Hence


Au B ~ B U A. Similarly B U A ~ AU B. Hence A U B = B U A.
(b) We need to prove, for an arbitrary x, that x E An (B U G) if and only if x E
(A n B) U (A n G). Suppose that x E An (B U G). Then x E A and x E BUG.
The latter condition means that x E B or x E G. If x E B, then x E A n B; and if
x E G, then x E An G. In either case x E (A n B) U (A n G). Conversely, suppose that
x E (A n B) U (A n G). First, assume that x E An B. Then x E A and x E B. Hence
x E BUG as well, so x E An(BUG). On the other hand, if x f/. AnB, then x E AnG.
Thus x E A and x E G. Hence x E BuG as well, so again x E A n (B U G) .
(c) Suppose that x E An U. Then in particular x E A. Conversely, if x E A, then
x E An U, since by convention x is always an element of U.
(d) Suppose that x E A U A. Then x E A or x E A, i.e., x EA. Conversely, if x E A,
then x E A UA.
(e) Suppose that x E AnA. Then x E A and x E A, i.e., x E A and x f/. A. This is
impossible, so no such elements x exist. Therefore A n A = 0.
(f) Suppose that x E A. Then it is not the case that x E A, i.e., it is not the case that
x f/. A. Therefore x EA. Conversely, if x E A, then x f/. A, whence x E A.
(g) Suppose that x E A U B. Then x f/. A U B. This means that it is not the case that
x E A or x E B, which implies that x is in neither A nor B. Hence x E A and x E B,
so x E An B. Conversely, if x E A n B, then x f/. A and x f/. B, so it is not the case
that x E A U B. Thus x E A U B.

23. (a) To see that A - B is not equal to B - A in general, take A 0 and B {I}. = =
Then A - B = =
0, but B - A {I}. It is also easy to see from the Venn diagrams that
A-BIB-A.
(b) It is true that A EB (B EB G) = (A EB B) EB G. Each side consists of all those objects
that are elements of an odd number of the sets A, B, and G. Indeed,
(A EB B) EB G = { x I (x E A EB B 1\ x f/. G) V (x E C 1\ x f/. A EB B) }
= { x I (x E A 1\ x f/. B 1\ x f/. G) V (x E B 1\ x f/. A 1\ x f/. G)
V (x E G 1\ x E A 1\ x E B) V (x E G 1\ x ct A 1\ x ct B) } .
The calculation for A EB (B EB G) is similar. See the Venn diagram for the solution to
Exercise 17c.
(c) To see that AU(BEBG) I (AUB)EB(AUG) in general, take A {I} and B G 0. = = =
= = =
Then AU (B EB G) {I}, but (A U B) EB (A U C) {I} EB {I} 0. One can also look at
the Venn diagrams for these two expressions.
(d) The double-hatched region on the left is An (B EB G). The shaded but not double-
hatched region on the right is (A n B) EB (A n C). These two sets are equal.
24
Chapter 2 SETS

A
.~B A

(e) I
A x (B n C) = { (x, y) x E A AyE B n C}
= {(x,y) I x E A AyE BAy E C}
= {(x,y) I (x E A AyE B) A (x E A AyE C)}
= {(x,y) I x E A AyE B} n {(x,y) I x E A AyE C}
= (A x B) n (A x C)

(f) I
A x (B U C) = { (x, y) x E A AYE B U C}
= { (x, y) I x E A A (y E B V Y E C) }
= {(x, y) I (x E A AYE B) V (x E A AyE C) }
= {(x,y) I x E A AyE B} U {(x,y) I x E A AYE C}
= (A x B) U (A x C)

25. These operations correspond in the sense that z E A - B if and only if it is not the case
that z E A implies z E B. (This follows from the definition of the difference of sets and
part (k) of Theorem 1 in Section 1.1.)

27. (a) The ~ relation for sets is analogous to the logical implication relation for propositions.
Just as A = B means that A ~ Band B ~ A, so P {:::::::} Q means that P ==::} Q and
Q ==::} P.
(b) Analogous to P ==::} P V Q is A ~ AU B. This is clear: If z E A, then x E AU B.
Analogous to P A Q ==::} P is An B ~ A. Again this is clear: If x E An B, then x EA.
Operations on Sets 25
Section 2.3

29. (a) This is true. If A E F, then A is finite, so certainly An B, which is a subset of A,


is finite.
(b) This is false. Let A be the set of even natural numbers, and let B be the set of odd
natural numbers together with 0 and 2. Then An B = {O, 2} rt I.
(c) This is true since IA U BI $ IAI + IBI·
(d) This is true. If either A or B is infinite, then certainly AU B is infinite. On the
other hand, 0 U 0 = 0.

31. (a) Q,since n(x-€,x+€)={x}


£>0

(b) R, since U(x - €,x + €) = R for each x


£>0

(c) R,since U(x-€,x+€)=Rforeach €>O


xeQ

(d) 0,since n(x-€,x+€)=0foreach€>0


xeQ
(e) 0, as in part (d)
(f) R, as in part (c)

33. For each prime number p, let Ap = {pq I q is prime}. For example, A2 = {4, 6, 10,
14, ... }, and A3 = {4, 9, 15, 21, ... }. The collection of all such sets Ap is an example
with the desired property. Indeed, for every distinct p and q, Ap n Aq = {pq} "I 0. On
the other hand, it is impossible for any number to have three distinct prime factors if
it has only two prime factors, so Ap n Aq n Ar = 0 whenever p, q, and r are distinct
primes.

35. (a) C is closed under complementation, since if A is finite, then A has a finite comple-
ment (namely A), and if A is finite, then A has a finite complement.
(b) Suppose that A and B are both in C. If either is finite, then An B is finite, hence
in C. Otherwise both A and B are finite, so AU B is finite. But Au B = An B, so
An B has a finite complement and hence is an element of C.
(c) Since AU B = An B, the fact that C is closed under complementation and inter-
section implies that C is closed under union.
(d) Similar to part (c), since A - B = An B.
26
Chapter 3 FUNCTIONS AND RELATIONS

CHAPTER 3
FUNCTIONS AND RELATIONS
SECTION 3.1 Functions
1. (a) no (it is not even a set)
(b) no (it is a function from {2} to {I, 2, 3, 4}, however)
(c) yes
( d) no (3 is missing from the domain)
(e) no (1 has two associated values)
(f) no (5 is not in the given codomain)

3. (a) {(1,2), (2,3), (3,4), (4,5)}


(b) {(1,8), (2,8), (3,8), (4,8)}
(c) {(1,2), (2,2), (3,4), (4,4)}

5. (a) In 5 -;.-In 2 = 2.32193


(b) In 10 -;.-In 2 = 3.32193 (note that this is 1 + log 5, since log(2. 5) = (log 2) + (log 5»
( c) 50 log 10 = 50 In 10 -;.-In 2 = 166.09640

7. (a) 6+5=11=4 (b) 1 +1=2 (c) 6· 4 = 24 = 3


(d) 0·2=0 (e) 56 = (5 2)3 = 25 3 = 43 = 64= 1

9. Each entry is the sum or prod uct in N, reduced modulo 5.


1

0
+ 0 2 3 4 X 0 1 2 3 4
0 0 2 3 4 0 0 0 0 0 0
1 1 2 3 4 0 1 0 1 2 3 4
2 2 3 4 0 1 2 0 2 4 1 3
3 3 4 0 1 2 3 0 3 1 4 2
4 4 0 1 2 3 4 0 4 3 2 1 ,
Section 3.1 Functions 27

11. (a) Let q be Prince William of Great Britain. Since q has no children, -.3p: f(p) = q.
(b) Since f is a function, this cardinality is always 1. Everybody has exactly one father.
(c) Since f is a function, this cannot happen. A person cannot have two different fathers.
(d) This can happen. Let q be Prince Charles of Great Britain, and let p and p' be his
sons William and Harry.

13. 'v'aEA:3!bEB:(a,b) E f

15. {({1,2,3},1), ({1,2},1), ({1,3},1), ({2,3},2), ({1},1), ({2},2), ({3},3)}

17. D: R X (R - {O}) -+ R given by D(x, y) = x/y is a function of two variables.

19. 0= {(a,b),c) l(c=ai\a2:b) V (c=bi\a:Sb)};orx0y=(x+y+lx-yl)/2

21. (a) no (3-7 tJ. N)


(b) yes
( c) yes « a/ b) + (c/ d) = (ad + bc) / (bd) )
(d) yes ( Va is a positive real number for all positive real numbers a)
(e) yes (see Exercise 3a in Section 1.3)
(f) no(3+5=8)

23. The answer is 1 if 1 :S n < 10, 2 if 10 :S n < 100, and so on. Taking common (base 10)
logarithms, we have
o :S 10glO < 1 < 10,
if 1:S n
1 :S 10glO < 2 if 10:S n < 100,
and so on. It is then easy to see that in general the number of digits is LloglO n J + 1.

25. (a) log 2 + log x = 1+ y


(b) 210g x = 2y
(c) (logx)/(log4) = y/2
(d) x
(p) 410gx = (')2)logx _ ')21ogx _ ')log(x2) _ ",2
28 Chapter 3 FUNCTIONS AND RELATIONS

27. (a) We can write the real number x as LxJ + f, so that f is a real number satisfying
o ~ f < 1. Since f = x - LxJ , we have 0 ~ x - LxJ < 1. The desired inequalities, Lxj ~ x
and x-I < Lx j , follow algebraically.
r
(b) This is similar to part ( a), but this time we write x = x1- f , where again 0 ~ f < 1.
r r
Then 0 ~ x1 - x < 1, and again the desired inequalities, x ~ x1 and x1 < x r + 1,
follow by trivial algebra.

29. The easiest way to accomplish this is to add 1/2 and then round down. This has the
effect of rounding up if the original number was more than half way to the next highest
integer. Thus round(x) = Lx + 0.5j .

31. If x == 0 (mod 6) or x == 3 (mod 6), then x = 6k or x = 6k + 3; in either case,


x is divisible by 3, and therefore (since x > 3), x is not prime. Similarly, if x == 2
(mod 6) or x == 4 (mod 6), then x is divisible by 2, hence not prime. Thus every
prime number must be congruent to either 1 or 5, modulo 6. Numbers of the former
form can be written as 6k + 1, and numbers of the latter form (since 5 == -1 (mod 6»
can be written as 6k - 1.

33. This is false. Let m = 5, a = b = 2, c = 1, and d = 6. Then 2 == 2 (mod 5) and 1 == 6


(mod 5), but 21 = =
21= 64 26 (mod 5).

35. The number 2 has no multiplicative inverse modulo 6, since 2k is always congruent to
0, 2, or 4 (mod 6), never 1.

37. (a) yes, since multiplication of integers is associative


(b) no, since a 8 (b 8 c) = a 8 (b + 2c) = a + 2(b + 2c) = a + 2b + 4c, whereas
(a 8 b) 8 c = (a + 2b) 8 c = (a + 2b) + 2c = a + 2b + 2c
(c) yes, since a 8 (b 8 c) =a8 b=a and (a 8 b) 8 c = a 8 c = a

39. The domain is P(N) - {0}. For each S in the domain, the image n of S under this
function is an element of S that satisfies n ~ m for all m E S. Thus we can describe
I
this function as the following set of ordered pairs: {(S, n) S E P(N) - {0} /I. n E
S /I. VmES: n ~ m } .
Section 3.2 Functions in the Abstract 29

SECTION 3.2 Functions in the Abstract


1. (a) The following picture represents the function {(1,a), (2,6), (3,d)}. Each element in
the codomain is used at most once.

(b) The following picture represents the function {(I,d), (2,6), (3,d)}. The element d
in the codomain is used twice, so the function is not injective.

3. (a) f(x) = x
(b) f(x) = x + 1 (not onto since 0 is not in the range)
(c) f(x) = Lx/2J (not one-to-one since, for example, f(3) = f(2»
(d) f(x) =3

5. Define f by setting f(O) = 1, f(l) = 0, and f(x) = x for all x;::: 2.


30 Chapter 3 FUNCTIONS AND RELATIONS

7. (a) This function is bijective; its inverse is f-l(y) = (y - 1)/2.


(b) This function is neither injective (1(1) = f( -1» nor surjective (0 is not in the
range).
(c) This function is bijective; its inverse is f-l(y) = V(y-l)/2.
(d) This function is injective but not surjective (only numbers between -7r /2 and 7r /2
are in the range).
(e) This function is surjective but not injective (1(1) = f(-l».

9. If A is a finite set, and f: A ---> A, then f is injective if and only if f is surjective.

11. (a) We need x to be either the father of the father or the father of the mother of y, so
we can write x =
f(J(y» V x f(m(y». =
(b) This time there are four possibilities: y = m(J(x» V y = m(m(x» Vy = f(J(x» V
y = f(m(x».
(c) We make the simplifying assumption that there are no half-brothers or half-sisters.
To say that x is the aunt or uncle of y is to say that x's mother is y's grandmother, but
that x is not the mother or father of y. Thus we write (x t
m(y) 1\ x f(y» 1\ 3u: (u = t
m(x) 1\ (u = m(J(y» V u = m(m(y)))).
(d) We just need to take this last expression and put it into a set description: {y I (x t
m(y) 1\ x t f(y» 1\ 3u: (u = m(x) 1\ (u = m(J(y» V u = m(m(y)))) }.

13. (a) (J+g)(x)=1+2=3 for all x


(b) (J. g)(x) = 1 ·2= 2 for all x
(c) We need to see what happens to odd and even arguments. The definition of the
function is given by

(J - g)(x) = f(x) _ g(x) = { 1 - 2 = -1 ~f x ~s odd


2- 1=1 If x IS even.
(d) Again we look at the odd and even arguments separately:

(J 0 g)(x) = f(g(x» = {21 ~ff x ~s odd = g(x).


I X IS even
Thus fog = g.
( e) This time

(J 0 J)(x) = f(J(x» = {I ~f x ~s odd = f(x).


2 If x IS even
Thus f 0 f = f·
(f) Here

(g 0 J)(x) = g(J(x» = {21 ~ff x ~s odd = g(x).


I X IS even
Thus go f = g.
Section 3.2 Functions in the Abstract 31

(g) In this case

( gog) ( x) = g(g(x) ) = { 2I if x is odd


'f'
1 X IS even
= f (x) .
Thus gog = f.

15. (a) We want to say that C consists of the images of the elements of A; in symbols,
'r/y:(y E C +-+ 3xEA:f(x) = y).
(b) We need to say two things about every y in the codomain-that there are two
distinct elements of the domain whose image is y, and that every element of the domain
whose image is y is one of these two elements (which we call Xl and X2 in the following
expression). Thus we have 'r/yEB: 3Xl EA: 3X2EA: (Xl "I x2 /I. f(Xl) = Y /I. f(X2) =
Y /I. 'r/xEA: [f(x) = y --> (x = xl V X = X2)])'

17. (a) This is true. Suppose that f(xd = f(X2). Then g(f(xd) = g(f(X2»' Since go f is
one-to-one, this means that Xl = X2. Therefore f is one-to-one.
(b) This is false. Let A = {a}, B = {b, d}, and C = {c}. Let f = {(a,b)} and
9 = {(b, c), (d, en.
Then go f = {(a, c)}. Clearly go f is one-to-one, but 9 is not.

19. We will prove the (equivalent) contrapositive: that such a function is not injective if and
only if some horizontal line intersects the graph in more than one point. Let f: A --> R be
the given function. If some horizontal line y = b intersects the graph of f in two distinct
points (xl,b) and (x2,b), then f is not injective, since f(xd = f(X2). Conversely, if f is
not injective, then there exist distinct real numbers Xl and X2 such that f(xd = f(X2).
If b is their common value, then the line y = b intersects the graph in more than one
point.

21. Take the graph of f and project it onto the vertical axis by moving each point (x, b) on
the graph horizontally over to the point (0, b). The resulting subset of the vertical axis
represents the range.

23. (a) If f: A --> Rand g: A --> R, then

f + 9 = {(x, u + v) I (x, u) E f /I. (x, v) E 9 } .

(b) iA={(a,a)laEA}

25. To prove that foi A = f, we simply note that foiA(a) = f(iA(a» = f(a) for all a E A.
Similarly, in 0 f(a) = in(f(a» = f(a) for all a E A, so in 0 f = f·

27. The range of a function is the empty set if and only if the domain is the empty set.
32 Chapter 3 FUNCTIONS AND RELATIONS

29. (a) 1(0) = {/(x) I x E 0} = {/(x) IF} = 0


(0) = {x E A I I(x) E 0} = {x E A IF} = 0
1
(b) 1-
(c) 1- 1 (B) = {x E A I I(x) E B} =A since I(x) E B for all x E A
(d) I(A) = {/(x) I x E A}, which is the range of I

31. (a) {x E Z I x mod 7 = O} = {7k IkE Z}, which is the set of all multiples of 7
(b) {x E Z I x mod 7 = 1 } = {7 k + 1 IkE Z}, which is the set of all integers that are
one greater than a multiple of 7
( c) {x E Z I x mod 7 = 8 mod 7} = {x E Z I x mod 7 = 1 }, the same set as in part (b)
(d) {x E Z I x mod 7 = 0 or 1}, the union of the two sets obtained in parts (a) and (b)
(e) {O, 1,2,3,4,5, 6}, since r(7) = 0, r(29) = 1, r(23) = 2, r(3) = 3, r(ll) = 4,
=
r(19) 5, and r(13) 6 =
(f) {1}
(g) {O, 1}

33. Let R ={a} and S =


{b, c}. Then RnS = 0, so I(RnS) = 0. But I(R) n/(S) =
{2} n {1, 2} = {2}:j: 0.

35. Let B = {1} and A = {a, b}. Let g(l) = a and I(a) = I(b) = 1. Then r 1 does not
exist, so g:j: /- 1 , but log: B -> B is i B .

37. There are 14 surjective functions from {1, 2, 3, 4} to {a, b}. The easy way to see this is
to observe that all functions from {1, 2, 3, 4} to {a, b} are surjective except the two that
send all elements of the domain to the same element of the codomain. Since there are
I{a, b}ll{1,2,3,4}i = 24 = 16 functions in all, there must be 16 - 2 = 14 surjective ones. A
more straightforward way to do this calculation is to consider three cases. There are six
functions in which exactly two elements of the domain are sent to a, since there are six
subsets of {1, 2, 3, 4} containing two elements (namely {I, 2}, {I, 3}, {I, 4}, {2, 3},
{2, 4}, and {3, 4}). There are four functions in which exactly one element of the domain
is sent to a (there being four ways to pick that element), and similarly four functions in
which exactly three elements of the domain are sent to a (there being four ways to pick
the element that is sent to b). Thus there are 6 + 4 + 4 = 14 surjective functions in all.

39. (a) yes (the sum of two continuous functions is continuous)


(b) yes (this follows from Theorem 2)
(c) no (/- 1 is not a function from A to B unless A = B; it is a function from B to A)
Section 3.3 Rela.tions 33

41. Let f be defined as follows. Given a rational number alb in lowest terms, with a an
integer and b a positive integer, let f(a/b) be 2a 3b if a ~ 0, and let f(a/b) = 5- 3
a b

if a < 0. It is clear that this function is injective, since alb can be found uniquely by
looking at the prime factorization of f(a/b).

SECTION 3.3 Relations


1. (a) {(1, 1), (1,2), (2, 2)}
(b) {(I, 1), (1,2), (2,2)}
(c) {(I, 1), (2,1), (3,1), (2,2)}
(d) {(I, 1), (2,2)}
(e) 0 (if x =y+3 and y = 1 or 2, then x =4 or 5, which are not in the domain)
(fj {(I, 1), (1,2), (2,1), (2,2), (3,1), (3,2)}

3. (a) (10,10), (10,11), (4,25) E R; (0,10), (6,6) f/: R


(b) (3,0), (3,1), (3,2) E R; (2,2), (2,3) f/: R
(c) There are no elements in R (i.e., R = 0), since xy can only be negative if one of x
and y is negative. Every element of N x N is not in R; for example, (2,1), (0,0) f/: R.

5. (a) We draw an arrow from x to y whenever x < y.

~--------3

(b) Note the loops in the digraph, since x :s x is true for all x.

o1 - ------~) - 2
0
1
4-(
1
-3

U U
(c) The relation ~{1,2,3,4} = {(I, 1), (2,2), (3,3), (4, 4)} , so the digraph consists only of
loops.
34 Chapter 3 FUNCTIONS AND RELATIONS

4- -3

U U
7. (a) G is not a function, since XCYl and XCY2 can both hold for Yl # Yl, namely if Yl
is x's mother and Y2 is x's father.
(b) The digraph has no loops since no one is his or her own child.
(c) The relation CoG consists of pairs (x, z) such that xGy and yG z for some y. In
other words, x is a child of some Y, who is a child of z. Thus GoG is the "is a grandchild
of" relation.

9. (a) The new elements that we need to consider are 6 and 7. We note that 516 + 2·2,
516 + 2 ·7, 513 + 2 ·6, 517 + 2 . 4, and 511 + 2·7. Thus the pairs (6,2), (6,7), (3,6),
(7,4), and (1,7) must be added to what we had in Example 7. Therefore the relation is
{(O,O), (0,5), (1,2), (1,7), (2,4), (3,1), (3,6), (4,3), (5,0), (5,5), (6,2), (6,7), (7,4)}.
(b) We need to add new points for 6 and 7 and the lines corresponding to the pairs we
have added to the relation.

3- ) -1
'\.. ).,/

4-
~
~(-------

( c) As usual, we put a 1 in location (i, j) to indicate that 51 i + 2 . j , and a 0 to indicate


that 5 Ai + 2 . j .
0 1 2 3 4 5 6 7
0 1 0 0 0 0 1 0 0
1 0 0 1 0 0 0 0 1
2 0 0 0 0 1 0 0 0
3 0 1 0 0 0 0 1 0
4 0 0 0 1 0 0 0 0
5 1 0 0 0 0 1 0 0
6 0 0 1 0 0 0 0 1
7 0 0 0 0 1 0 0 0
Section 3.3 Relations 35

11. (a) For each (x,y) E S, we need to look for what y is related to under R. For example,
since (a,3) E Sand (3,a) E R, we know that (a,a) E R 0 S. Since (3,b) ERas
well, we also have (a, b) E R 0 S. Doing this for all pairs in S, we obtain R 0 S =
{(a,a), (a,b), (b,a), (b,c), (c,cn.
(b) This is the same as part ( a), except that we reverse the roles of Rand S: For
each (x,y) E R, we need to look for what y is related to under S. Here we obtain
SoR= {(1,2), (1,3), (1,4), (3,1), (3,2), (3,3), (3,4), (4,2), (4,4n.
(c) We need to list all pairs in {1,2,3,4} x {a,b,c} that are not in R. This gives us
R= {(l,b), (2,a), (2,b), (2,c), (3,c), (4,a), (4,bn.
(d) We reverse all the pairs in R; this gives us a relation from {a, b, c} to {I, 2, ,3, 4}:
R- 1 = {(a, I), (c, I), (a, 3), (b,3), (c, 4n.
(e) First we need to compute S-l = {(I,b), (2,b), (2,c), (3,a), (4,b), (4,cn. Then we
need to compose this with R- 1 using the method explained in part (a). We obtain
R- 1 oS-l = {(1,3), (2,1), (2,3), (2,4), (3,1), (3,3), (4,1), (4,3), (4,4n.
(f) This is just like part (e), but the composition is in the opposite order: S-l 0 R- 1 =
{(a, a), (a, b), (b, a), (c, b), (c, cn.
(g) We take the reverses of all the pairs we obtained in part (a): (RoS) -1 = {(a, a), (a, b),
(b,a), (c,b), (c,cn. Note that this is the same as the answer to part (f); that is, S-1 0
R- 1 = (R 0 S)-l.

13. (a) By definition, Rof:l. A = {(a,b) 13a'EA:(a,a') E f:l.A /\ (a',b) E R}. Now for
each a E A there is a unique a' E A such that (a, a') E f:l. A , namely a' = a. Therefore
(a, b) E R 0 f:l.A if and only if (a, b) E R. In other words, R 0 f:l.A = R.
(b) By definition, f:l.B oR = {(a,b) 13b'EB:(a,b') E R /\ (b',b) E f:l. B }. Now for
each bE B there is a unique b' E B such that (b',b) E f:l.B, namely b' = b. Therefore
(a, b) E f:l.B 0 R if and only if (a, b) E R. In other words, f:l.B 0 R = R.
(c) This is false. Let A = B = {I, 2}, and let R =A x A. Then R- 1 =A x A and
R 0 R- 1 = A x A:/; f:l. A .
(d) This is false. Let A = {I}, B = {2, 3}, C = {4}, R = {(1,2)}, and S = {(2,4n.
Then So R = {(I, 4n, so So R = 0. On the other hand, R = {(I, 3n and S = {(3, 4)},
so SoR= {(1,4n.
(e) We must show that each pair in the left-hand side is in the right-hand side, and vice
versa. Suppose that (a, c) E So (R U R'). Then for some bE B we have (a, b) E R U R'
and (b, c) E S. If (a, b) E R, then (a, c) E SoR, and if (a, b) E R', then (a, c) E SoR'; in
either case (a,c) E (SoR)U(SoR'). Conversely, suppose that (a,c) E (SoR)U(SoR').
Without loss of generality, suppose that (a,c) E So R. Then for some bE B we have
(a,b) E Rand (b,c) E S. Thus perforce 3bEB:«a,b) E RU R' /\ (b,c) E S). so by
definition, (a, c) E So (R U R').
(f) This is false. Let A = {I}, B = {2, 3}, C = {4}, R = {(I,2)}, R' = {(I,3)},
and S = {(2,4), (3,4)}. Then So (R n R') = So 0 = 0, but (S 0 R) n (S 0 R') =
{(I,4)} n {(1,4)} = {(1,4)}.
36 Chapter 3 FUNCTIONS AND RELATIONS

15. A I-ary relation is any set of I-tuples from A, which can be thought of, more simply, as
just any subset of A.

17. (a) Let a be any element of A. Then (a,a) E R, so (a,a) ¢ R. Therefore R is not
reflexive.
(b) Suppose that (x,y) E R. Then (x,y) ¢ R. If (y,x) were in R, then (x,y) would
be in R as well; therefore (y, x) ¢ R. In other words, (y, x) E R. Thus R is symmetric.
(c) This is false. Take A = {x, y} and R = 0. Then R is antisymmetric, but R is not.
(d) This is false. Take A = {x} and R = 0. Then both Rand R are transitive.

19. Suppose that {R; hEf is the given collection of relations on A, and let R = niEI R; be
their intersection.
(a) Let a E A. Then since each R; is reflexive, (a,a) E R; for each i. Therefore
(a, a) E R, so R is reflexive.
(b) Let (x, y) E R, so that (x, y) E R; for each i. Then since each R; is symmetric,
(y,x) E R; for each i. Therefore (y,x) E R, so R is symmetric.

21. (a) This relation is clearly symmetric. It is also clear that it is not reflexive or antisym-
metric. Although one would have to research the publishing habits of mathematicians to
make sure, it is surely not transitive.
(b) antisymmetric, transitive (vacuously)
(c) antisymmetric, transitive
(d) reflexive, transitive
(e) None of the properties holds.
(f) None of the properties holds.
(g) symmetric
(h) antisymmetric, transitive
(i) reflexive, antisymmetric, and transitive (it is the same relation as ~)

23. Two points are related if and only if the first is just below or just to the left of the second.
Section 3.3 Relations 37

25. (a) Suppose that (x, y) E R /I. (y, z) E R. By symmetry we know that (y, x) E Rand
hence by antisymmetry, x = y. Therefore (y,z) = (x,z), so (x,z) E R.
(b) If (x,y) E R, then, as above, x = y. Hence R can contain no pairs (x,y) with
x -I y. In short, R ~ LlA .

27. (a) Two authors a and b are related if there is a sequence of authors a = ao, al, a2,
... , an = b such that each author in the sequence has written a joint paper with the next
one (i.e., ai-l and ai have written a joint paper, for i = 1, 2, ... , n).
(b) This is the relation that always holds.
( c) "is an ancestor of"
(d) This is the relation that always holds, as long as you adopt the view that every two
people have a common ancestor (Adam and Eve?).

29. (a) There are all l's along the main diagonal (i.e., each mii = 1).
(b) There are all O's along the main diagonal (i.e., each mii = 0).
(c) The matrix is symmetric about the main diagonal (i.e., mij = mji for every i and j).
(d) There are never two l's symmetrically located around the main diagonal (i.e., for
every i -I j, if mij = 1, then mji -I 1).

31. (a) Assume that R is symmetric. If (x, y) E R, then (y, x) E R, so (x, y) E R- 1 . Thus
R ~ R- 1 . Similarly, if (x,y) E R- 1 , then (y,x) E R, which implies by symmetry that
(x, y) E R. Thus R- 1 ~ R. Therefore R =
R- 1 . Conversely, assume that R R- 1 . If=
1
(x, y) E R, then (x, y) E R- , so (y, x) E R. In other words, R is symmetric.
(b) Assume that R is transitive. If (x, y) E R2, then there exists a z E A such that
(x, z) E Rand (z, y) E R. Thus by transitivity, (x, y) E R. This shows that R2 ~ R.
Conversely, assume that R2 ~ R. Let (x, y) E Rand (y, z) E R. Then by definition,
(x, z) E R2, so (x, z) E R. This shows that R is transitive.
(c) R is reflexive ¢:::} 'VaEA: (a, a) E R ¢=:} LlA ~ R
(d) Suppose that R is antisymmetric, and let (x, y) E RnR- 1 . Then (x, y) E R /I. (x, y) E
R- 1 . The latter condition means that (y,x) E R, so by antisymmetry, x = y. This shows
that R n R- 1 ~ LlA. Conversely, suppose that R n R- 1 ~ LlA. If both (x, y) E Rand
(y, x) E R, then (x, y) ERn R- 1 , so (x, y) E LlA. This means that x = y. Therefore R
is antisymmetric.
38 Chapter 3 FUNCTIONS AND RELATIONS

SECTION 3.4 Order Relations and Equivalence Relations


1. (a) We need to list all pairs (x,y) for which there is a rising path from x to y. This
gives us {(a, a), (a, b), (b,b), (e,e), (d,e), (d,d), (e,b), (e,e), (e,d), (e,e), (e,h), (I,a),
(I, b), (I, c), (I,d), (I, e), (1'/), (I, g), (I, h), (g,a), (g,b), (g,g), (h,b), (h,e), (h,h)}.
(b) We add a line between two points if there is a rising path between them.

8 d

3. All the pairs with a as their first coordinate come first, then the pairs with b as their first
coordinates, and so on. The second coordinate determines the order within each group.
The list is therefore (a, a), (a,b), (a,e), (b,a), (b,b), (b,e), (e,a), (e,b), (e,e).

5. (a) We draw an arrow for each pair in the relation.

(b) It is easy to see from the digraph that the relation is reflexive, symmetric, and
transitive.
(c) The connected pieces of the digraph give us the sets (equivalence classes) in the
partition: {{1,5}, {2,6}, {3}, {4}}.
(d) Each set in the partition is represented by one region in this picture.

-----.----
(e) [1] = {I, 5} = [5]; [2] = {2, 6} = [6]; [3] = {3}; [4] = {4}
Section 3.4 Order Relations and Equivalence Relations 39

7. (a) We list all pairs of numbers that are in the same set in the partition: {(1, 1), (1,2),
(1,3), (2,1), (2,2), (2,3), (3,1), (3,2), (3,3), (4,4), (4,5), (5,4), (5,5), (6,6)}.
(b) An arrow is drawn between two numbers if the corresponding pair is in our list from
part (a).

0~(--G •
~

9. (a) m is the minimum element of (A,::s) if and only if VxEA: m ::S x


(b) m is a minimal element of (A,::s) if and only if VxEA: (x ::S m ---> x = m)

11. The empty relation on {1} is antisymmetric and transitive (vacuously), but it is not
reflexive. The relation that always holds on {1, 2} is reflexive and transitive (trivially),
but it is not antisymmetric. The relation {(1, 1), (1,2), (2,2), (2,3), (3,3)} on {1, 2, 3}
is reflexive and antisymmetric, but it is not transitive (since (1,3) is missing).

13. A line from one point upward to another point means that the first activity must be
completed before the second activity can be started. (We are assuming that the vegetables
are cooked in boiling water, rather than boiling the water with the vegetables already in
the pot.)

• set table
carve drai n beans drai n potatoes
turkey
p~t turkey
1 n oven put beans
into boi 1

preheat stuff boi 1 ",ate r boi 1 ",ate r


oven turkey for beans fo r potatoes
40 Chapter 3 FUNCTIONS AND RELATIONS

15. (a) If y = px for some prime p, then x I y but there can be no intermediate numbers z
such that x I z and z I y, since each proper multiple of a number must have at least one
more prime factor. This characterizes the notion of being an immediate predecessor for
this relation.
(b) For each prime divisor of y, the integer yip is an immediate predecessor of y; there
are no others. Hence the number of immediate predecessors is equal to the numbers of
distinct prime divisors of y. (In particular, 1 has no immediate predecessors.)
(c) For each x and each prime p, the integer px is an immediate successor of x. Since
there are an infinite number of primes, each x has an infinite number of immediate
successors.

17. (a) The proof of Theorem 1 in Section 3.3 showed that the intersection of transitive
relations in transitive. Exercise 20d and 20e in Section 3.3 showed the same for reflexivity
and antisymmetry.
(b) This is false. Consider the :S and 2: relations on N. Their union is the relation that
always holds-it is not antisymmetric.
(c) This is always false. The complement is definitely not reflexive.

19. (a) Every element A E P(N) satisfies 0 ~ A ~ N. Therefore the minimum element
(and hence the only minimal element) is 0, and the maximum element (and hence the
only maximal element) is N.
(b) The minimum element (and hence the only minimal element) is (1, 1). The maximum
element (and hence the only maximal element) is (3,3).
(c) The minimal elements are a and b. There is no minimum element. The maximum
element (and hence the only maximal element) is e.
(d) The minimal elements are a, b, c, h, and i. The maximal elements are f, g, h,
and j. Note that h is both minimal and maximal. There are no minimum or maximum
elements.
(e) The minimum element (and hence the only minimal element) is f. The maximal
elements are band c. There is no maximum element.
(f) The element 1 is both the minimum and the maximum (and hence also minimal and
maximal).
(g) Both elements 1 and 2 are minimal and maximal. There is no minimum or maximum.

21. We could copy the proof of Theorem 2 word for word, replacing "dominate" by "are
dominated by," u ::; v by v ::; u, "maximal" by "minimal," and so on (the word "smallest"
is not changed, however). Here is another way to look at it. Let Xl be any element of A.
If Xl is minimal, then we are done. Otherwise there is an element X2 E A such that
X2 -< xl· If X2 is minimal, then we are done; otherwise there is an element X3 E A
such that X3 -< X2. We continue in this manner. We can never choose an element
previously chosen, for then we would have Xi -< Xi-1 -< ... -< Xj, with Xi = Xj, whence
Section 3.4 Order Relations and Equivalence Relations 41

by transitivity, Xi -< Xj, a contradiction. Since A has only a finite number of elements,
the process must therefore terminate at a minimal element.

23. For a relation that is symmetric and transitive, but not reflexive, take 0 on {I}. For a
relation that is reflexive and transitive, but not symmetric, take {(I, 1), (1,2), (2,2)}
on {I, 2}. For a relation that is reflexive and symmetric, but not transitive, take
{(I, 1), (1,2), (2,1), (2,2), (2,3), (3,2), (3,3)} on {I, 2, 3}. (See also Exercise 22 in Sec-
tion 3.3.)

25. (a) This is an equivalence relation by Theorem 3.


(b) This relation is not transitive: lR2 1\ 2R3, but 1$3.
(c) This is an equivalence relation. One way to see this fact is by applying Theorem 3
using "measures of the angles" as the function.
(d) This is an equivalence relation by Theorem 3, where f( x) is the set of all prime
divisors of x.
(e) This is an equivalence relation by Theorem 3, where f(x) = (x's father,x's mother).
(f) This relation is not transitive.

27. the equivalence classes of R

29. Since x - x = =0 0 . m is a multiple of m, we know that the relation is reflexive.


If x - y = km, then y - x = (-k)mj this tells us that the relation is symmetric. If
x-y=km and y-z=lm,then x-z=(x-y)+(y-z)=km+lm=(k+l)mjthis
tells us that the relation is transitive.

31. (a) one, namely 0


(b) one, namely {{a}}
(c) two,namely {{a,b}} and {{a}, {b}}

33. (a) Rather than list all the partitions, we will just figure out how many there are with
each pattern of cardinalities. There is one partition consisting of just one set. There are
four partitions consisting of a set with three elements and a set with one element, since
there are four ways to decide on the singleton. There are three partitions with two sets
of cardinality 2, since A can be in the same class as B, as C, or as D. There are six
partitions in which there is one set of cardinality 2 and two singletons, since there are six
ways to pick the doubleton. Finally, there is the one partition in which all the elements
are in sets by themselves. Hence the answer is 1 + 4 + 3 + 6 + 1 = 15.
(b) By part (a) and Theorem 4, the answer is 15.
42 Chapter 3 FUNCTIONS AND RELATIONS

35. (a) This follows from the proof of Theorem 1 in Section 3.3.
(b) This is false-transitivity may fail. For example, let R1 = {(I, 1), (1,2), (2,1),
(2,2), (3, 3)}, and let R2 = {(I, 1), a(2,2), (2,3), (3,2), (3, 3)}. Then R1 U R2 is not
transitive.
(c) Let R be an equivalence relation. We must show that R- 1 is reflexive, symmetric,
and transitive. For each a E A, (a, a) E R since R is reflexive, so (a, a) E R- 1 as well.
Thus R- 1 is reflexive. The inverse of any symmetric relation is itself (see Exercise 31 in
Section 3.3), so R- 1 is symmetric. Finally, suppose that (x, y) E R- 1 and (y, z) E R- 1 .
Then (y,x) E Rand (z,y) E R, so by the transitivity of R, (z,x) E R. This means that
(x, z) E R- 1 ; therefore R- 1 is transitive.
(d) This is always false; the complement is never reflexive.

37. Every positive integer x can be written as the product of a power of 2 and its "odd part":
x = 2m . y, where y is odd and m ~ O.
(a) Here the equivalence classes are the sets of numbers with the same power of 2
in this decomposition (which is the smallest element in each class): {{I, 3, 5,7, ... },
{2,6,10,14, ... }, {4,12,20,28, ... }, {8,24,40,56, ... }, ... }.
(b) Here the equivalence classes are the sets of numbers with the same odd part (which is
again the smallest element in each class): {{ 1,2,4,8,16, ... }, {3, 6,12,24, ... }, {5, 10, 20,
40, ... }, {7,14,28,56, ... }, ... }.

39. Since the equivalence relation must be reflexive, symmetric, and transitive, we need to
form its reflexive, symmetric, transitive closure. This is discussed at length in Section 3.3.

41. (a) Since the identity function on A is bijective, we have ARA. If ARB, then there
is a bijective function I: A -+ B. Then /- 1 : B -+ A is a bijective function as well, so
BRA. If ARB and B RC, then there are bijective functions I: A -+ Band g: B -+ C.
Then go I is a bijective function from A to C (Theorem 2 in Section 3.2), so ARC.
Alternatively, we can apply Theorem 3 with I(A) = IAI, recalling that all infinite subsets
of N have cardinality ~o.
(b) For i = 0,1,2, ... , let Ci be the set of all finite subsets of N with cardinality i; and
let Coo be the set of all infinite subsets of N. For example, C 1 = {{I}, {2}, {3}, ... }.
The Ci'S and Coo are the equivalence classes.

43. (a) The :S relation on R is dense. If xi y, then (x + y)/2 lies between them.
(b) The relation ~ on R x R given by (a, b) ~ (c, d) ...... (a :S c /\ b :S d) is dense but not
total. The pairs (1,3) and (2,2), for example, are not comparable, but if (a,b) -< (c,d),
then a:S c, b:S d, and either a < cor b < d, and in either case «a+c)/2,(b+d)/2)
lies between them.
(c) The :S relation on Z is not dense, since, for example, nothing lies between 3 and 4.
Section 3.4 Order Relations and Equivalence Relations 43

(d) Let a -< b. Then there is an element Xl such that a -< Xl -< b. Using the definition
of denseness again, we obtain an element X2 such that Xl -< X2 -< b. Continuing in this
way we obtain an infinite sequence of distinct elements Xl -< X2 -< X3 -< ....

45. (a) Let 71"1 = {{I}, {2,3}, {4,5}} and 71"2 = {{1,2,3},{4,5}}. Every set III 71"1 IS
contained in some set in 71"2 (for example, {2, 3} ~ {I, 2, 3}).
(b) Let 71"1 = {{1,2,3}, {4,5}} and 71"2 = {{I,2}, {3,4}, {5}}. The set {I, 2, 3} III 71"1
is contained in no set in 71"2, and the set {3, 4} in 71"2 is contained in no set in 71"1.
( c) We always have 71" :::S 71", since we can take Y = X in the definition. Thus the
refinement relation is reflexive. Next suppose that 71"1 :::S 71"2 and 71"2 :::S 71"1. Let X be an
arbitrary element of 71"1. Then X ~ Y for some Y E 71"2. Furthermore, Y ~ X' for some
X' E 71"1. Hence X ~ X'. Since the elements of 11"1 are nonempty and pairwise disjoint,
this can only happen if X = X'. Thus we have X ~ Y ~ X, whence X = Y. This
shows that every element of 71"1 is also in 71"2. By similar reasoning every element of 71"2 is
in 71"1, so 71"1 = 71"2. Thus we have established that :::S is antisymmetric. Finally, suppose
that 71"1 :::S 71"2 and 71"2 :::S 71"3. We must show that 71"1 :::S 71"3. Let X E 71"1. Then there is a
Y E 71"2 such that X ~ Y, and hence also a Z E 71"3 such that Y ~ Z. But then X ~ Z,
as desired.
(d) The partition {{I, 2, 3, 4, 5}} is the maximum element, since we can always take
Y = {I, 2, 3, 4, 5} in the definition.
(e) The partition {{I}, {2}, {3}, {4}, {5}} is the minimum element (i.e., {{I}, {2},
{3}, {4}, {5}} :::S 71"2 for all 71"2), since every element of {I, 2, 3, 4, 5} is in some element
of 71"2.
44 Chapter 4 ALGORITHMS

CHAPTER 4
ALGORITHMS
SECTION 4.1 The Idea of an Algorithm
1. Suppose that a, b, and c are the three numbers. Compare a and b. If a < b, then
compare a and c. If c < a, then give a as output; otherwise (c > a) compare band c,
and give b as output if b < c and c as output if c < b. On the other hand, if b < a, then
compare band c. If c < b, then give b as output; otherwise (c > b) compare a and c,
and give a as output if a < c and c as output if c < a.

3. Set i = 1. As long as i 2 :::; n, continue to add 1 to i. Stop as soon as i 2 > n. Then give
(i - 1)2 as output.

5. When the counter i first gets so large that i 2 > n, then the algorithm takes the branch
to the right and outputs the correct answer, namely (i - 1)2.

OUTPUT (i _1)2

7. (a) Since 900 = 22 . 32 . 52 and 1750 = 2 . 53 . 7, gcd(900, 1750) = 2 . 52 = 50.


(b) Since 46 = 2·23 and 27 = 33 , gcd(46, 27) = 1.
(c) Since 2323 = 23 . 101 and 9191 = 7·13·101, gcd(2323, 9191) = 101.

9. d = gcd(x, y) - [d I x /\ d I y /\ Va: (a I x /\ a I y) -+ a:::; d)]


Section 4.1 The Idea of an Algorithm 45

11. Let the prime factorizations of x and Y be x = pfl p~2 ... p~k and y = pi 1p~2 ... k , P1
respectively, where we included all the prime factors of both x and y, so that some of the
Xi'S or Yi'S might be O. Then gcd(x,y) =
pflp~2 ... pf/, where gj =
min(Xj,Yi). Now
suppose that d I x /\ d I y. Then d =
pt 1 p~2 ... p~k , where each di ~ Xi and di ~ Yi.
Therefore Vi:di ~ gi, so d I gcd(x,y).

13. (a) m = lcm(x,y) <-+ [x I m /\ y I m /\ Vz: (x I z /\ Y I z) --> m ~ z)]


(b) Let the prime factorizations of x and y be x = pfl p~2 ... p~k and y = pi 1 p~2 ... P1 k ,
respectively, where we included all the prime factors of both x and y, so that some of
the Xi'S or Yi'S might be O. Then lcm(x, y) = pilp~' ... p~k, where l; = max(xi, Yi).
(c) If x and yare positive integers and m is any positive common multiple of x and y,
then lcm(x, y) I m. Proof: (This is very similar to Exercise 11, above.) Write the prime
factorizations of x, y, and their least common multiple as in part (b). Now suppose
that x I m and y 1m. Then m = p'{'l p;" ... p';:k , where each mi 2: Xi and mj 2: Yi.
Therefore Vi: mj 2: Ii, so lcm(x, y) 1m.
(d) Using the notation in part (b) and Exercise 11, we have x = pfl p~2 ... p~k , Y = pi 1p~2
... pt k , lcm(x, y) = pilp~2 ... p~k, and gcd(x, y) = pflp~2 ... p!k , where Ii = max(xi, Yi)
and gi = min( Xi, Yi). Then the prime Pi appears to the power Xj + Yi in X· y, and to the
power Ii + gi in lcm( x, y) . gcd( x, y). Since for any two numbers u and v it is always true
that max( u, v) + min( u, v) = u + v, these two exponents agree. The desired conclusion
follows.
(e) Compute gcd(x, y) by the Euclidean Algorithm. Then compute xy/ gcd(x, y), which
by part (d) equals lcm(x,y).
(f) First compute gcd(50059, 98789) = gcd(98789, 50059) = gcd(50059, 48730) =
gcd( 48730, 1329) = gcd(1329, 886) = gcd(886, 443) = gcd( 443,0) = 443.
Then lcm(50059, 98789) = 50059·98789/ gcd(50059, 98789) = 50059 ·98789/443 =
11163157.

15. We want to prove that if d I gcd(x, y), then d I x and d I y. This is just a special
case of the transitivity of the "divides" relation (see Exercise 14 in Section 3.4), since
gcd(x,y) I x and gcd(x,y) I y.

17. Note that the remainder when x 2 - 1 is divided by x is x -1, since x 2 - 1 = x(x -1) +
(x - 1). Thus by Theorem 2 we have gcd(x 2 - 1, x) = gcd(x, x-I) = gcd(x - 1,1) =
gcd(l, 0) = 1.
46 Chapter 4 ALGORITHMS

19. (a) Since we can compute by the Euclidean Algorithm that gcd(238133, 341936) = 7, we
238133 238133/7 34019.
have 341936 = 341936/7 = 48848 In lowest terms.
(b) Since we can compute by the Euclidean Algorithm that gcd(238134, 341936) = 6106,
238134 238134/6106 39.
we have 341936 = 341936/6106 = 56 In lowest terms.
(c) Since we can compute by the Euclidean Algorithm that gcd(238135,341936) = 1, we
k h 238135. I ad . I
now t at 341936 IS are yIn owest terms.

21. We exploit here the facts that (1) we can assume that i ~ j ~ k < I and (2) there is
always a solution.

1. Set i equal to O.
2. Set j equal to i.
3. If i 2 + 3P > N, then replace by i + 1, return to step 2, and continue from
there. Otherwise, continue with step 4.
4. Set k equal to j.
5. If i 2 + P + 2k2 > N, then replace j by j + 1, return to step 3, and continue from
there. Otherwise, continue with step 6.
6. Set I equal to k.
7. Ifi 2 +P+k 2 +/2=N,thenoutput (i,j,k,/) and stop. Ifi 2 +P+k 2 +/2>N,
then replace k by k + 1 , return to step 5, and continue from there. Otherwise (i.e., when
i 2 + j2 + k 2 + 12 < N), replace I by I + 1 and repeat this step.

23. Set largest equal to SI, and set second equal to -00. [This is not the only way to
initialize the algorithm; we could also start by setting largest equal to the larger of S1
and S2, and second equal to the smaller.] Now for each i from 2 to n, repeat the
following steps: compare S,
to second, and if S,
> second, then replace second by S"
compare the new value of second to largest, and if second> largest, interchange second
and largest. At the end, output second.

25. 1. Set i equal to 1.


2. If i > N, then output 0 and stop. Otherwise, continue with step 3.
3. If W = Wi, then output i and stop. Otherwise continue with step 4.
4. Replace i by i + 1, return to step 2, and continue from there.
Section 4.1 The Idea of an Algorithm 47

27. In each case, let A ={al, a2, ... , an} and B =


{b 1 , b2, ... , bm } be the input sets, with
al < a2 < ... < an and bt < b2 < ... < bm . Set an+l and bm+1 equal to 00. The
output is the set C = {Cl, C2, ••. , cd.
(a) 1. Set i equal to 1; set j equal to 1; and set k equal to O.
2. If i = n + 1 and j = m + 1, then output {Cl, C2, .•. , Ck} and stop. Otherwise,
continue with step 3.
3. If ai = bj, then continue with step 4. If ai < bj , then replace i by i + 1;
otherwise (when ai > bj ) replace j by j + 1. In either of these cases, return to step 2
and continue from there.
4. Replace k by k + 1; set Ck equal to ai; replace i by i + 1; replace j by j + 1;
and return to step 2 and continue from there.
(b) 1. ,Set i equal to 1; set j equal to 1; and set k equal to O.
2. If i = n + 1 and j = m + 1, then output {Cl, C2, ... , Ck} and stop. Otherwise,
replace k by k + 1 and continue with step 3.
3. If ai = bj , then continue with step 4. If ai < bj , then skip to step 5 and
continue from there. If ai > bj , then skip to step 6 and continue from there.
4. Set Ck equal to ai; replace i by i + 1; replace j by j + 1; and return to step 2
and continue from there.
5. Set Ck equal to ai; replace i by i + 1; and return to step 2 and continue from
there.
6. Set Ck equal to bj ; replace j by j + 1; and return to step 2 and continue from
there.
(c) 1. Set i equal to 1; set j equal to 1; and set k equal to o.
2. If i = n + 1, then output {Cl, C2, ••. , Ck} and stop. Otherwise, continue with
step 3.
3. If ai = bj , then replace i by i + 1, replace j by j + 1, return to step 2 and
continue from there. Otherwise, if ai > bj , then replace j by j + 1 and repeat this step
from its beginning. Otherwise (i.e., when ai < bj ) continue with step 4.
4. Replace k by k + 1; set Ck equal to ai; replace i by i + 1; and return to step 2
and continue from there.

29. If and when we obtain a square, we are done-we have found the common measure. Given
any nonsquare rectangle B' CD E, we fold along AC, to bring corner B' to point B on
the opposite longer side, as shown below.

E~--------------~

D L---------~B---~I C
48 Chapter 4 ALGORITHMS

Then we cut along line AB. The greatest common measure of the remaining rectangle
AB DE is the same as the greatest common measure of the original (this is essentially just
Theorem 2). We continue this process--obtaining smaller and smaller rectangles-until
we obtain a square. If the sides of the original rectangle are not commensurate (i.e., if
their ratio is not a rational number), then the process will continue forever.

31. We use the bisection method, constantly narrowing an interval in which the desired
solution lies. Note that throughout the following algorithm, ../2 E (I, u). Thus when
the algorithm terminates (as it surely does, since u -I decreases by a factor of 2 on every
iteration), 1../2 -11 < lO-n. Thus the algorithm computes ../2 with an error of at most
1 in the nth decimal place.
1. Set 1 equal to 1, and set u equal to 2.
2. If u - 1 < lO- n , then output 1 and stop. Otherwise continue with step 3.
3. Set x equal to (u + 1)/2. If x 2 < 2, then replace 1 by x. Otherwise replace u
by x. In either case, return to step 2 and continue from there.

33. We need to check for reflexivity and transitivity in both cases, symmetry in part (a),
and antisymmetry in part (b). Form the matrix representing R, i.e., the n by n matrix
MR = (mij) in which mij = 1 if iRj and mij = 0 if not. To check for reflexivity, simply
check to see if mii = 1 for all i. To check for transitivity, compute MRoR, defined in
Section 3.3 to be the Boolean matrix product of M with itself. The relation is transitive
if and only if M RoR = M (given that R is reflexive). To check for symmetry, we need
to see that each below-the-diagonal entry, mij for i < j, has the same value as the
above-the-diagonal entry symmetrically located across the main diagonal, namely mji.
Finally, to check for antisymmetry, we need to check that for each below-the-diagonal
entry (mij for i < j) that has the value 1, the above-the-diagonal entry symmetrically
located across the main diagonal (namely mji) has the value o.

SECTION 4.2 Pseudocode Description of Algorithms


1. procedure smalLsum(A : list of integers)
{ A = (al' a2, ... ,an); sum is the sum of the elements of A less than 100}
sum - 0
for i - I to n do
if ai < 100 then sum - sum + ai
return( sum)
Section 4.2 Pseudocode Description of Algorithms 49

3. (a) procedure middle(a, b, c : distinct natural numbers)


{finds the middle value among a, b, and c}
if a < b then
if c < a then return( a)
else if b < c then return(b)
else return(c)
else if c < b then return( b)
else if a < c then return( a)
else return( e)

(b) procedure add_/raetions(a,b,e,d: integers)


{ assume that b > 0 and d > 0; returns the numerator and
denominator of (a/b) + (e/d)}
return( ad + be, bd)

(c) procedure largLsquare( n : positive integer)


{ computes largest perfect square :S n }
i +- 1
while i 2 :S n do
i+-i+l
return« i-I )2)

(d) procedure big_word (WI, W2, ... ,Wn : strings)


{finds a longest word in the list, and its length}
maxword +- WI
maxlength +- length( WI)
for i +- 2 to n do
if length( Wi) > maxlength then
begin
maxword +- Wi
maxlength +-length(wi)
end
return( maxlength, maxword)

5. (a) t +- m
while i:S n do
begin
statement
i+-i+l
end

(b) i +- n
while i ~ 1 do
begin
statement
i+-i-l
end
50 Chapter 4 ALGORITHMS

(c) i+-m
while i ~ n do
begin
statement
i+-i+k
end

7. Suppose that d is a common divisor of x, y, and z. Then d is a common divisor of


x and y, so by Theorem 1 in Section 4.1, d is a common divisor of gcd( x, y) and z.
Conversely, if d is a divisor of gcd(x, y), then by Exercise 15 in Section 4.1, d divides
both x and y. Hence d is a common divisor of x, y, and z. Thus we have shown that
the sets of divisors about which the two sides of the equation speak are identical, and so
their greatest elements are equal.

9. procedure naive_gcd(x, y : positive integers)


{computes gcd( x, y) by brute force}
d +- min(x, y)
while -,(d I x 1\ d I y) do
d+-d-l
return(d)

11. This algorithm finds the smallest factor of N greater than 1. It will necessarily be prime.

procedure smalLprime(N : integer> 1)


{finds smallest prime factor of N}
d+-2
while d" N do
d+-d+l
return(d)

13. The smallest nontrivial factor at each stage will necessarily be prime. This procedure
finds the highest power of this prime which divides N, then goes on to the next smallest
prime factor.
Section 4.2 Pseudocode Description of Algorithms 51

procedure Jactorization(N : integer> 1)


{the output will be a set of pairs, L = {(pt, ed, (p2, e2), ... , (Pk. ek)},
where N = p~l p~2 ... p~k is the prime factorization}
k - 0 {k will be the number of factors}
P - 2 {potential prime factor}
while N> 1 do
begin
e - 0 {e will be the largest power of P dividing N}
while piN do
begin
e - e+ 1
N-N/p
end
if e > 0 then {found a new prime factor}
begin
k - k+ 1
Pk - P; ek - e
end
P - P + 1 {go on to next potential prime factor}
end
return(L)

15. procedure mode(s : string of decimal digits)


{finds the digit that occurs most often in s; we assume that the
answer is unique; uses procedure tabulate from this section}
count - tabulate( s)
maxdigit - 0
for i - I to 9 do
if count(i) > count( maxdigit) then maxdigii +- i
return( maxdigit)

17. procedure order_4(a,b,c,d: distinct numbers)


{returns the same numbers, put into increasing order}
if a > b then interchange a and b {now a < b }
if b > c then interchange band c {now a, b < c}
if c > d then interchange c and d {now d is the largest}
if a > b then interchange a and b {now a < b }
if b > c then interchange band c {now a, b < c}
if a> b then interchange a and b {now a < b < c < d}
return(a, b, c, d)
52 Chapter 4 ALGORITHMS

19. procedure exercise_19(A : list of nonzero real numbers)


{assume that A = (al, a2, ... , an) has at least
one positive and one negative number}
pos_ +- countO; neg_ +- countO
pos_ +- sumO; neg_ +- sumO
for i +- 1 to n do
if ai > 0 then
begin
pos_ +- countpos_count + 1
pos_ +- sumpos_sum + ai
end
else
begin
neg_ +- countneg_count + 1
neg_ +- sumneg_sum - ai {since lail = -ai }
end
return«pos_sum/pos_count) - (neg_sum/neg_count))

21. procedure cireulant( al , a2, ... , an)


{constructs circulant matrix (cire) whose first row is (al, a2, ... , an) }
for i +- 1 to n do
for j +- 1 to n do
begin
k +- i - I + j {this does the shifting}
if k > n then k +- k - n
circ( i, j) +- ak
end
return( cire)

23. procedure phi(n : positive integer)


{ computes the number of numbers less than n
that are relatively prime to n }
count +- 0
for i +- 1 to n do {does i meet the condition gcd( i, n) = I?}
if euclid(i, n) = 1 then count +- count + 1
return( count)
Section 4.2 Pseudocode Description of Algorithms 53

25. procedure modes(s : string of decimal digits)


{finds the digits that occur most often in s; answer is given as a
set L of digits; uses procedure tabulate from this section}
count - tabulate(s)
maxdigit - 0
L - {O} {the tentative answer}
for i - 1 to 9 do
if count( i) = count( maxdigit) then
L - L U {maxdigit} {i occurs as often as maxdigit}
else if count( i) > count( maxdigit) then
begin {i alone is the new tentative answer}
maxdigit +- i
L - {i}
end
return(L)

27. procedure substring(8,t : strings)


{8 =8182 ... 8 n and t = t1t2'" t m ; determines whether 8 is a substring of t }
for j +- 0 to m - n do
begin {see whether 8 occurs starting at ti+1 }
matched +- true {until we find a difference}
for i +- 1 to n do
if 8; "I ti+; then matched - false
if matched then return( true) {otherwise try next location}
end
return(false) {no match found}

29. procedure length_of _repeat(n : positive integer)


{finds the length of the repeat in the decimal expansion of lin;
the array R holds the successive remainders in the long division
process; when a remainder recurs, we are done}
R(l) - 1 {the numerator is 1; it is the first remainder}
1+-1
while true do
begin
I-I + 1
R(1) - 10· R(1- 1) mod n
{bring down next 0 and find new remainder}
if R(1) = 0 then return(O) {decimal is finite}
for i _ 1 to I - 1 do {has this remainder occurred before?}
if R( i) = R( I) then return( I - i)
end
54 Chapter 4 ALGORITHMS

SECTION 4.3 Efficiency of Algorithms


1. (a) i +- ¥= a; i +- 2; eating ¥= curds; i +- 3; eating = eating; return 3
1; eating
(b) i +- 1; more ¥= a; i +- 2; more ¥= curds; i +- 3; more ¥= eating; i +- 4; more ¥= her;
i +- 5; more ¥= little; i +- 6; more ¥= miss; i +- 7; more ¥= muffet; i +- 8; more ¥= on;
i +- 9; more ¥= sat; i +- 10; more ¥= tuffet; loop finished, return 0
(c) low +- 1, high +- 10, middle +- 5; eating j little, so high +- 5, middle +- 3;
eating j eating, so high +- 3, middle +- 2; eating ~ curds, so low +- 3, loop finished;
eating = eating, so return 3
(d) low +- 1, high +- 10, middle +- 5; more ~ little, so low +- 6, middle +- 8;
more j on, so high +- 8, middle +- 7; more j muffet, so high +- 7, middle +- 6;
more ~ miss, so low +- 7, loop finished; more ¥= muffet, so return 0

3. (a) The 4n term and the coefficient 10 do not matter when we are dealing with big-oh,
so this function is in O( n 3 ) •
(b) Since log n < n, the first term dominates the second, so this function is in O( n 2 ).
(c) O(n1. 5 /(n + 1» = O(n1. 5 /n) = O(y'n)
(d) O(2n), since 2n > n 2 for large n

5. (a) O(n/2) = O(n)


(b) O(log3 n) = O(log n)
(c) O( 1), since the loop is iterated only once

7. (a) If (high - low) is even, then (high + low) is also even, so middle = (high + low)/2.
There are now two cases. If low is replaced by middle + 1, then the new value of
(high - low) is

high _ (high + low +


2
1) = high - 2low - 2= high - low _
2
1.
If high is replaced by middle, then the new value of (high - low) is
+ low _ low = high - low .
high
2 2
Hence either (high - low) is cut in half, or else it is cut in half and 1 more is subtracted.
On the other hand, if (high - low) is odd, then (high + low) is also odd, so middle =
(high + low - 1)/2. Again there are two ca.<;es. If low is replaced by middle + I, then
the new value of (high - low) is

high _ (high + low -


2
1+ 1) = high - low -
2'
1
If high is replaced by middle, then the new value of (high - low) is
high + low - 1_ I _ high - low - 1
2 ow - 2 .
Section 4.3 Efficiency of Algorithms 55

Hence in either case, 1 is subtracted from (high - low) and then the value is cut in half.
(b) We need to show that (high -low) never jumps from a positive number to a negative
number. If (high -low) is odd, then (high -low) 2: 1, so that the new value of (high -low)
is still greater than or equal to 0 by our formula from part (a). If (high - low) is even
and not yet 0, then (high - low) 2: 2, so again our formula from part (a) guarantees that
(high - low) remains nonnegative. Thus (high - low) is a constantly decreasing integer
that never becomes negative, so it must eventually equal 0, thereby terminating the loop.

9. From algebra we know that loga n = (logb n)j(logb a). Since Ij(logb a) is a positive
constant, loga n E O(logb n).

11. (a) Let C 1 = mmjm!, where m = fkl. Then for n> m we have

~n(n-l)··.(m+l)·mm

= n(n - 1)··· (m + 1) . C1 . m! = C 1n!,


so k n E O(n!).
(b) Since n! = n(n - 1)···2· 1 ~ n· n··· n· n = nn, clearly n! E O(nn).
(c) Let m = fkl. Let C 1 = mmjm!. Then if n > m,
mC1(n + I)! = mC1(n + l)n(n - 1) ... (m + l)m! = m(n + l)n(n - 1)··· (m + l)mm
2: m(n + l)m· m··· m· mm = (n + l)mn+1 2: (n + 1)kn+1 .
Thus (n + I)! 2: (n + 1) lC kn+1. In particular, (: ++!)! 2: (n + 1)~C ---+ 00 as
m 1 n m 1
n ---+ 00, so n! f/:. O(kn).
(d) nn = n· n···n 2: n(n - 1)···2· n 2: n!· n. Thus nnjn! 2: n ---+ 00 as n ---+ 00.
Therefore nn f/:. O(n!).

13. Let C 1 , C 2 , kl' and k2 be such that h(n) :S C 1g(n) for all n 2: k1, and h(n) ~ C 2g(n)
for all n 2: k 2 . Let C = C 1 + C 2 and let k = max(k1' k2)' Then for all n 2: k we have
f1(n) + f2(n) ~ C 1g(n) + C 2g(n) = Cg(n).

15. (a) This follows from the fact that under the hypothesis, f(n)+g(n) ~ g(n)+g(n) = 2g(n)
for all large n.
(b) This follows from the definition (let C =m and k = 1).

17. (a) n+n+···+n (n times) =n 2 EO(n 2)


(b) (n-l)+(n-2)+ ... +1+0~n2EO(n2)
(c) n+n+ .. ·+n (1+ LlognJ times) EO(nlogn)
n n n
(d) 2' + '4 + 8' + ... ~ n E O(n)
56 Chapter 4 ALGORITHMS

19. (a) First the algorithm finds that 12 is the largest element, so it interchanges 12 and 2,
yielding the sequence (2,4,5,8,6,10,12). Next it finds that 10 is the largest element
among the first six elements; interchanging 10 and 10 has no effect, so the sequence is
unchanged. The next pass reveals that 8 is the largest element among the first five, and
so 8 and 6 are interchanged, yielding (2,4,5,6,8,10,12). The next three passes again
result in no change, and the sequence is now sorted.
(b) After the outer loop is executed for a given value of end, aend is the endth largest
element in the list, in its correct place. Thus an, an-I, ... , a2 are all correctly placed,
and hence so is al.
(c) The comparison step is executed (n - 1) + (n - 2) + ... + 2 + 1 times, so the efficiency
is n(n - 1)/2 E 0(n 2 ).

21. procedure speedy(A, z)


{searches A for z, as in linear _search}
ao - z {the process will find z here if not before}
i-n
while true do
begin {loop executed at most n + 1 times}
if z = ai then return( i) {the only comparison}
i - i-I
end

23. Since 9 fI. 0(1), there is an increasing, infinite sequence of numbers nl, n2, ... , such
that g(ni)/I(ni) -+ 00 as i -+ 00. On the other hand, there exist positive constants C
and k such that I(n) ~ Cg(n) for all n 2: k. Without loss of generality we may assume
that C 2: 1. Let the function h be defined by
h( ) _ {g(n) if n = ni for some even i
n - I(n) otherwise.
Then h(n) ~ max(g(n),f(n» ~ max(g(n),Cg(n» = Cg(n) for all n 2: k, so hE O(g).
Similarly h(n) 2: min(l(n), g(n» 2: min(l(n),/(r:)/C) 2: I(n)/C, so 1 E O(h). But
h fI. 0(1) and 9 fI. O(h), since as i -+ 00,

and

25. (a) Using L'Hopital's rule we have



hm - -
nO

n-oo log n
= nhm•
o
an - = nhm
/
1

.... oo (1 n) log e
.
.... oo
(a)
- - n = 00.
0

log e

(b) We want to solve the equation n O.01 = log n. Taking logs of both sides yields
O.Ollog n = log(log n), or z = 100 log z, where z =log n. Solving z =
100 log z iter-
atively on a calculator (start with any big guess and repeatedly take log of the display
Section 4.4 Intractable and Unsolvable Problems 57

and multiply by 100) yields x ~ 996. (There is also a root near x = 1.007, which does
not concern us.) Therefore n = 2x ~ 2996 ~ 10300 . Thus no.Ot overtakes log n around
10300 .

27. Let I(n) = 2';;>. Then to evaluate the limit of I(n)/kn, take the logarithm and note
that Vn - n log k - -00 as n - 00. Thus the limit is 0, so I E O( kn). On the other
hand, a similar evaluation of the limit of I(n)/nk (since Vn - k log n - 00) shows that
I rt O(nk).

SECTION 4.4 Intractable and Unsolvable Problems


1. (a) Here is a short proof that the answer is yes (this is a nontautology): TV (F t\ T) is F.
(b) Here is a long proof that the answer is no (this is in fact a tautology). If either P
or Q is F, then the given proposition is T, because of the disjunction with P and Q.
Otherwise, P and Q are both true, so P t\ Q is T, whence (P t\ Q) V R is T, so again
the proposition is true. (We could also have drawn the truth table.)

3. In each case we let n be the number of digits in N.


(a) Given k =
N /2 as a hint, we can easily verify that N =
2k by a multiplication
of k by 2. Since k has about n digits, this takes only O( n) steps (using the usual
grade-school multiplication algorithm). Even more quickly, we can ignore any hint and
just check the last digit of N.
(b) Given k =
N /3 as a hint, we can easily verify that N =3k by a multiplication of k
by 3. Since k has about n digits, this again takes only O( n) steps.
(c) Given k = Vii as a hint, we can easily verify that N = k 2 by a multiplication of
k by k. Since k has about n/2 digits, this only takes O(n 2 ) steps (using the usual
grade-school multiplication algorithm-see Section 4.5).
(d) Given i, j, k, and / as a hint, we can easily verify that N = i 2 + P + k 2 + /2 m
O(n 2 ) steps, since each of the four numbers has no more than n digits.

5. We calculate by hand or on a computer with enough digits of accuracy that 193707721 x


761838257287 = 147573952589676412927 = 267 - 1. Thus 267 - 1 has nontrivial factors
and so is not prime.

7. (a) Given a hint as to which sets form the pairwise disjoint collection, we form their
pairwise intersections (there are only k(k - 1)/2 of them) to verify this.
(b) Given a hint as to the partition, we sum each half to verify that the sums are equal.
(c) Given such a C as a hint, which we can assume has no more than 2S elements, we
can take each pair in S and verify the condition by searching C.
58 Chapter 4 ALGORITHMS

9. Generate each subset of S (there are 2151 such subsets), and check whether its sum is g.
Since this takes at least 21 5 1 steps, it is a bad algorithm.

11. Sort S = {81' 82, ... , 8 n } so that 81 < 82 < ... < 8 n . If x is the sum of a subset of S,
then we can find this subset by the following algorithm.
for i +-- n down to 1 do
if 8i < x then
begin
x +-- x - 8i
put 8i into the subset
end

At this point x = 0 if and only if the original x was a sum of some subset of S. The
reason that this procedure works is that 8i > L:~:'i 8j , so that if 8i < x when we are
looking at 8i, then we know that we need to include 8i in the subset. Clearly this
algorithm has O( n) complexity.

13. Construct the following algorithm for the one-variable case. The input is the formula
for f, where f( x) = 0 is the given equation. Set n equal to O. Repeatedly calculate
f(n) and f(-n) and then add 1 to n. If you ever find that f(n) = 0 or f(-n) = 0,
then halt. Now we encode this algorithm and its input (I) and give it to a purported
algorithm for the halting problem. It answers yes if and only if the equation f( x) = 0
has an integral solution. Thus the solution to the halting problem gives a solution to the
polynomial problem. The multivariable case is only a little harder-the idea is the same.
In this case, the loop must test systematically for all solutions of f(X1,X2, ... ,Xk). For
each n, there are only a finite number of k-tuples in which the absolute value of each
coordinate is at most n. For the nth pass through the loop, then, the algorithm checks
all of these k-tuples, again halting if and when it finds a solution.

SECTION 4.5 Algorithms for Arithmetic and Algebra


1. (a) carry = 0; Co = 5+9+0 = 14, Co = 4, carry = 1; C1 = 7+5+ 1 = 13, C1 = 3,
carry = 1; C2 = 3+2+ 1 = 6, C2 = 6, carry = 0; C3 = 0; answer is 0634
(b) carry = 0; Co = 9+9+0 = 18, Co = 8, carry = 1; C1 = 9+9+ 1 = 19, C1 = 9,
carry = 1; C2 = 9 + 0 + 1 = 10, C2 = 0, carry = 1; C3 = 1; answer is 1089

3. We use a calculator and the rules of exponents to break these calculations down to man-
ageable size.
(a) 299 = (2 24 )4. 23 = 16777216 4 .23 == 16 4 .8 = 65536·8 == 36·8 = 288 == 88 (mod 100)
(b) 98 10 == (_2)10 = 1024 == 24 (mod 100)
(c) 52 52 = (52 2)26 = 2704 26 == 4 26 = (4 13 )2 = (2 13 )4 = 81924 == (-8)4 = 4096 == 96
(mod 100)
Section 4.5 Algorithms for Arithmetic and Algebra 59

5. (a) For the sum, Co = -2+5 = 3, Cl = 4+ 1 = 5, C2 = 3+0 = 3, so the sum is


3+5x+3x 2 • For the product, we have co=0+(-2)·5=-10, Cl =0+(-2)·1=-2,
Cl = -2 + 4·5 = 18, C2 = 0 + 4 . 1 = 4, C2 = 4 + 3 . 5 = 19, C3 = 0 + 3 . 1 = 3, so the
product is -10 + 18x + 19x 2 + 3x 3 .

(b) For the sum, Co = 0 + 0 = 0, Cl = 0 + 0 = 0, C2 = 3 + ( - 3) = 0, so the sum is


o + Ox + Ox 2 , i.e., the zero polynomial. For the product, we have Co = 0 + 0 . 0 = 0,
Cl = 0 + 0 . 0 = 0, C2 = 0 + 0 . (-3) = 0, Cl = 0 + 0 . 0 = 0, C2 = 0 + 0 . 0 = 0,

C3 = 0 + 0 . (-3) = 0, C2 = 0 + 3·0 = 0, C3 = 0 + 3·0 = 0, C4 = 0 + 3· (-3) = -9, so

the product is 0 + Ox + Ox 2 + Ox 3 - 9x 4 = -9X4.

7. We add entry by entry, obtaining

A+ B = [~! ~ 8 6i~8) -;2++(~-;~) _~ ~ ~1] - [! ~ -~ 1~]'

9. (a) 24six = 4 + 2·6 = 16 (b) 301 six = 1 + 3 . 62 = 109

(c) 2six = 2 (d) 10000six = 1 .6 4 = 1296

11. We apply Horner's method to evaluate do + dd3 + d 2 fJ 2 + ... + dn_1fJ n - 1 .

procedure to_ base_ ten(fJ : integer ~ 2, dn - 1dn - 2 ... d 1do : string of digits base fJ)
{computes the value of the base fJ numeral dn - 1dn - 2 ••. d1d o }
x f- dn - 1
for i f - n - 2 down to 0 do
x f - fJ· x + di
return(x)

13. We subtract digit by digit, from right to left, "borrowing" from the next column as needed.
60 Chapter 4 ALGORITHMS

procedure difference (x, y : natural numbers)


{x and yare represented by the decimal numerals an-l ... ao and bm - 1 ... bo ,
respectively; the answer z = x - y will appear as the decimal numeral
Ck-l· .. Co, where k = max(n,m); we assume that ai is defined to be 0
for i 2: n, that bi is defined to be 0 for i 2: m, and that x 2: y }
k +- max(n,m)
borrow +- 0
for i +- 0 to k - 1 do
begin
Ci +- ai - bi - borrow
if Ci < 0 then {need to borrow 10 from next column}
begin
Ci +- Ci + 10
borrow +- 1
end
else borrow +- 0
end
return(z)

The time complexity of the algorithm is O( k) = O( n + m) , since the main loop is iterated
k times.

17. If we take a number between 0 and 1, multiply it by N, and round down to an integer,
we will have an integer between 0 and N - 1, inclusive. We add 1 to get an integer in
the desired range.

procedure random_integer(N : positive integer)


{computes a random integer between 1 and N, inclusive; assume that rand returns a
random real number between 0 and 1 each time it is called}
x +- rand
return(1 + Lx· NJ)

19. (a) procedure matrix_add(A,B)


{ A = (aij) and B = (b ij ) are m by n matrices;
the sum is the m by n matrix C = (Cij) }
for i +- 1 to m do
for j +- 1 to n do
Cij +- aij + bij {add entry by entry}
return(C)
Section 4.5 Algorithms for Arithmetic and Algebra 61

(b) procedure matrix_multiply(A, B)


{A = (aik) is an m by n matrix and B = (bkj) is an n by p matrix;
the product is the m by p matrix C = (Cij) }
for i +- 1 to m do
for j +- 1 to P do
begin {compute (i,j)th entry as a sum of products}
Cij +- 0
for k +- 1 to n do
Cij +- Cij + ai/,bkj
end
return(C)

21. The matrix all of whose entries are 0 has this property, since aij + 0 = aij .

23. Since 224 = 16777216 == 16 t= 1 (mod 25), we know that 25 is not prime.

25. It is faster to multiply A x B first when pqr + prs < qrs + pqs (see Exercise 20). We
divide through by pqrs to obtain the nice condition s-1 + q-1 < p-1 + r- 1 .

27. (a) procedure slow(a1' a2, ... , an : sequence of real numbers)


{naively finds the sum of all products aiaj for i < j }
sum +- 0
for i +- 1 to n - 1 do
for j +- i + 1 to n do
sum +- sum + aiaj
return( sum)

The complexity of this algorithm is clearly proportional to n 2 .


(b) If we expand (a1 + a2 + ... + an )2, we obtain at + a~ + ... + a~ + 2· (desired sum).
We can therefore compute the answer as (a1 + a2 + ... + an )2 - ai - a~ - ... - a;')j2,
and this takes only O(n) steps.
62 Chapter 5 INDUCTION AND RECURSION

CHAPTER 5
INDUCTION AND RECURSION
SECTION 5.1 Recursive Definitions
1. In Example 1 we found that h = 21 and Is = 34. Hence 19 = 34 + 21 = 55, 110 =
55 + 34 = 89, and III = 89 + 55 = 144.

3. Each term is the sum of the three preceding terms. Thus the sequence begins 1, 1, 1,
3,5,9,17,31,57,105. In particular, alO = 105.

5. (a) A2 = A x A = [-~ -i]


(b) AD = 1= [~ n
( c) A3 -- A X A2 _
-
[-11 -4]
12-7

(d)Al=A=[i -~]

7. (a) yes (unsigned integer)


(b) no (no operator)
(c) no (the raised dot is not a legal symbol)
(d) no (no parentheses)
(e) yes (x2 is a variable name)
(f) no (needs more parentheses)

9. On day 0 we get, among other things, 1, 8, and 3. On day 1, (-1), (-8), and (3 + 1)
come into being. On day 2 we see the birth of «-1) - 8) and «-8) * (3 + 1». Finally,
on day 3 we can construct «(-1) - 8) + « -8) * (3 + 1))).
Section 5.1 Recursive Definitions 63

11. (a) P(l) = 1, P(2) = P(2 - P(l» + 1 = P(2 - 1) + 1 = P(l) + 1 = 1 + 1 = 2,


P(3) = P(3 - 2) + 1 = 2, P( 4) = P( 4 - 2) + 1 = 3, P(5) = P(5 - 3) + 1 = 3, P(6) = 3,
P(7) = 4, P(8) = 4, P(9) = 4, P(lO) = 4, P(ll) = 5, P(12) = 5, P(13) = 5,
P(14) = 5, P(15) = 5, P(16) = 6
(b) For this definition to be valid, n - P( n - 1) must be a positive integer less than n
for all n ~ 2, so that P( n - P( n - 1» makes sense and has already been defined. There
is no obvious reason that this will be true.
(c) one 1, two 2's, three 3's, four 4's, etc.

(b) Let lex, n) = XX , with n x's in the exponent (n + 1 x's in all). The recursive

definition is that l(x,O) = x, and l(x,n+ 1) = xI(x,n). Letting X = 0, we see that


1(0,0)=0,1(0,1)=0°=1,1(0,2)=0 1 =0, I(0,3)=00=1,andsoon. Thus I(O,n)
is 0 when n is even and 1 when n is odd.

15. (a) We apply the recursive definition repeatedly, finally using the base case <p(x,y,O) =
x + y three times:
'1'(3,3,1) = '1'(3, '1'(3, 2,1),0) = '1'(3, '1'(3, '1'(3,1,1),0),0)
= '1'(3, '1'(3, '1'(3, '1'(3, 0,1),0),0),0)
= '1'(3, '1'(3, '1'(3, 0, 0), 0),0) = '1'(3, '1'(3, 3, 0), 0)
= '1'(3,6,0) = 9
(b) For the last step here, we use the result from part ( a).
'1'(3,2,2) = '1'(3, '1'(3,1,2),1) = '1'(3, '1'(3, '1'(3, 0, 2), 1),1)
= '1'(3, '1'(3,1,1),1) = '1'(3, '1'(3, '1'(3, 0,1),0),1)
= '1'(3, '1'(3, 0, 0),1) = '1'(3,3,1) = 9

17. We apply the recursive definition repeatedly, using the base case A( x, 0) = x +1 six
times:
A(1,2) = A(A(O, 2),1) = A(A(l, 1), 1)
= A(A(A(O, 1),0),1) = A(A(A(l, 0), 0),1)
= A(A(2, 0), 1) = A(3, 1)
= A(A(2, 1),0) = A(A(A(l, 1), 0), 0)
= A(A(A(A(O, 1), 0), 0), 0) = A(A(A(A(l, 0), 0),0),0)
= A(A(A(2, 0), 0), 0) = A(A(3, 0), 0) = A( 4,0) = 5
64 Chapter 5 INDUCTION AND RECURSION

(b) For the base case (first line), A(n,O) is defined directly. For all other cases (second
and third lines) A(n,i) is defined in terms of values of A(n',i'), where (n',i') precedes
(n,i) in right to left lexicographical order, i.e., either i' < i or else i' = i and n' < n.

19. Variable names, 0, and 1 are Boolean expressions. If a and f3 are Boolean expressions,
then so are (a), a, af3, a . f3, and a + f3. Note that parentheses are allowed but not
required.

21. (a) al =1, a2 = 0.5, a3 = 0.6666667, a4 = 0.6, a5 = 0.625, a6 = 0.6153846,


a7 = 0.6190476, as = 0.6176471, ag = 0.6181818, alO = 0.6179775, all = 0.6180556,
a12 = 0.6180258, a13 = 0.6180371, a14 = 0.6180328, a15 = 0.6180344, a16 = 0.6180338

(b) The sequence {an} seems to be converging to a specific value around 0.618. In fact,
the value is (-1 + ,;5)/2, which is the positive root of the equation x = (1 + x)-l.

23. (a) There is clearly only one 4-nomino with four squares in a row. If a 4-nomino has
three squares in a row, then the other square can only be attached in two locations (up
to rotation and flipping), and the result of each of these possibilities is shown. Otherwise,
the 4-nomino must start with three squares in an L shape, and there are only two different
places to add the fourth square without creating four in a row; both of these pictures are
shown.
(b) There are 12 5-nominoes, as shown here.

+I-~~'
~
n.
25. (a) We exhibit the new lists and new insides that arise on each day.
new lists new insides
day 0 () 5
day 1 (5) 0; 5,5
day 2 «)); (5,5) (5); (),(); 0,5,5; 5,5,();
5,5,5,5; (),5; 5,(); 5,5,5
(b) We exhibit the relevant new lists and new insides that arise on each day.
"
Section 5.1 Recursive Definitions 65

new lists new insides


day 0 () 3; 4; 7; 2
day 1 (4) (); 7,2
day 2 (7,2) (),();(4)
day 3 «(),()) (7,2); 3,(4)
day 4 «(),()); 3,(4),(7,2)
day 5 3, (4), (7, 2), «), ())
day 6 (3, (4), (7,2), «), ()))

27. (a) day 0: 5,7;dayl: 5-1=4,7-1=6,5+5=1O,5+7=12,7+7=14;day2:


4 - 1 = 3, 4 + 4 = 8, 4 + 5 = 9 (also 10 - 1 = 9), 4 + 7 = 11, 14 - 1 = 13, 10 + 5 = 15,
10 + 6 = 16, 10 + 7 = 17, 12 + 6 = 18, 12 + 7 = 19, 10 + 10 = 20, 14 + 7 = 21,
10+12=22,12+12=24,12+14=26,14+14=28
(b) Since x E E ---* 2x E E, and since 5 E E, we see that E is unbounded (has arbitrarily
large elements). Since x E E ---* x-I E E, we see that E has no gaps below any number.
Therefore E = Z.

29. If d is a digit, then d. and .d are unsigned decimals. If d is a digit and 0' is an unsigned
decimal, then dO' and ad are unsigned decimals. If 0' is an unsigned decimal, then +0'
and -0' are signed decimals.

31. (a) For good measure we have shown Co, C 1 , C 2 , C3 , C4 , and C 5 .

o 1

(b) One segment of length 1/3 is removed; two segments of length 1/9 are removed;
four segments of length 1/27 are removed, and so on. Therefore the total length of the
removed segments is

~3 + ~9 + ~
27
+ ~ + ... = ~ (1 + ~ + (~)
81 3 3 3
2 + (~)
3
3 + ... ) = ~3 . 1 - 1
(2/3)
= l.

(c) The Cantor set contains the numbers 1/3, 1/9, 1/27, ... , since these are never
removed.
(d) Use base 3 notation. The removed segments are those values whose "decimals"
(base 3) must contain a 1. (For example, the numbers between 1/3 and 2/3 have a 1 in
the first digit after the "decimal" point in their base 3 expansions.) Thus all those base 3
"decimals" containing only O's and 2's remain. There are just as many of these as there
are base 2 "decimals" with O's and l's (replace each 2 by a 1), which represent all the
66 Chapter 5 INDUCTION AND RECURSION

numbers in the interval [0,1] (and then some, since the representations are not unique).
Since this latter set is uncountable, we are done.

33. (a) A game is winning for Righty if and only if there exists a game in R that is either
winning for Righty or winning for the second player and every game in L is either winning
for Righty or winning for the first player. A game is winning for the first player if and
only if there exists a game in L that is either winning for Lefty or winning for the second
player and there exists a game in R that is either winning for Righty or winning for the
second player. A game is winning for the second player if and only if every game in L is
either winning for Righty or winning for the first player and every game in R is either
winning for Lefty or winning for the first player. (The fourth case was given in the hint.)
(b) The game 0 is winning for the second player. The games * and ({ *, I}, { -I}) are
winning for the first player. The games 1, ({ O}, {I}) , and ({ I}, 0) are winning for Lefty.
The game -1 is winning for Righty.

SECTION 5.2 Recursive Algorithms


1. We indent the moves to show the levels of recursion.
Move disk 1 from peg A to peg B.
Move disk 2 from peg A to peg C.
Move disk 1 from peg B to peg C.
Move disk 3 from peg A to peg B.
Move disk 1 from peg C to peg A.
Move disk 2 from peg C to peg B.
Move disk 1 from peg A to peg B.

3. We need to concatenate the last symbol with the reverse of the first n - 1 symbols.
procedure reverse(s : string)
{assume that s = SlS2 ... Sn , with n ~ 0 }
if n :s 1 then return( s)
else return(snreverse(sls2 ... sn-d)

5. Assume that there is a new element 00 at the end of each list. We start by looking at the
first elements of the two lists. Since 1 E B is less than 3 E A, we make 1 the first element
in the merged list and then move to consider 6 E B. At this point we are comparing
3 E A with 6 E B. Since 3 is smaller, we put it as the second element in the merged list
and then consider 5 E:: A versus 6 E B. We continue in this way until both original lists
are exhausted (in this case, after 11 steps). Ties can be broken arbitrarily, by putting
either of the elements into the new list (although Algorithm 8 actually chooses the element
from B in such a case). The final merged list is (1,3,5,6,6,9,9,20,24,31,49).
Section 5.2 Recursive Algorithms 67

7. There is nothing to do if n = O.
procedure simpler _hanoi(X, Y, Z : peg names, n : natural number)
{assume that the peg names are A, B, and C in some order}
if n > 0 then
begin
call simpler_hanoi(X,Z, Y,n -1)
print( "Move disk" n "from peg" X "to peg" Y ".")
call simpler_hanoi(Z, Y,X,n -1)
end
return

9. (a) We need to compare In to the largest of the first n - 1 elements in the list.

procedure largest(L : list of numbers)


{assume that L = (1 1 ,12 , ••• , In), with n:::: I}
if n = 1 then return(ll)
else
begin
a f-- largest «(11 , 12 , ... , In-I))
if In > a then return(ln)
else return( a)
end

(b) This is the same part (a) except that the procedure returns the index rather than
the value.
procedure largesLindex(L : list of numbers)
{assume that L = (11,1 2 , ••• , In), with n :::: I}
if n = 1 then return(l)
else
begin
if-- largesLindex((ll, 12 , ... , In-I))
if In > Ii then return( n)
else return( i)
end

11. (a) We just copy the definition into the recursive procedure.

procedure fiL3(n : positive integer)


if 1;1. :::; 3 then return(1)
else return(fiL3(n - 1) + fiL3(n - 2) + fiL3(n - 3))

(b) This is exactly analogous to the iterative algorithm for calculating the terms of the
Fibonacci sequence.
68 Chapter 5 INDUCTION AND RECURSION

procedure fib_3_iterative(n: positive integer)


x+-l; y+-l; z+-1
for i +- 4 to n do
begin
next +- x + y + z
x +- y; y +- z; z +- next
end
return(z)

(c) The number of steps is in O( n) , since the loop is executed O( n) times.

13. procedure va/ides : string)


{assume that s = SlS2 ... Sn, with n ~ 1 }
if n = 1 and Si is a letter then return( true)
else if Sn is a letter or digit then return(valid(sls2 ... Sn-1))
else return(false)

15. Note how each procedure recursively calls the other, as well as itself.
procedure F( n : natural number)
if n = 0 then return(l)
else return(n - M(F(n - 1)))
procedure M(n : natural number)
if n = 0 then return(O)
else return(n - F(M(n - 1)))

17. In effect this procedure searches from back to front.


procedure linear(A, x)
{assume the setting of Algorithm 1 in Section 4.3}
if n = 0 then return(O)
else if x = an then return( n)
else return(linear«a1, a2, ... , an-d, x))

19. O(n + m), since the loop statement is executed n + m times

21. (a) procedure elemenLof(x : number, B : list of numbers)


{assume that B = (b 1, b2, ... , bn ), with n ~ 0 }
if n = 0 then return(false) {x is not in the empty list}
else if x = bn then return( true) {x is there}
else return( elemenLof(x, (b 1, b2 ,··· , bn-d))
{look for x in the rest of the list}

(b) procedure subseLof(A, B : lists of numbers)


{assume that A = (a1, a2, ... , am), with m ~ O}
if m = 0 then return(true) {0 S;; B always holds}
else return(elemenLof(am,B) /I. subseLof«a1,a2, ... ,am _1),B))
{see if am E B and the first m - 1 elements are all in B}
Section 5.2 Recursive Algorithms 69

(c) procedure equals(A,B: lists of numbers)


return(subseLof(A, B) A subseLof(B, A))

(d) procedure adjoin(x: number, B: list of numbers)


{assume that B = (b 1 , b2 , ... , bn ), with n ~ O}
return((b 1, b2 , •.. , bn , x))

(e) procedure reduce(A : list of numbers)


{assume that A = (a1,a2, ... ,an ), with n ~ O}
if n = 0 then return(A) {the empty set}
else if elemenLof(a n ,(a1,a2, ... , an..,. 1))
then return(reduce((a1,a2, ... , a n -1)))
{an is superfluous}
else return( adjoin( an, reduce ( (a1, a2, ... , a n -1))))
{reduce the rest and then put an back in}

23. The idea here is to list all the subsets that do not include i, and then those that do, as i
recursively ranges from n down to 1. The string s holds the final portion of the subset,
involving numbers greater than i. Recall that A is the empty string.
procedure subsets( n : positive integer)
{prints all subsets of {I, 2, 3, ... , n} }
call recsubsets( n, n, A)
return
procedure recsubsets(n : positive integer, i: natural number, s : string)
{prints all subsets of {I, 2, 3, ... , n} that consist of the elements listed
in s and any subset of {I, 2, 3, ... , i} }
if i = 0 then print(s)
else
begin
call recsubsets(n, i-I, s)
s <- the number i followed by a blank, followed by s
call rec_subsets(n, i-I, s)
end
return

25. procedure EVAL(L : list of items forming a valid FPAE)


{ assume that L = (/ 1 ,/2 , .•• , In), with n ~ 1; each Ii is either an unsigned
integer, a variable, an operator symbol, or a left or right parenthesis}
if n = 1 then return(EVALatom(ll))
else
begin {need to find middle operator symbol}
count <- 1
for i <- 2 to n - 1 do
if count = 1 and Ii is an operator symbol () then
return(EVAL((l2, ... , Ii-d) () EVAL(( 1i+1, ... ,In - 1 )))
else if Ii = "(" then count <- count + 1
else if Ii = ")" then count <- count - 1
end
70 Chapter 5 INDUCTION AND RECURSION

27. (a) It computes an approximation for the so-called arithmetic-geometric mean of 1


and 10. It returns approximately 4.250407.

(b) procedure gausL recursive (x, y, f : positive real numbers with x :::; y)
if y - x:::; f then return(x)
else return (gauss(y'xY, (x + y)/2, f»)

SECTION 5.3 Proof by Mathematical fuduction


1. This figure is produced by using the proof given in Example 1. The middle L-shaped
piece is placed first, dividing the problem into four smaller problems.

3. The base case (n = 2) checks: 1· 2 = 1·2·3/3. Assume the inductive hypothesis, that
1·2+ 2·3 + ... + (k - l)k = [(k - l)k(k + 1)]/3. Then

1·2+ 2·3 + ... + (k - l)k + k(k + 1) = (k - l)k(k + 1) + k(k + 1)


3

(k-1 ) = k(k.+ 1) (k+2)


= k(k + 1) -3- + 1 -3-

«k + 1) - l)(k + l)«k + 1) + 1)
3
as desired.

5. (S(l) 1\ 'v'k;:::l: (S(k) ---> S(k + 1») ---> 'v'n: Sen)


Section 5.3 Proof by Mathematical Induction 71

7. The base case (n = 1) checks: 1/2 ~ 1/2. Assume the inductive hypothesis, that
1 3 5 ... _
_._._ 2k --1> -1.
2 4 6 2k - 2k
Then
! . ~ . ~ ... 2k - 1 . 2k +1 > ~ . 2k + 1
2 4 6 2k 2k +2 - 2k 2k + 2
2k + 1 1
~'2k+2
1 1
> - - - -,-----,-
- 2k+2 - 2(k+l)'
as desired.

9. The base case checks: 1· I! = 2! - 1. Assuming the inductive hypothesis, we have


1:+1 I:
Lj· j! = Lj· j! + (k + l)(k + I)!
j=l j=l

= (k + I)! - 1 + (k + 1)(k + I)!


= (k + 1)!(1 + (k + 1)) - 1
= (k + 2)(k + I)! - 1 = (k + 2)! - 1,
as desired.

11. There are two base cases. For n = 0 or n = 1, the algorithm uses no additions, and
f( n) -1 = 1- 1 = O. Assume the inductive hypothesis, that Algorithm 3 requires f( i)-l
addition operations to compute f( i) for all i < k, where k ~ 2. Then to compute f( k) ,
the algorithm recursively computes f(k - 1) and f(k - 2) and adds the answers. This
requires [f(k - 1) - 1] + [f(k - 2) - 1] + 1 additions (the two bracketed quantities come
from the inductive hypothesis). But this is f(k -1) + f(k - 2) -1, which equals f(k)-l
by the definition of the Fibonacci sequence, exactly as desired.

13. We experiment a little to find the terms of the sequence whose nth term is
1 1 1
G3 + 3·5 + ... + (2n - 1)(2n + 1) .
The successive values are 1/3, 2/5, 3/7, 4/9, .... This suggest that the sum is n/(2n+l)
in general. The base case has just been verified. Assuming the inductive hypothesis
1 1 1 n
G3 + 3·5 + ... + (2n - 1)(2n + 1) = 2n + 1
72 Chapter 5 INDUCTION AND RECURSION

(we are letting n, rather than k, play the role of the variable to induct on now), we
compute
1 l I n 1
-
1.3
+ ... +
(2n - 1)(2n + 1)
+
(2n + 1)(2n + 3)
=- - + -:-:-----,-,,..,,..--,,..,..
2n + 1 (2n + 1)(2n + 3)
2n 2 + 3n + 1
(2n + 1)(2n + 3)
_ (2n+l)(n+l)
(2n + 1)(2n + 3)
n+l n+l
- 2n+3 - 2(n+ 1)+1'
as desired. Thus the given sum (where n = 50000) is 50000/100001 ~ 0.499995.

15. We first see what happens for small values of n: 2° = 1 > 0 = 02 , 21 = 2 > 1 = 12,
22 = 4 .,. 4 = 22, 2 = 8 .,. 9 = 32 , 24 = 16 .,. 16 = 42 , 25 = 32 > 25 = 52,
3

2 = 64 > 36 = 62 . We claim that the inequality holds for n = 0, n = 1, and n ;::: 5. It


6

remains to prove the last of these claims by mathematical induction, the base case n = 5
having already been done. Assume the inductive hypothesis that 2k > k 2 . Then
(k + 1)2 = k 2 + (2k + 1)
(since k ;::: 5)

17. (a) The base case was not checked. In fact it is false: 1"1 (1 + 1 +4)/2.
(b) We need to show for all k ;::: 1 that if 2k + 1 is prime then 2( k + 1) + 1 is prime,
not just this implication for k = 1. If fails for k = 3, since 7 is prime, but 9 is not.
(c) It is not true that a2 E B if k = 2. Indeed, in that case, B = {ad, and C = {a2},
and al and a2 need not have the same parity.
(d) Since we used the inductive hypothesis for i = k - 2, we needed to check two base
cases, n = 0 and n = 1. In fact the proposition fails for n = 1 (for any a "I 1).
(e) The base case is not true. If n = 1, then 11 + 1 = 2 is not odd.

19. Suppose that S(n) is a proposition with a free variable n that ranges over the positive
integers. Then if S(I) is true, and if for every k> 1 the implication S(k - 1) --+ S(k) is
true, then $( n) is true for all n.

21. Suppose that S( n) is a proposition with a free variable n that ranges over the natural
numbers. Then if S(O), S(l), and S(2) are true, and if for every k > 2 the implication
(Vi<k: S(i)) --+ S(k) is true, then S(n) is true for all n.
Section 5.3 Proof by Mathematical Induction 73

23. By Example 6, flOoo > 1.5 1000 . Thus IOg10 hooo > 1000 IOg10 1.5 :::::: 176.09. Therefore
hooo > 10 176 , so flOoo has more than 176 decimal digits.

25. We prove that for all n ~ 0, if x is a FPAE born on day n, then LP(x) = RP(x). If
n = 0 (base case), then x must be an unsigned integer or variable name, so L P( x) =
=
o RP(x). Let k > 0, and assume the inductive hypothesis, that for all i < k,
every FPAE y born on day i satisfies LP(y) = RP(y). Let x be a FPAE born on
day k; we must show that LP(x) = RP(x). By the recursive definition of FPAE, we
must have x = (0' + (3), X = (0' - (3), X = (0' * (3), X = (0'/(3), or x = (-0') for
some 0' and (3 born prior to day k. The cases are similar, so we will assume that
x = (0' * (3). By the inductive hypothesis, LP(O') = RP(O'), and LP((3) = RP((3). But
then LP(x) = 1 + LP(O') + LP((3) = 1 + RP(O') + RP((3) = RP(x), as desired.

27. We want to argue that if the base case and inductive step have been proved, then S(n)
must be true for all n. We will argue by contradiction. If "In: S(n) is not true, then
there must be one or more counterexamples-positive integers n that make S( n) false.
Let no be the smallest counterexample. Certainly no # 1, since the proof of the base
case explicitly showed that S(l) is true. On the other hand, if no > 1, then look at the
inductive step, with k = no - 1; it was proved that S(no - 1) -+ S(no). Since no is
the smallest counterexample, the inductive hypothesis S(no - 1) is true. Therefore the
conclusion of the inductive step must also be true, namely S(no). But this contradicts
our assumption that no was a counterexample to "In: S( n). Therefore Vn: S( n) has no
counterexamples, and our argument is complete.

29. In each case (i = 1,2,3) we find the correct formula by looking at the pattern that
appears when we calculate A( n, i) iteratively for successive values of n. Because of the
recursive definition, this computation uses the results for i - 1.
(a) The sequence begins 2, 3, 4, 5, ... , so we conjecture that A( n, 1) = n + 2. For the
base case A(O, 1) = A(l, 0) = 1 + 1 = 2 = 0 + 2. Assume the inductive hypothesis, that
A(k, 1) = k + 2. Then
A(k + 1,1) = A(A(k, 1),0) (by definition)
=A( k + 2,0) (by the inductive hypothesis)
=k + 2 + 1 (by definition)
=(k+1)+2.
(b) The sequence begins 3, 5, 7, 9, ... , so we conjecture that A( n, 2) = 2n + 3. For the
base case A(0,2) = A(l, 1) = 1 + 2 = 3 by part (a). Assume the inductive hypothesis,
that A(k,2) == 2k + 3. Then
A(k + 1,2) = A(A(k, 2),1) (by definition)
= A(2k + 3, 1) (by the inductive hypothesis)
= (2k + 3) + 2 (by part (a))
=2(k+1)+3.
74 Chapter 5 INDUCTION AND RECURSION

(c) The sequence begins 5, 13, 29, 61, ... , so we conjecture that A( n, 3) = 2n +3 - 3. For
the base case A(0,3) = A(l, 2) = 2· 1 + 3 = 5 by part (b), and 20 +3 - 3 = 5. Assume
the inductive hypothesis, that A( k, 3) = 2k+ 3 - 3. Then
A(k + 1,3) = A(A(k, 3), 2) (by definition)
= A(2k+3 - 3,2) (by the inductive hypothesis)
= 2(2k+ 3 - 3+3 (by part (b»
= 2(k+1)+3 - 3.

31. We claim that fn is odd when n == 0 or 1 (mod 3), and fn is even when n == 2
(mod 3). In other words, fn is even if and only if n == 2 (mod 3). The base cases are
easily checked: fa and II are odd. Assume the inductive hypothesis, that for all i < k, fi
is even if and only if i == 2 (mod 3). We must show that fk is even if and only if k == 2
(mod 3). Now if k == 2 (mod 3), then k - 1 == 1 (mod 3) and k - 2 == 0 (mod 3),
so by the inductive hypothesis, fk-l and fk-2 are both odd. Hence Ik = fk-l + fk-2
is even. If k == 0 (mod 3), then k -1 == 2 (mod 3) and k - 2 == 1 (mod 3), so by
the inductive hypothesis, Ik-l is even and fk-2 is odd. Hence fk = Ik-l + fk-2 is odd.
The case in which k == 1 (mod 3) is similar to this last case.

33. (a) This can most easily be proved by simple algebra (factoring), without mathematical
induction. Indeed, fJ+2 - fJ+1 = (In+2 - fn+d(Jn+2 + fn+d = fnfn+3 by the definition
of the Fibonacci sequence.
(b) We want to prove that fJ+l - fnfn+2 = (-It+l for all n. The base case (n = 0) is
clear: Jl- foh = 1- 2 = (_1)1. Assume the inductive hypothesis, that N+l - Ikfk+2 =
(-I)k+l.Then

ft+2 - fk+dk+3 = 11+2 - fk+l (Jk+2 + fk+l) (by definition)


= ft+2 - fk+dk+2 - ff+1
= t;,+2 - fk+dk+2 - (Jdk+2 + (-1 )k+l)
(by the inductive hypothesis)
= ff+2 - fk+2(Jk+l + fk) - (_I)k+1 (by factoring)
= ff+2 - fk+dk+2 - (_I)k+l (by definition again)
= _(_I)k+l =
(_1)k+2,

35. (a) Let n E N be the number of numbers being added, which are denoted aI, a2,
... , an· For the base case, n = 0, the empty sum is 0 by definition, and 0 is even.
Assume the inductive hypothesis, that the sum of k even numbers is even. Then the sum
(al + a2 + ... + ak) + ak+l is the sum of two even numbers (by the inductive hypothesis),
which is even by Exercise 2 in Section 1.3.
Section 5.3 Proof by Mathematical Induction 75

(b) Let 2n be the number of odd numbers being added, which are denoted aI, a2,
For the base case, n = 0, the empty sum is 0 by definition, and 0 is even.
... , a2n'
Assume the inductive hypothesis, that the sum of 2k odd numbers is even. Then the
sum (al + a2 + ... + a2k) + a2k+l + a2k+2 is the sum of an even number and two odd
numbers (by the inductive hypothesis), which is the sum of an even number and an even
number, which is even (by two applications of Exercise 2 in Section 1.3).
(c) Let 2n + 1 be the number of odd numbers being added, which are denoted aI, a2,
... , a2n+l. For the base case, n = 0, the sum of one odd number al is itself, which is
odd. Assume the inductive hypothesis, that the sum of 2k+ 1 odd numbers is odd. Then
the sum (al + a2 + ... + a2k+I) + a2k+2 + a2k+3 is the sum of an odd number and two
odd numbers (by the inductive hypothesis), which is the sum of an odd number and an
even number, which is odd (by two applications of Exercise 2 in Section 1.3).

37. (a) For the base case (n = 0) we have 3 I 6. Assume the inductive hypothesis, that
3 I k 3 - 4k + 6. Then
(k + 1)3 - 4( k + 1) + 6 = + 3k 2 + 3k + 1 - 4k - 4 + 6
k3
= (k 3 - 4k + 6) + (3k 2 + 3k - 3).
The first summand in parentheses in the final expression is divisible by 3 by the inductive
hypothesis, and the second is clearly divisible by 3, so 3 I (k + 1)3 - 4( k + 1) + 6, as
desired.
(b) We write n 3 -4n+6 = n 3 -n-3n+6 = n(n 2 -1)-3(n-2) = (n-1)n(n+1)-3(n-2).
Now the first term in the final expression is divisible by 3 since one of the three consecutive
numbers n - 1, n, and n + 1 is necessarily a multiple of 3. Clearly the second term is
divisible by 3. The result follows.

39. (a) We prove by induction on m that if the game table consists of n stones and n - m
piles, then exactly m plays remain. The base case is m = O. If there are n - 0 = n
piles, then clearly each pile contains one stone, so no plays remain. Assume the inductive
hypothesis, and suppose that there are n - (m + 1) = n - m - 1 piles. Whatever a
player P now does, the number of piles must increase by 1, leaving n - m piles. By the
inductive hypothesis, m plays remain after that. Thus counting P's move, m + 1 plays
remained when there were n - (m + 1) piles left. Thus the statement·is true for all m.
Letting m = n - 1 , we obtain the desired conclusion, that n - 1 plays remain when there
is one pile.
(b) The model described here gives the same game. Since there are n - 1 spaces between
adjacent stones, the game lasts exactly n - 1 moves.
(c) If n is odd, then the second player wins, since an even number (n - 1) of moves
remains. If n is even, then the first player wins.
76 Chapter 5 INDUCTION AND RECURSION

41. The base case is v = ,\. We have (uv)R = (u,\)R = u R = '\u R = ,\Ru R . Assume the
inductive hypothesis, that the statement is true for second strings of length k, and let
=
v ax, where a is a string of length k and x is a symbol. Then
(uv)R = (uax)R = ((ua)x)R
= x( ua)R (by the definition of R)
= x(aRu )R (by the inductive hypothesis)
= (x(aR))u R
= (ax)Ru R (by the definition of R)
= vRu R .

43. Let S( n) be the statement that any solution to the problem of transferring n disks from
one given peg to another (different) given peg, according to the rules of the towers of
Hanoi, requires at least 2n - 1 moves. We need to prove 'v'n~1: S(n). The base case is
clear, since if n = 1, then 21 - 1 = 1 move is required. Assume the inductive hypothesis,
that any solution to the problem of transferring k disks from one peg to another requires
at least 2.1: - 1 moves. Now in order to solve the problem with k + 1 disks, we must at
some point move disk k + 1. This can happen only when all the other disks have been
moved off the peg on which this largest disk sits, onto one of the other pegs. By the
inductive hypothesis, this requires at least 2.1: - 1 moves. Similarly, after disk k + 1 has
been transferred to the desired peg (for the last time, if it moved more than once), the
other k disks must make their way back onto the peg on which disk k + 1 now sits, and
again by the inductive hypothesis, this requires at least 2.1: - 1 moves. Thus the total
number of moves required is at least (2.1: - 1) + 1 + (2.1: - 1)= =
2 . 2k - 1 2.1:+1 - 1, as
desired.
Section 6.1 Fundamental Principles of Counting 77

CHAPTER 6
ELEMENTARY COUNTING TECHNIQUES
SECTION 6.1 Fundamental Principles of Counting
1. (a) 2·3=6 (b) {(a,a), (a,b), (a, c), (b,a), (b,b),(b,c)}

3. (a) 25 = 32 (b) 32 - 1 - 5 = 26 (exclude no toppings, one topping)

7. (a) Each of the sets {(a, a), (b,b), (e,e), (d,d)}, {(a, a), (b,a), (e,a), (d,a)}, and {(a,a),
(b, c), (e, c), (d, a)} is a function from X to Y.
(b) There are 54 = 625 possible functions by the multiplication principle, because for
each of the four elements in X we must choose one of the five elements of Y as its image
under the function.
(c) There are n k possible functions by the multiplication principle, because for each of
the k elements in X we must choose one of the n elements of Y as its image under
the function. (If n =0, then there are no functions unless k =
0, in which case there
is 0° = 1 function, namely the empty set; if k = 0, then there is always one function,
namely the empty set. These statements are consistent with our definitions that Ok = 0
for k > 0 and nO = 0 for all n.)

9. (a) 47 = 16,384
(b) 46 = 4096 (no choice on Friday)
(c) 47 - 37 = 14,197 (exclude the number of ways in which beef is not served)
(d) 47 - 37 - 7.36 = 9094 (exclude the number of ways in which beef is served no times
or just once; for the latter, we need to choose the day on which beef is to be served, then
choose the main courses for the other six days)
(e) 4.3 6 = 2916 (for each day after the first, there are just three choices; if there had
been a meal, the day before this week began and the restriction were in effect the first day
of the week, then the answer would be 37 = 2187, and similar comments apply to parts
(f) and (g»
(1) 4.3.2 5 = 384 (there are four choices the first day, three the next day, and two each
day after that)
78 Chapter 6 ELEMENTARY COUNTING TECHNIQUES

(g) (4.3 6 )/4 = 729 (by symmetry, exactly 1/4 of the choices for part (e) have fish on
Friday; alternatively, there are three choices for each of Saturday, Thursday, Wednesday,
Tuesday, Monday, and Sunday, in that order, so the answer is 36 )
(h) 4· (3 .2.1)2 = 144 (choose Wednesday's main course first, and then work toward the
ends of the week)

11. (a) No (there are an infinite number of such propositions-they can be arbitrarily long;
but there are only countably many by Exercise 34b in Section 2.3, since there are only a
finite number of propositions of each finite length)
(b) 232 = 4,294,967,296 (each of the 32 lines of the truth table can have either a T or
an F)
(c) 232 = 4,294,967,296 (as in part (b»

13. To specify a second place ticket, we must first choose one of the state's numbers to omit
from the ticket (this can be done in six ways), and then choose a replacement for it
from among the unused numbers (this can be done in 34 ways). Therefore the answer is
6·34 = 204.

15. (a) 3n
(b) [n(n - 1)/2] . 2n-2, assuming that n ~ 2 (choose the positions for the a's, then
choose the remaining letters from left to right)
(c) 3n - n . 2n - 1
- 2n , assuming that n ~ 2 (exclude strings with one a or no a's)
(d) [n( n - 1)/2] . (2 n - 2 - 2), assuming that n ~ 4 (choose the positions for the a's, then
fill the remaining positions, but exclude the possibility of all b's or all e's)

17. (a) 8 5 = 32,768


(b) 6 = 7776 (only six letters are available)
5

(c) 85 - 65 = 24,992 (exclude the strings that contain neither)


(d) 75 - 65 = 9031 (only seven letters are available; exclude the strings that do not
use a)
= 25,838 (using parts (b) and (d), since such a string either
(e) 65 + (7 5 - 65 ) + (7 5 - 65 )
must contain neither a nor b, or else must contain exactly one of them)
(f) 8 5 25838 = 6930 (exclude the strings counted in part (e))
-

(g) 8 + 84 - 83 = 7680 (the other four positions are free; the subtraction is because of
4

having counted twice the strings that both begin and end with e)
(h) 5· 74 =
12,005 (choose the position for the e, then fill in the remaining positions
with letters other than c)
Section 6.1 Fundamental Principles of Counting 79

19. (a) 8.9 4 = 52,488 (choose digits from left to right)


(b) 9.10 4 - 8.9 4
= 37,512 (exclude those that do not contain 5)
(c) 5·8·8·7·6 = 13,440 (choose the ones' digit, then the ten thousands', then the
remaining digits)
(d) 95 = 59,049 (choose the digits from left to right)

21. (a) 10·9·8·7·6·5·4·3·2·1 = 10! = 3,628,800


= 6!4! = 17,280
(b) (6·5·4·3·2 ·1)· (4·3·2 ·1)
(c) (6·5·4·3·2·1). (7·6·5·4) = 604,800 (after the men have lined up relative to
themselves, choose the places for the women among the seven gaps created by the men)
(d) 0

23. (a) 2 (101010 ... or 010101. .. )


(b) 2n - 2n - 2 (there are 2n - 2 strings in which the first and last bits are both l's)
( c) n (choose the location for the 1)
(d) n(n - 1)/2 (choose the locations for the l's)
(e) 2n /2 = 2n - 1 (by symmetry)

25. (a) 21AI (for each element of A, either include it in the subset or not)
(b) 2IBI+ICI (since IB U CI = IBI + ICI)
(c) 21BI ·2 1c1 (choose a subset of B, then a subset of C; note that this is the same as in
part (b»
(d) 21AI - IAI- 1 (exclude singleton sets and the empty set)

27. First we note that 1500/3 = 500 numbers have the factor 3 in common with 15. Similarly
1500/5 = 300 numbers have the factor 5 in common with 15. Now we have counted twice
the numbers that are multiples of 15, so we subtract the overcount, 1500/15 = 100, from
the sum, obtaining the answer 700.

29. First we will count the number of such strings in which there are at least two l's and
all the l's are consecutive. To specify such a string we need to choose the starting
and ending positions for the substring of l's. We can do this in 20·19/2 = 190 ways.
Similarly, there are 190 allowable strings in which there are at least two O's and all the O's
are consecutive. Both of these counts include strings of the form or 120 - r and 1r 020-r,
with 2 ::; r ::; 18, of which there are 2·17 = 34. This gives us 190 + 190 - 34 = 346
strings so far. In addition, there are 18 strings containing one 1 in which the O's are not
consecutive, and 18 strings containing one 0 in which the l's are not consecutive. This
gives us a total of 346 + 18 + 18 = 382.
80 Chapter 6 ELEMENTARY COUNTING TECHNIQUES

31. We can count these most easily if we imagine building the sequences from the back, rather
than from the front. There are nine decisions to make as we make our way from the back
to the front of the sequence: As we add a new number, should it be the largest of the
remaining numbers or the smallest? Thus there are 29 = 512 possible sequences.

33. (a) There are two ways: B-SS-SSS or BS-SS-SS.


(b) There are six ways to label the boxes in the first way of distributing the marbles given
in the solution to part (a), and there are three ways to label the boxes in the second.
Thus the answer is 6 + 3 = 9.
(c) In the first of the solutions for part (a), we can choose the two small marbles that go
into a box by themselves in 5 . 4/2 = 10 ways. In the second, we can choose the small
marble to go with the big marble in five ways, after which there are three ways to pair
up the remaining small marbles. Thus the answer is 10 + 5 . 3 = 25.
(d) Once we have made the decisions in part (c), we need to label the boxes, and there
are six ways to do so. Therefore the answer is 25 . 6 = 150.

35. There are 29 ways to choose a partner for the oldest student. There are then 27 ways to
choose a partner for the oldest unpaired student, etc. Thus the answer is 29·27·25··· 3·1 ~
6.2 x 10 15 . (See also Exercise 24 in Section 7.1.)

SECTION 6.2 Pennutations and Combinations


1. (a) 7!/4! = 7·6·5 = 210 (b) 7!/6! = 7 (c) 7!/0! = 7! = 5040
(d) 7!/l! = 7! = 5040 (e) 10!/2! = 10·9·8·7·6·5·4·3 = 1,814,400

3. (a) P(5,2)=5·4=20
(b) 13,15,17,19,31,35,37,39,51,53,57,59,71,73,75,79,91, 93, 95, 97
(c) C(5,3) = 5 ·4/2 = 10
(d) 135,137,139,157,159,179,357,359,379,579

5. (a) C(10,2) = 45 (b) C(10,6) = 210 (c) C(lO,O) =1 (d) C(10, 1) = 10

7. C(5,1)+C(5,2)=5+10=15

9. C(9, 2) + C(9, 3) + C(9, 5) + C(9, 7) = 36 + 84 + 126 + 36 = 282

11. P(21, 3) + C(21, 3) = 7980 + 1330 = 9310 (there were two cases to consider)
Section 6.2 Permutations and Combinations 81

13. (a) C(39,9) = 211,915,132


(b) C(10,3)· C(12, 3) . C(17, 3) = 120·220·680 = 17,952,000
(c) C(10, 9) + C(12, 9) + C(17, 9) = 10 + 220 + 24310 = 24,540
(d) C(29,,9) + C(27,9) - C(17,9) = 10015005 + 4686825 + 24310 = 14,677,520 (the
subset either contains only adult women and children, or it contains only adult men and
children; those choices in which there are only children have been counted twice)

15. There are two ways to look at this. We can note that there are C(80, 11) = 10,477,677,
064,400 possible ways for the state's drawing to turn out, and there are C(73,4) =
1,088,430 of these in which the state has picked the player's seven numbers and four others.
Therefore the answer is 1088430/10477677064400, or about 1 in 9,626,413. Alternatively,
we can view the state as having picked its numbers first; then the player can pick his
numbers in C(80,7) = 3,176,716,400 ways, of which C(11,7) = 330 will result in a
winning ticket. Therefore the chances of winning are 330/3176716400, which has the
same value as that previously obtained.

17. (a) C(12,5)· 3 7 = 1,732,104 (choose the positions for the a's, then choose the symbols
for the remaining positions, from left to right)
(b) C(12,3)· C(9, 3) . C(6, 3) . C(3, 3) = 369,600 (choose the positions for the a's, then
choose the positions for the b's, and so on)
(c) C(12,5)· C(7,4). 23 = 221,760 (choose the positions for the a's, then choose the
positions for the b's, then fill the remaining positions from left to right)
(d) C(12,5) .3 7 + C(12, 4) .3 8 - 221760 = 4,758,039 (subtract the overcount of those
strings that have exactly five a's and exactly four b's, computed in part (c))

19. 1 (there is only one outcome-k of the boxes will have a ball and the rest will not)

21. Think of gluing a pair of l's to the right of each o. Then there are four OIl's and 10
remaining l's to form a string with. We just need to choose the four locations in this
string of 14 things to receive the OIl's, so the answer is C(14,4) = 1001.

23. 12!f12 = 11! = 39,916,800 (by the circular symmetry)

25. (a) 12!f2 = 239,500,800 (the rectangular table has two-fold rotational symmetry)
(b) 12!/4 = 119,750,400 (the square table has four-fold rotational symmetry)

27. Since we just have to choose the positions for the n left parentheses among the 2n posi-
tions available, the answer is C(2n, n). (The question is much harder if the parentheses
have to make sense in order as grouping syl1lhols, so that, for example, ()) ( is not
allowed; see Exercise 42 in Section 7.2.)
82 Chapter 6 ELEMENTARY COUNTING TECHNIQUES

29. Once we know which elements are in Au B, we automatically know which are in each of
the two subsets. Therefore the answer is C( n, k + /).

31. Since we need to choose a 0 or a 1 for each entry in a matrix with n 2 entries, the answer
is 2n2.

33. Of the 2 16 bit strings, C(16,8) have an equal number of O's and l's. By symmetry, half
of the rest have more O's than l's. Therefore the answer is (216 - C(16, 8))/2 = 26,333.

35. (a) C(52, 13) = 635,013,559,600


(b) C(13,4). C(13,4)· C(13,3)· C(13,2) = 11,404,407,300 (choose the card from the
suits one suit at a time)
(c) C(4,2). C(13, 4)2. 2C(13, 3) . C(13, 2) = 136,852,887,600 (choose the two suits from
which the four cards are to come, choose the cards from each of these suits, choose the
suit from which three cards are to come, choose the cards from this suit, choose the cards
from the last suit)
( d) none (the hand needs 13 cards in all)
(e) There are 32 cards no better than a 9. Thus there are C(32,13) = 347,373,600
hands that qualify as a Yarborough. The chances of holding a Yarborough are therefore
C(32, 13)/C(52, 13), or about 1 in 1828.

37. The number of such tickets is C(6, 3) . C(34, 3) = 119680. The total number of tickets is
C( 40, 6) = 3838380. Therefore the chance of holding such a ticket is 119680/3838380, or
about 1 in 32.

39. (a) C( n - k, k) (arrange n - k things consisting of the k couples and n - 2k blank seats;
the only choice is in which positions to put the couples)
(b) C( n - k, k) . k! = P( n - k, k) (once it has been determined which seats will be
occupied, which is what we counted in part (a), assign an order to the couples)
(c) C(n - k, k) . k! ·2 k (once it has been determined which seats will be occupied by
which couples, which is what we counted in part (b), decide for each couple whether the
younger person will sit on the older person's left or right)
Section 6.3 Combinatorial Problems Involving Repetitions 83

41. (a) There are C( 4,2) ways to choose the two suits. There are C(26,13) ways to choose
cards from just these two suits. However, this includes the four cases in which all the
cards came from just one suit (which do we not wish to include), and each such case is
counted three times. Thus we have overcounted by 12. Therefore the answer is C( 4,2) .
C(26, 13) - 12 = 62,403,588.
(b) Since there are an odd number of cards in the hand, it is impossible for there to
be an equal number of red cards and black cards. Therefore by symmetry the answer is
C(52, 13)/2 = 317,506,779,800.
(c) First let us count the number of hands with the same number of spades as hearts,
and denote this number by S. Since such a hand can have anywhere from zero to six
cards in each of these two suits, it is clear that S = C(13,0)2 . C(26, 13) + C(13, 1)2 .
C(26, 11) + C(13, 2)2 . C(26, 9) + C(13, 3)2 . C(26, 7) + C(13, 4)2 . C(26, 5) + C(13, 5)2 .
C(26, 3) + C(13, 6)2 . C(26, 1) ~ 1.12 X 1011. Half of the remaining hands will have more
spades than hearts, so the answer is (C(52, 13) - S)/2 ~ 2.6 x 1011.

43. (a) C(n, k) (choose the elements to be included in the subsequence)


(b) 2n (the number of subsets of {I, 2, ... , n})
(c) If k = 0 then there is just one subsequence (the empty sequence). Otherwise, the
consecutive subsequence can start in positions 1, 2, ... , n - k + 1, a total of n - k + 1
possibilities.
(d) There are C( n, 2) consecutive subsequences of length greater than 1, since to specify
such a subsequence is to specify a pair of locations to be its beginning and end. In
addition, there are n consecutive subsequences of length 1 and the empty sequence.
Therefore the answer is C(n, 2) + n + 1 = (n 2 + n + 2)/2.

SECTION 6.3 Combinatorial Problems Involving Repetitions


8'
1. (a) 2! = 20,160 (because of the two e's)
12!
(b) 2!3!2! = 19,958,400 (there are two m's, three a's, and two f's)
4!
(c) 2!2! =6 (there are two n's and two o's)

3. (a) There are C(10 + 7 - 1,7) = C(16, 7) = 11,440 ways to choose a collection of seven
dinners from 10 dinners, with repetitions allowed.
(b) There are 10 7 ways to choose an ordered sequence of seven dinners from 10 dinners,
with repetitions allowed.
84 Chapter 6 ELEMENTARY COUNTING TECHNIQUES

5. (a) There are six choices for each of the four positions, so the answer is 64 = 1296.
(b) This time order is irrelevant, so we are asking for a collection of four items from a
set of six items, with repetition allowed. There are C(6 + 4 - 1,4) C(9,4) = =
126 such
collections.

7. (a) 33 = 27
(b) C(3 + 3 - 1,3) = C(5,3) = 10
(c) This amounts to arranging the entire bag, so Theorem 1 applies, and the answer is
10!
=
4!3!3! 4200.
(d) 1 (take the whole bag)
(e) There are 35 = 243 sequences of five colors using the colors W, R, and B. Not all
of these correspond to actual choices from the bag, since there are not enough balls of
each color. Let us count the sequences that are not allowed. There are three sequences
using only one color, and these are not allowed, since there are not five balls of anyone
color. Furthermore, there are 2·2·5 = 20 sequences that use either four R's or four B's
(choose the color to use four of, choose the other color to be used, choose the position for
the other color). Therefore the answer is 243 - 3 - 20 = 220.
(1) We need to count the number of solutions to w+ r+ b = 5, with 0 ~ w ~ 4, 0 ~ r ~ 3,
and 0 ~ b ~ 3. Without these restrictions, there are C(3 + 5 - 1,5) C(7,5) = 21 =
solutions. There is one way for the restriction on w to be violated (take w = 5); and
there are three ways each for the restriction on r or b to be violated (since then we are
counting solutions to an equation of the form x + y + z = 1). Therefore the answer is
=
21 - 1 - 2 ·3 14.

9. Let n be the length of the walk. We need r steps to the right and u steps up, r - 2 steps
left, and u - 3 steps down, in order to reach (2,3), where r + u + (r - 2) + (u - 3) = n.
Thus we need r ~ 2, u ~ 3, and 2(r + u) = n + 5. This implies that n is odd and at
least 5, and that

r = n+5 -u<n+5 -3= n-l


2 - 2 2 .
Thus r can have any value from 2 to (n - 1)/2. We see also that u = [(n + 5)/2] - r
and u - 3 = [( n - 1)/2] - r. Reasoning now as in Example 3, we see that the number of
walks from (0,0) to (2,3) is given by
(n-l)/2
n!
L
r=2
r!(r - 2)!([(n + 5)/2] - r)!([(n - 1)/2] - r)! .
We apply this formula to obtain the answers below.
(a) There is only one term, with r = 2, so the answer is 5!f(2!3!) = 10.
(b) none (there are not enough steps to reach (2,3); equivalently, our summation would
run from 2 to 1, and hence would be empty-the empty sum is 0)
Section 6.3 Combinatorial Problems Involving Repetitions 85

(c) Plugging into our formula with n = 15 we have


15! 15! 15! 15! 15! 15! _ 19 324 305
2!0!8!5! + 3!l!7!4! + 4!2!6!3! + 5!3!5!2! + 6!4!4!l! + 7!5!3!0! - , , .
(d) none (n must be odd)
(e) The general formula for odd n is displayed before our answer to part ( a); there are
no such walks if n is even.

11. (a) C(4 + 40 - 1,40) = C(43, 40) = 12,341


(b) C(5 + 39 - 1,39) = C( 43,39) = 123,410 (the number of solutions to Xl + X2 + X3 +
X4 + X5 = 39, where X5 ~ 0 is a slack variable)
(c) C(4+32-1, 32) = C(35, 32) = 6545 (the number of solutions to xi +X~+X3+X~ = 32,
where xi = Xl - 1, x~ = X2 - 1, and x~ = X4 - 6)
(d) C(4+40-1, 40) = C(43, 40) = 12,341 (the number of solutions to xi +X2 +X3+X~ =
40, where xi =
Xl + 2 and x~ X4 - 2) =

13. We seek the number of integer solutions to Xl + X2 + X3 + X4 = 25 with 2 ~ Xi ~ 10


for each i. By letting Xi = 2 + x~, we transform this into the problem of finding the
number of natural number solutions to xi + x~ + x~ + x~ = 17, with each xi ~ 8. Now
without the restriction the number of solutions is C( 4 + 17 - 1,17) = C(20, 17). There
are four ways to violate the restriction: Any of the variables might be greater than or
equal to 9 (but it is impossible for two of the conditions to be violated simultaneously,
since 9 + 9 > 17). The number of solutions with xi ~ 9 is the same as the number of
solutions of x1 + x~ + x~ + x~ = 8, which is C( 4 + 8 - 1,8) = C(11, 8). Therefore the
answer to our problem is C(20, 17) - 4C(11, 8) = 480.

15. We can distribute the blue balls in C(1O+8-1, 8) ways and the red balls in C(10+9-1, 9)
ways. Therefore the answer is C(17,8) ·C(18,9) = 1,181,952,200.

17. By the multiplication principle, the number of permutations with repetitions allowed is
just n"'.

19. All salaries are in terms of multiples of $100,000. Let Xl be the salary of the MVP
shortstop, let X2 be the salary of the ace relief pitcher, let X3 through X15 be the salaries
of the other first-string players, and let X16 through X25 be the salaries of the remaining
players. Thus the conditions are Xl ~ 10, X2 ~ 15, Xi ~ 2 for 3 ~ i ~ 15, and Xi ~ 1
for 16 ~ i ~ 25.
(a) The number of solutions to the equation Xl + X2 + ... + X25 = 200 subject to the
constraints is the number of natural number solutions to xi + x~ + ... + X~5 = 139. This
equals C(25 + 139 -1, 139) = C(163, 139) ~ 3.4 x 10 28 •
86 Chapter 6 ELEMENTARY COUNTING TECHNIQUES

(b) As we saw in part (a), there are 139 units of salary free to be distributed. If all of it
goes to the ace relief pitcher (who already has the highest minimum), then he will have
a salary of 15 + 139 = 154 units, i.e., $15,400,000.
(c) As we saw in part (a), there are 139 units of salary free to be distributed. If all of
it goes to one of the second string players, then he will have a salary of 1 + 139 = 140
units, i.e., $14,000,000.
(d) We may as well assume that players 17 through 25 each get their minimum one
unit of salary and ignore them for the rest of the problem. This leaves 191 units for the
remaining players, and we want to arrange for X16 to be as large as possible, under the
requirement that Xl ~ 10, X2 ~ 15, and Xi ~ X16 for all remaining i. Clearly X16 can
be at most L191/16J = 11, for otherwise there will not be enough money to go around.
Furthermore, we can achieve X16 = 11 by setting Xi = 11 for i "# 2, and X2 = 26. Thus
the answer is $1,100,000.

21. (a) The largest part can have size 1, 2, ... , rk/21. Thus the answer is rk/21.
(b) Choose a subset S other than the k-set A itself or 0. There are 2k - 2 ways to
do this. The parts of our partition are S and A - S. This over counts the number of
partitions by a factor of 2, since each partition can arise by choosing either S or A - S.
Therefore the answer is 2 k - l - 1. (We assume that k ~ 2; otherwise the answer is
clearly 0.)

23. We will first count the number of subsets of six numbers from {I, 2, ... , 40}, such that
there are no adjacent numbers in the subset. Let al , a2, ... , a6 be the six numbers. Let
Xl = al + 1, X2 = a2 - aI, X3 = a3 - a2, X4 = a4 - a3, X5 = a5 - a4, X6 = a6 - a5, and
X7 = 42 - a6· Then the sum Xl + X2 + ... + X7 telescopes to equal 43, and the given
conditions on the ai's translate exactly into the condition that each Xi ~ 2. By the usual
trick, the number of solutions to this equation is same as the number of natural number
solutions to x~ + x; + ... + x~ = 29, which is C(7 + 29 - 1,29) = C(35, 29) = 1623160.
Now since there are C( 40,6) = 3838380 subsets in all, we see that the remaining 2215220
subsets have at least one pair of adjacent elements. Therefore the answer to the question
is 2215220/3838380 :::::: 58%.

25. (a) Any subset of the 10 numbered balls gives us one choice (we choose enough unnum-
bered balls to bring the total to 10). Thus the answer is 2 10 .
(b) 20!/1O! = 670,442,572,800 by Theorem 1
(c) There are C(lO, 10 - i) . (lO!/i!) ways to make a selection that uses i unnumbered
balls (choose the 10 - i numbered balls to include, then choose a permutation of the 10
chosen balls, of which are identical). Since i can take any value from 0 to 10, the
answer is
10 10!2
?= i!2(10 - i)! '
.=0
Section 6.4 The Pigeonhole Principle 87

which works out to 234,662,231.

27. (a) First consider the colors of the four pegs as fixed. If the four colors are all different,
then there are 3! = 6 arrangements. If two of the colors are the same (and the other
two different), then there are three arrangements. If there is a pair of pegs of each of two
colors, then there are two arrangements. If three or four of the pegs are of the same color,
there is only one arrangement. Since there are six colors to choose from, we can compute
the number of ways to choose colors satisfying each of these possibilities (e.g., there are
6 . C(5, 2) ways to choose one color for a pair of pegs and two other colors for a single
peg each). Thus the answer is C(6, 4)·6 + 6· C(5, 2)·3 + C(6, 2)·2 + 6·5·1 + 6·1 = 336.
(b) The reasoning is pretty much the same as in part (a), yielding the answer C(6,4)·
3 + 6 . C(5, 2) ·2+ C(6, 2) ·2+ 6 . 5 . 1 + 6 ·1 = 231.
(c) Again the calculation goes along the same lines, yielding the answer C(6,4) . 12 + 6 .
C(5,2) ·6 + C(6, 2) ·4+ 6 ·5·2 + 6 . 1 = 666.

SECTION 6.4 The Pigeonhole Principle


1. In each case the pigeons are the socks, and the pigeonholes are the colors.
(a) There are 10 colors. We need to choose 11 socks to be sure of getting two in the
same color class.
(b) There are two colors. We need to choose three socks to be sure of getting two in the
same color class.

3. The average raise is $10000/9 ~ $1111.11. If every raise were at least $1200, then the
average would not be this low. Hence someone has to get a raise less than $1200.

5. In Theorem 6, take p = k, q = I, r = 2, S equal to the set of people at the party, and


T equal to the "is acquainted with" relation.

7. The number of subsets of S is C(10,4) = 210. The largest possible sum is 50 + 51 +


52 + 53 = 206. Since the sums are all natural numbers, by the pigeonhole principle at
least two of the subsets have the same sum.

9. Consider the partition {{I, 2}, {3,4}, {5,6}, ... , {2n - 1, 2n}}. By the pigeonhole prin-
ciple, any subset of cardinality n + 1 must contain two elements in the same set of this
partition, say 2k - 1 and 2k. Clearly gcd(2k - 1, 2k) = 1.
88 Chapter 6 ELEMENTARY COUNTING TECHNIQUES

11. Divide the square into four smaller squares as shown below. By the pigeonhole principle,
two of the five points are in the same small square. The diameter of each small square is
../2 by the Pythagorean Theorem. Therefore two of the points are within ../2 inches of
each other.

• •

• •

13. If each hole contained at least m pigeons, then there would be at least mn pigeons
altogether, contradicting the hypothesis. Therefore some hole contains fewer than m
pigeons.

15. Let 8 be a sequence of length n. Let m = rVnl -


1. Then m < Vn, so m 2 < n,
i.e., m + 1 ~ n. Look at the subsequence of 8 consisting of the first m 2 + 1 terms.
2

By Theorem 3, this subsequence (and hence 8, as well) has a monotone subsequence of


length m + 1. But m + 1 = rVnl
~ Vn, so there is a monotone subsequence of length
at least Vn.

17. We can show that R( 4) > 9 with the following situation. Let the people by A, B, C,
P, Q, R, X, Y, and Z. Each of A, B, and C knows each other; each of P, Q,
and R knows each other; and each of X, Y, and Z knows each other; but there are no
other acquaintances among these people. There can clearly be no subset of four mutual
acquaintances. On the other hand, among any four people there are at least two in one
of the sets {A, B, C}, {P, Q, R}, and {X, Y, Z}. Thus these four people cannot be
mutual strangers.

19. In this proposition the quantifiers on p, q, r, and N range over natural numbers, and
the quantifiers on 8, P, and Q range over sets: Vr~2:Vp~r:Vq~r:3N:V8:VT: [(181 =
NAT is a symmetric r-ary relation on 8) --+ ([3P: (P ~ 8 A IPI = pAT holds on P)] V
[3Q: (Q ~ 8 A IQI = q A T holds on Q)])] .

21. Look at the 128 numbers 7, 77, 777, ... , 77 ... 7. By the pigeonhole principle, two of
these numbers must be congruent modulo 127. Hence their difference is congruent to 0
modulo 127, i.e., is a multiple of 127. But their difference is of the form 77 ... 700 ... 0,
as desired.
Section 6.4 The Pigeonhole Principle 89

23. (a) If there were 27 or fewer training sessions, then some robot (say Robbie) would have
received three or fewer sessions, since r27/71 = 3. Thus there would be at least 10 - 3 = 7
workers who could not use Robbie. If these seven workers needed a robot at the same
time, only six robots would be available to serve them. Therefore there have to be at
least 28 training sessions.
(b) We train the robots as follows, where we have numbered the robots and the workers.
Robot 1 is trained for workers 1, 2, 3, and 4; robot 2 is trained for workers 2, 3, 4, and 5;
robot 3 is trained for workers 3, 4, 5, and 6; ... ;. robot 7 is trained for workers 7, 8,
9, and 10. To see that this training is sufficient to meet the demand, suppose that we
are given seven workers who need to use the robots simultaneously, say with numbers
WI, W2, ... , W7, where WI < W2 < ... < W7. Because of these inequalities, it must

be the case that 1 ::::; WI ::::; 4 (otherwise W7 > 10), 2 ::::; W2 ::::; 5 (otherwise WI < 1 or
W7> 10), ... , 7::::; W7::::; 10 (otherwise WI < 1). Thus worker Wi can use robot i.

(c) Assume that we have n workers and k robots. We need k( n - k + 1) training


sessions (otherwise some robot will serve at most n - k masters, and the other k workers
will have only k - 1 robots available to them). Furthermore, k( n - k + 1) sessions are
sufficient, for we can train robot i for workers i, i + 1, ... , i + n - k. By the same
argument as given in part (b), if we are given any collection of k workers, say with
numbers WI < W2 < ... < Wk , then the ith robot will necessarily have been trained for
worker Wi.

25. If n = 3, then five such bit strings are necessary to guarantee that two of them agree in
at least two places, since the strings 000, 011, 101, and 110 do not so agree. Conversely,
given five such strings, by the generalized pigeonhole principle at least three of them
agree in the first position. Among these, at least two agree in the second position as well.
For n ~ 4, three such strings are necessary: Look at 00 ... 0 and 11 ... 1. Conversely,
suppose that we have three such strings. By the pigeonhole principle at least two of them
start with the same bit. Assume that they do not agree in any other bit, and consider
the third string. In each of bits 2, 3, and 4, it must agree with one or the other of these
first two strings. Therefore again by the pigeonhole principle, it must agree with one of
them in at least two of these three bits.

27. The following algorithm follows the hint: Ii will be the length of the longest increas-
ing subsequence starting at Xi, and Wi will be the index of the next term in such a
subsequence.
90 Chapter 6 ELEMENTARY COUNTING TECHNIQUES

procedure long_increase(xI, X2, ... , Xn : distinct numbers)


In +- 1 {xn is the longest known subsequence starting at Xn }
Wn +- 0 {there is no next term}
for i +- n - 1 down to 1 do
begin
Ii +- 1 {no subsequence longer than Xi is known yet}
Wi +-- 0 {there is no next term}
for j +- i + 1 to n do {find a subsequence to stick Xi in front of}
if Xi < X j 1\ Ii < Ij + 1 then
begin {found a longer subsequence starting at Xi}
Ii +- Ij + 1
Wi +- j
end
end {Ii and Wi are now known}
max +--00
for i +-- 1 to n do {find maximum Ii }
if Ii > max then
begin
max +-li
start +- i {starting point for subsequence of length Ii }
end
return( max, start, (WI, W2, ... ,Wn ))
{ we return the starting point and length of the longest increasing subsequence,
as well as the information needed to reconstruct the subsequence}

29. Fix person A. By the generalized pigeonhole principle, he must have either 10 ac-
quaintances or 10 nonacquaintances at the party. By symmetry we can without loss of
generality assume that he has 10 acquaintances. By Exercise 28, among these 10 we can
find either three mutual acquaintances or four mutual strangers. In the latter case we are
done. In the former case, these three together with A form the desired set of four mutual
acquaintances. (Note that the symmetric analogue of Exercise 28 is needed if A has 10
nonacquaintances. )

31. Look at person A. He must have either six nonacquaintances, six friends, or six enemies
among the other party-goers (otherwise there would be only 5 + 5 + 5 = 15 other people).
Without loss of generality, assume that there are six nonacquaintances. If any two of
these are strangers to each other, then we have our three mutual strangers. Otherwise
we apply Theorem 4 to these six people (using the categories of friend and enemy) to get
three mutual friends or three mutual enemies.

33. An inductive proof can be given. Here is a cuter direct proof. Among the n! ways to pair
red and blue points, one (or more) results in a minimum total length of the line segments
used. We claim that the drawing that achieves this minimum has no intersections. If
there were an intersection, then the situation shown below must happen for at least
one pair of pairs of red and blue points. By the triangle inequality, RIBI + R2B2 =
(R IP+PBI)+(R2P+PB 2 ) = (RIP+PB2)+(R2P+PBd > R I B 2+R2 B I , contradicting
Section 6.4 The Pigeonhole Principle 91

the choice of the pairing as the one with the smallest total length (if we pair Rl with
B2 and R2 with B 1 , then we reduce the total length). Thus there must have been no
intersections.
92 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

CHAPTER 7
ADDITIONAL TOPICS IN COMBINATORICS
SECTION 7.1 Combinatorial Identities
1. (a) x 6 + 6x 5 y + 15x 4 y2 + 20x 3 y3 + 15x 2y4 + 6xy 5 + y6
(b) a 4 + 4(-3)a 3 + 6(-3)2a 2 + 4(-3)3a + (_3)4 = a4 - 12a3 + 54a 2 - 108a + 81
(c) (2x)5 + 5(2x)4(3y) + 1O(2x)3(3y)2 + 10(2x)2(3y)3 + 5(2x)(3y)4 + (3y)5 = 32x 5 +
240x4y + 720x 3 y 2 + 1080x2 y3 + 810 xy4 + 243 y 5
(d) x 8 + 8x 6 + 28x 4 + 56x 2 + 70 + 56x- 2 + 28x- 4 + 8x- 6 + x- 8

3. The next rows read as follows.

1 12 66 220 495 792 924 792 495 220 66 12 1


1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1

The sum of the first of these is, as expected 212 = 4096, the sum of the second is
213 8192, and the sum of the third is 214 16384. In each case the alternating sum
= =
is O.

5. C(6, 6) + C(7, 6) + C(8, 6) + C(9, 6) + C(1O, 6) = 1 + 7 + 28 + 84 + 210 = 330 = C(l1, 7)


7. Each term xy3z2 in the expansion can be thought of as an arrangement of one x, three
y's, and two z's, where the order is determined by the order in which we draw these
symbols from the successive factors, so we need to count the number of ways to form
such an arrangement. By Theorem 1 in Section 6.3, the number of such arrangements is
6!j(1!3!2!) = 60. Hence the coefficient of xy3z2 when (x+y+z)6 is multiplied out is 60.

n n
k
9. (a) L C(n,.k)2 =L C(n, k)2 k l n - k = (2 + It = 3n
k=O k=O
n n
(b) LC(n,k)(-2)k = L:C(n,k)(-2)kl n - k = (-2+ It = (-It
k=O k=O
Section 7.1 Combinatorial Identities 93

11. A triangular arrangement with one dot in the top row, two dots in the second row, ... ,
n - 1 dots in the last row, has a total of 1 + 2 + ... + (n - 1) = (n - 1)n/2 = C(n,2)
dots in all.

13. (a) C(2n,2) = C(n,2) + C(n, 2) + n . n = 2C(n, 2) + n 2


2n(2n - 1)
(b) C(2n,2) = 2 = n(2n -1) = 2n 2 - n

n( n - 1)
and 2C(n, 2) + n2 = 2 2 + n2 = 2 2 2
n - n + n = 2n - n

15. (a) 5C(10,5) = 5·252 = 1260 = 10·126 = 10C(9,4)


n' n!
(b) kC(n, k) = k k!(n ~ k)! = (k _ l)!(n _ k)!

andnC(n-1,k-l)=n (n-l)! n!
(k - 1)!«n - 1) - (k - I)! (k - l)!(n - k)!
(c) If n = 1, then k = 1 and we have l·C(l, 1) = 1 = I·C(O, 0). Assume that the identity
is true for n - 1; we will show it for n. If k = n, then both sides equal n. Otherwise,
k ::; n - 1, and we have by algebra, the inductive hypothesis and two applications of
Pascal's identity

kC(n, k) = k(C(n - 1, k) + C(n - 1, k - 1))


= kC(n - 1, k) + (k - I)C(n - 1, k - 1) + C(n - 1, k - 1)
= (n - 1)C( n - 2, k - 1) + (n - 1)C( n - 2, k - 2) + C( n - 1, k - 1)
= (n - 1 )[C( n - 2, k - 1) + C( n - 2, k - 2)] + C( n - 1, k - 1)
= (n -1)C(n - 1, k - 1) + C(n - 1, k - 1)
=nC(n-1,k-1),
as desired.
(d) To choose from a set of n people a committee of k people including a chairperson,
we can either choose the committee members (in one of C(n, k) ways) and then choose
a chairperson from among them (in one of C(k, 1) = k ways), or else we can choose the
chairperson first (in one of C(n, 1) = n ways), and then choose the other k -1 members
of the committee from among the other n - 1 people (in one of C(n - 1, k - 1) ways).

17. We want to show that 2:;=0 C(n, k)2k = 3n . Let us count the number of ways to paint
the elements of an n-set red, white, or blue. We can first decide how many of the elements
are to be red or white. Let k be this number, so 0 ::; k ::; n. (The remaining elements will
all be blue.) Now there are C(n, k) ways to select a subset of k elements to be red/white,
and then there are 2k ways to decide on the colors (red or white) for the elements in our
chosen set. Thus the left-hand side counts the desired quantity. Clearly the right-hand
side does so as well.
94 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

19. The right-hand side is the number of ways to choose n people from 2n people, who happen
to consist of n men and n women. The left-hand side is the number of ways to choose
from this collection k men and n - k women (namely, C(n, k)· C(n, n - k) = C(n, k)2),
summed over all possible values of k, which is again simply the number of ways to choose
n people.

(2m + 2n)!
21. Both sides equal
(m!)2(n!)2 .

23. The number of permutations of k copies of each of n distinct things (kn things in all)
.
IS,
b y Th eorem 1·III S ·
ectlon (kn)!
6. 3 , k!k! ... k! = (kn)!
(k!)n· S·Illce t h·· h I b
IS IS a woe num er,
(kl)n
.
must divide (kn)!.

25. The point of this exercise is the combinatorial identity


n
nC(2n - 1, n - 1) = I>C(n, i)2 .
i=1

(a) Choose a captain from among the n boys. Then choose the remaining n -1 debaters
from among the 2n - 1 remaining people.
(b) Let i be the number of boys who will be on the team. Then n - i is the number of
girls who will be on the team. The number of ways to choose the team with i boys and
n - i girls is therefore C( n, i) . C( n, n - i) = C( n, i)2. The number of ways to choose the
captain is i, since he must be one of the male debaters. We sum over all possible values
of i to obtain the total number of ways to pick the team and captain.

27. Call the top row row 1. Consider the kth person III row m. If 2 ~ k ~ m - 1, then
this person bears half the weight borne by person k in row m - 1 and half the weight
borne by person k - 1 in row m - 1, plus w (i.e., half the weight of each of these two
people). If k =
m or k =
1, then there is only one person above, contributing half of his
weight and burden. Thus we have the following equations recursively defining the weight
B(m, k) borne by the kth person in row m.

B(I,I)=O
1
B(m, 1) = 2(w + B(m - 1,1» for m> 2

1
B(m,m) = 2(w+ B(m -I,m-I» for m 2: 2

1
B(m, k)= w + 2(B(m - 1, k) + B(m - 1, k - 1» for 2 ~ k ~ m - 1, m 2: 3
In our triangle, we take w = 1 for simplicity.
Section 7.1 Combinatorial Identities 95

0.5 0.5

0.75 1.5 0.75

0.875 2.125 2.125 0.875

0.9375 2.5 3.125 2.5 0.9375

0.96875 2.71875 3.8125 3.8125 2.71875 0.96875

0.984375 2.84375 4.265625 4.8125 4.265625 2.84375 0.984375

29. We first observe the data for small values of n.


n= 0 C(O,O) = 1
n=l C(l,O)=l
n=2 C(2,0)+C(1,1)=1+1=2
n=3 C(3,0)+C(2,1)=1+2=3
n = 4 C( 4,0) + C(3, 1) + C(2, 2) = 1 + 3 + 1 = 5
n=5 C(5,0)+C(4,1)+C(3,2)=1+4+3=8
n= 6 C(6, 0) + C(5, 1) + C( 4,2) + C(3, 3) = 1 + 5 + 6 + 1 = 13
n= 7 C(7, 0) + C(6, 1) + C(5, 2) + C(4, 3) = 1 + 6 + 10 + 4 = 21
These numbers look like numbers from the Fibonacci sequence, so let us conjecture, as
holds up to n = 7, that L}~~2J C(n - i, i) = In, where In is the nth term in the
Fibonacci sequence defined in Section 5.1. Since we have already established the base
case, we only need to show that our sequence satisfies the same recursive property that
the Fibonacci sequence satisfies, namely that the nth term plus the (n+ l)th term equals
the (n + 2)th term. In our case that means showing that
In/2J l(n+l)/2J l(n+2)/2J
L C(n-i,i)+ L C(n+1-j,j)= L C(n+2-k,k).
;=0 j=O k=O
Assume first that n is even. Then the left-hand side of this equation equals
C(n, 0) + C(n - 1,1) + ... + C((n/2) + 1, (n/2) - 1) + C(n/2, n/2)
+ C(n + 1,0) + C(n, 1) + C(n - 1,2) + ... + C((n/2) + 1, n/2),
which by Pascal's identity applied to the terms written together vertically equals
1 + C(n + 1,1) + C(n, 2) + C(n -1,3) + ... + C((n/2) + 2,n/2) + 1.
On the other hand, the right-hand side is the same, since its first and last terms are also
both equal to 1. A similar messy calculation applies when n is odd.
96 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

SECTION 7.2 Modeling Combinatorial Problems with Recurrence


Relations
1. (a) The recurrence relation is A n+1 = 1.05A n , since 5% of the previous balance (the
interest) is added to the account. The initial condition is Ao = 1200, representing the
initial deposit.
(b) We have Al = 1.05·1200 = 1260, A2 = 1.05·1260 = 1323, A3 = 1.05·1323 = 1389.15,
and A4 = 1.05 ·1389.15 ~ 1458.61. Therefore after 4 years the balance will be $1458.61.

3. p(6) = C(5, 0)p(5) + C(5, l)p( 4) + C(5, 2)p(3) + C(5, 3)p(2) + C(5, 4)p(l) + C(5, 5)p(0) =
1·52 + 5·15 + 10·5 + 10 ·2+ 5 . 1 + 1·1 = 203

5. The partitions of 8 into parts no larger than 3 are 3 + 3 + 2, 3 + 3 + 1 + 1, 3 + 2 + 2 + 1,


3+2+1+1+1,3+1+1+1+1+1,2+2+2+2,2+2+2+1+1,2+2+1+1+1+1,
2 + 1 + 1 + 1 + 1 + 1 + 1 , and 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1. Thus P3(8) = 10. Working with
the recurrence relation, we have P3(8) = P2(8) + P3(5) = PI (8) + P2(6) + P2(5) + P3(2) =
1+PI(6)+P2(4)+PI(5)+P2(3)+P2(2) = 1+1+PI(4)+P2(2)+1+PI(3)+P2(1)+P2(2) =
1+1+1+2+1+1+1+2=10.

7. In each case we apply the recurrence relation T(n) = T(ln/2J) + T(fn/21) + n, with
T(l)=O.
(a) T(8) = 2T(4) +8 = 2(2T(2)+4)+8 = 2(2(2T(I)+2)+4)+8 = 2(2.2+4)+8 = 24
(b) T(9) = T(4) + T(5) + 9 = 2T(2) + 4 + T(2) + T(3) + 5 + 9 = 3T(2) + T(3) + 18 =
3T(2) + T(l) + T(2) + 3 + 18 = 4T(2) + 21 = 4(2T(1) + 2) + 21 = 29
(c) T(20) = 2T(1O)+20 = 2·34+20 = 88 (using the value of T(10) found in Example 11)
(d) T(50) = 2T(25) + 50 = 2(T(12) + T(13) + 25) + 50 = 2T(12) + 2T(13) + 100 =
2(2T(6) + 12)+2(T(6)+T(7) + 13)+ 100 = 6T(6) +2T(7) + 150 = 6(2T(3) +6) +2(T(3) +
T(4) + 7) + 150 = 14T(3) + 2T(4) + 200 = 14(T(1) + T(2) + 3) + 2(2T(2) + 4) + 200 =
18T(2) + 250 = 18(2T(I) + 2) + 250 = 286

9. An = A n - I + 2000 + 0.05A n _ 1 = 2000 + 1.05An _ 1 , with Ao = 0

11. The sequence can start with aI, after which any string of length n - 1 without three
consecutive O's gives a string of length n without three consecutive O's. This contributes
an-I to the sum. Similarly, the sequence can start Oland be followed by a string of length
n - 2 without three consecutive O's, or it can start 001 and be followed by a string of
length n - 3 without three consecutive O's. These are all the possibilities. Therefore
the recurrence relation is an = an-I + an-2 + an-3. The initial conditions are ao = 1
(the empty string), al = 2 (both strings of length 1), and a2 =
4 (all four strings of
length 2).
Section 7.2 Modeling Combinatorial Problems with Recurrence Relations 97

13. The sequence can start with a b or a c, after which any string of length n -1 without two
consecutive a's gives a string of length n without two consecutive a's. This contributes
2an - l to the sum. Similarly, the sequence can start ab or ac and be followed by a string
of length n - 2 without two consecutive a's, contributing 2a n -2 to the sum. These are
all the possibilities. Therefore the recurrence relation is an = 2a n - l + 2an -2· The initial
conditions are ao = 1 (the empty string), and al = 3 (all three strings of length 1).

15. (a) There is one way for the child to walk 0 inches (take no steps), and there is one way
for the child to walk 10 inches (take one little step), so we have ao = al = 1. In order to
cover IOn inches, the child can either take a little step and then walk 10( n - 1) inches
(and this can be done in an-l ways), or take a big step and then walk lO(n - 2) inches
(and this can be done in a n -2 ways). Therefore an = an-l + a n -2 for all n 2: 2. Note
that this is the same recurrence relation and initial conditions that defined the Fibonacci
sequence, so we conclude that an = In for all n.
(b) Since 10 feet is 120 = 10 ·12 inches, we seek a12' Iterating the recurrence relation,
we easily compute that a12 = 233.

17. (a) Reasoning as we did above Example 8, we have


M
q( n) = I: C( n - 1, k )q( n - k - 1) ,
k=O
where M is the smaller of n - 1 and 3, since at most three other elements can be in the
same set of the partition as n. The initial condition is q(O) = 1 (the empty partition).
(b) Clearly q( n) = p( n) for n ::; 4. There is only one nonallowed partition of a five-
element set (the one with only one class), so q(5) = p(5) - 1 = 51. Finally we use the re-
currence relation to compute q(6) = C(5, 0)q(5) +C(5, l)q( 4)+C(5, 2)q(3)+C(5, 3)q(2) =
1 ·51 + 5 . 15 + 10 ·5 + 10 . 2 = 196.

19. We know that p(n) = E;;;;~ C(n - 1, k)p(n - k - 1). Replace the dummy variable k by
= =
n - k - 1. The new range is then from k n - 0 - 1 n - 1 to n - (n - 1) - 1 0, which =
is the same as before, and C(n-l, n- k-l) = C(n-l, n -1- (n- k -1» = C(n-l, k).

21. Note that we need 0 ::; k ::; n in order for L(n, k) to have a nonzero value. The initial
conditions are L(O,O) = 1 (the empty string) and L(n,O) = L(n,n) = 1 (the string of
all l's and the string of all O's). To form a string of length n with exactly k O's, either
we need to take a .string of length n - 1 with k O's and append a 1 (and there are
L( n - 1, k) of these), or else we need to take a string of length n - 1 with k - 1 0 's
and append a 0 (and there are L(n - 1, k - 1) of these). Thus for all n 2: 1 we have
L(n, k) = L(n - 1, k) + L(n - 1, k - 1) as long as 1 ::; k ::; n - 1. These are exactly the
same conditions satisfied by C(n, k); see Pascal's triangle. Thus L(n, k) = C(n, k).
98 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

23. (a) We see that a1 = 1 (since 1 = 1 is the only partition), and a2 = 2 (since 2 = 2 = 1+1
are the only partitions). For n ~ 3 we see that an = a n -1 + a n -2, because an ordered
partition of n into l's and 2's can either begin with a 1 and be followed by an ordered
partition of n - 1, or begin with a 2 and be followed by an ordered partition of n - 2.
Note that {an} is the Fibonacci sequence.
(b) as = /5 = 8

25. (a) There is clearly only one way to get to any lattice point on the coordinate axes,
so T(a,O) =
T(O,b) =1 for all natural numbers a and b. To get to any other lattice
point (a, b), we can either travel along a path from the origin to (a - 1, b) (and there are
T(a -l,b) such paths) and then move to the right, or else travel along a path from the
origin to (a, b - 1) (and there are T(a, b - 1) such paths) and then move up. Therefore
T(a, b) = T(a - 1, b) + T(a, b - 1).
(b) To reach (a,b) we need a sequence of a moves to the right and b moves up, i.e., a
string of length a + b consisting of a R's and b U's. There are clearly C( a + b, a) such
strings. Thus T(a, b) = C(a + b, a). Note that the recurrence relation in part (a) is really
Pascal's identity.

27. (a) T(4) = 7T(2)+4.5·4 2 = 7·12+72 = 156; T(8) = 7T(4)+4.5·8 2 = 7·156+288 = 1380
(b) We see from the following table that the reorganized calculation first becomes more
efficient for n = 128.
k n = 2k T(n) = 8T(n/2) + n2 T(n) = 7T(n/2) + 4.5n 2
0 1 1 1
1 2 12 12
2 4 112 156
3 8 960 1380
4 16 7936 10,812
5 32 64,512 80,292
6 64 520,192 580,476
7 128 4,177,920 4,137,060

29. (a) For the initial condition we have T(l) = 1, since one comparison is needed to see if
the element in the list is the one we are looking for. For the recurrence, note that with
one comparison the list is cut nearly in half, so T( n) = 1 + T(fn/21).
(b) T(20) = 1 + T(10) = 1 + 1 + T(5) = 1 + 1 + 1 + T(3) = 1 + 1 + 1 + 1 + T(2) =
1 + 1 + 1 + 1 + 1 + T(l) = 1 + 1 + 1 + 1 + 1 + 1 = 6 (this agrees with the formula
TB (n) = Llog( n - l)J + 2 presented in Section 4.3, since Llog( n - l)J + 2 = 4 + 2 = 6)
Section 7.2 Modeling Combinatorial Problems with Recurrence Relations 99

31. (a) If the bit string of length n ~ 3 starts with a 0, then in order not to contain 101
it must continue as a string of length n - 1 with no 101 as a substring; and there are
an-l such strings. Otherwise the string starts with k 1's, for some k ~ 1, followed by
00, unless it ends before the 00 appears. The remaining n - k - 2 bits must form a bit
string without the substring 101. For each k from 1 to n - 2, then, there are a n -k-2
such strings. Finally, the string can be 11 ... 110 or 11 ... 111. Putting this all together,
we have
= an-l + a n -3 + a -4 + a -5 +: .. + al + ao + 2.
an n n

The initial conditions are ao = 1, al = 2, and a2 = 4, since no short strings can possibly
contain 101.
(b) We apply the recurrence to obtain a3 = a2 + ao + 2 = 7, a4 = a3 + al + ao + 2 = 12,
a5 = a4 + a2 + al + ao + 2 = 21, a6 = a5 + a3 + a2 + al + ao + 2 = 37, a7 =
a6 + a4 + a3 + a2 + al + ao + 2 = 65, as = a7 + a5 + a4 + a3 + a2 + al + ao + 2 = 114,
a9 = as + a6 + a5 + a4 + a3 + a2 + al + ao + 2 = 200, and alO = a9 + a7 + a6 + a5 + a4 +
a3 + a2 + al + ao + 2 = 351.
(c) If we subtract from the recurrence relation displayed above the same recurrence
relation with n - 1 in place of n:
an = an-l + a n -3 + a n -4 + a n -5 + ... + al + ao + 2
-(an-l = a n -2 + a n -4 + a n -5 + a n -6 + ... + al + ao + 2),
then most of the terms cancel and we obtain an - an-l = an-l - a n -2 + a n -3 for all
n ~ 4. This simplifies to an = 2a n - l - a n -2 + a n -3, with the initial conditions ao = 1,
al = 2, a2 = 4, and a3 = 7 (actually the recurrence relation holds for n = 3 as well).

33. (a) Let Xo be a fixed element of the k-set A. There are n ways to choose the image Yo
of Xo under a surjective function from A to the n -set B. In order for this function to be
surjective, we need to have either that it is still surjective when restricted to A - {xo} (and
there are I(k - 1, n) ways in which this can happen), or that it is surjective to B - {Yo}
when so restricted (and there are I(k - 1, n - 1) ways in which this can happen). The
recurrence relation follows.
(b) I(k, 1) =1 and I(k,k) = n!
(c) Working from the bottom up, we find the following values:

1(3,2) = 2(1(2,2) + 1(2, 1)) = 2(2 + 1) = 6;


1(4,2) = 2(1(3,2) + 1(3, 1)) = 2(6 + 1) = 14;
I( 4,3) = 3(1(3,3) + 1(3,2)) = 3(6 + 6) = 36;
1(5,3) = 3(1(4,3) + 1(4,2)) = 3(36 + 14) = 150;
1(5,4) = 4(1(4,4) + 1(4,3)) = 4(24 + 36) = 240;
1(6,4) = 4(1(5,4) + 1(5,3)) = 4(240 + 150) = 1560
100 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

35. (a) The paths to (3,3) that do not cross the diagonal are RRRUUU, RRURUU,
RRUURU, RURRUU, and RURURU, where R stands for a move to the right and
U stands for a move up.
(b) If b > a, then the point is above the diagonal, so there is no way to get there:
T'(a,b) = =
0 in this case. If b 0, then the point is on the x-axis, and the only way
to get there is by moving right a times, so T'( a, 0) = 1 for all a. These are the initial
conditions. The recurrence relation is the same as the one found in Exercise 25 (and for
the same reason): T'(a, b) = T'(a - 1, b) + T'(a, b -1) in all other cases (i.e., 0 < b:S a).
(c) We construct the following picture from the lower left (representing the number of
ways to get to (0,0», working toward the upper right (representing the number of ways
to get to (0,0», by using the recurrence relation and boundary (initial) conditions.
0 0 0 0 0 42
0 0 0 0 14 42
0 0 0 5 14 28
0 0 2 5 9 14
0 1 2 3 4 5
1 1 1 1 1 1
Thus we see that T'(5,5) = 42.

37. (a) The partitions of 7 into at most three parts are 7, 6 + 1, 5 + 2, 5 + 1 + 1, 4 + 3,


4 + 2 + 1, 3 + 3 + 1, and 3 + 2 + 2, a total of 8. The partitions of 7 into parts no larger
than 3 are 3 + 3 + 1, 3 + 2 + 2, 3 + 2 + 1 + 1, 3 + 1 + 1 + 1 + 1, 2 + 2 + 2 + 1, 2 + 2 + 1 + 1 + 1 ,
2 + 1 + 1 + 1 + 1 + 1, and 1 + 1 + 1 + 1 + 1 + 1 + 1, again a total of 8.
(b) To each Ferrers diagram representing a partition of k into at most m parts (i.e.,
k dots in at most m rows), there corresponds the Ferrers diagram representing a partition
of k into parts no bigger than m (i.e., k dots in at most m columns), and vice versa:
namely the one obtained by flipping the diagram around the line through the upper
left corner having slope -1. It is clear that the flip of a Ferrers diagram is again a
Ferrers diagram, and since flipping twice restores the original diagram, this is a one-to-
one correspondence.
Section 7.3 Solving Recurrence Relations 101

SECTION 7.3 Solving Recurrence Relations


1. (a) Plugging an = 3 into the right-hand side, we have
n- 1 2n - 4 n- 1 2n - 4
- - ·an-l +---·a n -2 = - - ·3+ - - · 3
n n n n
3n - 3 + 6n - 12 9n - 15
n n
Since this does not equal an , we know that the constant function an = 3 is not a solution.
(b) Plugging in an = 2n , we have
n- 1 2n - 4 n - 1 n-l 2n - 4 n-2
- - ·an-l
n
+ -n- ·a n -2 = --·2
n
+ -- n
·2
n2 n - 1 _ 2n - 1 + 2n . 2n - 2 - 4 ·2 n - 2

n
n2 n _3.2 n - 1 3·2_ n- 1
=2n _ _ _
n n
Since this does not equal an , we know that the function an = 2n is not a solution.
(c) Plugging in an = 0, we have
n- 1 2n - 4 n- 1 2n - 4
- - ·an-l + - - · a n -2 = - - ·0+ - - ·0= 0 =a n ·
n n n n
Therefore the function an = 0 is a solution.
(d) Plugging in an = 2n In, we have
n- 1 2n - 4 n - 1 2n - 1 2n - 4 2n - 2
- - ·a n - l
n
+ -n- ·a n -2 = -_.
n
--+
n-l
--_.--
n n-2
2 -
n 1 n
2. 2 - 2 2 n
= --+ = - = an·
n n n
Therefore this function is a solution.
(e) Plugging in an = 7 . 2n In, we have
n- 1 2n - 4 n- 1 2n - 1 2n - 4 2n - 2 2n
- - . an-l + - - . a n -2 = - - ·7· - - + - - ·7· - - = 7· - = an .
n n n n-l n n-2 n
Therefore this is a solution; note that it is a linear multiple of the solution checked in
part (d).
102 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

7. (a) We take the general solution an = A( -2t + B . 3 n obtained in Exercise 6a and

plug in ao = 2 and al = -1 to obtain the equations A + B = 2 and -2A + 3B = -l.


The solution to these equations is A = 7/5, B = 3/5. Therefore the solution is an =
(7/5) . (_2)n + (3/5) . 3n . As a check, a2 = 11, whether computed from the recurrence
or computed from this formula.
(b) We take the general solution an = A( _2)n + Bn . (_2)n obtained in Exercise 6b
and plug in ao = 2 and al = -1 to obtain the equations A = 2 and -2A - 2B = -l.
The solution to these equations is A = 2, B = -3/2. Therefore the solution is an =
2( _2)n - (3/2)n . (_2)n. As a check, a2 = -4, whether computed from the recurrence
or computed from this formula.
(c) We take the general solution an = A + B . 2n obtained in Exercise 6c and plug in
ao = 2 and al = -1 to obtain the equations A + B = 2 and A + 2B = :.....1. The solution
to these equations is A = 5, B = -3. Therefore the solution is an = 5 - 3 . 2n .
(d) We take the general solution an = A + Bn obtained in Exercise 6d and plug in ao = 2
and al = -1 to obtain the equations A = 2 and A + B = -1. The solution to these
equations is A = 2, B = -3. Therefore the solution is an = 2 - 3n.

9. (a) We plug an = 1/(1 + Cn) and an-l = 1/(1 + C(n - 1» into the right-hand side to
obtain
(1 - n)an-l _ (1 - n)/(1 + C(n - 1) _ 1- n
an-l-n - [1/(I+C(n-l»]-n -1-n(1+C(n-l»
I-n 1
=
I-n+Cn(l-n)
= I+Cn
= an,

which is the left-hand side.


(b) We set 1/(1 + C ·1) = 3 and solve to obtain C = -2/3. Thus the specific solution
is an = =
1/(1 - (2/3)n) 3/(3 - 2n).
(c) From the recurrence relation we compute a2 =
(1 - 2) ·3/(3 - 2) = -3, then
a3 = (1- 3)(-3)/«-3) - 3) = -1, and finally a4 = (1- 4)(-1)/«-1) - 4) = -3/5. In
each case this is the same as 3/(3 - 2n).
(d) One solution is an = 1, which corresponds to letting C = o. Our verification in
part (a) is valid for C = 0 (in fact it is valid for any C other than the reciprocal of a
negative inte.e:er). If we reallv want a solution that. is not. in t.his form fm :mv rIO.,,1 r.
Section 7.3 Solving Recurrence Relations 103

= =
13. (a) The recurrence relation is An 2000+1.05A n , with initial condition AD O. By the
iterative method (or applying the formula we obtained in this section, with i = 1.05 and
d = 2000), we see that An = 2000[(1.05 n - 1)/(1.05 - 1)] + 1.05 n AD = 40000(1.05 n - 1).
Recall that we had An = 42000(1.05 n -1) when investments were made at the beginning
of the year.
(b) We see from the two formulas that the ratio of money in the two accounts is always
40000/42000. In other words, under the original method, the balance is always 5% higher.
After 5 years these balances (to the nearest dollar) are $11,051 and $11,604; after 10
years the balances are $43,157 and $45,315; and after 15 years they are $132,878 and
$139,522.

15. We are told that the complexity function satisfies f( n) =


3f( n/2) + cn for some con-
stant c. We invoke Theorem 1, with a = 3, b = 2, and d = 1 (the hypothesis that f is
E O( n 1og3 ) ~ O(n
1585
increasing is reasonable to assume). Since a > bd , we see that f ).

17. (a) We easily compute that the sequence begins 1, 3, 4, 7, 11, 18, 29, 47, 76, and so
on.

(b) Since the recurrence relation is the same as that for the Fibonacci sequence, the
general solution is the same:

L. = A· (i+2v'5j" + C-2v'5)"

We need to plug in the initial conditions to determine A and B. Note that rather than
starting at L1 = 1, we can take Lo = 2 to simplify the algebra (since L2 = 1 + 2). Then
our initial conditions tell us that
2=A+B

1 A· C+2v'5) + B· C-2v'5)
=
104 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

(d) We expand the binomial terms and simplify.

L, = (1+2VSf + -2VS)' e
= ~(1 + 3V5 + 3V5 + K + 1- 3V5 + 3V5
2 2
- K)
1
= 8(2 + 6 . 5) = 4

19. (a) The characteristic equation of this homogeneous recurrence relation is r2 - r - 3 = 0,


and the quadratic formula tells us that the roots are r = (1 ± v'i3) /2. Therefore the
general solution to the recurrence relation is

an 1
= A . ( +2vT3 ) n + B . (1 -2vT3 ) n

(b) If we plug in the initial conditions, we obtain


3=A+B

1= (1 +;m) +
A. B. e- 2v'I3)
To solve this system, we substitute A = 3 - B (from the first equation) into the second
equation, and find that

B _ 1+ 3v'I3 _ 39 + v'I3
- 2vT3 - 26 '
and so A = (39 - vT3)/26. Thus

an = e9~;U). e\v'I3)" + e9~;U). C- v'I3)"2

21. The characteristic equation is r 4 - 8r 2 - 9 = 0, which factors as (r2 - 9)(r2 + 1) =


(r- 3)(r+3)(r- i)(r+i) = o. Therefore the general solution is an = A ·3 n + B.( _3)n +
C . in + D . (_i)n.
Section 7.3 Solving Recurrence Relations 105

Next we plug in the initial conditions and obtain the following system of linear equations.
1= A + C+ D
1= A +
B + iC - iD
1 = A+2B - C- D
2= A + 3B - iC + iD
Solving this system, we obtain A = B = 1/2, C = D = 1/4. Therefore the specific
solution we seek is
1 .n
an = -1 + -n
1
+ -1 + -1 ( -1.)n
2 2 4 4
(c) For a7 (which we saw above to be 4) we compute
1 7 1 ·7 1 ( .)7 4
a7 = '12 + '2. +:C + 4" -1 = - 1 . 1.
4"1 + 4"1 =4 ,
and similarly for al0 = 5.

25. (a) ao = 1, al = 2, a2 = 23 /1 2 = 8, a3 = 83 /2 2 = 128, a4 = 1283 /8 2 = 32768


(b) Let bn =
log an. Then upon taking logarithms the initial conditions become bo 0 =
and b1 = 1, and the recurrence relation becomes bn =
3b n - 1 - 2b n _ 2 . The general
solution to this is easily found to be bn = A + B . 2n , and then the initial conditions
are easily seen to yield A = -1 and B = 1. Therefore we have bn = 2n - 1. Thus
the solution to the original problem is an = 22 "-1. For n = 4, for example, we have
24 1
a4 = 2 - = 215 = 32768.
27. The recurrence relation we obtained there was an = a n -1 + a n -2 + a n -3. The character-
istic equation for this problem is therefore r3 - r2 - r - 1 = 0, which, by the rational root
test, is seen to have no rational roots. Thus we cannot easily find the roots. In fact, there
is only one real root, approximately 1.84, and two complex roots. In principle we can
write down these roots (they will be messy expressions involving the cube root symbol)
and (after plugging in the initial conditions) write down the specific solution, but the
formula will certainly not be very pretty.

29. The number of bit strings of length n that do not contain two consecutive O's is In+1
(see Example 6 in Section 7.2). Thus the number we seek is 2n - In+!. By Example 5
in the present section, we know a formula for In+!. Thus the solution is

31. Suppose that {an} satisfies the recurrence relation an = C1an-1 + ... + Ckan-k, with
Ck # o. If the characteristic equation has k distinct roots, r1, r2, ... , rk, then an =
106 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

33. (a) The recurrence relation is an = an-l +n 2 , with al = 1. The solution of the associated
homogeneous recurrence relation is an A· 1n = =
A. The particular solution of the given
recurrence relation is of the form an = Bn + Cn 2 + Dn 3 (a polynomial of degree 2,
multiplied by n because of the root r = 1 of the associated homogeneous characteristic
equation). Plugging this into the relation and simplifying, we obtain On 3 + (-3D+ 1)n 2 +
=
(-2C+3D)n+( -B+C- D) O. Equating coefficients and solving, we obtain D 1/3, =
C =
1/2, and B =
1/6. Therefore the general solution to the nonhomogeneous relation
IS

n n2 n3
an = A + "6 + "2 + "3 .
Finally we plug in the initial condition al = 1 and solve to find that A = O. Therefore
the formula we desire is an = (n/6) + (n 2 /2) + (n 3 /3).
(b) It is clear that the two formulas are algebraically equivalent.

35. (a) 1+2+···+n=n(n+l)/2


(b) Using part (a), we see that
n(n + 1) 1 2 1
Pn = Pn - l + 2 = Pn - l +"2 n +"2 n ,
with initial condition Po = O.
(c) The associated homogeneous equation has the solution Pn = A. We seek a particular
solution of the nonhomogeneous equation by trying Pn = Bn+Cn 2 + Dn 3 (a polynomial
of degree 2, multiplied by n because of the root r = 1 of the associated homogeneous
characteristic equation). Plugging this into the relation and simplifying, we obtain

On
3
+ (-3D +~) n + (-2C + 3D +~) n + (-B + C -
2
D) = O.
Equating coefficients and solving, we obtain D = 1/6, C = 1/2, and B = 1/3. Therefore
the general solution to the nonhomogeneous relation is
n n2 n3
Pn = A + "3 + "2 + "6 .
Plugging in the initial condition tells us that A = 0, so (after factoring to improve the
presentation) Pn = n(n + 1 )(n + 2)/6. In particular, Pd = d(d + 1)(d + 2)/6.
(d) Pl2 = 12 ·13 ·14/6 = 364 (almost enough to last the whole year).

37. By Exercise 36 in Section 7.2, the recurrence relation is Rn = Rn-l + n, with Ro = 1.


Section 7.4 The Inclusion-Exclusion Principle 107

39. This problem is the "logarithm" of Exercise 34.


(a) The recurrence relation is an = (a n _la n _2)1/2, with initial conditions ao = x and
al = y. Let bn = log an , and our problem becomes bn = (b n - 1 + bn _ 2) /2, with bo = log x
and b1 = logy.
(b) We solved this problem for bn in Exercise 34, obtaining (translated into this context)
1 2 ( l)n
bn = 3(log x + 2 log y) + 3 (log x -log y) -"2

Thus we have
an = 2b = 2 t (logx+2Iogy)+iClogx-logy)(-!f
n

= xl/3 y 2/3(x2/3 y -2/3)C-l/2)n


(c) As n - 00, (-1/2)n _ 0, so an _ x 1/ 3 y2/3 = \/xy 2.

SECTION 7.4 The Inclusion-Exclusion Principle


1. Let C, R, and A be the sets of students who like to play chess, bridge, and backgammon,
respectively. Then by the inclusion-exclusion principle we have 60 = IC U R U A I =
ICI+IRI+IAI-lcnRI-lcnAI-IRnAI+lcnRnAI = 37+31+19-11-16-5+lcnRnAI.
Thus 60 = 55+ ICnRnAI, so ICnRnAI = 5.

3. Let B, R, and G stand for the sets of competitors who won blue, red, and green ribbons,
respectively. We are told that IBI = = =
13, IRI 25, and IGI 23. We are also told that
=
IB n RI + IB n GI + IR n GI 17 and that IB n R n GI = o. Therefore by the inclusion-
exclusion principle we know that IB U R U GI = =
13 + 25 + 23 - 17 + 0 44 people won
ribbons. Since there are 100 competitors in all, the remaining 56 won no ribbons.

n-l

5. I:C(n,i)(-l)i(n-i)k
;=0

7. The prime numbers less than or equal to 40 are 2, 3, 5, 7,11,13,17,19,23,29,31,


and 37, for a total of 12. For the calculation based on Theorem 3, we note that since
v'4O < 7, we need only consider the primes 2, 3, and 5. Then the number of prime
numbers not exceeding 40 is

+l;~J+l;~J+l:~J-l2.~.5J
= 39 - 19 - 12 - 7 + 6 + 4 + 2 - 1 = 12.
108 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

= =
9. We are told that IGI 12, IFI 9, IRI = = =
12, IFnRI 1, IGnRI 3, and IFnGI 2. =
Therefore IG U FURl =
IGI + IFI + IRI - IF n RI - IG n RI - IF n GI + IF n Gn RI =
12 + 9 + 12 - 1 - 3 - 2 + IF n Gn RI = 27 + IF n Gn RI , which contradicts the fact that
only 26 people were present.

11. There are four sets, A, B, C, and D, each with 250 elements; C( 4,2) = 6 pairs
(such as B and D), each with 20 elements, and C(4,3) = 4 triples (such as A, C,
and D), each with three elements. Thus we have by the inclusion-exclusion principle
IA U B U C U DI = 4·250 - 6·20 + 4·3 - 1 = 891.

13. (a) Let x be the number of artists who use only oil and water color, y the number of
artists who use only oil and acrylic, and z the number of artists who use only acrylic and
water color. The Venn diagram for this problem is as shown here.

= = =
The given information tells us that x + y 7, x + z 9, and y + z 8. We want to find
x + y + z. If we add the three equations just presented, we find that 2(x + y + z) = 24,
so x + y + z = 12.
(b) The sum of all the numbers in the Venn diagram is x + y + z + 23, which by the
answer to part (a) is 12 + 23 = 35.

15. Note that unless otherwise stated, we need not assign a task to every employee.
(a) We model this problem by counting functions from the set of tasks to the set of
employees (the value of the function at a given task is the employee assigned to do that
task). We need to count the number of functions from the set of tasks to the set of
employees, which is 106 = 1,000,000.
(b) This time we need to count the number of surjective functions from the set of tasks to
the set of employees, since each employee must be in the range of the assignment function.
Since there are more employees than tasks, there are no such functions.
(c) This is really the resource allocation problem from Section 6.3; all that matters is
how many of the six tasks get assigned to each employee. Thus we want to count the
Section 7.4 The Inclusion-Exclusion Principle 109

number of solutions to Xl + X2 + ... + XlO = 6, where Xi is the number of tasks assigned


to employee i (each Xi 2: 0). The answer is therefore C( 10 + 6 - 1,6) = C( 15,6) = 5005.
(d) Again this is the resource allocation problem, except that now we want the number
of solutions to Xl + X2 + ... + XIO = 6, where each Xi 2: 1. Obviously if each Xi 2: 1,
then the sum is greater than 6, so there are again no solutions.

17. The formula for the number of derangements is


n!
dn = n! - - + -n! - -n! + ... ± n! n!
=f - .
I! 2! 3! (n-l)! n!
All of the terms on the right-hand side are even except that n!/n! = 1 is odd and
n!J(n -I)! = n is either even or odd, depending on the parity of n. Hence if n is even,
then the sum is odd; and if n is odd, then the sum is even.

19. If n - 1 objects are in their original positions, then there is no place for the other object
to go except its original position.

21. Note that there are 15! orders in which the hats can be returned. Thus these probabilities
will have 15! as their denominators.
(a) By symmetry the answer should be 1/15; he is just as likely to get his own hat back
as any of the 15 hats. More formally, of the 15! ways to return the hats, he can receive
his own hat back in 14! ways (the other 14 hats can be permuted arbitrarily); therefore
the answer is 14!/15! = 1/15.
(b) There are d l4 ways to derange the remaining 14 hats, so the answer is d I4 /15! ~
1/41.
(c) After we have given these two gentlemen their own hats back, there are 13! ways to
permute the remaining hats. Therefore the answer is 13!/15! = 1/(15·14) = 1/210.
(d) After we have given these two gentlemen their own hats back, there are d l3 ways to
derange the remaining hats. Therefore the answer is d I3 /15! ~ 1/571.
(e) There are 5! ways to permute the Zetas' hats and 10! ways to permute the hats of
the other fellows, so the answer is 5!1O!/15! = 1/3003.
(f) This can only happen in one way, so the answer is 1/15! = 1/1,307,674,368,000.
(g) There are 15 ways to choose the lucky man to get his own hat back, and then there
are d l4 ways to derange the remaining hats, so the answer is 15d I4 /15! = d I4 /14! ~ 1/3.
(h) This is clearly d IS /15! ~ 1/3. Note that for all practical purposes, this is the same
probability as in part (g), namely almost exactly l/e ~ 0.3679.
(i) At least one person receives his hat back if it is not the case that no person receives
his hat back. Therefore the answer is 1- (d IS /15!), or about 2 out of 3.
110 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

23. (a) If we want to leave all the odd numbers in their original positions, then we simply
permute the five even numbers. Therefore the answer is 5! = 120.
(b) We must derange the even numbers, so the answer is ds = 44.
(c) There are C(10,5) ways to choose the five numbers to leave fixed, and then there
are d s ways to derange the numbers not chosen. Therefore the answer is C(10,5)ds =
252·44 = 11088.
(d) A permutation fails to meet this condition if it is a derangement (and there are
dlO = 1334961 of these), or if it leaves one number fixed and deranges the rest (and there
=
are 10·dg 1334960 of these). Therefore the answer is 1O!-1334961-1334960 958,879. =

25. There are 300/2 = 150 odd positive integers not exceeding 300. There are L";300J = 17
perfect squares in this range. Furthermore, f17/21 = 9 of these perfect squares are odd.
By the inclusion-exclusion principle there are 150 + 17 - 9 = 158 positive integers in this
range that are either odd or perfect squares. This includes the nine numbers that were
both odd and perfect squares, and we are asked to omit these, so the answer is 149.

27. Let Ai be the set of 7-bit strings that have 00000 starting in position i, for i = 1, 2, 3.
Then we want to compute as follows.
IAI UA 2 UA 31 = 27 -IAII-IA21-IA31 + IAI nA21 + IAI nA31
+ IA2 n A31-IAI n A2 n A31
= 27 _ 3 . 22 +2+ 1+2- 1 = 27 - 8 = 120

29. A number in this range is divisible by some perfect square if and only if it is divisible
by a number from the set {4, 9, 25, 49, 121, 169,289, 361} (we need only worry about
squares of prime numbers). We count (using the inclusion-exclusion principle) in much
the same way that we counted to determine the number of prime numbers (the terms left
out are all 0).

500J l500J l500J l500J l500J


l 4 + 9 + 25 + 49 + 121

500 J l 500 J l500 J l500 J


l 4 . 49 4 . 121 9 ·25 9 . 49
= 125 + 55 + 20 + 10 + 4 + 2 + 1 + 1 - 13 - 5 - 2 - 1 - 2 - 1 = 194
Section 7.5 Generating Functions 111

31. We label the points of the figure as shown in the following diagram.

Let Ai be the set of triangles in this figure that have the point Pi as one of their vertices.
Note that every triangle involves at least one of these five points. Now each IAi I = 15;
for example the triangles involving PI are P I P2a, PIP2e, P I P 2P5 , P I P2b, P I P2P4 ,
PIP2P3 , Plae, P l aP5 , P l bP4 , P I P3 d, P I P3 P5 , P I P3P4 , Pl eP5 , P l dP5 , and P I P4P5 .
Next to compute IAi n Aj I, where i :p j, we note that there are two cases. If Pi and
Pj are adjacent, then (as we see from the list above for the case of PI and P2 ) there
are six triangles in Ai n A j . If Pi and Pj are not adjacent, then (as we see from the
list above for the case of PI and P3 ) there are four triangles in Ai n A j . Finally, we
see that IAi n Ai n Ak I = 1 for all triples of distinct i, j, and k. Now we apply the
inclusion-exclusion principle, noting that there are five Ai'S, five adjacent Ai - Aj pairs,
five nonadjacent Ai-Aj pairs, and 10 triples. Thus the answer is 5·15-5·6-5·4+10.1 =
35. (An alternative approach is to base the count on the number of triangles using each
of the segments PiPi+! and P5 P I . We find 5·6 - 5 = 25 triangles involving one or more
of these segments, together with (by inspection) 10 triangles involving none of them.)

SECTION 7.5 Generating Functions


1. (a) If we expand this binomial, we get 4 + 12x + 9x 2 . Therefore the sequence that this
function represents is 4, 12, 9, or 4, 12, 9, 0, 0, 0, ....
(b) Since 1/(1 + x) = 1 - x + x 2 - x 3 + ... , the sequence is 1, -1, 1, -1, .... Explicitly,
ak = (_I)k.
(c) Since 3/(1- 4x) = 3(1 + 4x + (4x)2 + (4x)3 + ... ), the sequence is 3,3.4,3.4 2 ,
3.43 , ... , i.e., 3, 12, 48, 192, .... Explicitly, ak = 3 ·4k
= =
(d) Since 3/(1- x 4) 3(1 + x4 + (x 4)2 + (x 4)3 + ... ) 3(1 + X4 + x 8 + Xl2 + ... ), the
sequence is 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, .... Explicitly, ak = 3 if k == 0 (mod 4) and
ak = 0 otherwise.
(e) Since 2x/(1 + x 2) = 2x(l- x 2 + x4 - x 6 + ... ) = 2(x - x 3 + x 5 - x 7 + ... ), the
sequence is 0, 2, 0, -2, 0, 2, 0, -2, .... Explicitly, ak =2 if k == 1 (mod 4); ak = -2
if k == 3 (mod 4); and ak = 0 otherwise.
112 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

3. In each case we use Theorem 3.


(a) The general term is C(k + 1,1) = k + 1; thus the sequence begins 1,2,3,4,5, ....
(b) The general term is C(k + 2,2) = (k + 2)(k + 1)/2; thus the sequence begins 1,3,
6, 10, 15, ....
(c) The general term is C(k + 3,3) = (k + 3)(k + 2)(k + 1)/6; thus the sequence begins
1,4, 10, 20, 35, ....
(d) The general term is C(k + 4, 4) = (k + 4)(k + 3)(k + 2)(k + 1)/24; thus the sequence
begins 1, 5, 15, 35, 70, ....

5. (a) We found that the generating function is 1 + 2x + 3x 2 + 3x 3 + 3x 4 + 3x + 2x + x •


5 6 7

Since the coefficient of x4 in this expression is 3, there are three ways to choose four
balls.
(b) We found that the generating function is x + x 2 + 2x 3 + x4 + 2x 5 + x 6 + X . Since
7

the coefficient of x4 in this expression is 1, there is one way to choose four balls.

7. (a) This sequence is just 2 times the sequence 1, -1,1, -1, .... Therefore its generating
function is /(x) = 2/(1 + x).
(b) This sequence is 4 times the sequence 1,2,4,8, .... Therefore by Theorem 1 with
=
a 2 its generating function is /(x) =
4/(1- 2x).
(c) This sequence is just 2 times the sequence 1, 2, 3, 4, .... Therefore by Theorem 3
with r = =
1 its generating function is /(x) 2/(1- x)2.
(d) This sequence is the same as 1,1,1,1, ... , shifted over three places. Therefore its
generating function is /( x) = x 3 / (1 - x) .
(e) Since /(x) = 1/(1 + x 2 ) is the generating function for 1,0, -1, 0, 1, 0, -1, ... , the
answer is /(x) = x/(1 + x 2).
(f) Note that

2 + 3x + 4x 2 + ... = -1( 1 + 2x + 3x 2 + 4x 3 + ... - 1)


x

=;;
1(1(l-x)2 -1
)= 1-(I-x)2
x(l-x)2

1 - 1 + 2x - x 2 2- x
x(l-x)2 - (l-x)2·
Therefore the generating function is /(x) = (2 - x)/(I- x)2.
(g) Using our result in part (c),

1 + 3x + 5x 2 + 7 x 3 + ...
= (2 + 4x + 6x 2 + 8x 3 + ... ) - (1 + x + x 2 + x 3 + ...)
2 1 1+x
(l-x)2
--- I-x (l-x)2·
Section 7.5 Generating Functions 113

Therefore the generating function is f(x) = (1 + x)/(l- x)2.


(h) Here we use the results from parts (c) and (g):

2 + x + 4x 2 + 3x3 + 6x 4 + 5x 5 + ...
= (2 + 4x 2 + 6x 4 + ... ) + x(l + 3x 2 + 5x 4 + ... )
2 x(l+x) x 2 +x+2
(1 - x )2 + (1 - x )2 = (1 - x 2)2 .
2 2

Therefore the generating function is f(x) = (x 2 + X + 2)/(1- x 2 )2.

9. Thinking of the sequence split in this way, we see that the generating function is

f(x) = 1~X-x2(1~X3).
We find a common denominator by recalling that 1 - x 3 = (1 - x )(1 + x + x 2 ), and after
a little algebra this function simplifies to f(x) = (1 + x)/(l- x 3 ).

11. (a) Here the coefficient of x lc represents the number of ways to achieve k cents. For the
3-cent stamps the generating function is 1 + x 3 + x 6 + x 9 + ... = 1/(1- x 3 ). Similarly the
generating function for choosing just the 4-cent stamps is 1/(1 - x4), and analogously
for the 5-cent stamps. Therefore the generating function is

f(x) = (1 + x 3 + x 6 + ... )(1 + x4 + x 8 + ... )(1 + x 5 + x


10 + ... )

1
- (1- x 3 )(1- x 4 )(1- x 5 ) •

To write this out explicitly we multiply out the left-hand side of the displayed equation,
obtaining f(x) = 1 + x 3 + x4 + x 5 + x 7 + 2x 8 + 2x 9 + 2X10 + ....
(b) Since the coefficient of x 10 in this expression is 2, there are two ways to achieve 10
cents (in fact, we can use two 5-cent stamps or two 3-cent stamps and a 4-cent stamp).

13. This question asks for the number of partitions of 6 under various restrictions. It is
probably easier to count the partitions than to work with the algebra. We can write 6
as 6,5+1,4+2,4+1+1,3+3,3+2+1,3+1+1+1,2+2+2,2+2+1+1,
2 + 1 + 1 + 1 + 1, and 1 + 1 + 1 + 1 + 1 + 1.
(a) The list above has 11 partitions, so the answer is 11.
(b) Four of the partitions listed above use only odd parts (1, 3, and 5), so the answer
is 4.
(c) Four of the partitions listed above use parts of unequal size (the first three and the
sixth one), so the answer is 4.
(d) All but the first two partitions shown above satisfy this condition, so the answer is
11-2=9.
114 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

15. (a) We want the coefficient of x 30 in (1 +x +x 2 + x 3 + .. -)4 = 1/(1- X)4. By Theorem 3,


this is C(30 + 3,3) = C(33, 3) = 5456.
(b) We want the coefficient of x 30 in the generating function

(1 + x + x 2 + x 3 + ... + x 9 )4
=(I_xlO)4
I-x
1 - 4XlO + 6x 20 _ 4 X30 + x 40
(1 - X)4
1 1
-,---:--:- - 4xlO + 6x 20 1 1 1
_ 4 x 30 + x40 -:-:-_--,-,.
(l-x)4 (l-x)4 (l-x)4 (l-x)4 (l-x)4
30
Now an x term arises from each of the first four terms in the last line. The coefficient of
x 30 in 1/(1- x)4 is 5456, a.., we found in part (a). The coefficient of x 30 in 4xlO /(1- x)4
is 4 times the coefficient of x 20 in 1/(1- x)4 , namely 4C(20 + 3,3). A similar analysis is
applied to the next two terms. The desired coefficient is therefore C(30 + 3, 3) - 4C(20 +
3,3) + 6C(10 + 3,3) - 4C(0 + 3, 3) = 5456 - 7084 + 1716 - 4 = 84.
( c) We want the coefficient of x 30 in
2 3 4 x4
(x + X + X + ... ) = (1 _ X)4 '

which is the coefficient of x 26 in 1/(1- x)4, namely C(26 + 3,3) = 3654.


(d) We want the coefficient of x 30 in

(x + x 2 + x 3 + ... + X9 )4 = X4 1 x9 )
_-_
4 x4 _ 4x 13 + 6x 22 _ 4X 31 + x40
( I- x (1 - x)4
which is C(26 + 3,3) - 4C(17 + 3, 3) + 6C(8 + 3,3) = 3654 - 4560 + 990 = 84.

17. For each die the generating function for the number of spots showing is x + x 2 + x 3 +
X4 + x 5 + x 6 • Therefore the generating function for the total number of spots showing on
n dice is

19. In each case we let f(x) = L~=o akxk be the generating function for the given sequence.
Then
00 00 00 00

xf(x) = L akxk+ = L ak_l xk


1
and x 2f(x) = L ak xk +2 = L ak_2 xk .
k=O k=l k=O k=2
(a) First we note that 1/(1- 4x) = L~=o 4kxk. Then in order to take advantage of the
Section 7.5 Generating Functions 115

recurrence relation, we look at


1
f(x) - 5xf(x) + 6x 2f(x) - --
I - 4x
00 00 00 00

=L ak xk - 5 L ak_l xk +6L ak_2 xk - L 4kxk


k=O k=l k=2 k=O
00

= L(ak - 5 a k_l + 6ak-2 - 4k)xk + ao + alx - 5aox - 1 - 4x


k=2
= 1 + 2x - 5x - 1 - 4x = - 7x .
We then solve algebraically for f(x) and try to decompose it into partial fractions (noting
that 1 - 5x + 6x 2 factors into (1 - 2x)(1 - 3x)).
2
f(x) = -7x + [1/(1 - 4x)] = -7x + 28x + 1
(1- 2x)(1 - 3x) (1- 2x)(1 - 3x)(I- 4x)
ABC
= 1- 2x + 1 - 3x + 1 - 4x .
To find A, B, and C, we multiply through by the common denominator and collect
terms, obtaining
2
28x - 7x + 1 = (12A + 8B + 6C)x2 + (-7 A - 6B - 5C)x + (A + B + C) .
Now we equate like coefficients and obtain three linear equations, which are solved to
yield A = 9, B = -16, and C = 8. Therefore
9 16 8
f(x) = 1 _ 2x - 1 - 3x + 1- 4x .
Since we know the sequences generated by these three functions, we immediately write
down the answer: ak = 9 . 2k - 16· 3k + 8 . 4k .

(b) Working as in part (a), we have


00 00 00
2
f(x) - xf(x) - x f(x) =L ak xk - L ak_l xk - L ak_2 xk
k=O k=l k=2
00
k
= L(ak - ak-l - ak_2)x + ao + alx'- aox
k=2
= l+x-x= 1.
We then solve algebraically for f( x) and, in preparation for the partial fraction decom-
position, factor the denominator (which, unfortunately, has irrational roots):
1 1 A B
f(x)- - ---+--
- 1 - x - x 2 - (l-ax)(l-,Bx) -I-ax l-,Bx'
116 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

where by the quadratic formula


1 1+/5 1 1-/5
a -2 and 73 -2
Clearing fractions and equating powers of x leads to the equations A + B = 1 and
(3A + aB = 0, whence A = a/( a - (3) and B = (3/({3 - a). (We will use shortly the fact
that (3 - a = /5, which follows from the definitions of a and (3.) Thus we have

f(x) = _a_(1 + ax + a 2x 2 + ... ) + _{3_(1 + {3x + (32x 2 + ... )


a-{3 {3-a
and so

ak 1 ak+ 1 + __
= __ 1 {3k+1
a-{3 {3-a

1 ( -2 )k+1 1 ( -2 )k+1
=-/5 1+/5 +/5 1-/5

= __1 1-/5 k+1 _1 ( 1+/5 )k+1


/5 ( 2 ) +/5 2
Note that this agrees with the formula for the Fibonacci sequence that we obtained in
Section 7.3.

21. The basic technique is the same as in Exercises 18 and 19; we let f(x) = I:~o akxk.

(a) First we see that


00 00

f(x) + 4x 2 f(x) = L ak xk +4L a k_2 xk


k=O k=2
00

= L(ak + 4ak_2)Xk + ao + alx


k=2
= 1 +2x.
Therefore
1 + 2x 1 + 2x
f(x) = 1+4x2 = 1+(2x)2
= (1 + 2x)(I- 22x 2 + 24X4 _ 26 X6 + ... )
= (1 - 22x 2 + 24x4 - ... ) + (2x - 23 x 3 + 2s x s - ... ).
Thus if k is even, then ak = (_I)k/2 .2 k , whereas if k is odd, then ak = (_I)(k-I)/2 ·2k.
We can express this in one formula by ak = (_I)lk/2J . 2k .
Section 7.5 Generating Functions 117

(b) Just as in part (a),


00 00

f(x) + x 4 f(x) = I>kXk + I>k_4Xk


k=O k=4
00

= L)ak + ak_4)x k + ao + a1x + a2x2 + a3 x3


k=4
= 1 + 2x + 3x 2 + x 3 .
Therefore

f(x) = 1+2x+3x 2 +x3


1 + x4
= (1 + 2x + 3x 2 + x 3 )(1 _ X4 + x8 _ x 12 + ... ).
From this we read off the answers. If k == 0 (mod 4), then ak = (_l)k/\ if k == 1
(mod 4), then ak = 2( _1)(k-1)/\ if k == 2 (mod 4), then ak = 3( _1)(k-2)/4; and if
k == 3 (mod 4), then ak = (_1)(k-3)/4.

23. In Exercise 12 we found that the generating function for the number of partitions of k
into parts of unequal size is n:1
(1 +xi ), and that the generating function for the number
of partitions of k into odd parts is n~l [1/(1 - x 2i -1)]. Thus we must show that

( 1 + x)(l +x
2
)(1 +x
3
) ... = 1-1 x 1
. 1 _ x3 . 1 _ x 5
1
....

We can write the right-hand side as


1 1 - x2 1 1
1 - x . 1 - x 2 . 1 - x 3 . 1 - X4 . 1 - x 5 . 1 - x 6 ...
which factors as
1 (l-x)(l+x) 1 1

25. The number of ways to get a sum of k rolling a die t times is the coefficient of xk in
(x + x 2 + x 3 + X4 + x 5 + X6)t. Thus for the generating function we need to sum over all
t from 0 to 00, which yields the given formula.

27. We will use the result of Exercise 26 after we first obtain a generating function for ak = k2 .
We have
1 00
_ - "xk
1-x-L.." .
k=O
118 Chapter 7 ADDITIONAL TOPICS IN COMBINATORICS

Differentiating both sides, we obtain

1 ~ k-l
(l_x)2=L kx ,
k=O
so
00

x = '""
L kx k .
( 1- x)2
k=O
Differentiating again, we have

(1-x)2+2x(1-x) = ~k2 k-l


(1-x)4 L x
k=O
1 + x _ ~ k 2 k-l
(1- x)3 - L X ,
k=O
so
:1 00
X +X k2 k
_ '""
(1- x)3 - L X .
k=O
Thus by Exercise 26, the generating function for 12 + 22 + ... + k 2 is

2 ~
2
x+x ) k
(1-x)4 = (x+x )~C(k+3,3 x .

Therefore ak = C(k + 2,3) + C(k + 1,3), which can be written explicitly as ak


k(k + 1)(2k + 1)/6.

29. In each case we want a30 for the generating function that models the problem.
(a) The generating function is

(1 + x 2 + x 4 + .. ·)(1 + x + x 2 + ...)2 = 1 _1 x2 1
. (1 _ x)2 .

We can factor the denominator on the right-hand side and find a partial fraction decom-
position:
1 1 ABC D
-_.
1 + x (1- x)3
=--+--+
1+ x 1- x (1 - x)2
+ (1 - x)3 .
This leads to A + B + C + D = 1, -3A - B + D = 0, 3A - B - C = 0, and - A + B = 0,
whence A = B = 1/8, C = 1/4, and D = 1/2. Thus the generating function is
00 00 00 00
1 1 1 1
I(x) = 8 L(-l)kxk + 8 Lxk + 4 L(k+ l)xk + 2 LC(k+ 2,2)xk.
k=O k=O k=O k=O
Therefore
1 1 1 1 32· 31
a30 = 8 + 8 + 4 . 31 + 2 . - 2 - = 256.
(b) We can use the result of part (a) directly to solve this problem. If there must be an
Section 7.5 Generating Functions 119

odd number of white balls, we can select one white ball and then find the number of ways
to choose 29 balls such that there are an even number of white balls. This was exactly
the problem solved in part (a), except for the meaningless change of color and the fact
that we want a29 instead of a30. Thus the answer is

a29 = --81 + -81 + -41 ·30 + -21 . -


31·30
2
- = 240.
(c) This is similar to part (a), but the generating function is
2
(1 + x + x4 + .. ·)(x + x 3 + x 5 .+ ... )(1 + x + x 2 + ... ).
We write this in closed form, factor the denominator, and look for a partial fraction
decomposition.
x 1 x
(1-x2)2 I-x (1-x)3(1+x)2
ABC D E
=--+
I-x (l-x)2
+ (l-xP +--+l+x (l+x)2
.
This leads to A + B + C + D + E = 1, B + 2C - 2D - 3E = 1, - 2A - B + C + 3E = 0,
-B + 2D - E = 0, and A - D = 0, whence A = -1/16, B = 0, C = 1/4, D = -1/16
and E = -1/8. Thus the generating function is
00 00 00 00
1 1 1
f(x) = -16 L xk + 4L C(k + 2, 2)xk - 16 L( _l)kxk - 81 L( -l)k(k + l)xk .
k=O k=O k=O k=O
Therefore

a30 = - -161 + -41 ·496 - 1 1


- - - ·31
16 8
= 120.
(d) We use the inclusion-exclusion principle applied to the results of the first three part
to obtain the answer of 256 + 240 - 120 = 376.
120 Chapter 8 GRAPHS

CHAPTER 8
GRAPHS
SECTION 8.1 Basic Definitions in Graph Theory
1. (a) Our picture consists of one point for each vertex, labeled p through t, and a line
segment joining each pair of distinct vertices other than pq and rs. Note that we were
able to draw the picture in such a way that all the lines were straight and no lines crossed,
but this is not required; many other pictures represent the same graph.

p_----.r

s q

(b) The edge set consists of all uv such that u· v is a multiple of 3, where u and v are
distinct natural numbers less than 9. Now u . v is a multiple of 3 if and only if either
u or v is a multiple of 3. Thus the vertices 0, 3, and 6 are joined by an edge to every
other vertex, but no two vertices among {I, 2, 4, 5, 7, 8} are joined by an edge. In our
picture, we have put the former three vertices on the bottom and the latter six on the
top. All the required edges have been drawn.

1 2 4 5 7 8

(c) This is similar to part (b), except that we need to worry about the reduction of each
number modulo 3. Thus 0, 3, and 6 form one class, and there is an edge from each of
these to the others, since the sum of two numbers congruent to 0 modulo 3 is congruent
to 0 modulo 3. This portion of the graph is a K 3 . The vertices 1, 4, and 7 form a
second class (the numbers congruent to 1 modulo 3), and 2, 5, and 8 form a third class
Section 8.1 Basic Definitions in Graph Theory 121

(the numbers congruent to 2 modulo 3). Since the sum of any member of this second
class and any member of this third class (such as 5 + 4) is congruent to 0 modulo 3, we
need to have an edge between them. Note that this portion of the graph is a K 3 ,3. There
are no other edges, since in no other cases do we have the sum congruent to 0 modulo 3.

6~
36147

(d) Our picture consists of four vertices and all the edges joining pairs of them. Note
that it was possible to avoid edges crossing by arranging the vertices as shown; it would
be equally valid to draw [(4 with the four vertices in a square, in which case two of the
edges could cross in the middle of the square.

(e) There is no way to avoid edge crossings in drawing the complete graph on six vertices.
We have just arranged the six vertices more or less in a circle and drawn all C(6,2) = 15
edges joining pairs of vertices.

(f) This complete bipartite graph consists of three vertices in one part, which we have
drawn on top, four vertices in the second part (drawn on the bottom), and all 3 ·4 = 12
edges joining vertices in different parts. There is no way to avoid edges crossings in this
case.
122 Chapter 8 GRAPHS

3. One set of correct labelings is shown below. Both Qo and Q1 are trivial. The empty
string (the only string of length 0) labels the only vertex in Qo, and the two strings of
length 1 label the vertices in Q1 (they differ in exactly one bit, so an edge joins them).
The picture of Q2 has the four bit strings of length 2 as the vertex labels; two vertices
are adjacent if their labels differ in one bit. (This labeling was easy to achieve, since once
we labeled 00, we knew that 01 and 10 had to be its neighbors.) Finally, the labeling of
Q3 can be arrived at as follows. First we label the four vertices at the top with bit strings
of length 3 beginning with a 1; the second and third bits of these labels are chosen so
that adjacent vertices differ in one bit. Then each of the four vertices on the bottom is
labeled with the same label as the vertex at the top to which it is joined by an edge,
except that the first bit is changed to a O.

101 111

10 11 ~ 1107
100
;>.. a 1
• • • 010
00 01

'"
VOOO
001 all

5. (a) Vertex a has two edges outgoing from it (the one to vertex b and the loop), so the
out-degree of vertex a is 2; in symbols, d+( a) = 2. Only the loop is an incoming edge
to a, so the in-degree of a is 1; in symbols, d-(a) =
l. Similarly, d+(b) =
0, d+(c) 1, =
d+(d) =
1, d+(e) =1, d+(f) = 0, d-(b) =
1, d-(c) =
2, d-(d) =
1, d-(e) =
0, and
d-(f) = O.
(b) There are six flights leaving Detroit, so d+( Detroit) = 6. Similarly, d+( Boston) = 3,
d+( Washington) = 3, and d+( Miami) = 4 (one of the edges leaving Miami is the loop).
There are six flights coming into Detroit, so d-(Detroit) = 6. Similarly, d-(Boston) = 3,
d-( Washington) = 3, d-(Miami) = 4.
(c) The vertices in this graph are {I, 2, 3, 4, 5, 6, 7}. There is an edge from x to y
whenever x <, y. Since 1 < y for each of the six numbers from 2 through 7, we know
that the out-degree of 1 is 6; in symbols, d+(I) = 6. Similarly, d+(2) =
5, d+(3) =
4,
d+( 4) =
3, d+(5) = 2, d+(6) = 1, and d+(7) = 0 (none of these numbers is greater
than 7). On the other hand, d-(1) = 0, d-(2) = 1, d-(3) = 2, d-(4) =
3, d-(5) =
4,
d-(6) = 5, and d-(7) = 6.
Section 8.1 Basic Definitions in Graph Theory 123

7. The complement of the complement of G contains all the edges that the complement of
G does not contain. The complement of G does not contain precisely the edges that G
does contain. Therefore the complement of the complement of G contains exactly the
same edges as G does, so G = G.

9. We put the elements of {I, 2, 3} on top and the (eight) elements of P({l, 2, 3}) (i.e.,
the subsets of {I, 2, 3} ) on the bottom, and we draw a line from each number to each
subset of which it is an element.

2 3

{1} {1,2} {1/2 /3} {2} {1 / 3} {2 / 3} {3}



{}

11. (a) Aside from the one isolated vertex, our graph will be a subgraph of [{5. There are
10 edges in [{5, so we need to draw all but one of these edges in order to have nine edges
in our graph. Thus the picture is as shown here.


(b) The statement is true. As we saw in part (a), if one vertex is isolated, then there can
be at most C(5, 2) = 10 edges. Therefore if there are 11 edges, no vertex can be isolated.
(c) The statement is false, essentially because there is no limit to the number of edges
in a pseudograph on a fixed number of vertices. For a counterexample, we can take a
multigraph with six vertices, one pair of which has 11 parallel edges between them, and
the other four of which are isolated.

13. (a) This is true. We can see C 5 as the perimeter of the picture of the Petersen graph as
shown in Figure 8.10.
(b) This is false. After looking at the Petersen graph for a few minutes, we can clearly
see that there are no cycles of length less than 5.
(c) This is false. The Petersen graph does not even have a triangle ([{3) as a subgraph,
so it certainly cannot contain [{5 (which itself contains [{3).
(d) This is false. A bipartite graph cannot contain J{3, since by the pigeonhole principle
at least two of the three vertices in any purported [{3 must be in the same part and
hence cannot be adjacent.
124 Chapter 8 GRAPHS

15. (a) With a little trial and error we find that the following graph has the desired degree
sequence.

(b) There is no such graph, since the sum of the terms in this sequence is odd (such a
graph would violate the corollary to Theorem 1).
(c) There is no such graph. Suppose that there were, say with vertices and
Vi, V2, Va,
V4 of degree 4, and vertices Ui and U2 of degree 1. Since at most three edges from any
Vi can go to vertices Vj, there must be at least one edge from each Vi to Ui and/or U2·
This makes a total of at least four edges involving Ui and U2, so Ui and U2 could not
both have degree 1.
(d) There is no such graph, since the largest possible degree in a graph with 5 vertices
is 4.
(e) Clearly the following graph has the desired degree sequence.

IIII
(f) Clearly the following graph has the desired degree sequence.

(g) Clearly the following graph has the desired degree sequence.
Section 8.1 Basic Definitions in Graph Theory 125

17. The possible degrees in a graph with n vertices are the n values 0, 1, 2, ... , n - 1. The
only way to avoid having two vertices with the same degree is for the degree sequence
to be precisely (n - 1, n - 2, ... ,2, 1, 0). But this is impossible, since if one vertex has
degree n - 1, then there can be no vertex with degree o. The statement need not hold
for multigraphs. For example, a multigraph on vertex set {a, b, c} in which there is one
edge from a to b and two parallel edges from b to c has degree sequence (3, 2, 1).

19. For the base case we just note that Qo is a single vertex. Now Qn+l is obtained from
two disjoint copies of Qn, say with corresponding vertices VI, V2, ... , V2n and v~, v;,
.•• , V~n, by adding the edges ViV~ for each i. To see that this is really Qn+l, we can
label the vertices as follows. Label both copies of Qn in the same way (i.e., for each i
the label on Vi is the same as the label on v:). Then put a 1 in front of each label on Vi
and put a 0 in front of each label on v:.

21. (a) The graph consists of a 5-cycle, with one additional vertex (which we put III the
middle) joined to each vertex on the cycle.

(b) The n-cycle contributes n edges, and the additional vertex contributes n new edges,
so there are 2n edges in all.
(c) The additional vertex has degree n, and each of the n vertices on the cycle has
degree 3, so the degree sequence is (n, 3, 3, ... , 3), in which there are n 3's.

23. (a) Since Kn is the graph with n vertices and all possible edges, K n must be the graph
with n vertices and no edges.
(b) The graph Km ,n consists of a set of m vertices and a set of n vertices, together with
all edges joining vertices in one set with vertices in the other. Therefore the complement
consists of these same m + n vertices, together with all edges joining vertices in the same
part. This is clearly the disjoint union of Km and Kn.
126 Chapter 8 GRAPHS

25. We need to find the degree of each of the 64 vertices in this graph, that is, the number
of attacked squares for each square on the chessboard. Consider the following picture, in
which we have labeled the squares of the chessboard with the letters A, B, C, or D.

A A A A A A A A
A B B B B B B A
A B C C C C B A
A B C D D C B A
A B C D D C B A
A B C C C C B A
A B B B B B B A
A A A A A A A A

Note that there are 28 squares labeled A, 20 squares labeled B, 12 squares labeled C,
and four squares labeled D. We can see that a queen on any square labeled A attacks 21
other squares (seven in its own row, seven in its own column, and seven in its diagonals);
a queen on any square labeled B attacks 23 other squares (seven in its own row, seven in
its own column, and nine in its diagonals); a queen on any square labeled C attacks 25
other squares (seven in its own row, seven in its own column, and 11 in its diagonals); and
a queen on any square labeled D attacks 27 other squares (seven in its own row, seven in
its own column, and 13 in its diagonals). Therefore the degree sequence is (4·27, 12·25,
20·23, 28·21), where k· d denotes k copies of the number d. This gives a vertex degree
total of 4·27 + 12·25 + 20·23 + 28·21 = 1456, so the number of edges is 1456/2 = 728.

27. (a) We represent each task with a vertex. To see which edges are present, we need to
determine which tasks must precede which other tasks. Before writing the draft of the
history paper, Sam must do the research and rent the word processor. Thus there is an
edge from task 1 to task 3 and from task 2 to task 3. Similarly, task 3 precedes task 4
(editing the draft), which precedes task 5 (returning the word processor), which precedes
task 12 (flying home). Task 6 (studying for history exam) precedes task 7 (taking the
exam), and by the same token task 9 (studying for discrete math exam) precedes task 10
(taking that exam). Now in order to perform task 11 (celebrating), all the work must be
done, and taking into account the prerequisites we have already discussed, this is forced
by requiring tasks 4, 7, 8, and 10 to precede task 11. Finally, task 11 must also precede
task 12. The resulting digraph is shown here.
Section 8.1 Basic Definitions in Graph Theory 127

1· ).--~).--~

2./3 4

6·--~

8 .----------~

9• ------------7
(b) If we want to let the activities be represented by edges, then we need to identify
certain points in time to be the vertices. One such point is the starting time of the entire
project (call it vertex a). Another is the point at which the history term paper is ready
to write (b). To get from point a to point b, Sam needs to perform tasks 1 and 2 (but
they can be done in either order). Thus we put two edges from a to b, namely 1 and 2.
Similarly, we put edge 3 from vertex b to vertex c (the point at which the draft of
the history paper has been written and is ready to edit), and edge 4 from c to d (the
point at which the paper has been finished). We let vertex e be the beginning of the
history exam and vertex f be the beginning of the discrete math exam, so we put edge
6 from a to e and edge 9 from a to f. Now let vertex 9 represent the beginning of
the celebration; since this point must come after the two exams and the handing in of
the discrete math exercise set, we put edges 7, 10, and 8 from vertices e, f, and a,
respectively, to vertex g. Furthermore, point d must precede point g, since the history
paper has to be finished. Therefore we put an edge from d to g. There is no activity on
this edge; it just represents a precedence relationship. Next we put edges 5 and 11 from
d and 9 (respectively) to a vertex h representing the point at which all the work at school
has been done (including returning the word processor and celebrating). Finally, edge 12
(flying home) goes from this vertex to a final vertex, i, representing the completion of
the entire project. The digraph is as shown here.

9 11
128 Chapter 8 GRAPHS

29. (a) This graph is not locally finite, since each vertex is adjacent to an infinite number
of other vertices, namely all the points on the circle of radius I inch, centered at that
vertex. An equilateral triangle I inch on a side shows that K3 is a sub graph of this graph.
Therefore Kn is subgraph for all n ~ 3. On the other hand, it is clearly impossible to
have four points in the plane all I inch from the others, so Kn is not a subgraph if
n ~ 4. Finally, Cn is a subgraph for all n ~ 3, since the regular n-gon with sides of
length I inch forms such a subgraph.
(b) This graph is not locally finite, since {I} is adjacent to all the vertices {I, k} for all
k ~ 2. We claim that Kn is subgraph for all n. To see this, just note that {I}, {I, 2},
{I, 2, 3}, ... are all adjacent. In fact even more is true than that Kn is a subgraph for
all n; we can say that Koo is a subgraph. Since each Kn is a subgraph, certainly each
C n is subgraph for all n ~ 3.
(c) This graph is locally finite; although the degrees of the vertices can be arbitrarily
large, no vertex has an infinite number of neighbors. Clearly Kn is subgraph for all n,
but note that Koo is not a subgraph. Again, since each Kn is a subgraph, certainly each
C n is subgraph.

31. (a) In order to state this definition, we will call the two centers of the stars a and b,
and we will call the vertices of degree I emanating from these centers ai and bj , where
I ~ i ~ m and I ~ j ~ n. Then we can say that the double star S(m, n) is a graph
whose vertex set is V = {a, b, ai, a2, ... , am, b1 , b2, ... , bn } with edges ab, aai for
all i, and bbj for all j.
(b) It is enough to identify the two parts. Let Vi ={a, b1 , b2 , ... , bn } and V2 = {b, ai,
a2, ... , am}. It is clear that no edge joins two vertices in the same part.

33. The parts are the set of all bit strings of length n with an odd number of I's and the set
of all bit strings of length n with an even number of I's. Clearly if two bit strings differ
in exactly one bit (which is how two vertices get to be adjacent in Qn), then one of them
must have one more I than the other, so that one of them is in Vi and the other is in
V2 ·

35. (a) If v is an isolated vertex, then v is incident to (i.e., an element of, since edges are sets'
of vertices) no edge; in symbols, v fI. e holds for all edges e. Thus the proposition that G
has an isolated vertex is 3vEV:\feEE:v fI. e. The following picture shows a graph with
an isolated vertex.


• • •
(b) To say that K3 is a subgraph is to say that there exist three distinct vertices Vi,
V2, and V3, each adjacent to the others. To say that K4 is not a subgraph is to say
the negation of the similar statement for four vertices. Thus the proposition is (3Vl EV:
Section 8.1 Basic Definitions in Graph Theory 129

3V2EV:3v3EV:({Vl, V2} E E 1\ {Vl, V3} E E 1\ {V2' V3} E E)) 1\ ..,(3VlEV:3v2EV:


3V3EV:3v4EV:({Vl' V2} E E 1\ {Vl, V3} E E 1\ {Vl, V4} E E 1\ {V2' V3} E E 1\ {V2' V4} E
E 1\ {V3, V4} E E)). The following graph satisfies this proposition.

( c) We just need to state that every edge joins vertices in different parts:

'v'eEE:3vlEVl:3v2EV2:e = {Vl,V2}.
The following graph is bipartite with parts Vl and V2 .


(d) A subgraph such as this is called a matching. A matching can be thought of as a
subset of the set of edges, such that each vertex is incident to exactly one edge in the
subset. Thus our proposition is 3E' ~E: 'v'vEV: 3!eEE': vEe. In the graph depicted here,
the matching is shown with heavy lines.

37. We claim that any such graph G is a disjoint union of cycles. To see this, suppose that we
start at any vertex v of G and "walk" along the edges. Since each vertex has degree 2,
our walk will continue until we return to v. When the walk has been thus concluded, we
have completed one cycle (a subgraph en for some n), and no other edges can be incident
to vertices in that cycle. If any vertices remain, we repeat this walking process and find
another cycle, disjoint from the first. We continue in this way until all the vertices have
been traversed.
130 Chapter 8 GRAPHS

39. The largest complete subgraph /{,. in G is called a maximal clique of G. In order to find
its size, we recursively find the size of a maximal clique in the graph G with its last vertex
deleted and the size of a maximal clique in the subgraph consisting of all neighbors of the
last vertex. The larger of the former and one greater than the latter is clearly the size of
a maximal clique in G, since any clique of G must either omit the last vertex or contain
it (and in the latter case contain only other vertices adjacent to it). This algorithm is
given below in pseudocode.
procedure maxclique (G : graph with vertices Vl, V2, ... , v n )
if n = 1 then return( 1)
else
begin
H 1 +- G with Vn deleted
H2 +- G with Vn and all vertices not adjacent to Vn deleted
{in each case, edges are kept if their endpoints remain}
return(max(maxclique(Hd, 1 + maxclique(H2 )))
end

SECTION 8.2 Traveling Through a Graph


1. (a) This sequence is none of these. It is not a walk, since Jg is not an edge. Since it is
not a walk, none of the other terms can possibly apply either.
(b) This is a walk of length 8; there is an edge joining each successive pair of vertices in
the sequence. It is also a trail, since no edge is repeated. It is not closed, since it does
not end at the same vertex at which it began. (In particular, it is not a cycle.) Finally,
it is not a path, since the vertex a, for example, is visited twice.
(c) This is a walk of length 2, specifically a closed walk, since it ends at the same vertex
(d) at which it began. It is not a trail (or any of the other things listed), since edge dJ
is used twice.
(d) This is a walk of length O. The terms trail and path also apply, but this walk is not
closed, since our definition required a closed walk to have length at least 1.
(e) This sequence is a cycle of length 6: It ends where it begins and otherwise uses no
vertex more than once. Clearly the terms walk, closed walk, trail, and closed trail also
apply.
(f) This walk of length 7 is closed. It repeats no edge, so it is a (closed) trail. It does
repeat a vertex (d), so it is not a cycle.
(g) This is a walk of length 7. None of the other terms apply, since edge bd is used twice.

3. Many answers are possible. We just need to use each edge exactly once. These Euler
tours can be found by trial and error or by using Algorithm 1. Two Euler tours are a, h,
i, j, d, i, c, h, j, J, e, d, c, J, g, a, g, c, b, a and a, h, j, i, h, c, i, d, j, J, e, d, c, J, g, a,
g, c, b, a.
Section B.2 Traveling Through a Graph 131

5. (a) We can form a graph containing a Hamilton cycle but no Euler tour by starting with
a cycle itself and then adding one extra edge, thereby destroying the property that each
vertex has even degree. The following picture shows such a graph.

(b) A graph such as the one shown below can have no Hamilton cycle, since a Hamilton
cycle would have to visit the middle vertex four times. It does have an Euler tour, since
the degree of each vertex is even.

(c) Clearly any cycle en has both a Hamilton cycle and an Euler tour (in fact it is its
own such cycle and tour).
(d) The graph consisting of just the path shown here clearly has neither a Hamilton cycle
nor an Euler tour.

7. None of these statements is necessarily true. The two graphs depicted below will provide
counterexamples. In both cases G is the subgraph shown in heavy lines, and H is the
entire graph.

(a) In the graph shown on the left, G is connected, but H is not.


(b) In the graph shown on the right, H is connected, but G is not.
(c) In the graph shown on the right, G has two components, but H has only one.
(d) In the graph shown on the left, H has two components, but G has only one.
132 Chapter 8 GRAPHS

9. Consider the graph consisting of two components, each one a copy of K 3 . We can model
this graph with two triangles of string. It might happen that the triangles are linked (one
triangle loops through the other). In that case, if we pick up one vertex of one of the
triangles, then the entire graph is "attached." The heuristic does not work in such a case.
This situation is illustrated in the following diagram.

11. Assume that G is not connected. Let V1 be the set of vertices in one component of G,
say having k vertices, where 1 :::; k :::; n - 1; and let V2 be the remaining vertices
of G. Then V2 has n - k vertices. The most edges that G can have is therefore
C(k, 2) + C(n - k, 2), which would happen if there were just two components, each one a
complete graph. But this sum equals [k(k -1)/2] + [(n - k)(n- k -1)/2], which simplifies
to H2k2 - 2nk + (n 2 - n)). This quadratic function of k attains its maximum at one of
the endpoints of the interval [1, n - 1], since the graph of this function is a right side up
parabola. If k = 1, then this expression yields ~(2 - 2n + (n 2 - n)) =H n - 1)( n - 2).
If n = k - 1, the same value is obtained. Therefore the answer to the question is
Hn - l)(n - 2). Note that it is not a correct proof to automatically assume that the
maximum occurs when just one vertex of G is isolated. It turned out that the maximum
we found is obtained with this arrangement, but we had to prove that this was so. At
first glance it is conceivable that the maximum might occur for some other splitting of
the vertices of G into components.

13. (a) There is no path from a vertex other than a to vertex a, so vertex a (together with
its loop) is in a strong component by itself. Similarly, there is no path from vertex b to
any other vertex, so vertex b is in a strong component by itself. Similarly each of e and
f is in a component by itself. Vertices c and d can each be reached from the other by a
path (in fact, by an edge), but there is no path from either of these vertices to any other
vertices of the digraph. Therefore these two vertices and the two edges connecting them
form a strong component. Note that edges ab and ec lie in no strong component.
(b) It is clear that each of the vertices 40, 50, 60, and 70 can be reached from the others
by traveling around the cycle, but that there is no path from any of these vertices to 20
or 30, nor fJ;om 80 or 90 to any of these vertices. Therefore vertices 40, 50, 60, and
70 and the four edges connecting them form one strong component. Each of the other
vertices is in a strong component by itself.
(c) Vertex a forms one strong component (since there is no path from b or c to a).
Vertices band c and the four edges involving only them form the other strong component.
Section B.2 Traveling Through a Graph 133

15. Let v =
Vo, el, VI, ..• , en, Vn =
V be a given closed trail starting and ending at V. If all
the vertices VI, V2, •.. , Vn are distinct, then we are done. If not, we let Vi and Vi, with
o < i < j be a pair of equal vertices in the trail. Excising the portion of the trail from
Vi to Vi (deleting Vi but not vi), we obtain a shorter trail. If this trail is a cycle, we
are done. Otherwise we repeat the process. We continue in this manner until no equal
vertices remain in our trail (except for the first equaling the last), at which point we have
the desired cycle.

17. Let U and V be distinct vertices in the digraph. By definition there are walks from U to V
and from V to u. Concatenating these walks gives a closed walk U = Uo, U I, ... , Un = U
from U to itself. Let j be the smallest natural number such that ui = Ui for some i < j;
clearly j ~ n, and the i for which Ui = ui is uniquely determined. Then the vertices
Ui+l, Ui+2, ... , ui are all distinct, so Ui, Ui+l, ... , ui is the desired cycle.

19. By the Corollary to Theorem 1 in Section 8.1, the hypothesis is false. Hence any conclusion
follows. (This is a vacuous proof.)

21. In each case we use the fact that a connected graph with at least one edge contains an
Euler tour if and only if the degree of each vertex is even.
(a) The degree of each vertex in J(n is n - 1. This is even if and only if n is odd. Thus
J(n contains an Euler tour if and only if n is odd (and greater than 1, to guarantee at
least one edge in the graph).
(b) The degrees of the vertices in J(m,n are m and n. Thus J(m,n contains an Euler
tour if and only if both m and n are even positive integers.
(c) Clearly for all n 2:: 3, the n -cycle is its own Euler tour.
(d) The vertices of Qn are the bit strings of length n, and each vertex is adjacent to
each of the n other vertices that differs from it in exactly one bit. Therefore the degrees
of the vertices are even if and only if n is even. Therefore Qn has an Euler tour if and
only if n is even (and greater than 0, to guarantee at least one edge in the graph).

23. Such a tracing is exactly an Euler trail; each edge of the pseudograph must be traced out
exactly once. We can apply the result obtained in Exercise 22 to determine whether such
tracings are possible: A tracing exists if and only if there are zero or two vertices of odd
degree.
(a) There are two vertices of odd degree in this graph, namely the vertices at the bottom.
Therefore there is an Euler trail starting at one of these bottom vertices and ending at
the other. The following figure shows one such trail.
134 Chapter 8 GRAPHS

(b) This graph has no tracing, since there are six vertices of odd degree, rather than none
or only two.
(c) There are no vertices of odd degree in this graph, so there is an Euler tour. The
following figure shows one such tour.

25. In order to begin to form the first closed trail C 1 , we had to start with an edge. If there
are no edges, then this cannot be done. In fact the conclusion is false if G has no edges.
In this case necessarily G = K 1 , and since by definition a closed trail must contain at
least one edge, we are not able to conclude that G has an Euler tour.

27. We claim that there is a Hamilton cycle if and only if m = n ~ 2. The sufficiency of
this condition is clear, since Ul, VI, U2, V2, ... , Un, V n , Ul (using the obvious notation) is
a Hamilton cycle in Kn,n for n ~ 2. Conversely, certainly K1,1 has no Hamilton cycle,
and if m =I- n then Km,n can contain no Hamilton cycle, since any cycle must visit each
part of Km,n equally often.

29. Our proof is very similar to the proof in the case considered in the text; we just have to
turn the arrows around. Since G is strongly connected, there is a walk from U to VI,
and hence, by Theorem 1, a path from U to VI. This path enters C for the first time at
some vertex Vi , having begun U = Ul, U2, ... , U/, Vi , where the Ui'S are distinct vertices
not in C. But now we see a longer cycle in G, namely VI, V2, ... , Vi-I, ul, u2, ... , u/,
Vi> Vj +1, ... , Vk, VI. This contradiction shows that C must have been a Hamilton cycle.

(If j = 1, then this cycle is VI, V2, ... , vk, Ul, U2, ... , U/, VI.)
Section B.2 Traveling Through a Graph 135

31. If G is bipartite, then every cycle must have even length, since it constantly jumps from
one part to the other and eventually ends up where it began. We prove the converse by
induction. Suppose that G has no cycles of odd length. If G has one or two vertices,
then clearly G is bipartite. Assume the inductive hypothesis, and let G be a graph with
n + 1 vertices, containing no odd cycles. Let v be a vertex of G, and let VI, V2, ... , Vr
be the vertices adjacent to v. Let G' be the graph obtained by removing v from G. By
the inductive hypothesis, G' (which still has no odd cycles) is bipartite. Choose the parts
VI and V2 so that for as large a k as possible, VI, V2, ... , Vk are in VI. If k < r, there
must be a path from Vk+l, which is in V 2 , to some Vi E VI, necessarily of odd length
(otherwise we could put Vk+1 into VI as well by switching parts for all vertices in the
same component as Vk+I). But then the cycle consisting of this path, followed by edge
Vi V , followed by edge VVk+l, is an odd cycle, contradicting the hypothesis. Therefore
k = r, and we can put v into V2 to obtain a bipartition of G.

33. (a) It is easy to see that the sequence 0011 satisfies the condition.
(b) In order to construct a de Bruijn sequence for n = 4, we may as well start with four
O's. Following the pattern displayed in the n = 3 case, we might guess to try four 1 's
next. If we do so, then it is not hard with a little trial and error to come up with the
following sequence: 0000111100101101. It is straightforward to check that all 16 four-bit
patterns appear in this arrangement (viewed circularly, of course).
(c) Following the hint, we construct a graph with 2n - 1 vertices and 2n edges. By
Exercise 32, there is an Euler tour in this digraph, since each vertex has in-degree and
out-degree 2. The labels on this tour are the desired de Bruijn sequence. To see this,
consider any n-bit string, and let v be the string consisting of its first n - 1 bits. The n
labels on edges in the portion of this tour ending at vertex v must always be exactly v,
and v occurs twice in the tour-once followed by an edge labeled 0 and once followed by
an edge labeled 1. Thus the given bit string occurs in the tour.
136 Chapter 8 GRAPHS

SECTION 8.3 Graph Representation and Graph Isomorphism


1. In each case we construct a matrix labeled by the vertices, and we put either a 1 or a 0
into the (i, j)th entry in the matrix if there is or is not an edge from vertex i to vertex j ,
respectively.
(a) The (a, c) entry is 1 (as is the (c, a) entry), for instance, since there is an edge
between a and c; but since there is no edge joining a and e, the (a, e) entry and the
(e,a) entry are both O. Note here that the isolated vertex b has only O's in its row and
column.
a b c d e f 9
a 0 0 1 1 0 0 1
b 0 0 0 0 0 0 0
c 1 0 0 1 0 0 0
d 1 0 1 0 1 1 0
e 0 0 0 1 0 1 0
f 0 0 0 1 1 0 1
9 1 0 0 0 0 1 0

(b) Note how the structure of this matrix displays the isolated nature of vertex e.
a b d
c e

T ~l
0 0 1
b 1 0 0 0
c 0 1 0 0
d 0 0 1 0
e 0 0 0 0

3. Our digraph must have vertices a, b, c, d, and e (the labels on the matrix), and edges
between pairs of vertices for which the corresponding entry in the matrix is a 1. There
is an edge from c to b, for instance, since the (c, b) entry is 1, but there is no edge from
b to c, since the (b, c) entry is O.
Section 8.3 Graph Representation and Graph Isomorphism 137

5. (a) There are three 1's in the row labeled c. Therefore there are three edges incident
to c, so d(c) = 3.
(b) There are three l's in the row labeled b. Therefore there are three edges outgoing
from b, so d+(b) = 3.
(c) There are two l's in the column labeled b. Therefore there are three edges incoming
to b, so d-(b) = 2.

7. We simply list the vertices of the graph, and for each vertex list the adjacent vertices.
(a) a: c, d, 9 (b) a: b, c, e
b: b: a, d
c: a, d c: a, d, e
d: a, c, e, f d: b, c, e
e: d, f e: a, c, d
f: d, e, 9
g: a, f

9. The adjacency matrix is easily constructed by putting a 1 in the (i, j)th entry to indicate
an edge from vertex i to vertex j, and putting a 0 to indicate no edge.
a b c d

~l
0 1

The graph is as shown here.


T
b
c
d
0
1
1
0
0
0
0
1 0

C b

8 d

11. For the incidence matrix, we label the rows with the vertex names, and represent each
edge by a column (which we have labeled el through es). The first column represents
the edge joining vertices a and c, for example.
el e2 e3 e4 es e6 e7 es
a 1 1 1 0 0 0 0 0
b 0 0 0 0 0 0 0 0
c 1 0 0 1 0 0 0 0
d 0 1 0 1 1 1 0 0
e 0 0 0 0 1 0 1 0
f 0 0 0 0 0 1 1 1
9 0 0 1 0 0 0 0 1
138 Chapter 8 GRAPHS

13. We count the trails by listing them explicitly. Note that matrix multiplication techniques
are not helpful here, since they cannot detect whether walks are trails (do not repeat any
edges).
(a) The trails of length 3 are a, e, d, b and a, c, d, b. Thus the answer is 2. We do not
count walks that are not trails, such as a, b, d, b.
(b) In addition to the two trails of length 3 found in part (a), there is the trail a, b of
length 1. (There are no trails of length 2.) Thus the answer is 3.

(c) The trails of length 4 are a, a, c, b, b; a, a, c, c, b; a, a, d, c, b; a, c, c, b, b; a, d,


a, c, b; a, d, c, b, b; and a, d, c, c, b. Thus the answer is 7.
(d) In addition to the seven trails of length 4 found in part (a), there are the trails
a, c, b; a, a, c, b; a, c, b, b; a, c, c, b; and a, d, c, b. Thus the answer is 12.

15. (a) In the complete graph, there is an edge from every vertex to every other vertex. Thus
the adjacency matrix contains only l's, except that there are O's on the diagonal, since
the graph has no loops.
0 1 1 1 1 1
1 0 1 1 1 1
1 1 0 1 1 1
1 1 1 0 1 1

1 1 1 1 0 1
1 1 1 1 1 0

(b) Let us suppose that the vertices are labeled 1, 2, 3, ... , n, and the edges join
vertices whose numbers differ by 1 (there is also an edge between 1 and n to complete
the cycle). Then the matrix looks like this.
0 1 0 0 0 1
1 0 1 0 0 0
0 1 0 1 0 0
0 0 1 0 0 0

0 0 0 0 0 1
1 0 0 0 1 0

(c) We can suppose that the first part of this complete bipartite graph contains vertices
1, 2, ... , m, and the second part contains vertices m+ 1, m+2, ... , n. In the adjacency
matrix we must put a 1 to represent each edge between a vertex in the first part and a
vertex in the second part, but there must be O's to indicate that no two vertices in the
Section 8.3 Graph Representation and Graph Isomorphism 139

same part are adjacent. Thus the matrix is as shown here.


0 0 0 0 1 1 1
0 0 0 0 1 1 1
0 0 0 0 1 1 1

0 0 0 0 1 1 1
1 1 1 1 0 0 0
1 1 1 1 0 0 0
..
1 1 1 1 0 0 0

17. (a) Since each 1 in the ith row represents an edge from vertex i to some vertex, the
sum of the entries in this row gives the out-degree of the ith vertex.
(b) Since each 1 in the jth column represents an edge from some vertex to vertex j, the
sum of the entries in this column gives the in-degree of the jth vertex.
(c) Since each 1 on the main diagonal represents a loop (an edge from some vertex to
itself), the sum of the entries on the main diagonal (known as the trace of the matrix) is
the number of loops in the digraph.

19. (a) We assume that the vertices are called a, b, c, and d, in the order in which they are
represented in the matrix. In this picture we have put two parallel edges from vertex b
to vertex c, for instance, since the (2,3)th entry in the matrix is 2.

(b) By the multiplication principle, the number of walks from vertex i to vertex j that
have vertex k as their penultimate vertex is the number of walks from i to k times the
number of walks from k to j. The latter quantity is just the number of edges from k
to j, and that is precisely the entry in the adjacency matrix. Therefore Theorem 1 IS
still valid.
(c) The out-degree of vertex i is the number of edges with i as their tail. The entry ajj
in the matrix tells us the number of edges from i to j. Therefore the out-degree of vertex
i is 2:7=1 aij· Similarly, the in-degree of vertex j is the number of edges with j as their
head. The entry aij in the matrix tells us the number of edges from i to j. Therefore
the in-degree of vertex j is 2:7=1 aij .
140 Chapter 8 GRAPHS

21. Our algorithm is straightforward. We initialize the incoming adjacency lists L' to be
empty. Then we scan the outgoing adjacency lists L in order, and for each entry Vj in
the list for Vi (which represents the edge from Vi to Vj), we adjoin Vi to the incoming
list for Vj.
procedure in_list(L : outgoing adjacency lists)
{ assume that the vertices are labeled VI, V2, ... , Vn ;
L and L' are indexed by {VI. V2, ... , vn } }
initialize L' to have all its entries empty
for i +- 1 to n do
for each entry Vj in L ( Vi) do
adjoin Vi to L'(Vj)
return( L') {incoming adjacency lists}

23. We represent each edge by a triple (v, w, c), where V and ware the endpoints (in either
order, since the graph is undirected) and c is the capacity in hundreds of cars per minute.
Thus we obtain the list (D,U,6), (D,N,5), (D,P,5), (B,U,4), (D,S,4), (N,U,3),
(P,U,3), (B,N,2), (B,P,2).

25. The identity function from V to itself is tautologically an isomorphism from G = (V, E)
to itself, so the relation "is isomorphic to" is reflexive. Next suppose that t.p: V -+ V' is
=
an isomorphism from G (V, E) to G' (V', E'). Thus =
V'uEV:V'vEV: (uv E E ..... t.p(u)t.p(v) E E').
Now since t.p is bijective it has an inverse t.p-l, and the condition is equivalent to
V'u'EV':V'v'EV':(t.p-l(u')t.p-l(v') E E ..... u'v' E E').
Thus t.p-l is an isomorphism from G' to G. This shows that the relation is symmetric.
Finally to show transitivity, let t.p: VI -+ V2 and 1/;: V2 -+ V3 be isomorphisms from
Gl = = =
(VI, Ed to G 2 (V2,E2), and from G2 (V2,E2) to G 3 (V3,E3), respectively. =
Thus

and

This implies that


V'uEV1 :V'vEV1 : (uv E El ..... 1/;(t.p(u))1/;(t.p(v)) E E3),
so 1/; 0 t.p: VI -+ V3 is an isomorphism from G 1 to G3 .

27. (a) We organize our catalog by the number of edges. There is clearly only one graph on
four vertices with no edges, and only one with one edge. There are two graphs with two
edges, depending on whether or not the edges are adjacent. If the graph has three edges,
then the edges can form a path, a triangle, or a star. Finally, all the graphs with four,
Section 8.3 Graph Representation and Graph Isomorphism 141

five, or six edges are just the complements of the graphs with two, one, or zero edges,
respectively. The entire collection of 11 graphs is shown below .

• •
• • • • r. n
(b) First we consider graphs in which there are no cycles. The first three pictures below
exhaust the possibilities (there is one graph each in which the longest path has length
4, 3, and 2). The edges could form a 4-cycle, or they could form a 3-cycle. In the
latter case there are two possibilities for the fourth edge. Thus we find a total of six such
graphs.

(c) We draw the Hamilton cycle first (which requires six edges) and then consider where
the additional edges, if any, might go. The first picture below shows the only such graph
with only six edges. If there are seven edges, then the seventh edge can either join vertices
diametrically opposite on the cycle or only removed by one intermediate vertex. These
two possibilities are not isomorphic, since the latter graph contains a triangle. Finally we
consider where we can place two additional edges. Some careful thought shows that the
six possibilities shown here are a complete catalog. This gives us nine graphs in all.

(d) We need to decide where to place the two edges. First suppose that the edges are
not loops. The first picture below shows the only case in which they are not adjacent.
In the next three pictures we find all the cases in which they are adjacent nonloops. If
the digraph has a loop, then the other edge can either be a nonloop related to the loop
as shown in the next three pictures, or it can be another loop. Thus there are eight
possibilities in all.
142 Chapter 8 GRAPHS

• .
~
)



)
• 71 :l

t)
) . ~ .
. D. . D.
~. t).
t)
• • • •
(e) A regular graph must consist of disjoint cycles. We organize our catalog in terms of
the length of the longest cycle or cycles. It should be clear that the following list of 17
graphs is complete: C 15 , C 12 U C3 , C ll U C 4 , C 10 U C 5 , C 9 U C 6 , C 8 U C7, C 9 U C 3 U C 3 ,
~U~U~,~U~U~,~U~U~,~U~U~,~U~U~,~U~U~,
~U~U~U~,~U~U~U~,~U~U~U~,~U~U~U~U~.
(f) Since a graph must have an even number of vertices of odd degree, there are no such
graphs.

29. (a) Since the complete graph on four vertices has six edges, a self-complementary graph
on four vertices must have three edges. It is not hard to see that the graph consisting of
three edges in a path is self-complementary.
(b) Since the complete graph on five vertices has ten edges, a self-complementary graph
on five vertices must have five edges. It is not hard to see that the two graphs shown here
are both self-complementary.

(c) There is no way for G and G to each have half of the edges, since K3 has 3 edges.

31. Let us begin by trying to find an isomorphism. In order for out-degrees to correspond,
vertex e must be paired with vertex x (the only vertices with out-degree 1), and vertex
c must be paired with vertex z. By looking at in-degrees, we see that vertex b must be
paired with vertex w (the only vertices with in-degree 1), and vertex f must be paired
with vertex y. Now vertex d is the only remaining vertex in the digraph whose matrix
is Al with out-degree 2, so it must be paired with the similarly describable vertex u in
the other digraph. This leaves vertex a to be paired with vertex v. Thus if there is an
isomorphism it must be given by the following correspondence: a ...... v, b ...... w, c ...... z,
Section 8.4 Planarity of Graphs 143

d ..... u, e ..... x, f ..... y. It remains to check that all the adjacencies are preserved. For
instance, there are edges from a to a, d, and f, so there must be (and are) edges from
v to v, u, and y. We check the remaining five vertices and conclude that the digraphs
are isomorphic.

33. The easiest way to prove this is to observe that the graph on the right is bipartite, but
the graph on the left is not.

35. Given a graph G, we can consider all the possible 0-1 matrices that can be the adjacency
matrix for G . We can order these lexicographically, where we consider the n 2 entries of
the matrix ordered row by row, from left to right in each row. Let M (G) be the matrix
in this collection that comes first in this order. For example, the following matrices all
represent the graph containing three vertices and one edge, but the one on the right is
the one that we would pick for our invariant, since 000001010 < 001000100 < 010100000.

Hl ~l [H II
o
[1 [! o
o
Clearly this matrix is well-defined by our description, so it is an invariant. Given two
matrices obtained in this way, it is trivial (in O(n 2 ) steps) to see whether they represent
the same graph: They will represent the same graph if and only if they are the same
matrix. The difficulty is that given G, there is no good way known to compute M( G)-
trying all possible n! orders of the vertices has more than polynomial time complexity.

37. In time O( v 2 ) we first construct an adjacency matrix for G by initializing it to be a v


by v matrix of O's and then going through the adjacency lists and putting a 1 in each
position corresponding to an edge of G. Now for each edge uu' of G (obtained from
the adjacency lists), and for each vertex w, we determine whether both u and u' are
adjacent to w. It takes O(max(e, v»steps to peruse the adjacency lists for all the edges,
and O(v) steps to check out all possible w for each edge (using the adjacency matrix).
Thus the efficiency of this algorithm is O(max(ev, v 2 ».

SECTION 8.4 Planarity of Graphs


1. (a) We find v = 16 vertices, e = 28 edges, r = 15 regions (including the outer region),
=
and c 2 components. Euler's formula checks: 16 - 28 + 15 2 + 1. =
(b) Here v = 14, e = 14, r = 4, and c = 3; we see that 14 - 14 + 4 = 3 + 1.
(c) In this pseudograph there are four vertices, 10 edges, eight regions, and one compo-
nent; sure enough, 4 - 10 + 8 = 1 + 1.
(d) There are 20 vertices, 22 edges, six regions, and three components: 20-22+6 = 3+1.
144 Chapter 8 GRAPHS

3. Clearly if G is a subgraph of H, and if H is planar, then G is planar, since an embedding


of H gives an embedding of G. Equivalently, if G is nonplanar, then so is H. In the
situation here, note that Kr is a subgraph of K6 if r ~ s. Thus since K4 is planar,
Kn is planar for all n ~ 4. On the other hand, no Kn is planar for n ~ 5, since K5 is
already non planar.

5. We can model the problem with a bipartite graph. The three houses are vertices in one
part, and the three utility companies are vertices in the other part. The brain-teaser asks
whether we can draw K 3 ,3 in the plane without edge crossings. The construction cannot
be done because K3,3 is not planar.

7. Intuitively, we just push the three vertices of the inner triangle toward the center of the
figure, thereby making room for the curved edges to become straight line segments. The
result is shown here.

9. In the planar embedding of H, we can slightly fatten each edge and replace it by the
required number of parallel edges. We can put any required loops in empty space near
their vertices. The following picture, for instance, shows how to embed a pseudograph
whose underlying graph is K 4 .

11. We can rewrite 2e ~ 3r as r ~ 2e/3. Then we have from Euler's formula (since a graph
has at least one component) 2 ~ 1 + c = v - e + r ~ v - e + 2e/3 = v - e/3. Multiplying
through by 3 we obtain 6 ~ 3v - e, which is clearly equivalent to e ~ 3v - 6.
Section BA Planarity of Graphs 145

13. (a) Following the instructions, we obtain the following picture.

(b) Clearly v = 10 and e = 15. There is just one component.


(c) Since e = 15, and 3v - 6 = 3 . 10 - 6 = 24, the inequality holds: 15::; 24.
(d) This graph is not planar because it contains the nonplanar graph K5 as a subgraph.
(e) Theorem 2 said that if G is planar, then e ::; 3v - 6, not the converse. If we have a
graph that is not planar, it mayor may not be the case that e ::; 3v - 6. Note that this
example points out that you can never prove a graph to be planar just by counting edges
and vertices and checking that e ::; 3v - 6.

15. The following two embeddings of the same graph differ in that in one case the two vertices
of degree 1 are in the same region, whereas in the other they are not.

17. Recall that the vertices of Q4 are bit strings of length 4, with two vertices adjacent if
the strings differ in exactly one bit. The following picture shows a subdivision of K 3 ,3 in
Q4, where the parts are {I, 2, 3} and {a, b, c}. Therefore Q4 is not planar.

3 _ - - - - - .b
0100
1001

1011
0110--------40111
146 Chapter 8 GRAPHS

Alternatively we can give a proof by contradiction. In Q4 there are v = 16 vertices,


e = 32 edges, c = 1 component, and no triangles. If Q4 were planar, Theorem 3 would
tell us that 32 ~ 2·16 - 4, a falsehood. Therefore Q4 is not planar.

19. We give a construction that amounts to a proof by mathematical induction. For v = 4,


the graph C 4 embedded in the plane satisfies v·= 2e - 4. Note that all (i.e., both) regions
are four-sided. Given a planar embedding of a graph for which the equality holds, we can
form a planar embedding of a graph with one more vertex for which the equality holds
by putting a new vertex u inside a region vwxy and adding edges uv and ux. Having
added one more vertex and two more edges, we have not disturbed the equality; and the
resulting planar embedding still has only four-sided regions. The following pictures show
the idea for v = 4, 5, 6 and 7.

21. Consider the graph K 2 , consisting of two vertices and one edge. It satisfies neither
inequality: e 1. 3v - 6 and e 1. 2v - 4. Otherwise, however, the hypotheses of these
theorems are met.

23. (a) Since every vertex has degree 4, the sum of the degrees must be 4v, whence the
number of edges must be 2v. If there are 10% more regions than vertices, we also know
that r = =
1.10v. Plugging these facts into Euler's formula tells us that v - 2v + 1.1 v 2,
=
and so 0.1v 2, or v 20. =
(b) The following picture shows such a graph.
Section 8.4 Planarity of Graphs 147

25. (a) This is K5 with one edge missing. By Exercise 2, it is planar. (We can simply reroute
two of the nonintersecting diagonals to the outside of the pentagon to obtain a planar
embedding. )

(b) This graph is planar. If we move the point inside the rectangle to the outside and
also move the diagonal from upper left to lower right to the outside, we can obtain the
following planar embedding.

(c) This graph is planar. We can reroute some of the lines to the outside of the figure to
obtain the following embedding.

(d) This graph is planar. We can reroute some of the lines to the outside of the figure to
obtain the following embedding.
148 Chapter 8 GRAPHS

(e) This graph is not planar. Indeed, it is a subdivision of K 3 ,3; the points around the
outside are the six vertices of K 3 ,3, in alternating parts.
(1) This graph is not planar by Theorem 2. It has seven vertices and 17 edges, and
17~3·7-6.

27. Suppose that a graph is embedded on the sphere. Pick a point in the interior of some
region, puncture the sphere there, and stretch it open to form a plane. The region that
was punctured becomes the unbounded region of the plane. All the other regions, as
well as vertices, edges, and components, remain unchanged. Thus Euler's formula for the
sphere follows from Euler's formula for the plane.

29. (a) Suppose that K11 is embedded in t planes. Each plane can contain at most 3·11-6 =
27 edges. Thus two planes can contain at most 54 edges, one short of the C(11,2) = 55
needed for K 11. Therefore the thickness t is greater than 2. The following picture, an
embedding of K 11 in three planes, shows that it at most 3. Therefore the thickness is
exactly 3.

8
3 9

(b) Suppose that K 7 ,7 is embedded in t planes. Each plane can contain at most 2·14-4 =
24 edges. Thus two planes can contain at most 48 edges, one short of the 49 needed
for K 7,7. Therefore the thickness is greater than 2. The picture for part (c) shows that
it is at most 3 (put the missing edge al in a third plane). Therefore the thickness is
exactly 3.
149
Section 8.4 Planarity of Graphs

(c) Every edge of K7,7 except edge al is shown in one or the other of these two planes.
Clearly this graph has thickness greater than 1, so we have proved that its thickness
is 2.

31. We can characterize the arrangement as consisting of d points forming a convex polygon,
with n-d points in its interior, where 3 ~ d ::; n. When play is finished, the picture must
consist of this d-gon with its interior completely triangulated. (Since every polygon of
more than three sides contains at least one diagonal in its interior, play cannot stop until
only triangles are left inside the d-gOD I) Thus the number of moves in the game is e, the
number of edges in this graph. It is fixed in advance and does not depend on the players'
strategies. To determine e, suppose that we add d- 3 edges in the exterior of the polygon,
thereby obtaining a triangulation. In any triangulation (see Exercise 20) the inequality
in Theorem 2 holds as an equality. Therefore in this case we have e + d - 3 = 3n - 6,
so e = 3n _ d _ 3 = 2n - 3 + (n - d). The parity of this number depends only on the
parity of n _ d. The first player wins if e is odd, which means that n - d is even; and
the second player wins if n _ d is odd. Thus the first player would like to see an even
number of points inside the convex polygon, and the second player would like to see an
odd number of points inside.
-~~--::-::~-------- ~-- - -----~~-.-.. --- ....----.~.. ---"'-,- ._---_ ..
-. ------_.. ----------._--- -
- ------
__.-

168
Chapter 9 TREES

(c) We choose vertex 000 as the root (it represents the smallest number in base 2). It
is adjacent to 001, 010, and 100, so these vertices are at level 1. Vertices 011 and 101
are both adjacent to the first of the level 1 vertices, and vertex 110 is adjacent to the
second of them. Finally vertex 111 appears at level 3, adjacent to vertex OIL Note that
no cross edges join vertices at the same level, since the graph is bipartite.

100

15. The breadth-first search spanning tree for Kn is a star, K1,n-l, since in Kn every vertex
is adjacent to the starting vertex. The depth-first search spanning tree for Kn is clearly
a path.

11. Suppose that an edge uv of G is not used in the depth-first search spanning tree. We
can assume without loss of generality that vertex u is encountered first durino the search
process. Since edge uv is not used, it must be the case that the search proceeded with
other neighbors of u, whose numbers were less than v, and while searching from one of
them, say Vi, encountered v. Thus v is in the subtree rooted at Vi, hence a descendant
of Vi. But Vi is a descendant of u, so v is a descendant of u.

19. There is a tree on five vertices that is neither a path nor a star (1<1,4); it consists of a
path of length 3, with the fifth vertex joined to one of the middle vertices of the path.
There is no way that this tree can be either the depth-first nor the breadth-first search
spanning tree of K s , since we saw in Exercise 15 that these trees are a path and a star,
respectively.
Section 9.2 Spanning 1}ees
169

path. Then clearly u is at a distance k -1 from the root, so by the inductive hypothesis,
it was visited. By the way the algorithm works, since v is adjacent to u, the algorithm
will necessarily have visited v before leaving vertex u. Therefore v will be included in
the tree as well.

23. We will find a spanning forest by finding a spanning tree in each component. We need
to modify Algorithm 2 so that it does not terminate when the queue L becomes empty,
but rather starts over with an unvisited vertex. In :Illore detail, we let F accumulate the
forest, one tree at a time. At each iteration, we search for an unvisited vertex, called
next, and then proceed with the searching steps starting the queue with just next in it.

procedure breadth_firsLsearch_forest(G: graph)


{assume setting of Algorithm 2}
F +- 0 {the forest is originally empty}
for i +- 1 to n do
visited( i) +- false {no vertices have been visited yet}
next +- 1 {first find the tree for the component containing vertex I}
while next> 0 do
begin {this much is virtually unchanged}
visited( next) +- true
T +- ({next}, 0)
L +- (next)
while L is not empty do
begin
i +- first element of L
L +- L with i removed
for j +- 1 to n do
if (j is adjacent to i) /I. not visited(j) then
begin
visited (j) +- true
add vertex j and edge ij to T
add vertex j to the end of L
end
end
F +- F U T {throw T into the forest}
next +- 0 {look for another component}
for i +- n down to 1 do
if not visited(i) then next +- i
end
return(F)

25. Vertices at distance 1 from vertex 1 are at level 1, since they get visited from vertex 1;
vertices at distance 2 from vertex 1 are adjacent to vertices at distance 1 from vertex 1,
so they must appear at level 2 as children of vertices at levell, and so on.
Chapter 9 TREES
170

27. (a) Add e to T. The result has a cycle. Let f be any edge of the cycle other than e.

Then T U {e} _ {J} is again a tree, since it is connected and has the right number of

edges.

(b) We need only show how, given a spanning tree T and another spanning tree T' =I T,

we can find a spanning tree Til which is the same as T except that one edge of T - T' has

been replaced by an edge e E T' - T (this is nonempty since T =I T'). Apply part (a),
being careful to pick the edge f to be deleted from T not to lie in T' (this is possible,
because not every edge in the cycle can lie in T').

29. We use the stack L to keep track of the vertices on which we are currently working.

Initially L contains only vertex 1. When we encounter an unvisited vertex we push it

onto the stack (as well as adding it and the appropriate edge to the tree). When we

have finished with a vertex (i.e., when we exhaust the search, in the inner while loop

below, for unvisited neighbors) we remove it from the stack and continue processing the

vertex that then appears at the top of the stack. The algorithm always works on the top

element of the stack. Our algorithm is somewhat inefficient, since every time a vertex

comes to the top of the stack we start over searching for unvisited neighbors, but it does

work correctly.
Section 9.3 Tree Traversal
171

procedure iterative_DFS'(G : connected graph)


visited(l) +- true {start at vertex I}
for i +- 2 to n do
visited( i) +- false {no other vertices have been visited}
T +- ({I}, 0) {the tree starts with no edges}
L +- (1) {the stack has only vertex I}
while L =I 0 do
begin
i +- first element of L {search from vertex i}
j +- 1 {look for unvisited neighbor}
found +- false
while j :$ n /I. not found do
begin
if j is adjacent to i /I. not visited(j) then
begin {found an unvisited neighbor}
visited(j) +- true
found +- true
add j to the front of L
{processing will continue with j }
add j and ij to T
end
j +- j + 1 {try the next neighbor}
end
if not found then remove first element from L
{we are finished with vertex i}
end
return(T)

SECTION 9.3 Tree Traversal


1. (a) The root a comes first. Then we need to list the vertices in the first (left-most)
immediate subtree in preorder. This begins with its root b, then b's only child e, then
e's first child h, e's second child i, and the last immediate subtree of the tree rooted
at e in preorder, namely j, 0. This finishes the subtree rooted at b, so we next list the
subtree rooted at c, namely just c itself, and finally the subtree rooted at d, which in
preorder is f, k, I, m, n, g. Putting this all together we have the preorder: a, b, e, h, i,
j, 0, c, d, f, k, I, m, n, g.

(b) The root a comes last. Before that we need to list all the immediate subtrees in
postorder. For the first of these, we will have b last, preceded bye, which is preceded by
h, i, 0, and j, in that order. Thus the sequence will start h, i, 0, j, e, b, and will end
with a. The rest of the listing is handled in a similar manner, giving the answer: h, i,
0, j, e, b, c, k, I, m, n, /, g, d, a.
Chapter 9 TREES
172

3. (a) Fully parenthesized this expression is «X *Y)+(A-B)). In particular the outermost


operation is +, and the two operands are each the result of applying a binary operator
to two operands. The expression tree reflects this analysis.

(b) Fully parenthesized by the precedence rules (in particular, the rule that additions
and subtractions are performed from left to right), this expression is
««X + Y) * Z) + Q) - «X - Y) * B)).
Thus we see that the outermost operator is the minus. Its first operand is the result of
the second addition operation, and so on. The expression tree makes it all clear.

(c) The outermost operation here is the second implication. Its right operand is just R,
but its first operand is the conjunction of two expressions, the second of which is an
implication. The tree shows this structure.
Section 9.3 Tree Traversal
173

(d) The following tree captures this calculation.

5. In each case we just traverse the tree in postorder and write down what we see.
(a) XY*AB-+
(b) X Y + Z * Q + X Y - B *_
(c) P PQ-+AR-+
(d) ABCunABnCn-

7. We work from the right, successively replacing the last operator and its two following
operands by the result of that operation.
(a) *+ 3 - 4 2 + 6 3 = * + 3 - 4 2 9 = * + 329 = * 5 9 = 45
(b) Un{1,2,3,4}U{1}{3,5}{6,7} = Un{1,2,3,4}{1,3,5}{6,7} = U{1,3}{6,7} =
{1,3,6,7}
(c) VFAAVFA-+TFTFT = VFAAVFAFTFT = VFAAVFFFT =
VFAAFFT= VFAFT= VFF = F

9. One way to approach these is to draw the expression tree (Exercise 8) and then write
down the vertices in postorder. An alternative approach is to move the first operator to
the end, find the two operands (i.e., the two complete prefix expressions following the
initial operator), and recursively apply this procedure to both of them. The base case is
that a constant is left alone.
(a) 342-+63+*
(b) {1,2,3,4}{1}{3,5}Un{6,7}U
(c) FFTF-+TAVFATAV

11. We work from the left, successively replacing the first operator and its two preceding
operands by the result of that operation.
(a) 33*44*+=944*+=916+=25
(b) {I, 2, 3}{4, 5} n {5, 6} U = 0 {5, 6} U = {5,6}
(c) FFFF-+-+-+ = FFT-+-+ = FT-+ = T
--------........---------------
174 Chapter 9 TREES

13. One way to approach these is to draw the expression tree (Exercise 12) and then write
down the vertices in preorder. An alternative approach is to move the last operator to
the front, find the two operands (i.e., the two complete postfix expressions preceding the
final operator), and recursively apply this procedure to both of them. The base case is
that a constant is left alone.
(b) Un{1,2,3}{4,5}{5,6}

15. We mimic the idea of preorder traversal of an ordered tree, except that to process a vertex
means to print it if it is a leaf (and do nothing if it ·is not a leaf).
procedure leaves(r : root of ordered tree)
if r has no children then print (r)
else for each child v of r, in order, do
call leaves(v)
return

17. We need to consider both subtrees, and the most convenient way to do so is by giving a
name to their heights. If one or the other of the subtrees is empty, then setting its height
to -1 has the right effect.
procedure height(r : root of binary tree)
if r has a left child then left_ +- heightheight(left_child(r))
else left- +- height - 1
if r has a right child then righL +- heightheight(righLchild(r))
else righL +- height - 1
return(1 + max(lefLheight, righLheight»)

19. Since A comes first in preorder, it must be the root of the tree. We find A in the middle
of the inorder listing and know immediately that the vertices listed to its left (B, F,
E, G, D, and C) must be in the left subtree, while the remaining vertices must be in
the right subtree. Now we know the preorder and inorder listing of both subtrees, so we
continue recursively in this manner until we have drawn the entire tree.

F
Section 9.3 Tree Traversal 175

21. We can show this with a simple example. The tree with root A and left child B has the
same preorder and postorder as the tree with root A and right child B.

23. (a) If T is empty, then TR is empty. If T has root r, then TR has root r, with left
subtree Tf, where Tl is the right subtree of T (if any), and right subtree Tfi, where T2
is the left subtree of T (if any).
(b) To construct the tree, we must create a new vertex for each vertex of the given
tree. We can work recursively, worrying only about the root. If the root is empty, there is
nothing to do. Otherwise, we create a new vertex ro for the root, recursively construct the
reverse of the right subtree and make it the left subtree of ro, and recursively construct
the reverse of the left subtree and make it the right subtree of ro. In pseudocode our
algorithm appears as follows.
procedure reverse(r : root of extended binary tree)
if r = 0 then return(0)
else
begin
create a new vertex ro
make reverse(righLchild(r» the left child of ro
make reverse(le/Lchild(r» the right child of ro
return(ro)
end

25. A variable name or a constant is a prefix expression. If al and a2 are prefix expressions
and 8 is an operator, then 8 al a2 is a prefix expression. A variable name or a constant
is a postfix expression. If al and a2 are postfix expressions and 8 is an operator, then
al a2 8 is a postfix expression. (We assumed here that only binary operations were used.
Otherwise we need to modify the definition slightly, so that if 8 is an n-ary operator, then
8 al a2 '" an is the prefix expression created by the recursive part, and al a2 ... an 8
is the analogous postfix expression.)

27. We can read these answers from the expression trees, or just form them directly, keeping
in mind that an operator immediately precedes its operand or operands.
(a) * - 4 e 3 7 (where e is unary minus)
(b) V +*AA*BB
(c) V +1'tA1'tB (where 1't is squaring)
(d) unA e B C (where e is complementation)
(e) -VP-'PQ

29. The problem is that it is not clear where to put the operator, since there is no notion
of "between" with only one operand. For example, for part (c) of Exercise 26, do we
write (V«A1't) + (B1't))) or (V«1'tA) + (1'tB))) or what? We are forced to use a hybrid
notation-part infix and part either prefix or postfix.
176 Chapter 9 TREES

31. This, like most orally unambiguous statements involving calculations, is in prefix notation.
The operator of squaring is mentioned before the things being squared ("the square of
... "), and the addition operator is mentioned before the summands ("the sum of ... ").

33. Essentially all we want to do is to perform a breadth-first search on the tree. The follow-
ing procedure is even simpler than the breadth-first search algorithm from Section 9.2,
however, since there is no need to keep track of which vertices have been visited (we know
that the children of a vertex have never been seen when we are looking at that vertex).
procedure leveLprocess(r : root of ordered tree)
{L is a list of vertices waiting to be processed}
L - (r)
while L is not empty do
begin
v _ first element of L
remove v from L
process v
for each child c of v from left to right do
add c to the end of L
end
return

35. There are a few base cases to handle-if the root has no children (automatically an AVL-
tree), or if there is only a right child (an AVL-tree if the right subtree has height 0), or
vice versa. In the general case, three things must be satisfied: The heights of the subtrees
must differ by at most 1, and each subtree must be an AVL-tree. The following procedure
incorporates these observations in a recursive algorithm.

procedure A VL( r : root of binary tree)


if r has no children then return( true)
else if r has no left child then
return(truth value of height(righLchild(v) = 0))
else if r has no right child then
return(truth value of height(lefLchild(v) = 0))
else return(truth value of
Iheight(lefLchild(v)) - height(righLchild(v))1 ~ 1
/I. AVL(lefLchild(v)) /I. AVL(righLchild(v)))

37. Let x be the first vertex in the first list: It needs to be the root of the tree. Find x in the
second list, and let L1 and L2 be the lists of vertices that precede and follow x in the
second list, respectively. A necessary condition that the tree exists is that the first list
consist of the vertices in L 1 , in some order, followed by the vertices in L2, in some order.
If the condition is met, then the left and right subtrees of x are determined recursively
by L1 and L2 and their preorder arrangements given in the first list.
Section 9.4 Further Applications of Binary Trees 177

SECTION 9.4 Further Applications of Binary Trees


1. We can put any word we wish at the root. Suppose that we decide that it will be "dog."
This forces "cat" to be its left child, since it is the only vertex in the left subtree (since
it is the only word in the list that precedes "dog" alphabetically). We again have a lot of
choice for the right subtree, however: Any of the remaining five words can be the right
child of "dog." We might choose "red." There are further choices for this vertex's left
child, and so on. The tree we have been discussing might end up like this.

If we make other choices along the way, such as deciding to put "tiger" at the root, then
our tree could end up like this.

3. (a) Since boy -< girl, we move to the left subtree, rooted at "dog," and apply the
algorithm recursively here. Now boy -< dog, so we move left again. Next boy -< cat,
and we move to the empty left child. Since this vertex is empty, the search has been
unsuccessful, and we return O. This returned value is passed back through all the layers
of recursion and becomes the final answer.
(b) This is even quicker. We find that "boy" precedes "cat" and immediately drop off
into the empty left subtree, so the output is again O.
Chapter 9 TREES
178

5. We start by placing "tuffet" at the root. As each new word is encountered, we use
Algorithm 2 to insert it in the appropriate spot. First "a" is compared to "tuffet" and is
found to precede it. Since "tuffet" had no left child, "a" becomes its left child. Next we
want to insert the word "on." We compare it to "tuffet" and find that we must move left
and insert it somewhere in the left subtree (calling the procedure recursively). At this
point, since "on" is greater than "a," and since "a" has no right child, we insert "on" as
the right child of "a." The return from the recursive call is followed by the return from
the main call to the procedure, and we have finished. In a similar manner we insert all
the remaining words. The tree ended up very unbalanced.

7. (a) The letter F occurs as the right child of the left child of the left child of the right
child of the root. In order to reach it, we must, starting at the root, move right, then left,
then left again, and finally right. Since we encode a move to the right with a 1 and a
move to the left with a 0, the letter F is encoded 1001. Similarly the next letter in the
message, I, is reached by moving right, then left, then right, so its code is 101. Thus the
code for FI is 1001101. We continue in this way, encoding D as 1110 and 0 as 1100.
Putting this all together, we have the entire encoding of FIDO: 100110111101100.
(b) This is similar to part (a); the encoding of SIT is 010101011.
(c) The encoding of this word is fairly long because the code for W, which occurs three
times, requires five bits. The answer is 100011001111011110110011110.

9. For the first tree, we calculate as follows. The word "dog" occurs with relative frequency
0.10, and since it is at the root it requires only one comparison to find it. Therefore it
contributes 0.10·1 = 0.10 to the average. There are two words at levell, "cat" and "red,"
and they require two comparisons to find (one comparison with "dog" and the successful
comparison). Since they occur with relative frequency 0.35+0.05 = 0.40, they contribute
0.40 . 2 = 0.80 to the average. Similarly, for the third we level, there is a contribution of
= =
(0.05 + 0.05)·3 0.30; and for the fourth level the contribution is (0.30+ 0.10)·4 1.60.
Section 9.4 Further Applications of Binary Trees 179

Therefore the average number of comparisons needed for a successful search in the first
tree we drew for Exercise 1 is 0.10 + 0.80 + 0.30 + 1.60 = 2.80. Similarly, for the second
tree the average is
0.05.1 + 0.05·2 + (0.10 + 0.10) ·3+ (0.35 + 0.30 + 0.05) ·4= 3.55.

11. This proposition is false. The stated condition is necessary but not sufficient. For a
counterexample, take a binary search tree with just three words in it: "hello" at the root,
"goodbye" as the left child of the root, and "mayday" as the right child of "goodbye."
The given condition is satisfied at both internal vertices, but "mayday" cannot be in the
left subtree of "hello" (which precedes it alphabetically) if this were to be a binary search
tree.

13. Three cases must be handled. If the word we are looking for (call it x) is the root r,
then we are finished; we return r. Otherwise we move either to the left subtree or to
the right subtree, according as x ~ contents(r) or vice versa. In either of these cases
there are two subcases. If the subtree in question is empty, then we create a new vertex,
make it the left or right child of the root, as appropriate, fill it with x, and return it.
Otherwise we recursively continue in the subtree. Our algorithm in pseudocode is shown
here.

procedure Jind_or_insert(r: root of nonempty binary search tree, x: word)


if x = contents(r) then return(r)
else if x ~ contents(r) then
if lefLchild(r) = 0 then
begin
create a new vertex v
contents( v) t - X
lefLchild(r) t - v
return(v)
end
else return(Jind_or_insert(lefLchild(r), x»
else {x ~ contents( r) in this case}
if righLchild(r) = 0 then
begin
create a new vertex v
contents( v) t - X
righLchild(r) t - v
return(v)
end
else return(Jind_or_insert(righLchild(r), x»
180 Chapter 9 TREES

15. We should make the tree as balanced as possible, with all leaves at level h or at level
h - 1. This will give us a tree with the minimum possible height, and there will be no
missing children in the tree except at the bottom level. In order to form such a tree if
r
there are n words, we simply make the n/21 th word the root and recursively apply this
procedure to the words that are thereby forced to go into the left and right subtrees. Two
examples of such a tree would be the tree shown in Figure 9.22 and the same tree with
the word "cat" removed.

17. Certainly one way for the substring 11111 to enter the message is as the encoding of Y.
However, it could also occur, for example, if the letter T was immediately followed by
the letter D, since the codes for these two letters are 011 and 1110, respectively.

19. We can draw all the possible full binary trees with four leaves (and therefore, by Theorem 3
in Section 9.1, three internal vertices), as shown here. Note that of these five trees, only
the first is really different (as an unordered tree); the others all have one code of length 1,
one code of length 2, and two codes of length 3.

21. (a) Initially each letter is a vertex by itself, with its own frequency. We start by combining
the two least frequent vertices, E and F, as children of new node t1 , whose frequency is
=
0.10+0.15 0.25. Then we form t 2 , with children C and D, and frequency 0.15+0.15 =
0.30. At this point the two vertices with smallest frequencies are t1 and B, so we make
them the children of t3, whose frequency is 0.15 + 0.25 = 0.40. Next t4 has t2 and A
as its children and frequency 0.30 + 0.30 = 0.60. Finally t4 and t3 become children of
the root. The tree is as shown here.

E F
Section 9.4 Further Applications of Binary Trees 181

(b) Following the same procedure as in part (a), we obtain the following tree, where the
symbol A has relative frequency 0.40.

E F

(c) The tree obtained this time looks like this, essentially the same as in part (b).

E F

23. If this were not the case, then we could exchange the positions of u and v to achieve a tree
with smaller average code length. We would cut down on the code length by the difference
in the relative frequencies between u and v times the number of levels separating them.

25. We will show this inequality by constructing a function f from permutations of {I, 2,
... , n} to binary trees; if we can show that this function is surjective, then we will know
that the number of trees is at most n!, the number of permutations. Given permutation
7r, construct a binary search tree by inserting the symbols of 7r, in order; f( 7r) is the
underlying binary tree. For example, if 7r is 35124, then the following tree is obtained.
182 Chapter 9 TREES

This function is onto the set of binary trees with n vertices, since given any such binary
tree, we can label its vertices with the set {I, 2, ... , n} in inorder and let 71" be the
permutation obtained by listing the labels in preorder-clearly f( 71") is the ,given tree.
(In our example, given the tree shown there, we would have 71" equaling 31254.) Thus
the number of binary trees is at most n!. Furthermore any binary tree in which the root
has two children (and for each n ~ 3 there is at least one such tree) can be obtained
from at least two different permutations, the usualleft-to-right preorder and a backward,
right-to-Ieft, preorder. The conclusion follows.

SECTION 9.5 Game Trees


1. We draw the game tree by putting the initial position at the root, representing the piles
of stones by the integers 3 and 2. According to the rules of the game, the first player
may now remove one, two, or all three of the stones from the first pile, leaving positions
22, 2 1, and 2, respectively; or he may remove one or both of the stones from the second
pile, leaving pos,itions 31 or 3. These five vertices are therefore the children of the root.
To find the children of these vertices we again invoke the rules, For example, the children
of 22 are 21 and 2. We continue in this way until the entire tree is constructed. The
following diagram shows most of the tree, but we have not filled in portions that occurred
elsewhere,
Section 9.5 Game Trees 183

r
l
r

For example, the subtree rooted at 21 {)ccurred rooted at the first grandchild of the root,
so we do not repeat it as the second child of the root. We will be able to determine the
value of the second child of the root by knowing the value of the first grandchild (since
the rules for the two players are the same).
(b) We start from the bottom left. Since the person with no move loses, the position at
the far bottom left is a loss for the second player; in other words, it has value 1 to the
first player. Therefore its parent, the square vertex with position 1, is also a win for the
first player. In turn its parent is 11, and 11 has only one child (there is only one move
the second player can make when faced with 11). Therefore it, too, has value 1. Now
since this represents a winning move for the first player when faced with 21, we see that
the value of the first grandchild of the root is also 1. (We have also filled in the rest of
that subtree, and 21's other children have value -1, but that is irrelevant here, since the
value of 21 is the maximum of the values of its children.) Next to determine the value of
the first child of the root (the circle position 22), we need to know the value of its other
child, namely 2 in a square. But this is clearly 1 also, since the first player can win when
faced with that position by taking both stones. Returning now to the circle position 22,
we see that both of its children have value 1, so it must have value 1 (the minimum of
1 and 1). This is enough to determine the value of the game, for the value of the root
is the maximum of the value of its children. In other words, the first player can win by
moving to position 22 on his first move.
Note that we did not need to compute the values of the rest of the vertices in the
tree, although they are shown in the diagram. For example, the value of the circle vertex
2 1 is -1, since we found the value of the square vertex 2 1 to be 1 (this follows by
symmetry-what is good for the first player when it is his turn to move must also be
good for the second player when it is her turn to move).
184 Chapter 9 TREES

(c) As remarked in part (b), the first player wins the game by taking one stone from
the pile with three stones. Then if the second player clears one pile, he clears the other;
otherwise he leaves position 11 for her.

3. (a) Each vertex containing a number k ~ 3 has three children, with positions k - 1,
k - 2, and k - 3. We build the game tree from the top down, as shown here. Only a
portion needs to be drawn in detail, as we will see in part (b).

(b) The circle vertices with 0 have the value 1, since the first player wins when the second
player cannot move. Similarly, the square vertices with position 0 have the value -1. We
fill in the values from the bottom up, finding that the square 1 has value 1 (and therefore
by symmetry the circle 1 has value -1), the circle 2 has value -1 (the minimum of the
values of its two children), the square 3 has value 1, and so on. Ultimately, we find that
the root has value 1.
(c) The first player wins, since the root has value 1. Only one child of the root has
the value 1, however, so the first player must be careful and take two stones (leaving
position 4) as his first move; otherwise he moves to a position with value -1 and the
second player can win.

5. (a) The game tree is shown here. We have omitted much of it, relying on facts obtained
in Example 1 and Exercise 4. For example, we saw in Exercise 4 that the value of circle
position 22 (second player to move) was 1, so we do not draw the subtree rooted there.
Section 9.5 Game Trees 185

(b) The values of the leaves are obtained from the results of Example 1 and Exercise 4.
Then we compute the values of the internal vertices by the basic rule, that the value of a
square vertex is the maximum of the values of its children (the first player will move to
maximize the payoff), and the value of a circle vertex is the minimum of the values of its
children (the second player will move to minimize the payoff).
(c) Since the value of the root is 1, the first player wins. Note that moving to position
2 2 is the only winning play.

7. Note that "Blue wins" really means "Blue will win if he follows the proper strategy." If
n = 0 or 1, then the statement is obvious. That is our base case of an inductive proof.
Assume the inductive hypothesis that in a game with a smaller number of piles of one
stone each, Blue can win if the number of stones (i.e., piles) is odd, and Red can win if it
is even. Now assume that n is odd and greater than 1. Blue takes one stone and by the
inductive hypothesis wins (he is now the second player in the game with a smaller, even
number of stones). Finally assume that n is even and greater than o. If Blue takes one
stone, then Red wins by the inductive hypothesis (she is now the first player in the game
with a smaller, odd number of stones). If Blue combines two piles into one, then Red
removes the new pile and wins by the inductive hypothesis (there are now n - 2 stones,
and n - 2 is a smaller, even number).

9. There is very little choice here. Red, whose turn it is to move when the curtain opens on
this drama, must first complete the upper right-hand square. Then she can draw either a
vertical segment or a horizontal segment; the two possibilities are shown in our tree. Blue
must then complete the square that is offered, and he has only one remaining move, up
to symmetry. The final position in either case has Red two squares ahead of Blue, so the
value of both leaves of our tree is - 2. Working up toward the root, we see that the value
of every vertex in this tree is also -2. What we see here is just one small subtree of the
entire game tree for this game, starting from the empty game board with nine dots.
186
Chapter 9 TREES

-2

11. In each case, we are asking for the number of ways for the game to proceed through the
first move of each player. This is a counting exercise.
(a) There are 20 opening moves in chess: Each of the eight pawns can move either one
square forward or two, and the two knights can each move to two different spots. The
second player can respond to each of these 20 moves with any of 20 similar moves from
her side. Thus the answer is 20 . 20 = 400.
(b) There are seven moves for each player to begin with (two moves for each of three
checkers and one move for the checker next to the edge of the board). Thus the answer
is 7·7 = 49.
(c) The game board has J rows of dots, with J dots in each row. In each row there
are J - 1 line segments that can eventually be drawn, so there are a total of J( J - 1)
horizontal line segments. Similarly there are J(I - 1) vertical segments. Thus there are
J(J - 1) + J(I - 1) moves in the entire game. Call this quantity n. Anyone of these n
moves can be the first move, and any of the remaining n - 1 moves can be the second.
Therefore the answer is n( n - 1). If we wanted to discount for symmetry, the answer
would be smaller, but harder to compute.

13. (a) A portion of the game tree is shown here. It is too big to draw in its entirety. We make
use of the observation made in the text that Red will always move to a position involving
smaller numbers and Blue will always move to a position involving larger numbers.
Section 9.5 Game Trees 187

(b) The values have been filled in from the bottom. The value of each leaf is the number
that is left (by definition of the payoff in this game). Then from the bottom up the value
of each internal square vertex is the maximum of the values of its children, and the value
of each internal circle vertex is the minimum of the values of its children. The value of
the entire game is 5. Note that almost all the vertices have the value 5, so it is hard
for the game to end with any other outcome, even if the players do not play their best
strategies.

15. (a) This game and the analysis are very similar to nim. Really all that changes is that
the value of a leaf is exactly opposite to what it was before. The relevant portion of the
game tree is shown here.
188 Chapter 9 TREES

(b) As usual we analyze the tree by finding the values from the bottom up. The circle
O's have the value -1 (since Red wins by reaching the position with no stones), and
the square O's have the value 1 (since Blue wins in this case). For internal vertices the
minimax rule applies.
(c) Since the root has the value 1, the first player wins. He must move to the position
22 (taking one stone from the pile with three stones) if he wants to guarantee a win.

17. (a) A portion of the game tree is shown here; the complete game tree would be too large
to fit on the page. From the initial position, which we denote by 0(5)0 to indicate that
there is a pile of five stones remaining, and neither player has any stones in his own pot
yet, the first player can either give the five stones to the other player, yielding position
0(0)5, or split the pile into two piles, yielding position 0(4,1)0 or 0(3,2)0.

-1
10(2,2,1)01
-1
0(2,1,1,1)0

(b) A few final positions (leaves) are shown in this tree, such as 1(0)4 in the next to
last row. The position is a win for the first player if he has more stones in his pot, and
it is a win for the second player if she has more stones in her pot. The position 1(0)4 is
a win for the second player, for example, so it has value -1. The values of the vertices
in the tree shown here were computed by extending the relevant branches of the tree, or
by common sense (for instance, 3(1)1 is a win for the first player, since he already has a
majority of the stones).
(c) Since the value of the root is -1, the second player wins this game. The strategy
that she must follow is indicated by the paths of -1 '8. For example, if the first player
moves to 0(4,1)0 on his first move, then the second player can move to 0(3,1,1)0 or
0(2,2, 1)0 as her response.
1S9

19. Suppose that there are two piles, of sizes m and n. If m = n then Red wins as follows.
If Blue ever merges the piles, then Red takes the resulting pile and wins. Otherwise Red
copies Blue's take in the other pile (for instance, if Blue takes 17 stones from one pile,
then Red takes 17 stones from the other). Since Red will never be at a loss for a move,
she wins. On the other hand, if m # n, then Blue wins by taking 1m - nl stones from the
larger pile to create the position of two piles of equal size, and then he is in the position
that Red was in-the two piles are of equal size and he is the second player; thus Blue
wins this game. To summarize: Red wins if and only. if the piles are of equal size.

21. (a) Maintain a global list of positions already analyzed, and their values. As a first
alternative when P is not a leaf, check the list and return the appropriate value if the
position is on the list. Otherwise proceed with the recursive algorithm, but make sure to
update the list before returning the value. Note that part of the information kept for each
position already analyzed is the player whose turn it is to move; if the game's rules are
symmetric, then a position in which Blue is about to move will have the negative value
of the same position in which Red is about to move, and vice versa.
(b) Add one more parameter to the procedure, depth_ to_go, which will keep track of how
deeply to continue to recurse. The initial call to game_ value uses a predetermined value
of depth-to_go. Each recursive call to game_value passes on depth-to_go-1 (or perhaps
some other value depending on the situation). As a first alternative when P is not a leaf,
if depth_ to_go = 0, then return the value determined by the heuristic evaluation function.
(c) Add one more parameter to the procedure, goal. The idea is that once the procedure
realizes that its value is going to be worse than goal, it just returns goal. The initial
call to game_ value uses goal = 00. Modify the first innermost begin ... end block of the
procedure to read as follows.
begin
Q t-- (P followed by move m)
v' t-- game_value(Q, Red, v)
if v' > v then
begin
v t-- v'
if v 2: goal then return(goal)
end
end
Modify the second innermost begin ... end block in a similar way (with each inequality
reversed).
(d) The first outermost begin ... end block is changed to read as follows (and the second
in a dual way).
begin
for each legal move m for Blue do
if game_value(P followed by move m, Red) =1
then return(l)
return( -1)
end
190 Chapter 9 TREES

23. (a) The initial position is P = N (the set of natural numbers). A move consists of
replacing f by anonempty proper subset of Pif Pis infinite) or any proper subeet of
p ~f P 1s Rnite. It would be foolil3h for any player to move to a finite set, since then
the opponent would immediately move to the empty set and win. Thus each player will
always move to an infinite set, and the game will continue forever.
(b) Again the initial position is P = N. This time a move consists of replacing P by a
proper subset of P. The first player can win immediately by replacing N by 0.
(c) As above, the initial position is P = N. A move consists of replacing P by a finite
proper subset of P. The game cannot go on forever, since as soon as the first move
is made, say to a set Q, then only IQI more moves can be made before the empty set
appears. On the other hand, consider the game that consists of the first player's moving
to any subset of cardinality /-1, with each subsequent move being to remove one element
from the remaining set. This game lasts / moves.
Section 10.1 Shortest Paths and Longest Paths 191

CHAPTER 10
GRAPHS AND DIGRAPHS
WITH ADDITIONAL STRUCTURE
SECTION 10.1 Shortest Paths and Longest Paths
1. (a) By inspection we can write down the paths. Edge al is a path of length 1. There
are two paths of length 2: a, b, 1 and a, e, I. There is one path of length 3: a, b, c, I.
(b) The weight of path a, 1 is just the weight of the edge, namely 5. The weight of
a, b,1 is the sum of the weights of the edges ab and bI, namely 3 + 1 = 4. Similarly
the weight of a, e, 1 is 2 + 6 = 8, and the weight of a, b, c, 1 is 3 + 3 + 3 = 9.

3. The following picture shows the weighted digraph model of this situation. For convenience
we have changed units, so that each weight represents 1000 pieces of mail. Thus, for
example, the edge from B to C is labeled 4, since there are 4000 pieces of mail from
banks to consumers; and the edge from C to B is labeled 0.3 since there are 300 pieces
of mail in the opposite direction.

c

~\3E 0.5

5. We represent the operation of the algorithm by a sequence of snapshots, showing the labels
of all the vertices. The number following each vertex is the current value of distance from
the source (vertex b in this exercise) to that vertex (using only vertices that are final).
The superscript is the vertex from which the currently known path comes. An asterisk
indicates that the vertex has been marked final. Once the sink (in this case vertex e) has
been marked final, the algorithm is finished. Initially, the source has distance 0, and all
the other vertices have distance 00.
a:oo b:O c:oo d:oo e:oo 1:00 g:oo
192 Chapter 10 GRAPHS AND DIGRAPHS WITH ADDITIONAL STRUCTURE

Since vertex b is the nonfinal vertex with smallest label, it becomes final and the distance's
to the other vertices are updated. In this case, the label on vertex a is 3, since there is
an edge of weight 3 from b to a, and the superscript on a is b; and similarly for vertices
c and f.
a : 3b b*: 0 c : 3b d : 00 e : 00 f : 1b 9: 00

Next vertex f becomes final. The label on vertex 9 becomes 51, since there is now a
known path from the source to 9 passing through vertex f, of weight 1 + 4 = 5, and
similarly for vertex e. The labels on vertices a and c do not change, however, since the
path through vertex f is no better than the previously known paths to these vertices.
Thus our snapshot looks like this.
a : 3h b* : 0 c : 3b d : 00 Ib g: 51r:
We continue in this way, obtaining the following snapshots.
a* : 3b b* :0 c: 3b d: 00 e : 5a r: Ib 9 : 51
a* : 3b b* :0 c* : 3b d: 5c e : 5a r: Ib g: 51
a* : 3b b* :0 c* : 3b d* : 5c e : 5a r: Ib 9 : 51
a* : 3b b* :0 c* : 3b d* : 5c e* : 5a r: Ib 9 : 51

At this point vertex e has been labeled, so we know that the minimum weight path has
weight 5, and comes from a. Since the superscript for vertex a is b, we know that the
path arrived at a from b. Thus the entire path is b, a, e.

7. We give a proof by mathematical induction on l. If 1 = 1, then the (i, j)th entry of


A = AI, namely, a;j , is the weight of the minimum weight walk of length 1 from vertex i
to vertex j: Either there is a walk along the edge from i to j, or else there is no edge
and a;j = 00. Assume the inductive hypothesis, that the statement is true for 1. Then
a minimum weight walk of length at most 1 + 1 from i to j is either a minimum weight
walk of length at most 1, or consists of a minimum weight walk of length I to some
vertex k, followed by edge kj. Let at] denote the (i, j)th entry of AOl. The weight of a
minimum weight walk of length at most 1 from i to j is thus at], which can be written
as ar] + 0 = at] + ajj ; and the weight of a minimum weight walk of length 1 from i to k
followed by the edge kj is atk + akj. Thus the (i,j)th entry of A<>(I+l) = AOl <>A, Ilamely
min (ark + akj), is the weight of a minimum weight walk of length at most 1 + 1 from i
l<k<n
to r

9. Consider the digraph consisting of edge ab with weight 10, edge be with weight -6, and
edge ca with weight -7. There is no minimum weight walk from a to b, since we can
make the weight of a walk as small as desired simply by traveling arouw.l the triangle
sufficiently often before stopping at b.
Section 10.1 Shortest Paths and Longest Paths 193

11. We represent the execution of the algorithm in the same way as in the solution to Exer-
cise 5. At each stage we find the vertex with the smallest label, make it final, and then
update the labels on all the vertices adjacent to the newly finalized vertex, if a path using
that vertex is less costly.

a:O b:oo c:oo d:oo e:oo f:oo g:oo h:oo i: 00 j:oo k:oo I: 00 z:oo
a*:O b:3 a c:1 a d:5 a e:oo f:oo g:oo h:oo i: 00 j:oo k:oo I: 00 z:oo
a*:O b:3 a c*: 1a d: 5a e:3 c f: 3c g:oo h: 5c z: 00 j:oo k:oo I: 00 z:oo
a*: 0 b*: 3a c*: 1a d:5 a e:3 c f:3 c g:oo h: 5c z: 00 j:oo k:oo I: 00 z:oo
a*:O b*:3 a c*: 1a d:4 e e*:3 c f:3 c g:oo h: 5c i: 5e j:oo k:oo I: 00 z:oo
a*:O b*: 3a c*: 1a d:4 e e*:3 c j*:3 c g:41 h: 5c i: 5e j:oo k:oo I: 00 z:oo
a*:O b*:3 a c*: 1a d*:4e e*:3 c j*:3 c g:41 h: 5c i: 5e j:oo k:oo I: 00 z:oo
a*:O b*: 3a c*: 1a d*:4 e e*: 3c j*:3 c g*:4 1 h:5 c i: 5e j:7 g k:9 g I: 00 z:oo
a*:O b*: 3a c*: 1a d*:4e e*:3 c j*:3 c g*:4 1 h*:5 c i: 5e j:7 g k:9 g I: 00 z:oo
a*:O b*:3 a c*: 1a d*:4 e e*:3 c j*:3 c g*: 41 h*: 5c i*: 5e j:7 g k:9 g I: g; z:oo
a*:O b*: 3a c*: 1a d*:4e e*:3 c j*:3 c g*:41 h*:5 c i*: 5e j*:7g k:9 g I: gi z:oo
a*:O b*: 3a c*: 1a d*:4 e e*:3 c j*:3 c g*: 41 h*: 5c i*: 5e j*:7 g k*:9g I: gi z: 13 k
a*:O b*: 3a c*: 1a d*:4 e e*:3 c j*:3 c g*: 41 h*: 5c i*: 5e j*: 7g k*:9g l*: g; z: 111
a*:O b*: 3a c*: 1a d*:4e e*:3 c j*:3 c g*: 41 h*:5 c i*: 5e j*: 7g k*:9g l*: gi z*: 111

At this point we know that the minimum weight path has weight 11. Furthermore, by
tracing the superscripts backward from vertex z, we see that a minimum weight path is
a, c, e, i, I, z.

13. We assume that the vertices of the digraph are 0, 1, ... , n, where 0 is the source and n
is the sink. The weight of edge ij is w(i,j). We compute the completion time for each
vertex, T( v), and we keep track of the pointers needed to reconstruct the critical path
(previous(v) is a predecessor of v that causes the completion time of v to be as large as
it is).
194 Chapter 10 GRAPHS AND DIGRAPHS WITH ADDITIONAL STRUCTURE

procedure critieaLpath(G : weighted acyclic digraph)


for i - I to n do
T( i) - -1 {to indicate no time yet assigned}
T(O) - 0 {completion time of the source is O}
for i - I to n do {compute T for (i.e., label) another vertex}
begin
v-n
v' -0
while v' ¥- v do {find vertex all of whose predecessors are labeled}
begin
v' - v
for j - 1 to n - 1 do
if jv is an edge and T(j) = -1 then v _ j
end {v is such a vertex}
for j - 1 to n - 1 do {label v}
if jv is an edge and T(j) + w(j, v) > T(v) then
begin
T(v) - T(j) + w(j, v)
previous( v) - j
end
end
return(T, previous)

15. We claim that a maximum weight Hamilton cycle is b, e, e, d, a, b, whose weight is 5 +


5 + 4 + 2 + 3 = 19. (This cycle was obtained by inspection, by trying to use edges with as
large a weight as possible.) The proof that this cycle has maximum weight is similar to
the argument given in Example 6. The best that we could possibly hope for would be to
use the two edges of largest weight adjacent to each vertex. This would give a total weight
of [(3 + 3) + (5 + 4) + (5 + 5) + (4 + 2) + (5 + 4)]/2 = 20. Now in fact this is impossible
to achieve, since if we used be and ee (the only edges of weight 5 incident to e), then
we could not use be (otherwise the cycle would close prematurely); this means that we
could not achieve the desired maximum weight as we pass through vertex b. Therefore
20 - 1 = 19 is the best possible.

17. (a) There are n! Hamilton cycles. (We are assuming that we do not recognize two cycles
with the same edge sets as identical. Thus a cycle is determined by a permutation of the
vertices of the graph.) Therefore it would take

20! . 10- 5 seconds ~ 2.4 x 10 13 seconds ~ 770,000 years


to carry out this analysis.
(b) We are asked to find the largest n such that n!· 10- 5 :::; 3600. This is equivalent to
n! :::; 3.6 x 108 . Since 12! ~ 4.8 x 10 8 and 11! ~ 4.0 x 10 7 , the answer is 11.
Section 10.1 Shortest Paths and Longest Paths 195

19. (a) If there is no path from s to t, then vertex t can never be marked final. Thus the
while loop will never terminate, and the procedure will never halt. (What will happen is
that the vertex v chosen in that loop will continue to be the last vertex chosen.) Similarly,
it will not halt if there is no directed path from s to t, in the case of a digraph.
(b) Suppose that we insert before the statement final( v) f- true the following statement.
if m = 00 then return( distance, previous)
Then in case the algorithm was unable to find a new vertex to mark final it will imme-
diately halt.

21. We can apply Dijkstra's algorithm n -1 times, once with each vertex (except one) as the
source (we change the stopping condition, as in Exercise 12, so that all distances from
the source are computed). This will determine the distances between all pairs of vertices
3
in O(n ) steps (O(n) iterations of an O(n 2 ) algorithm). The smallest among these n 2
values is the diameter, and we can find it in O(n 2 ) steps.

23. Work backward from the sink, labeling vertices. The label L( v) is intended to be the
latest time at which the subproject represented by v may be started in order to finish the
entire project by time T(t). We start by setting L(t) = T(t), which really says nothing,
except that we get to the end of the project at the final completion time. Successively
find a vertex u all of whose successors have been labeled (this is possible because the
digraph is acyclic), and set L(u) = min(L(v) - w(u,v», where the minimum is taken
over all successors v of u. We do this to maintain the possibility of arriving at vertex v
at the right time.
196 Chapter 10 GRAPHS AND DIGRAPHS WITH ADDITIONAL STRUCTURE

SECTION 10.2 Minimum Spanning Trees


1. (a) We carefully plot the 10 points given, together with the origin, obtaining the following
figure (ignore the lines temporarily).

(b) According to Prim's algorithm, we can build the tree by successively adding in edges
of smallest weight (which here is physical distance) between vertices already in the tree
and vertices not yet included. Let us start at the central computer (the circled point in
the figure). The nearest vertices are those at (11,11) and (11, -11), so they are added
to the tree. Next the vertex at (21,20) is closest (it is near the vertex at (11,11», so we
add it. We continue in this way, just using our eyesight to determine the unused vertex
closest to the tree at each stage. The final tree is as shown above.

3. In each case we break all ties in favor of alphabetical order (the edges are assumed to be
listed in the alphabetical order of their endpoints). At each stage in the execution of the
algorithm, we add an edge of smallest weight whose addition will not create a cycle (we
make this determination visually).
(a) We add the edges in the following order: b f, ae, cd, de, ab, f g. The total weight
of the tree is 1 + 2 + 2 + 2 + 3 + 4 = 14.
(b) We add the edges in the following order: bd, ad, cd, ae. The tree has weight
1+2+2+3=8.
(c) We add the edges in the following order: ac, de, f g, hi, be, ee, ef, eh, ij, jl, lz,
jk, to obtain a minimum spanning tree of weight 1+1+1+1+2+2+2+2+2+2+2+3 = 21.
(d) We add the edges in the following order: ad, be, ae, be j the tree has weight 1 + 1 +
2 + 2 = 6.
Section 10.2 Minimum Spanning Trees 197

5. (a) When applying Prim's algorithm, ,,:e can start with vertex v and edge e. The
minimum spanning tree we find will perforce contain e.
(b) Consider K 3 , in which each edge has weight 1. Let e be one of the edges. Then
the conditions of this problem are satisfied. However, the tree consisting of the other two
edges of K3 is a minimum spanning tree, and it does not contain e.

7. (a) We express the algorithm in pseudocode, where the argument G is a complete


weighted graph with vertices 1, 2, ... , n. We construct path as a list of vertices by
chosing at each stage an edge of smallest weight that will take us to a vertex we have
not visited before. Clearly after n - 1 iterations this will produce a Hamilton cycle, but
there is no reason to believe that it will produce a minimum weight Hamilton cycle.
procedure greedy_hamilton(G : complete weighted graph)
path - (1)
visited(1) - true
for j - 2 to n do
visited(j) - false
v-I
for i - I to n - 1 do
begin
m-oo
for j - 1 to n do {find edge of smallest weight
to an unvisited vertex}
if (-.visited(j)) A (w(v,j) < m) then
begin
w-j
m - w(v,j)
end
path - path followed by w
visited(w) - true
v-w
end
path - path followed by 1 {close the cycle}
return(path)
(b) Following this algorithm, we start at vertex a and choose the least weight edge
incident to the vertex at which we are currently located that will take us to a vertex that
we have not yet visited. In doing so we obtain the cycle a, d, b, e, c, a. This cycle has
total weight 2 + 1 + 4 + 5 + 3 = 15, whereas we saw in Example 6 of Section 10.1 that a
minimum weight Hamilton cycle has weight 13.

9. We assume that the edges, denoted el, e2, ... , em, have been sorted so that w(eI) ~
w( e2) ~ ... ~ w( em). We will have the algorithm go through the list of edges only once,
including any edge that does not complete a cycle in the spanning forest being generated
as we go along. In pseudocode the algorithm goes as follows.
198 Chapter 10 GRAPHS AND DIGRAPHS WITH ADDITIONAL STRUCTURE

procedure sorted_kruskal( G : connected weighted graph)


{same setting as Algorithm 2}
j -1
F - the empty tree
for k _ 1 to n - 1 do {add n - 1 edges in all}
begin
while F U {ej} contains a cycle do
j _ j + 1 {pass over any edges that cannot be used}
F _ F U {ej} {this edge does not form a cycle}
j _ j + 1 {go on to consider the next edge}
end
return(F)

11. (a) There are at least two "obvious" ways to do this. One is to follow Prim's or Kruskal's
Algorithm, but add the largest weight edge at each stage, rather than the smallest weight
edge (consistent with the rules of the algorithm). The other solution would be to replace
each edge weight wee) by its negative -wee) and apply the algorithm as written (we
never used the fact that weights were positive).
(b) Following the first of the suggestions given here, we select the edges in the following
order: bc, df, ab, be, de. Thus the maximum spanning tree has weight 31.

13. We will show that after each deletion, the resulting graph still contains a mInImUm
spanning tree of G. Then since we end up with a tree, it must be a minimum spanning
tree. We proceed by induction on the number of deletions, the base case being T = G
(no deletions); we already know that G contains a minimum spanning tree. Now suppose
that T contains a minimum spanning tree S, and suppose that in the operation of this
algorithm, edge e is deleted to form T'. We must show that T' contains a spanning tree.
If e is not in S, there is nothing to prove. If e is in S, consider S - {e}. It is a forest
with two components, C I and C2 . Since e was in a cycle in T, there must be an edge
e' in T joining a vertex in C 1 and a vertex in C2 . Since e' was not deleted from T to
form T' (even though e' is in a cycle with e), we know that w( e') ::; w( e). Furthermore,
S' = S - {e} U {e'} is a tree. The weight of S' is at most the weight of S. Thus S' is
a minimum spanning tree of G, and S' is a subgraph of T' , since e' is in T'. In other
words, we have found the desired minimum spanning tree contained in T'.

15. It is not enough to observe here that if the weights of the edges are unique, then there are
no choices involved in the execution of Prim's or Kruskal's algorithm. All we proved in
this section was that these two algorithms produce minimum spanning trees; there may
well be (and are) other algorithms that give us minimum spanning trees as well, and we
have no control over how they might operate. What is asked for here is a proof that
no algorithm could ever possibly produce a different minimum spanning tree (under the
hypothesis that the edge weights are all distinct).
Section 10.3 Flows
199

For a valid proof, let T be the minimum spanning tree of G produced by Prim's
algorithm, containing edges el, e2, ... , en-I. We must show that there is no other
minimum spanning tree. Suppose instead that G does have another minimum spanning
tree, and let T' be one that agrees with T on el, e2, ... , ek for the largest possible k <
n - 1. Now proceed as in the proof of the correctness of Prim's algorithm. The tree Til
constructed there has strictly smaller weight than T', since w(eHd < w(e'). This is
impossible, since T' was a minimum spanning tree. Thus no such minimum spanning
tree T' f; T exists, so T is the unique minimum spanning tree.

17. Let Tk be the tree constructed after the kth pass through the outer loop of Prim's
algorithm. We will show by induction that each Tk is contained in some minimum
spanning tree of G; Theorem 1 follows by taking k = n - 1. The assertion is trivial for
k = o. Suppose that it is true for Tk. Let S be a minimum spanning tree containing
n. We must show that Tk U {ek+1} is contained in a minimum spanning tree. If ek+1
is in S, we are done. If not, look at S U {eHI}. It contains a cycle. Since THI does
not contain a cycle, there is some edge in S - Tk+1 on the cycle. We follow the cycle
around, starting at ek+l, until we come to the first such edge; call it e. Thus e was a
candidate when eHI was added to n, so w(e) ~ w(eHI). But S' = SU{eHd-{e} is
a tree, and its weight does not exceed the weight of S. Thus S' is the desired minimum
spanning tree containing THI.

SECTION 10.3 Flows


1. To produce a flow we need to choose a nonnegative flow in each edge no greater than
the capacity of the edge, so that the net flow into each vertex other than the source and
sink is o. There are many possibilities, such as the zero flow and the flows given in the
following table (none of these is a maximum flow).

su sv uv ut vt
1 1 0 1 1

l 2
3
3
2
0
0
1
1
2
2
2
2
0
1
1
0
2
2
3
3

3. We add 1 to the flow in each edge of the path, namely edges sv, vu, and ut. Note that
the flow along vu is currently - 2, since there is a flow of 2 from u to v. Hence we
increase it to -1, which means a flow of 1 from u to v. The new flow is as follows.
200 Chapter 10 GRAPHS AND DIGRAPHS WITH ADDITIONAL STRUCTURE

5. As a simple example we have the following network. The "bottleneck" is caused by the
edge in the middle; it is saturated, but neither of the other two edges is saturated .

.4,1 )
s
• 1,1 ) • 3,1 )
•t

7. We might try to push flow along some obvious paths. We can certainly send 2 units of
flow along the top: (s, b, e, t); 2 units of flow along a lower middle road (s, d, g, t), and
1 unit along the bottom (s, f, g, t). Further inspection shows that we can augment this
by 4 units along s, f, e, t, and again by 1 unit along s, b, e, d, g, t. In all this produces
the flow shown here. We will save any further attempts at improving this for Exercise 9.

9. We begin with the flow we obtained in Exercise 7 and carry out the labeling algorithm.
First we label the source (00, -) to indicate that any amount of extra flow can arrive at
the source. Then we process the source (the only labeled but as yet unprocessed vertex).
Only one edge from the source, sf, is not yet saturated. There is an excess capacity in it
of 9 - 5 = 4 units. Therefore we label f with (4, s) to indicate that 4 units of flow can
come from the source to vertex f. Now f is the only unprocessed labeled vertex, so we
look at it. The edge to vertex e has excess capacity of 7 - 4 = 3 units, so we label e with
(3, J). Similarly there is unused capacity (2 - 0 = 2 units worth) in edge eb, so we can
now label vertex b with (2, e). Again there is unused capacity (6 - 3 = 3 units worth) in
edge be, so we can now label vertex e. Since only 2 units could arrive at vertex b, only 2
units can go on to vertex e, so we label e with (2, b); in other words, the numerical label
on e is the minimum of the excess capacity through be and the numerical label on b. We
continue in this way and see that this extra 2 units can make it all the way to the sink.
The completed labeling process gives us the following picture.
Section 10.3 Flows 201

The heavy lines in this picture show the augmentation path s, " e, b, c, d, g, t,
which can be obtained in reverse order by following the second coordinates of the labels,
starting with the sink t. We add 2 to the flow in each edge along this path, obtaining
the flow shown below (ignore the labels for a moment).

Now we label this network. The labels on s, f, and e are obtained in the same
manner as before. We see that 1 unit of flow can make its way to vertex e. However,
at that point we are stuck, since both edges between e and unvisited vertices are now
saturated. Therefore the algorithm tells us that we have found a maximum flow. In fact
we can also read off the minimum cut from this picture. It is the set of edges leading
from labeled vertices to unlabeled ones, namely sb, sd, f g, eb, and et. The sum of the
flows in these three saturated edges, 3 + 2 + 1 + 2 + 4 = 12, is the value of this maximum
flow. This value is also the total flow out of the source and the total flow into the sink.

11. We present the operation of the algorithm in the following table, showing the flows at
each stage and the augmentations performed. The first row shows the zero flow and the
augmentation path found on the first pass. The new flow is shown in the second row, and
so on. The final flow (as well as the cut produced by the algorithm) is shown in the last
row. Note that there happened to be no "backward" edges involved here, in which the
flow decreased from one pass to the next. The flow we obtain is the same flow as that
found in the solution to Exercise 9.
.................----------------------

202 Chapter 10 GRAPHS AND DIGRAPHS WITH ADDITIONAL STRUCTURE

sb sd sf bc eb dg cd fe fg ct et gt
0 0 0 0 0 0 0 0 0 0 0 0 augment along s, b, c, t by 2
2 0 0 2 0 0 0 0 0 2 0 0 augment along s, f, e, t by 4
2 0 4 2 0 0 0 4 0 2 4 0 augment along s, d, g, t by 2
2 2 4 2 0 2 0 4 0 2 4 2 augment along s, b, c, d, g, t by 1
3 2 4 3 0 3 1 4 0 2 4 3 augment along s, f, g, t by 1
3 2 5 3 0 3 1 4 1 2 4 4 augment along s, f, e, b, c, d, g, t by 2
3 2 7 5 2 5 3 6 1 2 4 6 cut {sb, sd, fg, eb, et} determined

13. We could apply the Ford-Fulkerson algorithm to find the maximum flow and minimum
cut, but let us try to do it by inspection. In other words, we will find the· augmentation
paths by just looking for them as intelligent human beings looking at a useful picture,
rather than by the mechanical labeling process. We might begin by pushing 2 units of
flow along the path a, b, c, d, g, to come in through the vertex d (and note that this
is as much as we can possibly get through d, since the only edge coming into d has
capacity 2), and 4 units of flow along a, f, g (and this, too, is the best we can do, since
the capacity of edge f g is only 4). The argument given here shows that we have found
the maximum flow, namely 2 + 4 = 6. The corresponding cut is the two saturated edges
fg and cd; they are the only two edges from {a, b, c, e, f} to {d, g}.

15. Add a new vertex S to be the new source, and put an edge of capacity 00 from S to
each original source. This allows as much of the commodity as necessary to reach each
original source unimpeded.

17. Following the ideas in Exercises 15 and 16, we can imagine a supersource S to the left,
with edges Sa, Sb, Sc, and Sd, all of capacity 00, and a supersink T to the right with
edges jT, kT, and IT, again all with infinite capacity. Then we can apply the Ford-
Fulkerson algorithm, or try to find a maximum flow by inspection. Let us try the latter.
We really need not be concerned with the supersource and supersink explicitly-we just
think of as much flow as we need emanating from each of the four sources and as much
as we desire being absorbed by each of the three sinks. First we push 7 units of flow
along a, e, h, k. Four more units can travel along be; at e three of the units follow el
to I, and the remaining unit follows the path e, h, j. Now we try sending 9 units of flow
along bg. At' g, five of the units then travel along gj, and the remaining 4 units follow
g, i, k. We can sneak one more unit in along the augmentation path b, f, h, j and one
more along d, g, i, I. Finally, we can send 2 units directly from d to I. This gives us a
total flow of 24. To summarize, the flows we have obtained are shown in the following
picture.
Section 10.3 Flows 203

A few more minutes of staring at the network fails to show us any more augmentation
paths, so we think that maybe this is a maximum flow. To test this out, we see what
one pass of the labeling algorithm will produce. Vertices a, b, c, d, f, g, and i will be
labeled, but then the saturated edges ae, be, fh, gj, ik, ii, and dl-all the edges from
labeled vertices to unlabeled ones-form a cut, and its capacity is, indeed, 7 + 4 + 1 + 5 +
4 + 1 + 2 = 24. Our picture above shows the labeled vertices underlined, and the edges
in the cut are those that the gray swatch passes through.

19. First we alter the network using the idea in Exercise 18, expanding vertex d into vertices
d; and do (the subscripts stand for "in" and "out") with an edge dido of capacity 3, and
similarly for vertex e. The resulting network is shown here. Note that edges into d or e
are now directed into d; or e;, and edges out of d or e are now directed out of do or eo.

~...,.-+-... t

Before we look for a maximum flow, let us simplify things a bit. Vertex do has
only one edge coming in and one edge going out, so we can do away with it entirely by
replacing the path di, do, g by an edge dig of capacity 3 (the smaller of the capacities of
the two edges in series that we are eliminating). Similarly, we replace f, ei, eo by edge
204 Chapter 10 GRAPHS AND DIGRAPHS WITH ADDITIONAL STRUCTURE

leo, with capacity 5 . The network now looks like this. (We have removed the subscripts
for convenience.)

~~-.. t

Application of the Ford-Fulkerson algorithm (or finding augmentation paths by in-


spection) gives us the following maximum flow, with value 10. The corresponding cut is
{dg, Ig, ct, et}.

sb sd sl be dg Ie Ig cd ct eb et gt
316 4 3 5 1 2 2 1 4 4

21. One approach is to replace each undirected edge by a pair of antiparallel edges, each with
the capacity of the undirected edge. This allows flow to go in either direction. After each
new flow is found, we combine the flows on all pairs of antiparallel edges into a net flow
in one of each pair and no flow in the other.
There is a better, more general way to look at this problem, however. Each directed
edge currently comes with a maximum capacity, Gij; its minimum capacity is 0, indicat-
ing that no flow can go backward in an edge. If we want to allow flow in either direction,
then we can set the minimum capacity to be a negative number, Dij. More generally, let
Dij be the minimum allowable flow in edge ij. We require simply that Dij ~ Gij for
each edge and that the flow Fij satisfy Dij ~ Fij ~ Gij. In the case of undirected edges
we will take Dij = -Cij and impose an arbitrary direction on each edge. The algorithm
now takes on more of a symmetric flavor. The portion of the algorithm in which backward
oriented edges are considered is replaced with the following code.
else if wv is an edge of G with FWIJ > DWIJ then
begin
~' <- min(~, FWIJ - D wlJ )
{~' is necessarily greater than 0 }
label w : (~', v)
put w into L
end
Section 10.3 Flows 205

23. Following the hint, let us look for a minimum cut separating a from z. One good
candidate seems to be {ab, ac, de}, with a value of 3 + 1 + 1 = 5. If we can find a flow
of 5, then we will know that we have found both the maximum flow and the minimum
cut. It is not hard to find one, such as the following, by inspection. (We are free to orient
the edges in a convenient direction. The edges not mentioned here have a zero flow.)

ad de ac ce ei ab bc bl Ig ch hi ij hg il lz jg gk kz
1 1 1 1 2 3 2 1 1 212 1 1 1 2 4 4
$

Das könnte Ihnen auch gefallen