Автор: Johnsonbaugh R.  

Теги: mathematics  

ISBN: 0-13-117687-0

Год: 2005

Текст
                    |NEiTRL|l3TC|R’Ei NIANLIAL
DISCRETE
MATH EMATICIS
Richard Johnsonbaugh


Editor-in-Chief: Sally Yagan Acquisitions Editor: George Lobell Supplements Editor: ]ennifer Urban Vice President of Production & Manufacturing: David W. Riccardi Executive Managing Editor: Kathleen Schiaparelli Managing Editor: Nicole ]ackson Production Editor: Allyson Kloss Manufacturing Manager: Trudy Pisciotti Asst. Manufacturing Manager: Michael Bell Manufacturing Buyer: Ilene Kahn Supplement Cover Designer: Elizabeth Wright  PEARSON  PI‘ Copyright © 2005 by Pearson Education, Inc., Han Upper Saddle River, New Iersey, 07458. Pearson Prentice Hall.  All rights reserved. No part of this book may be reproduced in any form or by any means, without permission in writing from the publisher.  Pearson Prentice Hall® is a trademark of Pearson Education, Inc.  The author and publisher of this book have used their best efforts in preparing this book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The author and publisher make no warranty of any kind, expressed or implied, with regard to these programs or the documentation contained in this book. The author and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.  This work is protected by United States copyright laws and is provided solely for the use of instructors in teaching their courses and assessing student learning. Dissemination or sale of any part of this work (including on the World Wide Web) will destroy the integrity of the work and is not permitted. The work and materials from it should never be made available to students except by instructors using the accompanying text in their classes. All recipients of this work are expected to abide by these restrictions and to honor the intended pedagogical purposes and the needs of other instructors who rely on these materials.  Printed in the United States of America  10987654321  ISBN III-L3-LL?l:.fi?-III  Pearson Education Ltd., London Pearson Education Australia Pty. Ltd., Sydney Pearson Education Singapore, Pte. Ltd. Pearson Education North Asia Ltd., Hong Kong Pearson Education Canada, Inc., Toronto Pearson Educacién de Mexico, S.A. de C.V. Pearson Education—]apan, Tokyo Pearson Education Malaysia, Pte. Ltd. 
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13  Appendix  Table of Contents  29  41  49  73  83  109  129  151  175  181  193  209  215 
Chapter 1  Solutions to Selected Exercises  Section 1.1  2. Not a proposition 3. Is a proposition. Negation: For every positive integer n, 19340 7E n - 17. 5. Not a proposition  6. Is a proposition. Negation: The line “Play it again, Sam” does not occur in the movie Casablanca.  8. Not a proposition 10. No heads were obtained. 11. No heads or no tails were obtained. 14. True 15. True 17 . False 18. False 20. _.___  (fipv sq) Vp T  ’1"f.a‘>-3*-P8 ’1H’1H»-Q  T T T  21. (pV  *1'1>-3+—3*s mamao w~a~::~::S  23.  (p/\q)V(fipVq)  ’=1’1j>—]H"8 wawao +€>—3w>—3 
24.  26.  28.  32. 34. 35. 37. 38. 40.  42. 49. 53.  56. 57.  CHAPTER 1 SOLUTIONS  pq7‘fi(p/\q)V(7‘/\fip) TTT F TTF F TFT T TFF T FTT T FTF T FFT T FFF T pqrfi(p/\q)V(FqV7") TTT T TTF F TFT T TFF T FTT T FTF T FFT T FFF T  —(p /\ q). True. 29. p V -(q /\ 7-). True.  . Lee takes computer science and mathematics.  Lee takes computer science or mathematics. Lee takes computer science but not mathematics. Lee takes neither computer science nor mathematics. It is not Monday and either it is raining or it is hot. It is not the case that (today is Monday or it is raining) and it is hot.  Today is Monday and either it is raining or it is hot, and it is hot or either it is raining or today is Monday.  p/\q 43.p/\—»q 45.pVq 46. (pvq)/\-up 48.p/\-:7‘ p/\q/\7' 51. -wp/\—1q/\7' 52. -1(pVqV-:7‘) p q pexorq T T F T F T F T T F‘ F F  lung AND disease AND NOT cancer minor AND league AND team AND illinois AND NOT midwest 
CHAPTER 1  SOLUTIONS 3  Section 1.2  2  11.  19.  26.  33.  34.  36.  37.  39.  40.  43.  50.  53.  54.  If Rosa has 160 quarter—hours of credits, then she may graduate. If Fernando buys a computer, then he obtains $2000. If a better car is built, then Buick will build it. If the chairperson gives the lecture, then the audience will go to sleep.  Contrapositive of Exercise 2: If Rosa does not graduate, then she does not have 160 quarter- hours of credits.  False 12. False 14. False 15. True 17. True Unknown 20. Unknown 22. True 23. Unknown 25. Unknown Unknown 29. (p /\ 1") —-> (1 30. —((r /\ —q) —+ 1")  If it is not raining, then it is hot and today is Monday. If today is not Monday, then either it is raining or it is hot.  If today is Monday and either it is raining or it is hot, then either it is hot, it is raining, or today is Monday.  If today is Monday or (it is not Monday and it is not the case that (it is raining or it is hot)), then either today is Monday or it is not the case that (it is hot or it is raining).  Let p: 4 > 6 and q: 9 > 12. Given statement: p —-> (1; true. Converse: q —-> p; if 9 > 12, then 4 > 6; true. Contrapositive: —.q —-> —‘p; if 9 3 12, then 4 5 6; true.  Let p: I1] < 3 and q: -3 < 1 < 3. Given statement: (1 —-> 1); true. Converse: p —> (1; if |1| < 3, then ~3 < 1 < 3; true. Contrapositive: —-p —-> —q; if |1| 2 3, then either —3 2 1 or 1 2 3; true.  P,,=éQ 46.P,,=éQ 49.P,,=éQ PaéQ  (a) If p and q are both false, (p z'mp2 q) /\ (q z'mp2 p) is false, but p <—> q is true.  44.PEQ 47.PEQ  (b) Making the suggested change does not alter the last line of the z'mp2 table.  19 <1 n(p/M1) npvnq T T F F T F T T F T T T F F T T 
4  CHAPTER 1 SOLUTIONS  Section 1 .3  13. 14. 16. 17.  20.  21. 23. 24. 26. 29. 30. 34. 40.  42.  43.  45.  . 1 divides 77. True.  . The statement is a command, not a propositional function.  The statement is a command, not a propositional function.  . The statement is not a propositional function since it has no variables.  . The statement is a propositional function. The domain of discourse is the set of real numbers.  9. 3 divides 77. False. 11. For some n, n divides 7 7 . True. Some student is taking a math course. Every student is not taking a math course. It is not the case that every student is taking a math course.  It is not the case that some student is taking a math course.  There is some person such that if the person is a professional athlete, then the person plays soccer. True.  Every soccer player is a professional athlete. False. Every person is either a professional athlete or a soccer player. False. Someone is either a professional athlete or a soccer player. True. Someone is a professional athlete and a soccer player. True. 3~’v(P(£v) /\ Q(9=)) V~’v(Q(5v) -+ P(6v))  True 35. True 37. False 38. True  No. The suggested replacement returns false if —1P(d1) is true, and true if -wP(d1) is false.  Literal meaning: Every old thing does not covet a twenty—somethjng. Intended meaning: Some old thing does not covet a twenty—something. Let P(a:) denote the statement “as is an old thing” and Q(a:) denote the statement “as covets a twenty—something.” The intended statement is Ela:(P(a:) /\ -1Q(a:)).  Literal meaning: Every hospital did not report every month. (Domain of discourse: the 74 hospitals.) Intended meaning (most likely): Some hospital did not report every month. Let P(a:) denote the statement “as is a hospital” and Q(a:) denote the statement “as reports every month.” The intended statement is 3a:(P(a:) /\ —1Q(a:)).  Literal meaning: Everyone does not have a degree. (Domain of discourse: People in Door County.) Intended meaning: Someone does not have a degree. Let P(a:) denote the statement “at has a degree.” The intended statement is 33:-P(a:). 
CHAPTER 1  46.  48.  49.  50.  SOLUTIONS 5  Literal meaning: No lampshade can be cleaned. Intended meaning: Some lampshade cannot be cleaned. Let P(a:) denote the statement “at is a lampshade” and Q(a:) denote the statement “as can be cleaned.” The intended statement is 3a:(P(a:) /\ —»Q(a:)).  Literal meaning: No person can afford a home. Intended meaning: Some person cannot afford a home. Let P(a:) denote the statement “at is a person” and Q(a:) denote the statement “:1; can afford a home.” The intended statement is 3a:(P(:z;) /\ -1Q(a:)).  Literal meaning: No circumstance is right for a formal investigation. Intended meaning: Some circumstance is not right for a formal investigation. Let P(a:) denote the statement “as is a circumstance” and Q(a:) denote the statement “:1: is right for a formal investigation.” The intended statement is 3a:(P(a:) /\ —1Q(a:)).  (a) _____  P ‘I 19*”! (I—“>P T T T T T F F T F T T F F F T T  One of p —> (1 or q —> p is true since in each row, one of the last two entries is true.  (b) The statement, “All integers are positive or all positive numbers are integers,” which is false, in symbols is  <v:c<P<sc) —+ c2<x>>> v <v:c<c2<a:> —+ P<sc>>>. This is not the same as the given statement  V~’v((P(~’v) ~> Q(~’v)) V (Q(~'v) -+ P($v))),  which is true. The ambiguity results from attempting to distribute V across the or.  Section 1.4  12.  15.  23.  32.  Everyone is taller than someone else. False. Someone is taller than everyone else. True. Everyone is taller than or the same height as someone. True. Someone is taller than or the same height as everyone. True.  ‘v’a:‘v’yL(a:,y). False. 13. ElccElyL(a:,y). True.  (Exercise 11) ‘v’a:Ely—1L(a:,y). False. 17 . True 18. False 22. True False 25. False 26. False 28. False 29. False 31. True True 34. True 35. False 37. True 38. True 
40.  41.  43.  44.  46.  48.  49.  CHAPTER 1 SOLUTIONS  for 1' : 1 to n if (fomll_dj(i)) return true return false  fomll_dj(t') { for j : 1 to n if (fiP(di,d;')) return false return true  }  for 1' : 1 to n for j = 1 to n if (P(di,dj)) return true return false  Since the first two quantifiers are universal and the last quantifier is existential, Farley chooses a: and y, after which, you choose z. If Farley chooses values that make as 2 y, say as 2 y : 0, whatever value you choose for z, (z > as) /\ (z < y)  is false. Since Farley can always win the game, the quantified propositional function is false.  Since the first two quantifiers are universal and the last quantifier is existential, Farley chooses a: and y, after which, you choose z. Whatever values Farley chooses, you can choose z to be one less than the minimum of as and y; thus making  (2 < 2:) /\ (z < y) true. Since you can always win the game, the quantified propositional function is true.  Since the first two quantifiers are universal and the last quantifier is existential, Farley chooses a: and y, after which, you choose z. If Farley chooses values such that as 2 y, the proposition  (~’v<3/)-+((z>~’8)/\(z<y))  is true by default (i.e., it is true regardless of what value you choose for z). If Farley chooses values such that a: < y, you can choose z 2 (as + y) / 2 and again the proposition  (m<y)-+((Z>5v)/\(Z<y)) is true. Since you can always win the game, the quantified propositional function is true.  The proposition must be true. P(a:, y) is true for all as and y; therefore, no matter which value for as we choose, the proposition ‘v’yP(a:,y) is true.  The proposition must be true. Since P(cc,y) is true for all as and y, we may choose any values for :1: and y to make P(a:, y) true. 
CHAPTER 1  51.  52.  54.  55.  57.  58.  60.  61.  SOL UTIONS 7  The proposition can be false. Let P(a:, y) be the statement as 2 y and let the domain of discourse be the set of positive integers. Then ‘v’:c3yP(a:, y) is true, but Ela:‘v’yP(a:, y) is false.  The proposition must be true. Since ‘v’a:ElyP(a:, y) is true, if we choose any value for :1? whatso- ever, there exists a value for y for which P(:1:,y) is true. Therefore Ela:ElyP(a:, y) is true.  The proposition can be false. Let the domain of discourse consist of the persons James James, Terry James, and Lee James, and let P(a:,y) be the statement “a:’s first name is the same as y’s last name.” Then El:1;‘v’yP(a:, y) is true, but ‘v’a:ElyP(a:, y) is false.  The proposition must be true. Since Ela:‘v’yP(a:, y) is true, there is some value for :1: for which ‘v’yP(:z;,y) is true. Choosing any value for y whatsoever makes P(a:,y) true. Therefore Ela:3yP(a:,y) is true.  The proposition can be false. Let P(:::, y) be the statement as > y and let the domain of discourse be the set of positive integers. Then Ela:ElyP(a:,y) is true, but ‘v’a:ElyP(a:, y) is false.  The proposition can be false. Let P(a:, y) be the statement :1: > y and let the domain of discourse be the set of positive integers. Then Ela:ElyP(a:, y) is true, but Ela:‘v’yP(a:, y) is false.  Not equivalent. Let P(a:, y) be the statement as > y and let the domain of discourse be the set of positive integers. Then -1(‘v’a:ElyP(a:, y)) is true, but ‘v’a:—1(3yP(a:, y)) is false.  Equivalent by De Morgan’s law  Section 1.5  2.  11.  For allcc, forally,cc+y=y+ar:.  An isosceles trapezoid is a trapezoid with equal legs.  . The medians of any triangle intersect at a single point. . If 0 < a: < 1 and 5 > 0, there exists a positive integer n satisfying as" < 5.  . Let m and n be odd integers. Then there exist k1 and kg such that m = 2k1 + 1 and n : 2kg+1.  Now Tn-l’Tl=(2/C1-f"1)-l~(2/<22-I-1)=2(/<31-I’/<72-I-1).  Therefore, m + n is even.  . Let m and n be even integers. Then there exist k1 and kg such that m = 2k1 and n : 2kg.  Now mn Z (2/{71)(2k2) = 2(2/(71,92).  Therefore, mn is even.  Let m be an odd integer and n be an even integer. Then there exist kl and kg such that m = 2k1 + 1 and n : 2kg. Now  mn : (2191 + 1)(2kg) 2 2(2k:1k:2 + kg).  Therefore, mn is even. 
12  14.  15.  17.  18.  20.  21.  23.  CHAPTER 1 SOLUTIONS  From the definition of max, it follows that d 2 d1 and d 2 d2. From as 2 d and d 2 d1, we may derive a: 2 d1 from a previous theorem (the second theorem of Example 1.5.5). From as 2 d and d _>_ d2, we may derive a: 2 d2 from the same previous theorem. Therefore, as 2 d1 and as 2 d2.  Step Justification 1. my : 0,9: 7E 0, y 7E 0 Hypothesis 2. ct: - 0 = 0 Exercise 7 3. my : as - 0 Two things equal to the same thing are equal to each other. 4. y = 0 Steps 1 and 3 and the property given in the statement of Exercise 8.  Suppose that every box contains less than 12 bafls. Then each box contains at most 11 balls and the maximum number of balls contained by the nine boxes is 9 - 11 : 99. Contradiction.  Suppose that there does not exist 1' such that s,- _>_ A. Then, for all 1', s,- < A. Now  _81+®+“”+£n<1m+A+'“+A;_nA_ _ n n ‘n-  A  A,  which is a contradiction. The statement is false. A counterexample is s,- = A for all 1'.  First assume that as 2 0 and y _>_ 0. Then my 2 0 and [my] = my = [sully]. Next assume that a: < 0 and y 2 0. Then my 3 0 and [my] = -333; = (—cc)(y) : |cc||y|. Next assume that as 2 0 and y < 0. Then my 3 0 and [my] = -931; = (a:)(—y) : |a:||y|. Finally assume that a: < 0 and y < 0. Then my > 0 and Iccyl 2 my : (—a:)(—y) = |a:Hy|.  First, note that from Exercise 20, for all cc, I-ml =l(-1)rvl :1-lllfvl =l~’vl-  Exa111ple 1.5.14 states that for all as, a: < |cc|. Using these results, we consider two cases:  a:+yZ0anda:+y<0. Ifa:+yZ0,wehave |m+y|:6v+ySl6vl+|y|- Ifa:+y<0,wehave  l6v+1/1: —(~’v+y) : -66+-y S I-ml +|-yl = Irv! +111!-  Suppose that my > 0. Then eithera: > 0 and y > Oor a: < 0 and y < 0. Ifa: > 0 and y > 0,  sgn(a:y) = 1 : 1 - 1 : sgn(a:)sgn(y).  Ifa:<0andy<0, sgn(a:y) 2 1 = -1 - -1 = sgn(a:)sgn(y). 
CHAPTER 1  24. 26.  27.  29.  30.  SOLUTIONS 9  Next, suppose that my 2 0. Then either as 2 0 or y 2 0. Thus either sgn(a:) 2 0 or sgn(y) 2 0. In either case, sgn(a:)sgn(y) 2 0. Therefore  sgn(:I:y) : 0 = sgn(:v)sgn(y)-  Finally, suppose that my < 0. Then either :1: > 0 and y < 0 or a: < 0 and y > 0. If as > 0 and y < 0. sgn(a:y) 2 -1 2 1 - -1 2 sgn(:1:)sgn(y). Ifa:<0andy>0,  sgn(a:y) 2 -1 2 -1 - 1 2 sgn(a:)sgn(y).  lacy! = sgn(:vy)cvy = sgn(rv)sgn(y)rcy = isgn(:v)rvl[sgn(y)yl = lrvllyl Suppose that as 2 y. Then lcv - 1/! = as - y-  max{a:, y} 2 st: and  Thus 2_cv_sv+y+cv—y _sv+z/+19:-1/I  max{a:, y} 2 CC 2  2 2 2 The other case is a: < y. Then max{a:, y} 2 y and |a: — y| 2 y — cc. Thus 2 Suppose that as 2 y. Then min{a:, y} 2 y and la: - y] 2 :1: — y.  Thus 2_y:rc+y-(Iv-y) 296+:/-lcv-1/I.  2 2 2  min{rc, y} 2 y : The other case is a: < y. Then  min{a:,y} 29: and |a:-y| 2y-cc. Thus 22: : 22+:/-<2;-cc) :sv+y—lcv—yl_  2 2 2  min{:::, y} 2 :1? 2  Let 1' be the greatest integer for which s,- is positive. Since .91 is positive and the set of indexes 1, 2, . . . ,n is finite, such an 1' exists. Since 5,, is negative, 1' < n. Now .9,-+1 is equal to either 5,-+1 or 5, - 1. If .9,-+1 = s,- + 1, then .9,-+1 is a positive integer (since 5, is a positive integer). This contradicts the fact that 1' is the greatest integer for which .9,- is positive. Therefore, .9,-+1 2 s,- -1. Again, if 5, - 1 is a positive integer, we have a contradiction. Therefore, .9,-+1 2 51- - 1 2 0.  A counterexample is n 2 3. 
10  32.  33.  35.  37.  38.  40.  42. 46.  48.  CHAPTER 1 SOLUTIONS  Invalid  P *9 Q -17‘ —) —1q 7' Valid  p<—>7' 7'  p Valid 19 —> (<1 V 7‘) -wq /\ -v7‘ -11) If 4 megabytes of memory is better than no memory at all, then either we will buy a new computer or we will buy more memory. If we will buy a new computer, then we will not buy  more memory. Therefore if 4 megabytes of memory is better than no memory at all, then we will buy a new computer. Invalid.  If 4 megabytes of memory is better than no memory at all, then we will buy a new computer. If we will buy a new computer, then we will buy more memory. Therefore, we will buy more memory. Invalid.  If 4 megabytes of memory is better than no memory at all, then we will buy a new computer. If we will buy a new computer, then we will buy more memory. 4 megabytes of memory is better than no memory at all. Therefore we will buy more memory. Valid.  Valid 43. Valid 45. Valid  Suppose that p1, pg, . . . , p” are all true. Since the argument p1, pg / p is valid, p is true. Since p, p3, . . . , p,, are all true and the argument  p1p3a---apn / C  is valid, c is true. Therefore the argument  p1,p2,...,pn / c is valid. Let  p(:c): CI) is good.  q(sv)= 7‘(:(:): as is short enough.  :c is too long.  The domain of discourse is the set of movies. The assertions are 
CHAPTER 1  50.  54.  55.  57.  SOL UTIONS 1 1  Vflmwranflwfl V$(*P($)-+ “T($)) p( “Love Actually”) q( “Love Actually”).  By universal instantiation, p(“Love Actually”) —-> —1q(“Love Actually”).  Since p( “Love Actually”) is true, then —-q(“Love Actually”) is also true. But this contradicts, q(“Love Actually”).  Modus ponens 51. Disjunctive syllogism 52. Universal instantiation  Let p denote the proposition “there is gas in the car,” let (1 denote the proposition “I go to the store,” let 7 denote the proposition “I get a soda,” and let 5 denote the proposition “the car transmission is defective.” Then the hypotheses are:  P *9 Q» ‘‘7'-  fl -9 7‘, From p —> (1 and q —+ 7, we may use the hypothetical syllogism to conclude p —~> 7. From p —> 7 and -17, we may use modus tollens to conclude -119. From —-p, we may use addition to conclude —»p V s. Since -119 V .9 represents the proposition “there is not gas in the car or the car transmission is defective,” we conclude that the conclusion does follow from the hypotheses.  Let 1) denote the proposition “Jill can sing,” let (1 denote the proposition “Dweezle can play,” let 7 denote the proposition “I’ll buy the compact disk,” and let 5 denote the proposition “I’ll buy the compact disk player.” Then the hypotheses are:  ®V®nnp,&  From p, we may use addition to conclude p V (1. From p V q and (p V q) —+ 7, we may use modus ponens to conclude 7. From 7 and s, we may use conjunction to conclude 7 /\ .9. Since 7 /\ s represents the proposition “I’ll buy the compact disk and the compact disk player,” we conclude that the conclusion does follow from the hypotheses.  Let P(a:) denote the propositional function “:7: is a member of the Titans,” let Q(a:) denote the propositional function “:1: can hit the ball a long way,” and let R(a:) denote the propositional function “:7: can make a lot of money.” The hypotheses are  P(Ken), Q(Ken), Va: Q(a:) —~> R(a:).  By universal instantiation, we have Q(Ken) —+ R(Ken). From Q(Ken) and Q(Ken) —+ R(Ken), we may use modus ponens to conclude R(Ken). From P(Ken) and R(Ken), we may use conjunction to conclude P(Ken)/\R(Ken). By existential generalization, we have 39: P(:z;)/\R(:1:) or, in words, someone is a member of the Titans and can make a lot of money. We conclude that the conclusion does follow from the hypotheses. 
12  58.  60.  61.  63.  CHAPTER 1 SOLUTIONS  Let P(a:) denote the propositional function “as is in the discrete mathematics class,” let Q(a:) de- note the propositional function “at loves proofs,” and let R(a:) denote the propositional function “as has taken calculus.” The hypotheses are  Va: P(a:) —+ Q(a:), 39: P(:z:) /\ -1R(a:).  By existential instantiation, we have P(d) /\ -1R(d) for some d in the domain of discourse. From P(d) /\ -1R(d), we may use simplification to conclude P(d) and —1R(d). By universal instantiation, we have P(d) —+ Q(d). From P(d) —-> Q(d) and P(d), we may use modus ponens to conclude Q(d). From Q(d) and —-R(d), we may use conjunction to conclude Q(d) /\ —»R(d). By existential generalization, we have 3 Q(a:) /\ -R(a:) or, in words, someone who loves proofs has never taken calculus. We conclude that the conclusion does follow from the hypotheses.  The truth table  <  P Q  ’1’TjHv€"8 *'rJ>-]fi>-30 *TJ>-3*-3*-3  shows that whenever p is true, 19 V q is also true. Therefore addition is a valid argument. The truth table  P/VI  wwaaws *1H’1H»-Q *11’1*'fJ>-3  shows that whenever p /\ q is true, p is also true. Therefore simplification is a valid argument. The truth table  p—>q q—->7‘ p->7‘  *1’1j*1’fi>-3*-3*-3*-P8 *1’fi>-3>—]’1’1>-3*-3~Q *1>-331*-]fi>-3"1d>-3* >-3*-3*-3*-]"IJ’1>-3*-3 >-3*-31>-3*-3*-333+-3 >-3*-3*-3*-]’1H’=1>-3  shows that whenever p —-> (1 and q —-> 7' are true, p —-> 7' is also true. Therefore hypothetical syllogism is a valid argument. 
CHAPTER 1 SOLUTIONS 13  64. The truth table  I9 ‘I PVQ “P T T T F T F T F F T T T F F F T  shows that whenever p V q and —1p are true, (1 is also true. Therefore disjunctive syllogism is a valid argument.  66. By definition, the proposition 3:1: 6 D P(a:) is true when P(a:) is true for some as in the domain of discourse. Taking as equal to a d E D for which P(d) is true, we find that P(d) is true for some d E D.  67. By definition, the proposition E13: 6 D P(a:) is true when P(a:) is true for some as in the domain of discourse. Since P(d) is true for some d E D, 33: E D P(a:) is true.  Section 1.6  3. —1p V 1' —w7' V q I9 -up V (1 from 1,2 (1 from 3,4  .°‘:‘>9°F°!“  —1pVt —1qVs —1rVs -17'Vt pVqVrVu tVqV7-Vu from 1,5 sVtVrVu from2,6 sVtVu from3,7  9°.\‘F”.°‘:‘>§'°!°t“  6- (19 <-> 7‘) E (p—> 7‘)(7‘ +29) 5 (~pV1")(firVp) —wpVr -17'Vp 7- p from 2,3  :4>.°°.'°E“  a V -b a V c —wa —d b negated conclusion -b from 1,3  F”.°‘t‘>P°E°‘.“ 
14 CHAPTER 1  Now 5 and 6 combine to give a contradiction.  Section 1.7  In some of these solutions, the Basis Steps are omitted.  2.1-2+2-3+---+n(n+1)+(n+1)(n+2) : n(n+ 1)(n+2) 3 3. 1(1!)+2(2!)+---+n(n!)+(n+1)(n+1)! :(n+1)!—1+(n+1)(n+1)!:(n+2)!—1  +(n+1)(n+2): (n+1)(n—?|)—2)(n+3)  5. 12 — 22 + ---+(—1)"+1n2 + (—1)”+2(n + 1)? (-1)"+1n(n+ 1)  = :7-: + (—1)”+2(n + 1)  6.13+23+---+n3+(n+1)3  2 : (—1)”+2(n + 1)(n + 2) 2  Z [n(n+1)]2+(n+1)3: [(n+1)(n+2)]2 2 2 1 1 3 1 3 -(2n—1) 1-3---(2n—1)(2n+1) 8.~—+ +- 24 2-46 2-4---(2n+2) 2-4--~(2n+2)(2n+4) _1_1-3---(2n+1) 1-3---(2n—1)(2n+1) *2 2-4---(2n+2) 2-4--~(2n+2)(2n+4) 1 1-3---(2n+3) 2'2-4--.(2n+4) 9___1___+;+...+ 1 + 1 22-1 32-1 (n+1)2—1 (n+2)2—1 _3 1 1 1 ’Z’2(n+1)'2(n+2)+(n+2)2—1 A3 1 1 'Z'flWm”MTw>3  11. The solution is similar to that for Exercise 10, which is given in the book.  13. First note that  1-3---(2n—1)(2n+1)< 1 2n+1 2-4-~-(2n)(2n+2) ’ t/n+12n+2'  The proof will be complete if we can show that 211 + 1  1 < . (2n+2)\/n+ 1 ' \/n+2  This last inequality is successively equivalent to  n+2 1/2 <n+1)  2n+2 2n+1  SOL UTI ON S 
CHAPTER 1 SOLUTIONS 15  n + 2 4(n + 1)? n +1 (271 + 1)? (n + 2)(2n + 1)2 4(n + 1)3 4n3 + 12112 + 9n + 2 4n3 + 12112 + 1211 + 4 -2 311.  |/\  I/\ I/\ I/\  This last inequality is true for all n 2 1. 14. 2(n+1)+1 =(2n+1)+2 g2"+2g2"+2":2"+1 16. By the inductive assumption, n a + . . . + a n ((11. ..a2n)1/2 S 1% (L1)  a2"+1 + ‘ ‘ ' + a2"+1  (a2"+1 ' ' ' a2"+1)1/2” — 271  (1.2)  Let  a1 + - - - + azn 211. 0,271+] + ' ' ' + a2n+1 2" '  A : B : Multiplying inequalities (1.1) and (1.2), we have (a1---a2..+1)1/2" 3 AB. (1.3) Applying the Basis Step to the numbers A and B, we have  A+B 2  (AB)1/2 S  or, equivalently,  AB<  [G1 + + G2"+1]2 (1.4)  2n+1  Combining inequalities (1.3) and (1.4), we have n a + ' ' ' + a n 2 (a1...a2"+1)1/2 S  Taking the square root of both sides of the last inequality gives the desired result.  17. (1 + :(:)"+1 (1 + a:)”(1 + cc) (1 + na:)(1 + 1:) 1 + ms + as + 112:2  1+(n+1)a:  IV ll IV ll 
16  19.  20. 22.  23.  25.  27.  CHAPTER 1 SOLUTIONS  If we sum the terms in the diagonal direction, we obtain one 7', two 7-2’s, three 7'3  that is, we obtain the sum  ’s, and so on;  1-r1+2-r2+---+m~". Multiplying the inequality of Exercise 18 by 7' yields  for all n 2 0. (1.5)  r1+r2+---+r"+1<1L  Thus, the sum of the entries in the first column is less than 7-/ (1 -7‘). Similarly, the sum of the entries in the second column is less than 7'2/(1 — 7'), and so on. It follows from the preceding  discussion that 1 :(’f‘1+’f‘2+"'+’f‘n).  Using inequality (1.5), we obtain the desired result  1—:—7(r1+r2+---+r”)< =(+P.  1-7'1+2-7‘2+---+m‘”<  1-r1+2-r2+---+m~”<  Take 7' : 1/2 in Exercise 19. Assume that 11” — 6 is divisible by 5. 11"+1—6:11"-11—6:11"(10+1)—6= 10-11"+11”—6, which is divisible by 5.  Suppose that 4 divides 6 - 7” — 2 - 3”. Now  6-7"+1—2-3"“ = 7~6-7”—3-2-3” : 6-7”—2-3”+6-6-7”—2-2-3” : 6-7”—2-3”+36-7”—4-3”.  Since 4 divides 6- 7” -2 - 3”, 36 - 7”, and -4-3", it divides their sum, which is 6- 7”“ -2 - 3”“. n  n+1  We use induction on n, the number of lines, to prove the result. If there is one line, the result is certainly true. Suppose that there are n > 1 lines. Remove one line. By the inductive hypothesis, the regions that result may be colored red and green so that no two regions that share an edge are the same color. Now restore the removed line. The regions above (or, if the line is vertical, to the left of) the restored line are colored red and green so that no two regions that share an edge are the same color, and the regions below (or, if the line is vertical, to the right of) the restored line are also colored red and green so that no two regions that share an edge are the same color. Now reverse the color of every region below (or, if the line is vertical, to the right of) the restored line. The regions below (or, if the line is vertical, to the right of) the restored line are still colored red and green so that no two regions that share an edge are the same color. Since the colors below the restored line have been reversed, regions that share an edge that is part of the restored line do not have the same color. Therefore the regions may be colored red and green so that no two regions that share an edge are the same color, and the inductive proof is complete. 
CHAPTER 1  28.  30.  31.  33.  34.  SOLUTIONS 17  We assume that we proceed around the circle in clockwise order. The proof is by induction on the number n of zeros with the Basis Step, as usual, omitted.  Suppose that the result is true for n zeros, and we are given 11+ 1 zeros and 11+ 1 ones distributed around a circle. Find a zero followed, in clockwise order, by a one. Temporarily remove these two numbers. By the inductive assumption, it is possible to start at some number and proceed around the circle to the original starting position in such a way that, at any point during the cycle, one has seen at least as many zeros as ones. Notice that this last statement remains true if we restore the removed zero and one.  A tromino can cover the square to the left of the missing square as shown  or in a symmetric fashion by reversing “up” and “down.” In the first case, it is impossible to cover the two squares in the top row at the extreme left. In the second case, it is impossible to cover the two squares in the bottom row at the extreme left. Therefore, it is impossible to tile the board with trominoes.  Such a board can be tiled with ij 2 x 3 rectangles of the form  '1  By symmetry, we may assume that the missing square is located in the 7 x 7 subboard shown in the following figure. Exercise 32 shows how to tile this subboard. Exercise 31 shows that the two 6 X 4 subboards can be tiled. Exercise 29 shows that the 5 x 5 subboard with a corner square can be tiled. Thus the deficient 11 X 11 board can be tiled with trominoes.  H  7X7 6x4  H  6X4 5x5  Basis Step (n = 0). In this case, the 2” x 2” L-shape is a tromino and, so, it is tiled.  Inductive Step. Assume that we can tile a 2”‘1 X 2”” L-shape with trominoes. Given a 2" x 2" L-shape, divide it into four 2”” x 2”‘1 L-shapes: 
18  37.  38.  40.  41.  CHAPTER 1 SOLUTIONS  By the inductive assumption, we can tile each of the four 2”‘1 x 2”‘1 L-shapes with trominoes. The inductive step is complete.  Arguing as in the solution to Exercise 36, the numberings  1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1  show that the only possibility for the missing square is the center square. This board can be tiled:  An argument like those in the solutions to Exercises 36 and 37 shows that the only board that can be tiled with straight trominoes is the one with the missing square in row 3, column 3 (and the three boards symmetric to it).  We show only the inductive step. There are two cases: a[k] < ml and a[k] 2 val. If a[k] 2 ml, the value of h does not change. Thus, we still have a[p] < val, for all p, 1' < p S h. After k is incremented, for all p, h < p < k, ab] E val.  If a[k] < val, then h is incremented and a[h] and a[k] are swapped. Let hold denote the original value of h, and hue,” denote the new (incremented) value of h. The value at h,,,,,,, is the original a[k]. Since this value is less than val, the value of a[hn,m,,] is less than val. Thus, for all p, i < p 3 h,,,,,,,, a[p] < val. After the swap, the value at k becomes h,,e,,,. By the inductive assumption, this value is greater than or equal to val. Thus after is is incremented, for all p, hnew < p < k, a[p] 2 val.  The argument is essentially identical to that of Example 1.7.6 that shows that any 2” x 2” deficient board can be tiled with trominoes. 
CHAPTER 1  42.  44.  45.  46.  48.  49.  51.  SOLUTIONS 19  Notice that k3 — 1 : (k — 1)[(k — 2)(k — 4) + 7(k — 1)].  Since 7 divides k3 — 1, 7 divides k — 1 or (k — 2)(k — 4) + 7(k — 1). If 7 divides the latter expression, 7 also divides (ls — 2)(k — 4). If 7 divides (k — 2)(k — 4), 7 divides either is — 2 or k — 4.  The Inductive Step fails if either a or b is 1. In this case, the inductive hypothesis is erroneously applied to the pair a — 1, b — 1, which includes a nonpositive integer.  To argue by contradiction, one must assume that the proposition fails for some n 2 2. The alleged proof assumes that the proposition fails for all n 2 2.  For n : 2, the inequality becomes % + § < §, which is true. Thus the Basis Step is true.  Assume that the given statement holds for n. Now  1 2 n n+1 n2 n+1 _ 2 3 n+1 n+2 n+1 n+2 The Inductive Step will be proved provided n2 n+1 (n+1)? n+1 n+2 n+2‘  If we multiply the last inequality by (n + 1)(n + 2), we obtain n2(n + 2) + (n + 1)? < (n + 1)3. which is readily verified as true.  In the following figure  5 5  a and b are both survivors.  Suppose that there are three persons. The two persons closest together throw at each other, and the third person throws at one of the two closest. Therefore the third person survives. This complete the Basis Step.  Suppose that the assertion is true for n, and consider n + 2 persons. Again, the closest pair throws at each other. There are now two cases to consider. If the remaining n persons all throw at one another, by the inductive assumption, there is a survivor. If at least one of the remaining n persons throws at one of the closest pair, among the remaining n persons, at most n — 1 pies are thrown at one another. In this case, someone survives because there are not enough pies to go around. The Inductive Step is complete.  The statement is false. In the following figure  CL  a throws a pie the greatest distance, but is not a survivor. 
20  53.  54.  56.  CHAPTER 1 SOLUTIONS  Let :61 be a common point of X2,X3, X4; let :62 be a common point of X1, X3,X4; let :63 be a common point of X1, X2, X4; and let :64 be a common point of X1, X2, X3. Since :61, :62, :63 6 X4, the triangle :61:62:63 (perimeter and interior) is in X4. Similarly, the triangle :61:62:64 is in X3; the triangle :61:63:64 is in X2; and the triangle :62:63:64 is in X 1. We consider two cases:  CASE 1: One of the points :61,:62,:63,:64 is in the triangle whose vertices are the other three points. For example, suppose that :61 is in triangle :62:63:64. Since triangle :62:63:64 is in X1, :61 6 X1. By definition, :61 6 X2 0 X3 0 X4. Therefore, :61 6 X1 0 X2 0 X3 0 X4.  CASE 2: None of the points :61,:62, :63,:64 is in the triangle whose vertices are the other three points. In this case, :61, :62, :63, :64 are the vertices of a convex quadrilateral:  5132 5131  373  554  Now the intersection, :6, of the diagonals of this quadrilateral belongs to each of the triangles and, thus, to each of X1, X2,X3, X4.  The proof is by induction on n. The Basis Step is n 2 4, which is Exercise 53.  We turn to the Inductive Step. Assume that if X1, . . . , X,, are convex sets, each three of which have a common point, then all n sets have a common point.  Let X 1, . . . ,X ,1, X,,+1 be convex sets, each three of which have a common point. We must show that all n + 1 sets have a common point. By Exercise 52,  X1,...,Xn_1,XnflXn+1 (1.6)  are convex sets. We claim that any three of the sets in (1.6) have a common point. The claim is true by hypothesis if the three sets are any of X1, . . . , X,,_1. Consider X,-, X,-,X,, fl X,,+1, 1' < j 3 n — 1. By hypothesis, any three of X,-, X -7-, X”, Xn+1 have a common point. By Exercise 53, X,-, X,~, X”, X,,+1 have a common point. Therefore, X,-, X,-, X,,flX,,+1 have a common point. Thus, any three of the sets in (1.6) have a common point. By the inductive assumption, the sets in (1.6) have a common point. The Inductive Step is complete.  We first prove the result for n : 3. Let A1, A2, A3 be open intervals such that each pair has a nonempty intersection. Choose :61 6 A1 0 A2, :62 6 A1 0 A3, :63 6 A2 0 A3. Note that if any pair (:61,:62 or :61,:63 or :63,a:3) is equal, it is in A1 0 A2 0 A3. We may assume :61 < :62. We consider three cases. First suppose that :63 < 331. Since :62,:63 6 A3, [:63, :62] Q A3. ([a, b] is the set of all :6 satisfying a 3 :6 3 b.) Thus 1:1 6 A3. Therefore :61 6 A1 0 A2 0 A3.  Next suppose that :61 < :63 < :62. Since a:1,:62 6 A1, [:61,:62] <_I A1. Thus 333 6 A1. Therefore .733 6 A1 flA2flA3.  Finally suppose that :61 < :62 < :63. Since a:1,:63 6 A2, [:61,:63] Q A2. Thus :62 6 A2. Therefore :62 6 A1 HA2 fl A3. We have shown that if A1, A2, A3 are open intervals such that each pair has a nonempty intersection, then A1 0 A2 0 A3 is nonempty.  We now prove that given statement using induction on n. The Basis Step (n : 2) is trivial. 
CHAPTER 1  58. 59.  61.  62.  65.  SOLUTIONS 21  Assume that if I1, . . . ,In is a set of open intervals such that each pair has a nonempty intersec- tion, then I1 0 - - - H In is nonempty. Let I1, . . . ,In+1 be a set of open intervals such that each pair has a nonempty intersection. Since In H In+1 is nonempty, it is an open interval. We claim that  I1, ...,In_1,In flIn+1  is a set of open intervals such that each pair has a nonempty intersection. This is certainly true for pairs of the form In, I,-, 1 3 1' < j 3 n — 1. Consider a pair of the form I,-, 1' 3 n — 1, and In flIn+1. Since each pair among I,-, In, In+1 has nonempty intersection, by the case n = 3 proved previously, I,- 0 In H In+1 is nonempty. Therefore,  I1, ...,In_1,In flIn+1  is a set of open intervals such that each pair has a nonempty intersection. By the inductive assumption  Ii 0 flIn_1 fl(In flIn+1)  is nonempty. The inductive step is complete. 5  5  After j rounds, 2,4, ...,2j have been eliminated. At this point, there are 2*" persons. This is exactly the Josephus problem when the number of persons is a power of 2, except that the round begins with person 237 + 1, rather than with person 1. By Exercise 60, person 237 + 1 is the survivor.  977  Aan = an+1 — an 2 (n + 1)2 — n2 : 2n+ 1. Let bn = Aan. Then  b1+b2+---+b.. = (2-1+1)+(2-2+1)+~--+(2n+1) : 2(1+2+~--+n)+(1+1+---+1) = 2(1+2+---+n)+n.  By Exercise 64, b1+b2+~--+bn:an+1—a1 :(n+1)2—12 =n2+2n. Combining the previous equations, we obtain n2+2n=2(1+2+---+n)+n. Solving for 1 + 2 + - - - + n, we obtain  n2+2n—n n2+n n(n+1) 1+2+---+n= 2 = 2 = 2 . 
22  66.  68.  CHAPTER 1 SOLUTIONS  Let an : n!. Then Aan = an+1— an = (n+ 1)! —n! = n![(n+ 1) — 1] : n(n!). Let b” : Aan. Then b1+b2+---+b,,‘= 1(1!)+2(2!)+---+n(n!).  By Exercise 64, b1+b2+---+bn=a,,+1—a1 =(’/7,-I-1)l—1l.  Combining the previous equations, we obtain 1(1!) + 2(2!) + +n(n!) = (n + 1)! — 1.  Since p is divisible by Is, there exists t1 such that p : tlk. Since q is divisible by Is, there exists t2 such that p = tgk. Now 19+ (1 = 75119 -I-tgk = ($1 + t2)/<2.  Therefore, p + q is divisible by k.  Problem-Solving Corner: Mathematical Induction  1.  The Basis Step (11 = 0) is H1 3 1 + 0. Since H1 : 1, the Basis Step is true. Now assume that Hgn 3 1 + n. Then  1 1 2"+1+"'+2_"37 1 2n+1  g1+(n+1).  H2n.+1 = H2n+  < 1 _ +n+2n+1+ +  TL  = 1 +n+2n+1  The Inductive Step is complete.  . The Basis Step (n = 1) is H1 = 2H1 — 1. Since H1 : 1, the Basis Step is true.  Now assume that H1+H2+---+H,, =(n+1)Hn—n.  Then  H1+H2+"'+Hn+Hn+1 2 (n+1)Hn—n+Hn+1  1 ‘n'l"Hn+1  : (n + 2)H,,+1 — (n + 1).  by Exercise 3  The Inductive Step is complete. 
CHAPTER 1 SOLUTIONS 23  1 1 1 1 1 1 1 1 1 3_Hn __: _ _ _ _ :_ _ _:Hn +1 n+1 <1+2+ +n+n+1) n+1 1+2+ +  4. We prove the assertion by induction. The Basis Step is n : 1:  For the Inductive Step, assume the assertion if true for n. Now  1-H1+---+nH,.+(n+1)H,,+1 = fl"2Ji)Hn+1—7—‘—(—"—4i1—)+(n+1)Hn+1 = (n+1)H,,+1[g+1]—@ : Hn+1[(n+ 1);n+2)] _n(n4+1) : H,,+2—7H1_2] l————("+1§("+2)] by Exercise3 _£("_+1_) I Hn+2[ln+1);n+2)]_n;r1_n(n:1) : Hn+2[(n+1);n+2)J_(n+1§n+2).  Section 1.8  2. Verify directly the cases n = 24,...,28. Assume that the statement is true for postage 2' satisfying 24 3 1' < n. We must show that we can make n cents postage using only 5-cent and 7-cent stamps. We may assume that n > 28. Then n > n — 5 > 23. By the inductive assumption, we can make n — 5 cents postage using 5-cent and 7-cent stamps. Add a 5-cent stamp to obtain n cents postage.  4. The Basis Step (n : 6) is proved by using three 2—cent stamps. Now assume that we can make postage for n cents. If there is at least one 7-cent stamp, replace it by four 2—cent stamps to make n + 1 cents postage. If there are no 7-cent stamps, there are at least three 2—cent stamps (because n 2 6). Replace three 2—cent stamps by one 7-cent stamp to make 11+ 1 cents postage. The Inductive Step is complete.  5. The Basis Step (n : 24) is proved by using two 5-cent stamps and two 7-cent stamps. Now assume that we can make postage for n cents. If there are at least two 7-cent stamps, replace two 7-cent stamps with three 5-cent stamps to make 11+ 1 cents postage. If there is exactly one 7-cent stamp, then there are at least four 5-cent stamps (because n 2 24). Replace one 7-cent stamp and four 5-cent stamps with four 7-cent stamps to make n + 1 cents postage. If there are no 7-cent stamps, then there are at least five 5-cent stamps (again because n 2 24). Replace five 5-cent stamps with three 7-cent stamps and one 5-cent to make n + 1 cents postage. The Inductive Step is complete. 
24  CHAPTER 1 SOLUTIONS  7. We omit the Basis Step. For the Inductive Step, we have  2 Cu = CL”/2] -I- 77,2 < 4  2 +n2g4<;) +n2=2n2<4n2.  9. We omit the Basis Step. For the Inductive Step, we have  10.  13. 14. 16. 17. 19.  20.  an : 40'.”/2] ‘I’ TL  S 4I4(In/2] - D2] + n 4[4(n/2 — 1)2] + n 4112 — 1511 + 16  4(n — 1)2.  I/\  I I  I /\  The last inequality reduces to 12 3 7n, which is true since n > 1.  We omit the Basis Steps (n : 2, 3). We turn to the Inductive Step. Assume that n 2 4. Then  71/2 3 2, so In/2] 3 2. Then  Cn = 40'.”/2] +71  4([n/2] + 1)2/8 + n 4K” - 1)/2 + 1I2/8 + n (n + 1)2/8 + n (n+ 1)2/8.  V  IV  I I  V  We used the fact that In/2] Z (n — 1)/2 for all n.  q=—6,r:7 q=0,r:7 q=0,r=0 q:1,7':0 If 2:: 9 H1  1 1 +...  7722 nk:  where n1 < n2 < < nk, another representation is  p 1 1  4711712  1 + 1 + 1 nIc(nIc + 1)  nknl nk + 1  (b) Since p/q < 1, n > 1. Since n is the smallest positive integer satisfying 1/11 3 p/q and  n — 1 is a positive integer less than n (d) We have  21 2 91 Since 1/11 < p/q, equation (1.7) show  ,1?/<1 < 1/(n - 1)-  "p"1:P_l (17) nq q n ' sthat P1  0<—. Q1 
CHAPTER 1 SOLUTIONS 25  Since 2< 1 (1 11-1’ wehave nP—P<(I or  P1 3 WP ' Q < P- The third inequality is established. Now 1 1 ‘5<p p~ p .1:—. (1.8)  1 (11 Q1 W1 "Q" 71  In particular,  We have established the second inequality. By the inductive assumption, pl/ql can be expressed in Egyptian form. The last equation follows.  (e) See (1.8).  (f) The equation is true because of (d). For any 1' : 1, . . . , Is,  1 1 1 .__I£<_ Th 711 nk Q1 71 It follows that n,n1,...,n;, are distinct. 21- %=%+2%i»%=%+%+%al-3=%+%+5—17  24. Enclose the missing square in a corner (n — 3) x (n — 3) subboard as shown in the following figure. Since 3 divides n2 — 1, 3 also divides (n — 3)2 — 1. Now n — 3 is odd, n — 3 > 5, and 3 divides (n — 3)2 — 1, so by Exercise 23, we may tile this subboard. Tile the two 3 x (n — 4) subboards using the result of Exercise 31, Section 1.7. Tile the deficient 4 x 4 subboard using Example 1.7.6. The n x n board is tiled.  TL  (11-3) X (11-3) 3X(n-4)  3><(n—4) 4X4 
26  25.  26.  CHAPTER 1 SOLUTIONS  Ifn=0,d-1:d>0, and1isinX. Ifn>0, d(2n) =n(2d) >n; thus 2nisinX. In either case X is nonempty. Since d > 0 and n 2 0, X contains only positive integers. By the Well—Ordering Property, X contains a least element q’ > 0. Then dq’ > n. Let (1 = q’ — 1. We cannot have dq > n (for then q’ would not be the least element in X); therefore, dq 3 n. Let 7' = n — dq. Then 7' 2 0. Also  r=n—dq=n—d(q’—1)<dq'—d(q'—1):d. Therefore, we have found (1 and 7' satisfying  n:dq+'r 0_<_r<d.  We first prove Theorem 1.8.5 for n > 0. The Basis Step is n 2 1. If d = 1, we have n = dq+ 7', whereq=nandr:0,0§7'<d. Ifd>1,wehaven=dq+7',whereq:0andr:1, 0 3 7- < d. Thus Theorem 1.8.5 is true for n : 1.  Assume that Theorem 1.8.5 holds for n. Then there exists q’ and 7" such that  n:dq'+7" 0§7"<d.  Now n+1=mHHW+n. If 7" < d — 1, then 7" + 1 < d. In this case, if we take (1 : q’ and 7' = 7" + 1, we have  n+1:dq+r 0§r<d.  If7":d—1, we have n+1:d(q’+1).  In this case, if we take (1 = q’ + 1 and 7' : 0, we have  n+1:dq+'r' 0_<_7'<d.  The Inductive Step is complete. Therefore, Theorem 1.8.5 is true for all n > 0.  If n : 0, we may write n : dq + 7',  where q : 7' : 0. Therefore, Theorem 1.8.5 is true for n = 0.  Finally, suppose that n < 0. Then -11 > 0, so by the first part of the proof, there exist q’ and 7" such that 0 3 7" < d.  —n:dq’+r' If 7-’ :0, we may take (1: —q’ and 7'=0to obtain n=dq+0. Ifr’>0,wetakeq:—q’—1and7':d—r’. Then0<7'<dand n=d(—q’)—r’:d(q+1)+(r—d):dq+7-.  Therefore, Theorem 1.8.5 is true for n < 0. 
CHAPTER 1  28.  29.  SOLUTIONS 27  Suppose that we have a propositional function S(n) whose domain of discourse is the set of integers greater than or equal to no. Suppose that S(no) is true and, for all n > no, if S (k) is true for all Is, no 3 k < n, then S (n) is true. We must prove that S (n) is true for every integer n 3 no. We first assume that no 2 0.  We argue by contradiction. So assume that S(n) is false for some integer n1 2 no. Let X be the set of nonnegative integers for which S(n) is false. Then X is nonempty. By the Well- Ordering Property, X has a least element n2. Since S(no) is true, no > no. Furthermore, for any k, no 3 k < n2, S(lc) is true [otherwise no would not be the least integer n for which S(n) is false]. Since S(k) is true for all Is, no 3 k < n2, by hypothesis, S (no) is true. Contradiction.  If no < 0, apply the previous argument to the propositional function S'(n) 2 S(n + no) with domain of discourse the set of nonnegative integers.  The strong form of induction clearly implies the form of induction where the Inductive Step is: “If S(n) is true, then S(n + 1) is true.” For the converse, use Exercises 27 and 28. 
28  CHAPTER 2 SOLUTIONS 
Chapter 2  Solutions to Selected Exercises  Section 2.1 2. {2,4} 3.{7,10} 5.{2,3,5,6,8,9} 6.{1,3,5,7,9,10} 8. A 9. 0 11. B 12. {1,4} 14. {1}  15. {2,3,4,5,6,7,8,9,10}  18.  19.  29 
30 CHAPTER 2 SOLUTIONS  21.  22.  24.  26. 32 27. 105 29. 51  31. Suppose that n students are taking both a mathematics course and a computer science course Then 4n students are taking a mathematics course, but not a computer science course, and 7n students are taking a computer science course, but not a mathematics course. The following Venn diagram depicts the situation:  Math E  Thus, the total number of students is  CompSci  4n+n+7n=12n.  The proportion taking a mathematics course is  5n 5  E ” 12’ which is greater than one-third. 33- {(0,1),(a»2),(b»1),(b»2).(Ca1),(C,2)} 34- {(1,1),(1.2),(2,1),(2,2)} 37- {(1,a.a),(2aa»a)} 
CHAPTER 2 SOLUTIONS  38.  41.  42.  45. 54.  55. 62. 63. 66. 68. 69. 72. 76. 77. 78.  80. 81. 83~93. 94.  {(171:1):(1:2:1):(2:1:1):(2:2:1):(1:1:2):(1:2:2):(2:1v 2): (2: 2:  {1,2} {1},{2}  {a.b,C} {aab},{C} {a.C},{b} {b,c}.{a} {a}.{b},{C}  False 46. True 49. Equal 50. Equal  0: {G}: {C}: {a: b}: {a: C}: {a: d}: {b: C}: {b: d}: {c: d}: {a’: b: C}: {as b: d}: {a, c, d}, {b, c, d}, {a, b, c, d}  52. Not equal  2m=1m¢2N—1:1m3 W X=Y 59Tme mflnm False. Take X = {1,2}, Y : {2,3}, U 2 {1,2, 3}. False. Take U 2 {1,2,3,4,5}, X : {2, 3}, Y = {3, 4}. 65. True  False. Take U : {1,2}, X : {1}, Y : {2}.  False. Take X 2 {1,2}, Y : {1}, Z : False. Take X : {1,2}, Y : {1,3}, Z = {1,4}. B Q A 73. A = U The symmetric difference of two sets consists of the elements in one or the other but not both. AAA:0, AAA:U, UAA:A, (0AA:A  The statement is true. We first prove that A Q B. Let a: E A.  We divide the proof into two cases. First, we consider the case that as E C. Then as ¢ AA C. Therefore as 5! B AC. Therefore as E B (since if as ¢ B, then as E B A C).  Next, we consider the case that as ¢ C. Then as 6 AA C. Therefore :1: E B AC. Therefore :1: E B U C. Therefore as E B.  In either case, as E B, and so A Q B. Similarly, B Q A, and so A : B. |AuBuCp4AH+m+KH—mnBL4AnCy4BnCH4AnBnC The center of C Argue as in the proof given in the book of the first distributive law [Theorem 2.1.12, part (c)]. We prove part (a) only. The Basis Step is immediate. Assume that  XFMXfiLfiLb~UXJ:%XflXfiU(XflXfiU-~U@YflXfl. 
32 CHAPTER 2 SOL UTIONS  We must prove that Xfl(X1LJX2LJ---UXnUX,,+1)=(XflX1)LJ(XflX2)LJ---LJ(XflX,,)LJ(XflXn+1). Let Y = X” U Xn+1. By the inductive assumption, Xn(X1uX2u---uXn_1uY) =(XnX1)u(XnX2)u---u(XnXn_1)u(XnY). By the associative law, Xfl(X1UX2U---UXn_1LJY) :Xfl(X1UX2U---UXnLJXn+1). By the distributive law, XflY : Xfl(XnLJXn+1) : (X flXn) U (XflXn+1). Therefore (XflX1)LJ(XflX2)LJ- - -LJ(XflX,,_1)LJ(XflY) : (XflX1)U(XflX2)LJ- - -LJ(XflX,,)U(XflXn+1),  and the Inductive Step is complete.  Section 2.2 2. Not a function  3. It is a function from X to Y; domain : X, range = Y; it is both one—to—one and onto. Its arrow diagram is  1 a 2 b 3 4 d X Y  The inverse function is {(c, 1), (d, 2), (a, 3), (b, 4)}.  For the inverse function, domain : Y, range : X. Its arrow diagram is  a 1 b 2 c 3 d 4 
CHAPTER 2 SOLUTIONS  5. It is a function from X to Y; domain = X, range 2 Its arrow diagram is  11.  12.  14.  15.  17.  18.  1 . 2\:  3 .0 4 .d X Y  It is neither one-to-one nor onto.  4; H- ”6—J 3» (——l (—l 2 6-—l e—1 1———1 -21?/53‘/5 ‘.1 I 95953  Not one-to-one. f(4/3) = f(—2/3). Not onto. f(a:) 7E 0 for any real 51:. Not one-to-one. sin0 = sin 27r. Not onto. sina: 7E 2 for any real as. One-to—one. Not onto. f (cc) yé -2 for any real cc.  Not one-to-one. Notice that f (a:) = f(1/cc). Thus any value of as, as 7E 0, as 7E 1, shows that f is not one-to-one. Not onto. f (cc) 7E 1 for any real 2:. (In fact, -1 /2 3 f (cc) 3 1/2 for all real 2:.)  Let f be the function from X : {a, b} to Y : {y} given by f 2 {(a, y), (b, y)}.  The function {(1,1),(2,1)} from {1,2} to {1,2}.  33 
34  20  24. 26.  27. 30. 31. 33. 34. 36.  37.  39.  43. 44. 46.  47. 50.  51.  CHAPTER 2 SOLUTIONS  21. f‘1(y) = 21*/3  _ +5 1/3 f 1(y)=1os3y y——)  23. r1<y> : ( 4  f‘1(y) = [10g2(y - 6) + 1]/7  (f° f)(iI>) = 2(2n+ 1) + 1, (9°9)(~’v) = 3(3n- 1) - 1. (f°9)(93) = 2(3n — 1) + 1, (9°f)(~’l?) = 3(2n+1) -1  (f 0 f)(cv) = 04, (9 0 9)(w) = 22". (f 0 9)(w) : 22", (9 0 f)(w) = 2”2 9(56) : 1/93, h(iI«‘) = 293, M93) = 932, (9 ° ho w)(iI«‘) : f(03) 9(93) = 293: M93) = 511193, f(113) : (h ° 9)(5'3) g(a:) = 3:4, h(a:) = 3 + as, w(:1:) : sings, (g o h o w)(a:) = f(a:) g(a:) = 1/9:3, h(a:) 2 69:, t(a:) : cosas, f(:1:) = (go t o h)(a:)  4; one-to-one functions: {(1, a), (2, b)} and {(1, b), (2, a)}. In this case, the onto and one-to-one functions are the same.  (a) f0 f : {(a.a). (ab), <c,a)}, f0 f o f = {(a,b), (b, a), (c, 12)} (b) f9 : f. I623 : f  f = {(0, 0), (1,4), (2,2), (3,0), (4,4), (5,2)}. f is neither one-to-one nor onto. The arrow dia- gram of f is  O O  U1:-$>C»Dt\3  f.5 XX  714 ; 0,631 :2,26 : 9,373 ; 16,775 : 10,906 : 5,509 : 1,2032 : 11,42 : 8,4 : 4,136 : 3,1028 ; 12 53:4,13:5,281:3,743:6,377:9,20:7,10:1,796:8  During a search if we stop the search at an empty cell, we may not find the item even if it is present. The cell may be empty because an item was deleted. One solution is to mark deleted cells and consider them nonempty during a search.  No. If the data item is present, it will be found before an empty cell is encountered.  False. Let X = {1}, Y = {a, b}, Z = {a,fi}. A counterexample is f : {(a,a),(b,fi)}, g : {(110)}-  False. Let X = {1,2}, Y = {a, b}, Z = {a,fi}. A counterexample is f : {(a,a),(b,a)}, g : {(1,a),(2,b)}- 
53.  54.  CHAPTER2 SOLUTIONS 35 True False. Let X 2 {1}, Y 2 {a, b}, Z 2 {a}. A counterexample is f 2 {(a,a),(b,a)}, g 2  56.  58.  59.  60.  61.  63.  {(1.0)}-  True. Let z E Z. Since f o g is onto, there exists as E X such that f(g(a:)) 2 z. Let y 2 g(a:). Then f (y) 2 2. Therefore f is onto Z.  Suppose that f is not one—to—one. Then, for some as and y, f(a:) 2 f(y), but as 7E y. Let A = {:6}, B 2 {1/}-» Suppose that f is one—to—one. Let y E f(A 0 B). Then y 2 f(a:) for some as E Am B. Thus 3; E f(A) flf(B). Let y E f(A) flf(B). Then y 2 f(a) 2 f(b), for some a E A, b E B. Since f is one-to-one, a 2 b. Therefore, y E f (A H B). [The case: If g is one-to-one, then f o g is one—to-one implies that f is one—to—one.]  Suppose that f is not one-to-one. Then there exist distinct 501,932 6 X with f (331) 2 f(a:2). Let A 2 {1, 2}, and let g 2 {(1,a:1), (2, a:2)}. Now g is one-to-one, but f o g is not one-to-one, which is a contradiction.  Suppose that f is onto Y. Let g be a function from Y onto Z. We must show that go f is onto Z. Let z E Z. Since g is onto Z, there exists y E Y, with g(y) 2 z. Since f is onto Y, there exists as E X, with f(a:) 2 y. Now g o f(a:) 2 z. Therefore, g o f is onto.  Suppose that whenever g is a function from Y onto Z, g o f is onto Z. Suppose that f is not onto Y. Then there exists yo 6 Y such that for no as E X do we have f(a:) 2 yo. Let Z 2 {0, 1}. Define g from Y to Z by g(y0) 2 1, and g(y) 2 0 if y 7E yo. Then g is onto Z, but g o f is not onto Z.  If as e X, then as e f‘1(f({a:})). Thus u{S 1 S e 5} : X.  Suppose that a e f‘1({y}) n f“1({z}) for some y, z E Y. Then f(a) 2 y and f(a) 2 z. Thus y 2 z. Therefore, 5 is a partition of X.  IfccEX—Y, then CXU;/(as) 2 1 2 1 + 0 — 1-0 2 CX(a:) + Cy(a:) — CX(a:)Cy(a:). Similarly, if as E Y — X, the equation holds. If as E X H Y, then CXUy(:l3) 2 1 2 1 + 1 — 1- 1 2 CX(a:) + C;/(cc) — CX(a:)Cy(a:). Ifa:¢XUY, then CXU;/(as) 2 0 2 0 + 0 — 0-0 2 CX(a:) + Cy(a:) — CX(a:)Cy(a:).  Thus the equation holds for all as E U. 
36  64.  66.  67. 69.  71. 72. 74.  76. 77.  79. 80. 82.  83. 87.  CHAPTER 2 SOLUTIONS  Ifa: E X, thena: ¢X; thus, Cf(a:)=0:1—1:1—CX(a:). Ifa: ¢X, thena: EX; thus, Cf(a:)=1:1—0:1—CX(a:).  If C),-(cc) = 0, the inequality obviously holds. If CX(a:) = 1, then as E X. Since X Q Y, a: E Y. Thus Cy 2 1 also. Again, the inequality holds.  CXA3/(cc) : C'X(CL‘) + C3/(:1?) — 2C'X(:(:)Cy(a3)  Suppose that there is a one—to-one function f from X to Y. Let R be the range of f and choose a E X. If y E R, let g(y) : f“1(y). If y E Y — R, let g(y) 2 a. Then g is a function from Y onto X.  Suppose that there is a function g from Y onto X. For each as E X, choose one y E Y with g(y) 2 cc. Define f (cc) 2 y. Then f is a one—to-one function from X to Y.  f is not a binary operator since the range of f is not contained in X. f is a commutative, binary operator. f is a commutative, binary operator. To see this, note that if cc, 3; E X, then 1 3 say. Now 0 S (iv-1/)2 =63 -2:61/+1/2;  hence, 1 S:vyS:v2-:vy+y2:f(w.y)-  f(X) : X U {1} Let R denote the set  {(1/,rv)l(cv,y)E f}-  The set of y such that (y,a:) E R is Y since f is onto. If (y,a:), (y,a:’) E R, then as : cc’ since f is one-to-one. Thus R is a function from Y to X.  For each :1: E X, there is exactly one 3; E Y with R(y) : as since f is a function. Therefore R is one-to-one and onto.  False. A counterexample is as : y = 1.5. False. A counterexample is 1: : 2, y : 2.6.  Since n is an odd integer, n : 219 + 1 for some integer Is. Now  n2 4k2+4k+1 2 1 2 Mi 4 H.....,i and 2 41¢? 4k 1 3 n+3:( + +)+ :k2+k+1_ 4 4 51:21.5  August 
CHAPTER 2 SOLUTIONS 37 Section 2.3 4. 5 5. 13 6. 199 7. 4153 8. 9 9. 45 10. 15 11. 3465 12. 5,, : 2(n+ 1) - 1 13. Yes 14. No 15. No 16. Yes 17. 8 18. 26 19. 41 20. 8 21. Yes 22. No 23. No 24. Yes 31. No 32. No 33. Yes 34. Yes 35. Yes 36. Yes 37. Yes 38. Yes 51. 2 52. 5 53. cu = 71/2, ifn is even; cn : (n — 1)/2 —n, if n is odd. 54. d,, = (—1)”/2n!, if n is even; d” = (—1)(”+1)/2n!, if n is odd. 55. No 56. No 57. No 58. No 59. 9 60. 30 61. 3n 62. 3” 63. No 64. No 65. Yes 66. Yes 74. 3/4 75. 10/11 76. 1 - 1/(n + 1) 77. 1/[(n + 1)(n!)2] 78. No 79. Yes 80. Yes 81. No 82. 3"n! 87. 21,22,23,24,25,26,27 88. 21,22,24,27,211,215,222 89. nk = flk——_2i+—2 90. t... : 2"~ : 2W-1>+21/2 95. -1 96. -14 97. -88 98. -476 99. 3-21’ -45" 100. 3 - 2"-1 - 4- 5"-1 101. 3- 2"-2 - 4 - 5"~2 102. 77',,_1 — 107'n_2 : 7(3 - 2"-1 - 4- 5"-1) - 10(3 - 2"-2 - 4- 5"-2) : 3(7 - 2"-1 - 10- 2"-2) - 4(7 - 5"~1 - 10- 5"-2) : 3 (§2" - 1-402") - 4 (§5" - 495") =3-2"-4-5"=r,, 103. 2 104. 9 105. 36 106. 135 107. (2+e‘)3*' 108. (1+n)3"~1 109. 713"” 110. 6zn_1 - 9z,._2 : 6(1 + n)3"-1 - 9(n3”“2) : 2(1 + n)3” - n3”  112.  115.  3”[2(1 + n) — n] = (2 + n)3” : zn  11-1 n—1 2(1: + 1)27'"'k_1 113. Z C,-C”...--1 lc:0 i=0  The first sum is the sum by rows of the matrix  0/111 0/211  G12 G13 G22 G23  G11  a’11/I1. 
38  116.  118. 121.  122.  123.  CHAPTER 2 SOLUTIONS  and the second sum is the sum by columns of the same array. Thus the two sums are equal.  (a) baabcaaba (9) 9 (f) 9 (k) baabcaababbab  (b) caababaab (c) baabbaab (g) 8 (h) 10 (i) baab (l) caabacaababbabbaab  (d) caabacaaba  (j) caaba  A,0,1,00,01, 10,11 119. 000, 001, 010, 011, 100, 101, 110, 111 A, b, a, c, ba, ab, bc, bab, abc, babc  A, a, b, aa, ab, ba, bb, aab, aba, baa, abb, aaba, abaa, baab, aabb, aabaa, abaab, baabb, aabaab, abaabb, aabaabb  Basis Step (11 : 1). In this case, {1} is the only nonempty subset of {1}, so the sum is 1 — : 1 2 n. 1  Inductive Step. Assume that the statement is true for n. We divide the subsets of {1,...,n,n+1} into two classes:  C1: C2:  class of nonempty subsets that do not contain n + 1 class of subsets that contain 11 + 1.  By the inductive assumption, 1 Z ,7-, . . .,,  C1 ‘V  :71.  Since a set in C2 consists of n + 1 together with a subset (empty or nonempty) of {1, . . . ,n},  1 n1...n.  Ic  Z 1 Z 1 + 1 C2(n+1)n1---nk n+1 n+1  [The term 1/ (n + 1) results from the subset {n + 1}.] By the inductive assumption,  1 + 1 Z 1 _ 1 + 1 n_1 n+1 n+1C1n1---n;c_n+1 n+1 M" Therefore, 1 Z —1. C2 (n+1)n1 -11,, Finally, 1 1 1 C1UC2n1---nk C1 n1 nk C2 (’I’L+ )’/L1 -nk 
CHAPTER 2 SOLUTIONS  125.  126.  128.  39  Taking a : A, the first rule tells us that aab = ab 6 L and baa = ba 6 L. Taking a 2 ba and fl : ab, the second rule tells us that afi = baab E L. Finally, taking a = baab and fl = ab, the second rule tells us that afi : baabab E L.  Exercise 127 shows that if a E L, a has equal numbers of a’s and b’s. Since aab has more a’s than b’s, aab is not in L.  We use strong induction on the length n of a to show that if a has equal numbers of a’s and b’s, then 0! E L. The Basis Step is n = 0. In this case, a is the null string, and the null string is in L by the definition of L.  Suppose that a has length n > 0, and a has equal numbers of a’s and b’s. Notice that, because of the first rule, the length of a is at least two. First suppose that a starts with a and ends with b, that is, a : afib. Then fl has length less than n, and fl has equal numbers of a’s and b’s. By the inductive assumption, fl E L. By the first rule, a 2 afib E L. Similarly, if a starts with a and ends with b, then a E L.  Now suppose that a has equal numbers of a’s and b’s and a starts with a and ends with a, that is, a : afia. We claim that some proper substring of a starting at the beginning contains equal numbers of a’s and b’s; that is, we claim that a 2 76, where 7 and 6 have equal numbers of a’s and b’s, and neither 7 nor 6 is the null string. Assuming that this claim is true, by the inductive assumption 7 and 6 are in L, and it follows from the second rule that a E L. The Inductive Step is complete.  To prove the claim, for each substring 5 of a starting at the beginning, consider val(€) = number of a’s — number of b’s.  Consider val(e) for substrings 5 of increasing length. For the first substring, a, val(a) : 1. For the next—to-last substring (a with the trailing a omitted), we have val(e) : -1. When the length of the substring increases by one, val(e) increases or decreases by one. Since val’s first value is 1 and its last value is -1, for some substring fl, val(fi) : 0. Thus fl has equal numbers of a’s and b’s, and the claim is proved. 
40  CHAPTER 3 SOLUTIONS 
Chapter 3  Solutions to Selected Exercises  Section 3.1 2. {(a,3),(b,1),(b,4),(c, 1)} 3. {(Sa1ly,Math), (Ruth,Physics), (Sam,Econ)} 6. ¢ Roger Music Pat History Ben Math Pat Po1ySci 7. 1 1 2 1 3 1 4 1 2 2 3 2 4 2 2 3 3 3 4 3 2 4 3 4 4 4 10. 2 11. 1 2 3 1 Q 4 3 14. {(1,1),(2,2),(3,3),(3,5),(4,3),(4,4),(5,5),(5,4)} 15. 0  18. (Exercise 1) {(Hammer, 8840), (P1iers,9921), (Paint,452), (Carpet,2207)} 20. {(1,1),(4,1),(2,2),(5,2),(3,3),(1,4),(4,4),(2,5),(5,5)}  41 
42  21. 26.  27. 31. 33. 36. 37.  40. 41. 43. 46. 48. 54. 55. 58. 61.  62.  63.  CHAPTER 3 SOLUTIONS  {1,2,3,4,5} R = {(1, 2), (2, 3), (3,4), (4, 5)} R-1={(2,1>,<3,2>,<4,3>,<5,4>} domain of R : {1, 2, 3,4} range of R : {2, 3,4, 5} domain of R-1 = {2,3,4,5} range of R‘1 : {1,2, 3, 4}  23. {1,2,3,4, 5} 24. {1,2,3,4,5}  Symmetric 30. Antisymmetric, transitive  Reflexive, antisymmetric, transitive, partial order  Reflexive, symmetric, transitive 34. Reflexive, symmetric, transitive  Reflexive, symmetric  Reflexive: Suppose that (131,332) is in X1 >< X2. Since R; is reflexive, a:1R1a:1 and a:2R2a:2. Thus (961,962)R(931,932)-  Antisymmetric: Suppose that (a:1,cc2)R(a:’1,a:§) and (331,932) 7E Then a:1R1:1:’1 and a:2R2a:§ and either 331 75 a:’1 or 3:2 7E We may suppose that 331 75 Since R1 is antisym- metric, (a:’1,a:1) is not in R. Thus (a:’1,a:§),R(:c1,a:2). Therefore, R is antisymmetric.  Transitivity is proved similarly. {(1,1), (2,2),(3,3),(4,4),(1,2),(2,3)} {(1, 1), (2,2), (3,3), (4,4), (1,2), (2,3)} {(1,2),(2,3),(1,3)} 45. True False. Let R : {(2,3), (4, 5)}, S : {(1,2), (3,4)}. True 49. True  51. True 52. True  False. Let R = {(2,3), (3,2)}, 5' = {(1,2),(2,1)}. True 57. True False. Let R = {(2,3),(1,1)}, S : {(1,2),(3,1)}.  R is reflexive, not symmetric, not antisymmetric, transitive, and not a partial order. To see that R is not symmetric, consider A = {1} and B = {1, 2}. To see that R is not antisymmetric, consider A = all real numbers and B = all rational numbers.  R is reflexive, symmetric, not antisymmetric, transitive, and not a partial order. To see that R is not antisymmetric, consider A 2 all real numbers and B = all rational numbers.  If may be the case that for as E X, there is no y E X such that (cc,y) E R. Consider, for example, X = {1,2,3}, R 2 {(1, 1), (2,2), (1,2), (2, 1)}, and as = 3. 
CHAPTER 3 SOLUTIONS  43  Section 3.2  2.  10.  13.  16.  17.  19.  20.  21.  23.  25.  26.  28.  29.  31.  . Equivalence relation. [1] 2  Not an equivalence relation (not transitive) Not an equivalence relation (not reflexive)  [4] = [5] = {1,2,3,4,5}.  . Equivalence relation. [1] = [5] = {1, 5}, [2] = {2}, [3] : {3}, [4] = {4}.  . Not an equivalence relation (not reflexive, not symmetric, not transitive)  Not an equivalence relation (not transitive) 11. Equivalence relation  Equivalence relation 14. Equivalence relation  {(1a1):(272):(3,3),(4a4)¢(3a4)a(413)}a [1] = {1}, [2] = {2}, [3] = [4] = {3,4} {(1,1),(2,2),(3,3),(4,4)}, [1] 2 {1} for 1 = 1,...,4 {(131) [M E {1.2,3=4}}, [1] = [2] = {(1»1)» (2,2),(2,4),(4a2)a(4a4)a(3,3)}, l1l={1}a [2] = [4] = {?«»4}, [3] = {3} Reflexive: ARA since A U Y : A U Y.  Symmetric: If ARB, then AU Y = B U Y. Now B U Y : A U Y, so BRA.  Transitive: Suppose that ARB and BRC. Then AUY = B UY and B U Y : C U Y. Therefore AUY :CUY. Thus ABC.  [3] : [4] : {1a2a3!4}  Eight. An equivalence class is determined by the presence or absence of 1, 2, and 5.  Since R is an equivalence relation, R is reflexive. Therefore (33,513) E R for all as E X. Therefore  domain R : range R : X.  If R is a relation on X having the given property,  R:{(a:,y)]:z; andyare in X}.  {(11 1): (21 2)» (313): (4: 4)! (5! 5)» (676): (1,2): (2! 1): (314)) (41 3)}  Five, corresponding to the partitions {{1}, {2}, {3}}, {{1}, {2, 3}}, {{1,2}, {3}}, {{1,3}, {2}}, {{1» 2, 3}} (a) Reflexive: (a, b)R(a, b) for all a, b E X since ab = ba for all a, b E X. Symmetric: Suppose that (a, b)R(c, d). Then ad : be. Since cb : da, (c, d)R(a, b).  Transitive: Suppose that (a,b)R(c,d) and (c, d)R(e, f). Then ad 2 bc and cf : de. Now af : adf/d = bcf/d = bde/d : be. Therefore (a,b)R(e, f). 
44  32.  34.  35. 37.  38. 40. 41. 44. 45.  47.  CHAPTER 3 SOLUTIONS  (1a1)7(1a2)7 (1a3)7(1a4)a (175): (17 6):(177)7(1a8)7(179)7(1710): (2a1):(273)7(275)7(2>7)a (23 9), (33 1)) (35 2)’ (3! 4), (37 5)? (3? 7)} (3, 8)’ (3! (45 1), (4, 3), 47 5), (41 7)? (47 9)! (571)7(5a2)a(5a3)a(5a4)1(5)6):(5a7)1(518)7(5a9)7(6a1)a(6a5)7(6a7)a(771)7(7a2)a (77 3)7 (73 4)7 (77 5)7(776)a (778)7(779)a(7a 10)7(8a1)7(8a3)7(875)1(8a7)7(879)7(97 1): (95 2)’ (93 4)) (95 5)! (95 7)! (97 8)? (93 1)’ 3)! 7)’ (c) (a, b)R(c, d) if and only if if : (9,.  We show symmetry only. Let (a, b) E R H R‘1. Then (a, b) E R, so (b, a) E R'1. Since  (a, b) E R'1, (b, a) E R. Thus (b, a) E R 0 R‘1 and R H R‘1 is symmetric.  R is reflexive since for every cc, as E S for some S E S. R is also symmetric, for suppose that a:Ry. Then 93,3; 6 S for some S E 8. Thus y,a: E S and yR:z:. R need not be transitive. Let X : {1,2,3}, S1 : {1,2}, S2 2 {2,3}. Then X : S1 US2. Now 1R2 and 2R3, but 1,R3.  (b) Cylinder Reflexive: For every as E X, by the definition of a function f (as) is defined. Since f (ac) : f(:1:), a:Ra: for every as E X. Symmetry: Suppose that a:Ry. Then f(a:) = f(y). Since f(y) = f(a:), yRa:. Transitivity: Suppose that :1;Ry and yRz. Then f (as) = f (y) and f (y) = f (z). Therefore f(a:) = f(z) and a:Rz. Suppose that f = Cy. The equivalence classes are Y and 7. When a: and y are in the same equivalence class Suppose that [as] = [y]. Then a:Ry. Therefore, g(a:) : g(y). Since (y, y) 6 {(33,513) la: 6 X} for all y E X, (y,y) E p(R) for all y E X. Thus p(R) is reflexive.  Let (a:,y) be in RU R'1. If (a:,y) is in R, (y,:1:) is in R'1, so (y,a:) is in R U R'1. If (a:,y) is in R'1, then (y,a:) is in R, so (y,a:) is in RU R'1. In any case, if (as, y) is in RU R'1, (y,a:) is in R U R'1, so R U R'1 is symmetric. Since  R Q p(R), R Q a(R), R Q T(R), (3.1)  it follows that R Q T(a(p(R))). By (3.1), p(R) Q T(a(p(R))) and by Exercise 44, p(R) is reflexive. Therefore, r(a(p(R))) is reflexive. By Exercise 45, a(p(R)) is symmetric. We show that if R’ is any symmetric relation, r(R’) is symmetric. We can then conclude that T(a(p(R))) is symmetric. Let R’ be a symmetric relation. Let (cc,y) E T(R’). Then there exist as 2 3:0, . . .,a:,, = y E X such that (cc,-_1,a:,-) E R’ fOI"i : 1, . . . ,n. Since R’ is symmetric, (cc,-,a:.--1) E R’ for 1' : 1, . . . , n. Thus (y,a:) E T(R’) and T(R’) is symmetric. By Exercise 46, T(a(p(R))) is transitive; hence T(a(p(R))) is an equivalence relation contain- ing R. 
CHAPTER 3 SOLUTIONS  48.  51. 52. 54. 58. 59.  45  By Exercise 47, T(a(p(R))) is an equivalence relation containing R. We first observe that if R1 Q R2 Q X x X, then  ,0(R1) Q /J(R2), 0(R1) E 0(R2), T(R1) Q T(R2)- It follows that if R’ is a relation on X and R’ Q R, T(0(,0(R'))) 2 T(0(,0(R)))-  The conclusion will follow if we show that if R’ is an equivalence relation on X, R’ : T(a(p(R’))).  Suppose that R’ is an equivalence relation. Since R’ is reflexive, p(R’) = R’. Since R’ is symmetric, a(R’) = R’. Thus a(p(R’)) : R’. We show that T(R’) = R’. Clearly, R’ Q T(R’). Let (a:,y) E T(R’ Then (a:,y) E R’” for some positive integer n. Thus there exist 1:0, . . . ,cc,, 6 X with as : 330, y : cc”, and (cc,-_1,a:,-) E R’ for 1' : 1,. ..,n. Since R is transitive, (as, y) = (a:o,a:,,) E R’. Thus R’ Q r(R’). Therefore, R’ = T(R’). Now  R’ = T(R') = T(0(,0(R')))- False. Let R1 : {(1,1),(1,2)}, R2 : {(2,2),(2,1)}. False. Let X 2 {1,2,3}, R1 = {(1,2)}, R2 : {(2,3)}. False. Let R1 = {(1,2), (2,3)}. 55. True  X and Y have the same number of elements.  The function f(n) = 2n is a one—to—one, onto function from {1, 2, . . to {2, 4, . .  Section 3.3  9. 12. 15.  0 0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0 1 1 0 1 0 3. 1 1 0 0 5. 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 1 . 1 0 0 1 0 0 0 1 7. [For Exercise 13] 0 0 1 1 0 0 0 0 0 0 0 0  {(1, 1), (1,3), (2,2), (2, 3), (2,4)}  Symmetric and transitive  10, {(w,w), (w,y), (1/,w), (1/,1/), (2,2)) 13. Take the transpose of the given matrix.  [For Exercise 4] The matrix of R is  0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 , 0 0 0 0 1 0 0 0 0 0 
46 CHAPTER 3 SOLUTIONS  and its square is  @966 ©©©©© COG?-‘ ©©>-‘C ©r—l©©  0 000  The entry in row 1, column 3 of the square is nonzero, but the entry in row 1, column 3 of the original matrix is zero. Therefore the relation is not transitive.  1010 1000 2110 0100 1100 1100 17'(a)0010 @1110 @1110 0001 1111 1111 1110 1100 (d) 1110 1111 1), (23 2)? (27 3)? (33 1), (35 2), (45 1)’ (4, 2), (4, 3)? (53 1)’ (55 2)’ (53 3)’ (57 11111 00000 11110 11110 10000 11100 18.(a)11100 (b)01000 (c)11000 11000 00100 10000 10000 00010 00000  (d) The matrix of part (c) is the matrix of the relation R2 o R1. (9) {(111).(1,2)a(1»3),(1,4),(2,1),(2,2),(2,3),(3,1),(3,2)a(411)}  20. Let a,-,~ denote the ijth entry of A1 and bij denote the ijth entry of A2. Let n be the number of elements in Y. The tkth entry of A1A2 is found by taking the product of the 1th row of A1 and the kth column of A2. Thus if c,-;, is the ikth entry of the product, we have  TL Cue I Z azijbjlv i=1  Now a term in this sum is nonzero only when both factors in the term are nonzero. This wifl be the case for all j such that a.-,- = 1-,, = 1. This happens only when (t',j) E R1 and (j, k) E B2. c,-;, is then precisely the number of these j’s.  22. Suppose that the ijth entry of A is 1. Then the zjth entries of both A1 and A2 are 1. Thus (’i,j) E R1 and (’i,j) E R2. Therefore (’i,j) E R1flR2. Now suppose that (’i,j) E R1flR2. Then the ijth entries of both A1 and A2 are 1. Therefore the zjth entry of A is 1. It follows that A is the matrix of R1 0 R2.  23. The matrix A of Exercise 21 is  1-o>—» o>—»>—» >é>é@ 
CHAPTER 3 SOLUTIONS  24.  26. 27.  47  whose relation is R1 U R2 : {(1> 1): (1.1 2): (2: 2)» (21 3): (3: 1): (3:  The matrix A of Exercise 22 is  1-100 O>—*C>  whose relation is R1 0 R2 : 2): (3: 1): (3:  Every column must contain at least one 1.  Every column must contain at most one 1.  Section 3.4  2. 3.  10.  12.  13.  {(23,Jones), (04,Yu), (96, Zamora), (66,Washingt0n)}  {(04,335B2,220), (23,2A,14), (04,8C200,302), (66,42C,3), (04,900,7720), (96,20A8,200), (96,1199C,296), (23,772,39)}  {(Unjted Supp1ies,2A), (ABC Un1imited,8C200), (United Supp1ies,1199C), (J CN E1ectronics,2A), (United Supp1ies,335B2), (ABC Un1imited,772), (Danny’s,900), (United Supp1ies,772), (Under- handed Sa1es,20A8), (Danny’s,20A8), (DePau1 University,42C), (ABC Un1imited,20A8)} DEPARTMENT[Manager]  Jones, Yu, Zamora, Washington  SUPPLIER[Part No] 335B2, 2A, 8C200, 420, 900, 20A8, 11990, 772 TEMP1 :: EMPLOYEE[Manager = Jones] T EMP2 2: TEMP1[Name] Kaminski, Schmidt, Manacotti TEMP ;: SUPPLIER[Dept : 96] TEMP [Part No] 20A8, 11990 TEMP1 := DEPARTMENT[Dept = 04]  TEMP2 :2 TEMP1[TEMP1.Manager = EMPLOYEE.Manager] EMPLOYEE TEMP3 ;= TEMP2[Name]  Jones, Beaulieu  TEMP ;= SUPPLIER[Amount 2 100] TEMP[Part No]  335132, 8C200, 900, 20A8, 11990 
48  15.  16.  19.  23.  24.  CHAPTER 3 SOLUTIONS  TEMP1 :: BUYER[Name : United Supplies] TEMP2 :: TEMP1[TEMP1.PaI‘t No : SUPPLIER.PaI‘t No] SUPPLIER T EMP3 2: T EMP2[Part No, Amount]  Part No Amount 335B2 220 2A 14 11990 296 772 39  TEMP1 :: BUYER[Name : ABC Unlimited] TEMP2 :: T EMP1 [Part No : Part No] SUPPLIER TEMP3 :: TEMP2 [Dept : Dept] DEPARTMENT TEMP3[Manager]  Yu, Jones, Zamora  TEMP1 :: DEPARTMENT[Manager : Jones] TEMP2 :: TEMP1[TEMP1.Dept : SUPPLIER.Dept] SUPPLIER TEMP3 2: T EMP2[TEMP2.Part No : BUYER.Part No] BUYER TEMP4 :: TEMP3[Name]  United Supplies, JON Electronics ABC Unlimited  TEMP1 :: EMPLOYEE[Name : Suzuki] TEMP2 :: TEMP1 [Manager : Manager] DEPARTMENT TEMP3 :: TEMP2 [Dept : Dept] SUPPLIER T EMP4 2: TEMP3 [Part No : Part No] BUYER TEMP4[Name]  Underhanded Sales, Danny’s, ABC Unlimited, United Supplies  The intersection operator will operate on two relations with the same set of attributes (arranged in the same order). The relation resulting from the intersection will have the same set of attributes. A tuple in the new relation will be a tuple in both of the two relations operated on. We will express the intersection operation using the set intersection symbol.  TEMP1 ;: BUYER[Part N0 = 2A] TEMP2 :: TEMP1[Name] TEMP3 ;= BUYER[Part N0 = 11990] TEMP4 ;: TEMP3[Name] TEMP5 :: TEMP2 n TEMP4  Let R1 and R2 be two n-ary relations. The difiemnce of R1 and R2 is the n—ary relation R1 —R2.  TEMP1 :: EMPLOYEE [Manager : Manager] DEPARTMENT TEMP2 :: TEMP1[Dept : 04] TEMP3 2: TEMP1 — TEMP2 TEMP3[Name]  Suzuki, Kaminski, Ryan, Schmidt, Manacotti 
Chapter 4  Solutions to Selected Exercises  Section 4.1  3. m2'n(a,b,c) { small : a if (b < small) small = b if (c < small) small : c return small  }  4. second-smallest(a, b, c) { as : a y = b z : c if (as > y){ temp : as 5'3 2 1! y 2 temp } if <2; > z) { temp = y 1! : Z 2 = temp } if (as > y) { temp = as as = y y = temp }  return y  49 
50  6. find_large_2nd_large(s, n, large, second_largest) { if (51 < 52) {  large = 52 second_largest : 51 } else { large : s1 second_largest : 52 }  for 1 : 3 to n if (s,- > second_largest) if (s,- > large) { second_largest = large large 2 51- } else second_largest : 5,-  }  7. find_small_2nd_small(s, 11, small, second_smallest) { if (51 < 82) { small = .91 second-smallest : .92  } else { small : s2 second_smallest = 51 }  for 1 : 3 to n if (5; < second_smallest) if (s,- < small) { seeond_smallest 2 small small : s,~ } else second_smallest : 5,-  }  9. find_largest_element(s,n) { large : 51 1'ndea:-large : 1 for 1 2 2 to n if (s,- > large) { large : 5,- 1'ndea:_large = 1  }  CHAPTER 4  SOL UTIONS 
CHAPTER 4  10.  12.  13.  15.  16.  18.  SOLUTIONS 51  return 2'ndea:_large  }  find_last_largest_element(s, n) { large : 51 2'ndea:_large : 1 for 2' : 2 to n if (s,- 2 large) { large = 5,- z'ndea:_la7ye : i }  return z'ndea:_large  }  find_out_of_order1 (5, n) { for 1' 2 2 to n if (Si < 8,‘_1) return i return 0  }  find_out-of_order2(s, n) { for i = 2 to n  if (Si > Si_1) return 1' return 0 } Assume that s,,,sn_1,...,s1 and tn,tn_1,...,t1 are the decimal representations of the two numbers to be added. The output is un+1,u,,, . . . ,u1.  add(s,t,u, n) { c : 0 for 1' = 1 to n { Let my be the decimal representation of the sum c + s,~ + t,-.  u,~:y 0:113 'U.n+1:C  }  transpose(A, n) { for 2' = 1 to n — 1 for j = i + 1 to n swap(A1-J-,A,-1-)  }  The input is the n x n matrix A of the relation, and n. 
52 CHAPTER 4  2's_symmetrz'c(A,n) { for 1' = 1 to n — 1 f0I‘j:’i+1 ton if (Aij “ 2 A1”) return false return true  }  19. The input is the n X n matrix A of the relation, and n.  z's_tmns1Jtz've(A, n) { // first compute B = A2 for 1' : 1 to n for j = 1 to n { B-5]‘ Z 0 for k = 1 to n } Bij : Bij + Aik * Akj  // if an entry in A2 is nonzero, but the corresponding entry // in A is zero, the relation is not transitive for 1' : 1 to n for j : 1 to n { if (Bij *1: 0 /\ Aij == 0) return false return true  }  21. The input is A, the m x n matrix of the relation, and m and n.  2's_functz'on(A,m,n) { for 1' : 1 to m { sum : 0 for j : 1 to n sum : sum + Aij if (sumwz 1) return false  }  return true  }  22. The input is the n x n matrix A of the relation, and n.  z'm)erse(A,n) { for 1' : 1 to n — 1 for j : i + 1 to n swap(A,‘,-, Aji)  SOL UTIONS 
CHAPTER 4 SOLUTIONS 53  24. pa1'r_sum(s, n, as) { for 1 = 1 to n — 1 for j : 1 + 1 to n if (.73 :1‘ Si + 8]‘) return true return false  Section 4.2  2. First 1' and j are set to 1. The while loop then compares tltgtg : “bal” with p : “lai”. Since “b” and “l” are not equal, 1' increments to 2 and 3’ remains 1.  The while loop then compares t2t3t4 : “ala” with p : “lai”. Since “a” and “l” are not equal, 1' increments to 3 and j remains 1.  The while loop then compares t3t4t5 = “lal” with p = “lai”. Since “l” and “l” are equal, 9' increments. Since “a” and “a” are equal, j increments again. Since “l” and “i” are not equal, 1 increments to 4 and j is reset to 1.  The while loop then compares t4t5t5 2 “ala” with p : “lai”. Since “a” and “l” are not equal, 1' increments to 5 and 3' remains 1.  The while loop then compares t5t5t7 = “lai” with p : “lai”. Since the comparison succeeds, the algorithm returns 1 = 5 to indicate that p was found in t starting at index 5 in t.  3. First 1 and j are set to 1. The while loop then compares t1t2t3 = “OOO” with p : “OO1”. Since “O” and “O” are equal, 3’ increments. Since “O” and “O” are equal, j increments again. Since “O” and “1” are not equal, 1' increments to 2 and j is reset to 1.  The while loop then compares t2t3t4 = “O00” with p = “O01”. Since “O” and “O” are equal, 9' increments. Since “O” and “O” are equal, j increments again. Since “O” and “1” are not equal, 1 increments to 3 and j is reset to 1.  This pattern repeats until the first for loop terminates. The algorithm then returns 0 to indicate the p was not found in t.  5. First 20 is inserted in  34  Since 20 < 34, 34 must move one position to the right  34  Now 20 is inserted  20 34 
54  CHAPTER 4  Since 19 < 34, 34 must move one position to the right  20 34  Since 19 < 20, 20 must move one position to the right  20 34  Now 19 is inserted  19 20 34  Since 5 < 34, 34 must move one position to the right  19 20 34  Since 5 < 20, 20 must move one position to the right  19 20 34  Since 5 < 19, 19 must move one position to the right  19 20 34  Now 5 is inserted  The sequence is now sorted.  . Since 55 > 34, it is immediately inserted to 34’s right  34 55  Since 144 > 55, it is immediately inserted to 55’s right  34 55 144  Since 259 > 144, it is immediately inserted to 144’s right  34 55 144259  SOL UTIONS 
CHAPTER 4  10.  12.  SOLUTIONS 55  The sequence is now sorted.  We first swap a,- and aj, where 1' : 1 and j : mnd(1, 5) = 2. After the swap we have  57 34 72 101 135 T T 1 1  We next swap a,- and a,-, where 1 = 2 and j = mnd(2, 5) 2 5. After the swap we have  57 135 72 101 34  T T J  Z  We next swap a,- and a,-, where 1 = 3 and j : mnd(3, 5) : 3. The sequence is unchanged.  We next swap a,~ and aj, where 1 : 4 and j : mnd(4, 5) 2 4. The sequence is again unchanged.  We first swap a,- and aj, where 1 2 1 and j = mnd(1, 5) = 5. After the swap we have  135 57 72 101 34 T T 1 1  We next swap a,- and aj, where 1 = 2 and j = mnd(2, 5) : 5. After the swap we have  135  34 72 101 57 T T 1 1  We next swap a,- and a,-, where 1 : 3 and j : mnd(3, 5) : 4. After the swap we have  135 34  101 72 T T 1 1  57  We next swap a,- and aj, where 1' 2 4 and j = mnd(4, 5) = 4. The sequence is unchanged.  Use the invariant: 51, . . . ,s,- is sorted.  13. find_fi1"st_key(s,n,key) {  for 1 : 1 to n if (key :2 5,-) return 1 return 0 
56  15. msert(s,n,a:) {  }  2'21 while (1 3 n/\a: > 5,-) z'=t'+1 // move 31-, . . .,.9,, down to make room for as jzn while (j _>_t'){ 5J‘+1=5j 1:2’-1 } //inserta: 8,'=.’I3  16. Replace the line  18.  by  While (tz'+;‘~1 == Pa") {  while _<_ m /\ t,'+j_1 Z: pj) {  Replace the line  lw  return 1'  println(z')  and remove the line  return 0  CHAPTER 4  SOL UTIONS  The worst case occurs when the for loop and the while loop run as long as possible. This situation is achieved when t consists of n 0’s and p consists of m — 1 0’s followed by one 1.  19. z'nsertz'on_sort_nonincreasing(s,n) {  forz'=2ton{  val : s,- // save s,- so it can be inserted into the correct place  j:1—1  // if val > 5,-, move .9,- right to make room for .9,-  while (j 2 1 /\ val > s,~){ =’>‘j+1 = 5:‘ j:j—1 }  5,-+1 : val // insert val 
CHAPTER 4 SOLUTIONS  57  21. [For Exercise 4] Selection sort first finds the smallest item, .92, and places it first by swapping  .91 and .92. The result is  20 34 144 55 T T 1 2  Selection sort next finds the smallest item, .92, in .92, .93, .94, and places it second by swapping .92  and .92. The sequence is unchanged.  Selection sort next finds the smallest item, 54, in .93, .94, and places it third by swapping .93 and  54. The result is  20 34 55 144  W—) 4>—)*  The sequence is now sorted.  22. In the pseudocode  select2'on_sort(s,n) { forz':1ton—1{ // find smallest in .9,-, . . . , .9” small_z'ndea: 2 2' for j : i + 1 to n (Sj < 5small__indez) smalljndea: = j 8wa'p(5ia 5sm.all_indez)  } }  the for loops always run to completion regardless of the input.  Section 4.3  2. em?) 3. e(n3) 5. e(n1gn) 6. e(n5) 9. o(n1gn) 11. em) 12. e(2") 14. o(n3) 17. o(n) 18. e(n2) 20. o(n2) 21. o(n3) 24. e(n) 26. ®(lglgn) 27. o(n) 30. (a) Even: 371/2 -2 Odd: (3n—1)/2 -1 (b) em)  32. Use Example 4.3.6.  8. ®(n2) 15. @(n5/2)  23. e(n3) 
58  CHAPTER 4 SOLUTIONS  34. 2”=2-2---2:2-2~2---2£2(2-3---n):2n! \?,_./ \_V_./  n2‘s n—12’s 35. First note that n Zz'lgt'§n(nlgn)=n2lgn. i=1 Therefore n Zilgi=O(n2lgn). 1:1 Now " . . " . . " n n n+1 n n n 2 n 3”“? Z “W Z l§l1gl§l=l 2 llallglal 3 (5) 1%)- i=1 i=fn/21 i=fn/21  37.  38.  40.  As in Example 4.3.9, if n 3 4,  Therefore if n 2 4, ", , n 2 n n nlgn_n2lgn .Z“g'3<§)1g<§)Z<’i) 4 ‘ 8 '  Zilgi = Q(n2 lgn). 1'21  It follows that  Therefore n Zilgi = ®(n2lgn).  1:1 For sufficiently large n, nk 2 max{2, c}. Therefore, for sufficiently large n, lg(n'° + c) S lg(n" + nk) = lg 2n'° 3 lg nknk : lg nm“ : 2k lg n.  Also, lg(n" + c) 2 lg nk = klgn for all n. Therefore, 1g(n'“ + c) : @(lg  Ek:lg(n/2*") : (k+1)lgn—(1+2+---+k) 1:0 : (k+1)1c—’”('”+1) : (lc+1)k 2 2 : (1+lg2n)lgn :®(1g2n)  We show that if f(n) : Q(g(n)), and f(n) > 0 and g(n) 2 0 for all n 2 1, then, for some constant C, f(n) 2 Cg(n) for all n _>_ 1-  Proof. Since f(n) : Q(g(n)), g(n) : O(f(n)). By Exercise 39, for some constant C’, g(n) S C’f(n) for all n 21. Taking C 2 1/(1 + C’), we have Cg(n) S f(n) for all n 2 1. 
CHAPTER 4  41.  43. 45. 47. 48. 54.  55.  57.  58. 59. 61. 63.  SOLUTIONS 59  Exercises 39 and 40 show that if f(n) : ®(g(n)), and f(n) > 0 and g(n) > 0 for all n 2 1, then, for some constants C1 and C2, C1g(n) 3 f (n) 3 C2g(n) for all n 2 1.  True: [2 + sinn| 3 3 _<_ 3|2 + cosn|. True False. A counterexample is f (n) : 1 for all n, and g(n) = 1 + 1/n.  False. A counterexample is f (n) = n, g(n) = n2. 50. True 51. True  If f(n) 7E 0(g(n)), then for every C > 0, lf(n)l > C|g(n)| for infinitely many n. If g(n) gé O( f (n)), then for every C > 0, lg(n)| > C| f (n)! for infinitely many n. However, there is no guarantee that even one n for which | f (n)! > C|g(n)| is true also makes |g(n)l > C] f (n)] true.  1 if n is even W‘) ‘{ 0 ifnis odd, We prove the result by using induction on k.  Basis Step (k : 1). By Exercise 17, Section 1.7, 1 + nzz: 3 (1 +33)”, for as 2 -1 and n 2 1. Thus, for as > 0 and n 2 1, na: < (1 +93)” or  mm:1—mm  1 n < —(1 +33)”. as  Taking C : 1/9: and c = 1 + 1: gives the desired result.  Inductive Step. Assume that if c > 1, there exists a constant C such that n'° 3 Cc" for all but finitely many n. Let c > 1. By the inductive assumption, there exists a constant C1 such that  n'° s C1(\/5)” for all but finitely many n. By the Basis Step, there exists a constant C2 such that n S C2(\/5)” for all but finitely many n. Multiplying these inequalities, we obtain n'°+1 : nkn g C1C2(\/E)”(\/E)” : C1C2c”  for all but finitely many n. The Inductive Step is complete. Therefore nk = O(c”) for all k 2 1 and c > 1.  f (n) = h(n) = t(n) 2 na 9(n) = 2n The @—notation ignores constants that are present in the formula for the actual time. Yes By referring to a graph like that of Exercise 62, with y : 1/as replaced by y : 33'”, we find that  1)'n'L+1 _ 1 (n + 1)m+1 m + 1 m + 1  n+1 1'”+2'”+---+n'”</ a:'”da:= (TM 1  The other inequality is proved in a similar manner. 
60  65.,  66.  68.  CHAPTER 4 SOLUTIONS  We rewrite the inequality of Exercise 64 as b”[b — (n +1)(b — a)] < a”+1.  If we set a 2 1 + 1/(n + 1) and b = 1 + 1/11, the term in brackets reduces to 1 and we have  111. 1 n+1 (1+—) <(1+ ) . n n+1  Therefore, the sequence {(1 + 1/n)”} is increasing.  We rewrite the inequality of Exercise 64 as b”[b — (n + 1)(b — a)] < a”+1.  If we set a = 1 and b = 1 + 1/(2n), the term in brackets reduces to %, and we have  1 n 1 —— 2. (+2n) <  Squaring both sides gives  By Exercise 65, {(1 + 1/n)”} is increasing; thus,  1 TL 1 211 <1+—) 41+”) n 2n  Using Exercise 67, we have  ” 1 " . . E §Z[1g(1+1)—1gz]:1g(n+1)§1g2n:1+1gng21gn, i=1 i=1 ifn22. Thus, " 1 E; :O(1gn). i=1  Again, using Exercise 67 , we have  " 1 1 n , _, 1 1 > §g[1g(z+ 1) —1gz] ~ §1g(n+ 1) Z Elgn. Thus, : Q(1gn). 1:1 1 Therefore, = ®(1gn). 
CHAPTER 4  69.  71.  72.  74.  75.  76.  77.  SOLUTIONS 61 In the argument given, the constant is dependent on n. False. A counterexample is f (n) = n and g(n) : n2. True. In fact, we can conclude that f (n) : @(g(n)) (see the hint to Exercise 73). False. A counterexample is f (n) : 1 for all n, and ()_ 1, ifniseven gn _ 2, ifnisodd. False. For a counterexample, see the solution to Exercise 7 4. Inductive Step. Assume that the inequality holds for n. Now lg(n + 1)! : 1g(n + 1) + lgn! 2 lg(n+1)+ glgg. If we can show that n n n + 1 n + 1 the inductive step will be complete. This last inequality is equivalent, in turn, to 1(n+1)+91 11-9 > "+11(n+1)—"+1 g 2 g 2 — 2 g 2 — 1 1 glgn _ n lg('n+1)—§ nlgn Z (n— 1)lg(n+ 1) — 1 nlgn 2 nlg(n+ 1) —lg(n+ 1) — 1 1 + lg(n + 1) Z n[lg(n + 1) — lgn] + 1 1+lg(n+1) 2 n<lgnn ) n + 1 " 1g<2<n + 1)) 2 1g( n ) n + 1 ” 1 ” 2 1 > : 1 — 4.1 <n+»—<.> <+.> <>  By Exercise 66, 1 TL <1+ -) < 4, n for all n. Thus inequality (4.1) holds for all n.  In the following figure, 
62  79.  CHAPTER 4  yzlnz  2: 11-1 11.  1 2 3  the area of the rectangles exceeds the area under the curve from 1 to n, so  [nlnmdx 3 Zlnk. 1 Ic=1  Now n nlnn—n < nlnn—n+ 1 2! lnccdcc. 1  The inequality may be rewritten §i<1gn>— 11 s Igm. Assuming the result of Exercise 78, it suflices to show that n §[(lgn) — 1] 3 nlgn —nlge, or, equivalently 1 §l(1gn) — 11 s ign —1ge, or, equivalently  lgn  1 (1g€)—§ S 2  Since 1 (lge)—§ 2 1.44...—0.5:0.9...,  SOL UTIONS  (4.2)  inequality (4.2) is obviously true for n 2 4. (The given inequality is clearly true for n 2 1, 2, 3.)  Problem-Solving Corner: Design and Analysis of an Algorithm  1.  Input: Output:  81, . . . , 81-, mass, maximum sum of consecutive values begz'n_z'nd, starting index of values that give the maximum sum, or 0 if every sum is negative endjnd, ending index of values that give the maximum sum, or 0 if every sum is negative 
CHAPTER 4 SOLUTIONS  ma,a;_sum4 (s,n) { man: 2 0 sum 2 0 begz'n_1'nd 2 0 endjnd 2 0 local_begz'n_1'nd 2 1 for 1' 2 1 to n { if (sum+ s,- > 0){ local_end_md 2 2' sum 2 sum + sl-  } else { local_begz'n_z'nd 2 i + 1 sum 2 0 }  if (sum > mam) { begz'n_1'nd 2 local_begz'n_z'nd endjnd 2 local_end_z'nd man: 2 sum }  } }  Section 4.4  2. Since n 2 2, we proceed to line 6 where we divide the board into four 2 X 2 boards:  At line 8 we place one right tromino in the center:  I  At lines 9 through 12, we recursively tile the 2 x 2 boards: I :l  3. Since n 2 2, we proceed to line 6 where we divide the board into four 4 X 4 boards: 
64 CHAPTER 4 SOLUTIONS  At line 8 we place one right tromino in the center (we do not show the board rotated):  At lines 9 through 12, we recursively tile the 4 x 4 boards:  {i H}  5. Since n 7E 1 and n 7E 2, we execute the line  return robot_walk(n — 1) + robot_walk(n — 2) with n 2 4. When we compute mbot_walk(3), since n 7E 1 and n 34$ 2, we execute the line  return robot_walk(n — 1) + robot_walk(n — 2)  with n : 3. The algorithm returns the value 2 for robot_walk(2) and the value 1 for robot_walk(1).  Therefore for n : 3, the algorithm returns the value robot_walk(2) + robot-walk(1) : 2 + 1 = 3. Therefore for n : 4, the algorithm returns the value  7'obot_walk(3) + robot-walk(2) : 3 + 2 : 5.  6. Since n 7E 1 and n 7E 2, we execute the line return robot_walk(n — 1) + robot_walk(n — 2))  with n : 5. Exercise 5 shows that the algorithm returns the value 5 for robot_walk(4) and the value 3 for robot_walk(3). Therefore for n = 5, the algorithm returns the value  robot_walk(4) + mbot_walk(3) : 5 + 3 = 8. 
CHAPTER 4 SOLUTIONS 65  8. We use induction on n. The Basis Steps, which are readily verified, are n : 1,2. For the Inductive Step, assume that  walk(Ic) = f;c+1  for all k < n. From the formula in this section, we have walk(n) : walk(n — 1) + walk(n — 2). By the inductive assumption, walk(n — 1) = f,, and walk(n — 2) 2 f,,_1.  Now walk(n) : walk(n — 1) + walk(n — 2) = f,, + f,,_1 = f,,+1.  9. (a) Input: n Output: l+2+---+n  sum(n) { if (n :: ) return 1 return n + sum(n — 1)  }  (b) Basis Step (n = 1). If n is equal to 1, we correctly output 1 and stop.  Inductive Step. Assume that the algorithm correctly computes the sum when the input is n — 1. Now suppose that the input to this algorithm is n > 1. Since n 7E 1, we invoke this procedure with input n — 1. By the inductive assumption, the value 12 returned is equal to 1+»-'+(n—1).  We then return v+n:1+-~-+(n—1)+n,  which is the correct value.  11. (a) Input: n Output: The number of ways the robot can walk n meters  walk3(n) { if (n :2 1) return 1 if (n =2 ) return 2 if (n =2 ) return 4 return walk3(n — 1) + walk3(n — 2) + walk3 (n — 3)  } 
66  12.  14.  CHAPTER 4 SOLUTIONS  (b) Basis Steps (n 2 1,2,3). If n is equal to 1, 2, or 3, we correctly output the number of ways the robot can walk 1, 2, or 3 meters. Inductive Step. Assume that the algorithm correctly computes the sum when the input is less than n. The robot’s first step is either 1, 2, or 3 meters. If the first step is 1 meter, the robot must finish its walk by walking n — 1 meters. By the inductive assumption the robot can complete the walk in walk3(n — 1) ways. Similarly, if the first step is 2 meters, the robot can complete the walk in walk3(n — 2) ways, and if the first step is 3 meters, the robot can complete the walk in walk3 (n — 3) ways. Thus the total number of ways the robot can walk n meters is  walk3(n — 1) + walk3(n — 2) + walk3(n — 3). Since this is the value computed by the procedure, the algorithm is correct.  Input: Output:  The sequence 51, .92, . . . , 5,, and the length n of the sequence The minimum value in the sequence  find-mz'n(s,n) { if (n :2 ) return 51 as : find_mz'n(s,n — 1) if (a: < 5”) return :1: else return 5,,  We prove that the algorithm is correct using induction on n. The Basis Step is n : 1. If n 2 1, the only item in the sequence is 51 and the algorithm correctly returns it.  Assume that the algorithm computes the minimum for input of size n, and suppose that the algorithm receives input of size n + 1. By assumption, the recursive call  as :: find_m2'n(s, n)  correctly computes a: as the minimum value in the sequence 51, . . . , 5”. If as is less than s,,+1, the minimum value in the sequence .91, . . . ,s,,+1 is a:—the value returned by the algorithm. If as is not less than sn+1, the minimum value in the sequence 51, . . . , sn+1 is s,,+1—again, the  value returned by the algorithm. In either case, the algorithm correctly computes the minimum value in the sequence. The Inductive Step is complete, and we have proved that the algorithm is correct.  Input: Output:  The sequence 5,-, . . . ,5,-, 1', andj The sequence in reverse order  reverse(s, 1,37) { if (i Z 3') return 
CHAPTER 4 SOLUTIONS  15.  }  swap(s,-, 5,-) reverse(s,t' + 1,37 — 1)  Input: n  Output: n!  factorial (n) {  }  fact = 1  for 1' 2 2 to n fact : 1' a: fact return fact  67  17. To list all of the ways that a robot can walk n meters, set .9 to the null string and invoke this algorithm.  Input: n, 5 (a string)  Output: All the ways the robot can walk n meters. Each method of  walking n meters includes the extra string 5 in the list.  l2'st_wallc2(n, s) {  um==>{ pr7Intln(s + “ take one step of length 1”) return  } um==>{ prz'ntln(s + “ take two steps of length 1”) prt'ntln(s + “ take one step of length 2”) return } um=:>{ prz'ntln(s + “ take three steps of length 1”) prz'ntln(s + “ take one step of length 1 and one step of length 2”) prt'ntln(s + “ take one step of length 2 and one step of length 1”) prz'ntln(s + “ take one step of length 3”) return } s’ = 5 + “ take one step of length 3” // + is concatenation l2'st_walk2 (n — 3, 5’) s’ = s + “ take one step of length 2” l2'st_walk2 (n — 2, 5’) s’ : s + “ take one step of length 1” lz'st_walk2(n — 1, s’) 
68  CHAPTER 4 SOLUTIONS  19. 233  20. We use strong induction on n. The Basis Steps are n = 1, 2. If n = 1, there is 1 = f2 way to  22. 23.  25.  tile a 2 X 1 board with 1 x 2 rectangular pieces:  2 D 1 If n : 2, there are 2 2 f3 ways to tile a 2 X 2 board with 1 X 2 rectangular pieces:  2 2  2 2  Now suppose that n > 2 and if k < n, the number of ways to tile a 2 x is board with 1 x 2 rectangular pieces is f;c+1. Now the first two vertical 1 x 1 squares can be covered in two ways: using one 1 x 2 rectangular piece  2 2><(n-1)  1  or by using two 1 x 2 rectangular pieces  2 2><(n—2)  2  By the inductive assumption, in the first case the remaining 2 x (n — 1) board can be tiled in fn ways, and in the second case, the remaining 2 x (n — 2) board can be tiled in f,,_1 ways. Thus the total number of ways to tile a 2 x n board with 1 x 2 rectangular pieces is fn ‘t’ fn—1 : fn+1-  The inductive step is complete.  fr?+2 ‘ f3+1 : (fn+2 + fn+1)(fn+2 ' fn+1) : fn+3fn Using Exercises 21 and 22 and the recurrence relation for the Fibonacci sequence, we have fn—2fn+2 : fn—2(fn + fn+1) : fnfn—2 + fn—2fn+1 : f3—1 + (‘1)n+1 + _ f3—1- The conclusion now follows immediately. Basis Step (n=2). f4=3=4——1=f§—ff.f5=5:1+4:f§+f§. Inductive Step. Assume true for n. Now  f2n+1 + f2n fi+fiH+fiH'fid 2f3+1 *1’ f3 ’ f3—1 — 2f3+1+ f3-(fn+1 - fa)? = 2f3+1 + L3 - f3+1 + 2fnfn+1 ~ f3 : 3+1 + 2fnfn+1 : (fn+1 + fn)2 ’  2 : n+2'_.f1g'  f 2n+2 
CHAPTER 4 SOLUTIONS  69  We now use the just proved formula for f2,,+2 to prove the formula for f2,,+3:  2  f2n+3 = f2n+2 + f2n+1: fn+2 * fr? + f: + fin : f5+1+ f3+2-  The inductive step is complete.  26. Basis Steps (n : 1,2). fl and f2 are both odd (fl : f2 : 1) and neither 1 nor 2 is divisible by 3. Therefore, the statement is true for n : 1, 2.  Inductive Step. Assume that the statement is true for all k < n. We must prove that the statement is true for n. We can assume that n > 2. We consider two cases: n is divisible by 3  and n is not divisible by 3.  If n is divisible by 3, then neither n — 1 nor n -2 is divisible by 3. By the inductive assumption, both f,,_1 and f,,_2 are odd. Since fn = f,,_1 + f,,_2, f,, is even. Therefore, if n is divisible by  3, f,, is even.  If n is not divisible by 3, then exactly one of n — 1 or n — 2 is divisible by 3. By the inductive assumption, one of f,,_1 and f,,_2 is odd and the other is even. Since f,, = f,,_1 + f,,_2, f,, is odd. Therefore, if n is not divisible by 3, f,, is odd.  We have shown that fn is even if and only if n is divisible by 3, so the Inductive Step is complete.  28. Basis Steps (n=1,2). f1=1g1:2°; f2:1g2:21  Inductive Step. Assume that the equation is true for n — 2 and n — 1. Now  fn : j-n_1 + j-n_2 S 211-2 + 211--3 < 211--2 + 2n—2 : 2n—1.  29. Basis Steps (n=1,2). Forn=1, wehave f2:1=2—1=f3—1, and f1:1:f2. Forn:2,wehavef2+f4:1+3:5—1:f5—1,andf1+f3:1+2=3=f4.  Inductive Step.  n+1  Z f2Ic lc:1  n+1  Z f2Ic—1 19:1  31. We show that the representation  I E”: f2lc + f2n+2  lc=1 = f2n+1 — 1 + f2n+2 = f2n+3 — 1  TL = Z f2Ic—1 4' f2n+1  lc:1 Z f2n + f2n+1 2 f2n+2  (4.3)  Tn 71 = Zflc, i:1  given in the hint for Exercise 30 is unique.  By Exercise 29, the partial sum of Fibonacci numbers with even indexes is  TL 2 fzk = f2n+1 - 1- Ic:1 
70  32.  CHAPTER 4 SOLUTIONS  If we do not allow f1 as a summand, the partial sum of Fibonacci numbers with odd indexes becomes  En: f2Ic—1 = E”: f2k—1 — f1 = f2n * 1, k—2 k=1  where we have again used Exercise 29.  Suppose by way of contradiction that some integer has a representation as the sum of distinct Fibonacci numbers no two of which are consecutive different from (4.3). Let n denote the smallest such integer. Let  i n : Zftn ‘i=1  where t1 > t2 > ..., be another representation of n as the sum of distinct Fibonacci numbers no two of which are consecutive.  Since ft, 5 n and fk, is the largest Fibonacci number less than or equal to n, ft, 3 f;,,. If ft, 2 f;,,, n — flu has at least two representations as the sum of distinct Fibonacci numbers no two of which are consecutive, which contradicts the minimality of n. Therefore ft, < f;,,. Thus  ftl S flc1—1'  In the representation, no two Fibonacci numbers are consecutive, thus  ftz S. fIc1—31 fta S. fIc1—5a "-  Therefore  Tl = ft1+ftg+""+ft] S. fI::1—1+fk1—3+"”+fk1_(2j_1) 3 f;,,_.1+f;,,_3+---+fp wherep:2or3 = f;,, — 1 by the preceding comments < n,  which is a contradiction. Therefore the representation of an integer as the sum of distinct Fibonacci numbers no two of which are consecutive is unique if we do not allow f1 as a summand.  Exercise 21 shows that f: : fn—1fn+1 ‘l’ (_1)n+1a n 2 2: so fg : fn—1(fn ‘l’ fn-1) + (‘1)n+1a n 2 2 or L3 - fn—-lfn — f3_1-(—1)"“ : 0, n 2 2.  The quadratic formula gives  _ rm i \/f3_1- 4[- 3-1 — <~1)"+11 fn — 2  ,,_. i,/5 2_ +4—1 "+1  _ 2 9 
CHAPTER 4  34.  SOLUTIONS 71  The negative sign gives an extraneous root since if chosen, we would have, for n 2 3,  f” < .fn2—1 or 2(fn—1 + fn—2) < fn—1 or  f'n—-1 + 2fTL—2 < 0  which is impossible. The formula for n : 2 is correct by inspection.  The formula reduces the problem of integrating log” [cc] to the problem of integrating log”“1 |cc|, a simpler instance of the original problem. Eventually the problem is reduced to integrating log [as], which is straightforward.  Another example of a recursive integration formula is  - 211 _ sin / s1n2" :1: da: = —  2n—1 2n  ‘1 cccosa: 2n  /sin2”‘2 as dcc. 
72  CHAPTER 5 SOL UTIONS 
Chapter 5  Solutions to Selected Exercises  Section 5.1  2.  10.  11.  13.  23.  26.  Since Lx/E] 2 6, the for loop in Algorithm 5.1.8 runs from d 2 2 to 6. For each of these values, n mod d 2 0. Therefore the algorithm returns 0 to signal that 47 is prime.  Since Lx/209] 2 14, the for loop in Algorithm 5.1.8 runs from d 2 2 to 14. For d 2 2 to 10, n mod d 2 0. When d 2 11, n mod d 2 0. Therefore the algorithm returns 11 to signal that 209 is composite and 11 is a divisor of 209.  . Since [x/1007] 2 31, the for loop in Algorithm 5.1.8 runs from d 2 2 to 31. For d 2 2 to 18,  n mod d 2 0. When d 2 19, n mod d 2 0. Therefore the algorithm returns 19 to signal that 1007 is composite and 19 is a divisor of 1007.  Since Lx/4141] 2 64, the for loop in Algorithm 5.1.8 runs from d 2 2 to 64. For d 2 2 to 40, n mod d 2 0. When d 2 41, n mod d 2 0. Therefore the algorithm returns 41 to signal that 4141 is composite and 41 is a divisor of 4141.  Since L\/1050703] 2 1025, the for loop in Algorithm 5.1.8 runs from d 2 2 to 1025. For d 2 2 to 100, n mod d 2 0. When (1 2 101, n mod d 2 0. Therefore the algorithm returns 101 to signal that 1050703 is composite and 101 is a divisor of 1050703.  (For Exercise 1) 9 2 3 - 3 11! 2 11-10-9-8-7-6-5-4-3-2 : 11-(5-2)-(3-3)-(2-2-2)-7-(3-2)-5-(2.2)-3-2 28345271111 5 14. 30 16. 20 17. 15 19. 331 20. 1 22. 15 7 (For Exercise 13) We have gcd(5,25) 2 5 and lcm(5,25) 2 25. Thus  gcd(5,25) - lcm(5,25) 2 5-25.  73 
74 CHAPTER 5 SOLUTIONS  27. Since d I m, m : dql for some integer ql. Since d | n, n : dqg for some integer qg. Now m —n = dqi —dq2 : d(q1 — <12)- Therefore, d I (m —  29. Since d1 | m, m : d1q1 for some integer q1. Since dz I n, n : d2q2 for some integer qg. Now  7"" = (d1<11)(d2fI2) Z (d1d2)(Q1f12)- Therefore, d1d2 I mn.  30. Since dc | no, no : dcq for some integer (1. Since do is a divisor of no, c yé 0. Therefore, we may cancel c in no = dcq to obtain n = dq. Therefore, d | n.  32. After checking whether 2 is a divisor of n, we need not check whether 4,6,8, . .. divide n. Implementing this change cuts the time by about one—half:  z's_pm'me(n) { if (n mod 2 =2 0) return 2 d : 3 while (d s Lx/El) { if (n mod d := ) return d d = d + 2 }  return 0  }  Continuing this idea, if we store the primes less than or equal to L‘/H], we need only check whether any of these primes divides n.  33. 2-3-5-7~11-13+1:30031:509-59  Section 5.2  2. 6 3. 7 5. 8 6. 1001 9. 27 10. 219 12. 255 13. 3547 15. 111101 16. 11011111 18. 10000000000 19. 11000000110100 21. 101000 22. 1100011 24. 1000100010 25. 100010100 27. 489 28. 15996 30. 8349 31. 307322 33. (For Exercise 14) 22 34. (For Exercise 26) 111010 36. 903 37. 565D 39. 130FF7  41. 1101010 represents a number in binary, decimal, and hexadecimal. 
CHAPTER 5 SOLUTIONS  43. 49.  53.  55.  57.  75  4003 44. 4041 46. 519 47. 179889  (For Exercise 14) 42 50. (For Exercise 26) 72 52. Yes  30470 does not represent a number in binary, but it does represent a number in octal, decimal, and hexadecimal.  Suppose that the base b representation of m is  lc m : Z qb’, i=0 ck 7E 0. Then bk S clcbk _<_ ma and  b‘°+1 — 1  TT : bk+1 — 1 < bk+1.  mgEk:(b—1)bi=(b—1)§:bi=(b—1)  i=0 i:0  Since bk 3 m, taking logs to the base b, we obtain k 3 logb m. Since m < bk“, again taking logs, we obtain log,, m < k + 1. Combining these inequalities, we have k+1§ 1+logbm< k+2. Therefore, the number of digits required to represent m is  k+1: [1+logbmj.  The algorithm begins by setting result to 1 and as to a. Since n = 15 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result becomes result * as = 1 * a : a. as becomes a2,  and n becomes 7.  Since n = 7 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result becomes result an a: : a * a2 : a3. a: becomes a4, and n becomes 3.  Since n : 3 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result becomes result an as = a3 ac a4 : a7. a: becomes as, and n becomes 1.  Since n : 1 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result  becomes result ac as = a7 ac as 2 0,15. :13 becomes am, and n becomes 0.  Since n = 0 is not greater than 0, the while loop terminates. The algorithm returns result, which is equal to LL15. 
76  58.  60.  61.  CHAPTER 5 SOLUTIONS  The algorithm begins by setting result to 1 and as to a. Since n : 80 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as becomes a2, and n becomes 40.  Since n : 40 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as becomes a4, and n becomes 20. Since n 2 20 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as becomes as, and n becomes 10. Since n : 10 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. cc becomes am, and n becomes 5. Since n = 5 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result  _16  becomes result * as 2 1 * am — a . as becomes G32, and n becomes 2.  Since n : 2 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as becomes LL64, and n becomes 1.  Since n 2 1 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result  becomes result * as = a16 >I= LL64 : G80. as becomes am‘, and n becomes 0.  Since n = 0 is not greater than 0, the while loop terminates. The algorithm returns result, which is equal to LL80.  The algorithm begins by setting result to 1 and as to amod z = 143 mod 230 : 143. Since n : 10 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as is set to (as * cc) mod z = (143 >1: 143) mod 230 = 20449 mod 230 : 209, and n is set to 5.  Since n = 5 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result is set to (result * cc) mod 2 = 209 mod 230 = 209. as is set to (as ac cc) mod z = (209 ac 209) mod 230 : 43681 mod 230 = 211, and n is set to 2.  Since n = 2 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as is set to (as >I= cc) mod z = (211 * 211) mod 230 = 44521 mod 230 2 131, and n is set to 1.  Since n = 1 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result is set to (result * cc) mod z = (209 * 131) mod 230 : 27379 mod 230 : 9. as is set to (as * 51:) mod z : (131 an 131) mod 230 = 17161 mod 230 = 141, and n is set to 0.  Since n : 0 is not greater than 0, the while loop terminates. The algorithm returns result, which is equal to a" mod z : 14310 mod 230 = 9.  The algorithm begins by setting result to 1 and as to a mod z : 143 mod 230 = 143. Since n : 100 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as is set to (as * cc) mod z : (143 >1: 143) mod 230 : 20449 mod 230 = 209, and n is set to 50.  Since n = 50 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. as is set to (st: >I= cc) mod z : (209 ac 209) mod 230 = 43681 mod 230 : 211, and n is set to 25. 
CHAPTER 5 SOLUTIONS  63.  64.  77  Since n 2 25 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result is set to (result ac cc) mod z 2 211 mod 230 2 211. :1: is set to (cc ac cc) mod z 2 (211 ac 211) mod 230 2 44521 mod 230 2 131, and n is set to 12.  Since n 2 12 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. cc is set to (cc ac cc) mod z 2 (131 ac 131) mod 230 2 17161 mod 230 2 141, and n is set to 6.  Since n 2 6 > 0, the body of the while loop executes. Since n mod 2 is not equal to 1, result is not modified. cc is set to (cc ac cc) mod z 2 (141 ac 141) mod 230 2 19881 mod 230 2 101, and n is set to 3.  Since n 2 3 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result is set to (result accc) mod z 2 (211 ac 101) mod 230 2 21311 mod 230 2 151. cc is set to (ccaccc) mod z 2 (101 ac 101) mod 230 2 10201 mod 230 2 81, and n is set to 1.  Since n 2 1 > 0, the body of the while loop executes. Since n mod 2 is equal to 1, result is set to (result ac cc) mod 2: 2 (151 ac 81) mod 230 2 12231 mod 230 2 41. :1? is set to (cc ac cc) mod 2 2 (81 ac 81) mod 230 2 6561 mod 230 2 121, and n is set to 0.  Since n 2 0 is not greater than 0, the while loop terminates. The algorithm returns result, which is equal to a” mod z = 143100 mod 230 = 41.  Basis Step (n 2 1). Since T"; 2 0 and S” 2 1, the result holds for n 2 1.  Inductive Step. Assume true for n. Now T(n+1)! = T(n+1)n! : Tn+1 + Tn! : Tn+1 + n — Sm where we have used the result of Exercise 62 and the inductive assumption. Thus the inductive  step will be complete if we can show that T,,+1 2 1 + S” — S,,+1.  Suppose that n is even. Then n+1 is odd, so T,,+1 2 0. Now n 2 . . .0 in binary, so n+1 2 . . . 1. Therefore S,,+1 2 1 + S”. Thus T,,+1 2 1 + S” — S,,+1, if n is even.  Suppose that n is odd, say,  n2...011...11. \._\,_./ I::1’s Then n+12...100...00. \_§,_g lc0’s  Thus Sn — S,,+1 2 k2 — 1 and T,,+1 2 I9. Therefore T,,+1 2 1 + Sn — Sn“, if n is odd.  b, m, b’, n prod, the binary product of b and b’  Input: Output:  add(p + q,t',r) computes the sum of the binary numbers p and (1, except that q is shifted 1' places left (effectively appending ‘l zeros on the right), with the result in r. 
78  65.  CHAPTER 5 SOLUTIONS  binary_product(b, m, b’, n) {  prod = 0 for 2' = 1 to n if (b; :2 1)  add(prod + b, 1', prod) return prod  }  The for loop runs in time 0(n). Adding prod and b takes time m (the appended zeros are not added). Thus the time is O(mn). Since m and n are the number of bits to represent the numbers that are multiplied, the result follows.  Section 5.3  13.  15.  16.  18.  .1 3.  20 5. 20 6. 331 8. 495 9. 23 12. 89,55  Suppose that lines 3 and 4 in Algorithm 5.3.3 are deleted. If a 2 b, clearly the result is the same as in the original form. If a < b, then b 34$ 0 and the first iteration of the while loop swaps a and b. Thereafter, the algorithm proceeds as in the original form, and again the result is the same.  Let m be a common divisor of a and b. By Theorem 5.1.3(a), m divides a + b. Thus m is a common divisor of a and a + b.  Let m be a common divisor of a and a + b. By Theorem 5.1.3(b), m divides (a + b) — a : b. Thus m is a common divisor of a and b.  Since the set of common divisors of a and a + b is equal to the set of common divisors of a and b, gcd(a, b) = gcd(a, a + b). Let m be a common divisor of a and b. By Theorem 5.1.3(b), m divides a — b. Thus m is a  common divisor of b and a — b.  Let m be a common divisor of b and a — b. By Theorem 5.1.3(a), m divides (a — b) + b 2 a. Thus m is a common divisor of a and b.  Since the set of common divisors of b and a — b is equal to the set of common divisors of a and  b, gcd(a, b) = gcd(a — b, b).  The algorithm given in the hint in the book to Exercise 17 does m subtractions in the worst case, which occurs when a : m and b : 1. 
CHAPTER 5  19.  21.  22.  SOLUTIONS 79 b 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 G 0 — o o o o 0 0 0 o o o o o 0 0 o o o 0 0 o o 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 o 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 3 0 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 4 0 1 1 2 1 2 2 3 1 2 2 3 1 2 2 3 1 2 2 3 1 2 5 0 1 2 3 2 1 2 3 4 3 1 2 3 4 3 1 2 3 4 3 1 2 6 0 1 1 1 2 2 1 2 2 2 3 3 1 2 2 2 3 3 1 2 2 2 7 0 1 2 2 3 3 2 1 2 3 3 4 4 3 1 2 3 3 4 4 3 1 8 o 1 1 3 1 4 2 2 1 2 2 4 2 5 3 3 1 2 2 4 2 5 9 0 1 2 1 2 3 2 3 2 1 2 3 2 3 4 3 4 3 1 2 3 2 10 o 1 1 2 2 1 3 3 2 2 1 2 2 3 3 2 4 4 3 3 1 2 11 0 1 2 3 3 2 3 4 4 3 2 1 2 3 4 4 3 4 5 5 4 3 12 0 1 1 1 1 3 1 4 2 2 2 2 1 2 2 2 2 4 2 5 3 3 13 0 1 2 2 2 4 2 3 5 3 3 3 2 1 2 3 3 3 5 3 4 6 14 0 1 1 3 2 3 2 1 3 4 3 4 2 2 1 2 2 4 3 4 3 2 15 0 1 2 1 3 1 2 2 3 3 2 4 2 3 2 1 2 3 2 4 2 3 16 0 1 1 2 1 2 3 3 1 4 4 3 2 3 2 2 1 2 2 3 2 3 17 0 1 2 3 2 3 3 3 2 3 4 4 4 3 4 3 2 1 2 3 4 3 18 0 1 1 1 2 4 1 4 2 1 3 5 2 5 3 2 2 2 1 2 2 2 19 0 1 2 2 3 3 2 4 4 2 3 5 5 3 4 4 3 3 2 1 2 3 2o 0 1 1 3 1 1 2 3 2 3 1 4 3 4 3 2 2 4 2 2 1 2 21 o 1 2 1 2 2 2 1 5 2 2 3 3 6 2 3 3 3 2 3 2 1 a b n (2 number of modulus operations) 1 0 0 2 1 1 3 2 2 5 3 3 8 5 4 13 8 5 21 13 6  Using induction on n, we prove that when the pair f,,+2, f,,+1 is input to the Euclidean algo- rithm, exactly n modulus operations are required.  Basis Step (11 = 1). Table 5.3.2 shows that when the pair f3, f2 is input to the Euclidean algorithm, one modulus operation is required. Inductive Step. Assume that when the pair f,,+2, f,,+1 is input to the Euclidean algorithm, 11 modulus operations are required. We must show that when the pair fn+3, f,,+2 is input to the Euclidean algorithm, n + 1 modulus operations are required. At line 6, since .fn+3 : .fn+2 + .fn+1; 7' = f,,+1. The algorithm then repeats using the values of f,,+2 and f,,+1. By the inductive assumption, exactly n additional modulus operations are required. Thus a total of n+1 modulus operations are required.  We prove this result by induction on max(a, b). We omit the Basis Step.  Without loss of generality, we assume that a 2 b. If b = 0, zero modulus operations are required to compute gcd(a, b) and gcd(ka, kb). Suppose that b > 0. Suppose that when we divide a by b, we obtain a:bq+7', 0£7'<b. 
80  24.  25.  28.  29.  31.  33.  40.  CHAPTER 5 SOLUTIONS  Multiplying these last inequalities by Is, we obtain lea 2 (kb)q + /97‘, 0 3 k7‘ < kb.  Thus when we divide lea by kb, we obtain the remainder kr. In computing gcd(a, b), we continue by computing gcd(b, 1'). In computing gcd(ka, kb), we continue by computing gcd(kb, kr). By the inductive assumption, these computations require the same number of modulus operations. Thus the number of modulus operations required to compute gcd(a, b) is the same as the number of modulus operations required to compute gcd(ka, kb). The Inductive Step is complete.  If p divides a, we are done; so suppose that p does not divide a. We must show that p divides b. Since p is prime, gcd(p, a) 2 1. By Theorem 5.3.7, there are integers 5 and t such that  1 2 5p + ta. Multiplying both sides of this equation by b, we obtain b 2 5pb + tab.  By Theorem 5.1.3(c), p divides 5pb and p divides tab. By Theorem 5.1.3(a), p divides 5pb + tab 2 b.  p24, a26, b210 X has a least element by the We1l—Ordering Property. Letg25a+tb. Ifc] aandclb, thencl 5a+tb2g.  Exercise 30 shows that g is a common divisor. Exercise 29 shows that g is the greatest common divisor.  521 34.523 36.52134 37.5267  The subsection Computing an Inverse Modulo an Integer shows that if gcd(n, <12) 2 1, then n has an inverse modulo <12.  Now suppose that n has an inverse 5 modulo <1). Then n5 mod (1) 2 1. Since 1 is the remainder, there exists (1 such that n5 2 (pg + 1.  Now suppose that c is a positive common divisor of n and ti). Then c divides ns and ¢q and also ns — gbq 2 1.  Therefore c 2 1 and gcd(n, (1)) 2 1. 
CHAPTER 5 SOLUTIONS 81  Problem-Solving Corner: Making Postage 1. Let k : gcd(p,q). Suppose that we can make m cents postage using a p-cent and b q-cent  stamps. Then ap + bq 2 m. Then is | m. Since is > 1, k ,}’m + 1. Therefore we cannot make m + 1 cents postage. The conclusion follows.  Section 5.4  NJ  . DRINK YOUR OVALTINE  CO  . WEISERKYEIEFTKKU 5. c : a” mod z = 33329 mod 713 : 306 6. a = c“’ mod z = 411569 mod 713 = 500 8. ¢=(p—1)(q—1)=16-22=352 9. 5 = 159 11. a : 0" mod 2 = 250159 mod 391 2 10 13. ¢= (p—1)(q—1) : 58-10025800 14, s 2 3961  16. a = c“’ mod z = 2503961 mod 5959 = 5648 
82  CHAPTER 6 SOLUTIONS 
Chapter 6  Solutions to Selected Exercises  Section 6.1  2.  7.  19.  29.  36.  44.  50.  53.  55.  59.  63.  67.  68.  2-3-5 3.3-3-5 5.5-6-2-3»3 626-1  Since there are three kinds of cabs, two kinds of cargo beds, and five kinds of engines, the correct number of ways to personalize the big pickups is 3- 2 - 5 : 30~not 32.  . 3 10. 6 12. 6 13. 10 15. 5-5 16. 2-32 18. 502 50-49 21. 24 22. 26 24. 8 25. (8-7)/2 27. 24 432 30.324 32.5-4+5.4-3 33.2-5.4 35.5-4-3 52 38. 43 39. 4-3-2 41. 3-4-3 43. (200—4)/2 (200—4)/2 45200-72 47.5+9-9+9-8 49.196—(9+2+18) 1+1-9-9-2 52.2+3+---+9=44 (a)12-11-10-9-8 (b)125 (c)125—12-11-10-9-8 (5!)(2!)(3!) 56. (5!)(5!) 58. 8!-9-8  26+26-36+26-362+26-363+26-364+26-365 60.m" 62.2-3-3-2  A subset X has n elements or less if and only if 7 has more than n elements. Thus exactly half of the subsets have n elements or less. Therefore, the number of subsets is %22”+1 : 22".  28 _ 26 Let  selections in which Ben is chairperson : selections in which Alice is secretary  83 
84  70.  CHAPTER 6 SOLUTIONS  By Exercise 65, |XLJY[ : ]X|+lYl —|XflY].  By previous methods, we find that  |X| = |Y| =5-4, !XnY] :4. Therefore |XLJY| :20+20—4=36. 6 + 18 — 3 = 21 71. n”2 72. n"("-1)/2  Section 6.2  2.  12.  14.  17.  18.  abcd, abdc, acbd, acdb, adbc, adcb, bacd, badc, bcad, bcda, bdac, bdca, cabd, cadb, cbad, cbda, cdab, cdba, dabc, dacb, dbac, dbca, dcab, dcba  P(4,3) =4(3)(2) :24 5. 11! 6. P(11,5) : 11 - 10-9-8-7  P(12, 4) 2 12-11 - 10-9 9. P(12, 3) : 12- 11-10 11. 3! - 3! Tokens labeled AE, C, and DB can be permuted in 3! ways. %5! since half have A before D and half have A after D.  We first count the number of strings containing either AB or CD. To this end, let  X Y:  I I  strings that contain AB strings that contain CD  By Exercise 65, Section 6.1, |XLJYl : ]Xl+|Y] —|XflY]. By previous methods, we find that IX] : |Yl :4!, |XflY| : 3!.  Therefore there are 4! + 4! — 3! strings that contain either AB or CD. Since there are 5! total strings, the number that contain neither AB nor CD is 5! — (4! + 4! — 3!).  C(5, 3) - 2!. Pick three slots for A, C, and E. Then place the two remaining letters.  Let  strings that contain DB : strings that contain BE 
CHAPTER 6 SOLUTIONS  20.  22. 23.  26.  27.  29.  33.  35. 36.  38. 42. 45.  46.  48  85  By Exercise 65, Section 6.1, |XuY| = |X| +lY] —|XnY]. By previous methods, we find that |X| : |Y| 24!, |XflY] : 3!.  Therefore |XLJY| :4!+4! —3!.  First, line up the Vesuvians and the Jovians. This can be done in 18! ways. For each of these arrangements, we can place the Martians in 5 of the 19 in-between and end positions, which can be done in P(19, 5) ways. Thus there are 18! - P(19, 5) arrangements.  9!  Seat the Martians (4! ways). Seat the Jovians in the in—between spots (5 -4- 3 - 2- 1 ways). The answer is 4! - 5!.  {a, b, c}, {a, b, d}, {a, c, d}, {b, c, d}  M  {a. b. 0} {tn 17, d} {a» C» 61} {ba 041} 3—combinations  °‘§Q.. 99.9 9.90‘ §..°"P Q‘O§.. °‘Q..(': OQ‘§..  Cb bc dd  pa-n pne- c-an c-n9 096-‘ no‘; 99:. 99.6“ 909.. 99.0 099.. ORE man 9.09  3-permutations  C(12,4) 30. C(44, 6), C(48,6) 32. C(13, 7)  C(13, 4) — C(6, 4) [The number of possible committees is C(13, 4). The number that have no women is C(6,  C(13, 4) —[C(6, 4)+C(7, 4)] (The total number of minus the number with all men or all women.)  C(13, 4) — C(1 1, 2) [The number of possible committees is C(13, 4). The number in which Mabel  and Ralph serve together is C(11, 2).] C(8,3) 39. Six: 00011111, 10001111, 11000111, 11100011, 11110001, 11111000 13 - C (48, 1) (Choose the denomination and then the odd card.) 43. C(13, 5)  4 - C(13, 2) - 133 (You must pick two of one suit and one of each of the three remaining suits. First choose the suit to have two cards. Then choose two cards. Then choose one of each of the remaining suits.)  4  . 9 - 45 (Pick the lowest card’s denomination. Then pick the suit of each of the denominations.) 
86  49.  51.  52.  54.  55.  57. 59. 62. 65.  67.  68.  69. 72. 73.  75.  CHAPTER 6 SOLUTIONS  C(13, 2)C(11, 1)C(4, 2)C(4, 2)C(4, 1) (Pick the two denominations that receive two cards; pick the denomination to receive one card; pick two cards from each of the chosen denominations; pick one card from the other denomination.)  4  C(4,2)[C(26, 13) — 2] [Pick the two suits. The number of hands containing cards from the chosen suits is C(26, 13). Subtract the two hands that contain only cards of one of the chosen suits.]  C(13, 5)C(13, 4)C(13, 3)C(13, 1)  4!C(13,5)C(13,4)C(13,3)C(13, 1) [Pick the suits (the order determines which gets 5,4, 3, 1). Then pick the desired number of cards from the selected suits.]  C(32, 13) (Select 13 cards from among the 32 non-face cards.)  out), 3) 60. C(10, 3) + C(10, 2) + C(10, 1) + C(10, 0)  C(10, 5) 64. C(46, 4)  C(46, 2)C(4, 2) (Select 2 good and 2 defective.)  Represent each of the two 10’s by a star (“ac”). The remaining n — 4 bits can be placed in the three in-between and end positions with respect to the two stars. For each of these three groups of bits, if a 1 occurs, the bits to its right in that group must also be 1’s. We place a vertical bar “l” in between the 0’s and 1’s in each of these groups. Each string can be represented by 0“|1”*0°|1“*0“]1f, where 0 3 a,b,c,d,e,f 3 11-4 and a+b+c+d+e+f = 11-4. Note that the length of the string is n + 1. A particular string is determined by the choice of five slots from n + 1 slots for the pattern I ac | ac |. Hence there are C(n + 1, 5) such strings.  Fix n — k 1’s. The is 0’s must be assigned to the n — k + 1 positions between the 1’s or at either end. This can be done in C(n — k + 1, 19) ways.  Look at the formula for C(n, lc). Argue as in Example 6.2.23.  Note that the minimum number of votes for Wright is [n/2]. Thus, By Exercise 72, the number of ways the votes could be counted is  1+ low)-C<n,r+1>1:c<n.rn/21>. 1':|'n/2'|  (The first term, 1, is the number of ways Wright receives n votes and Upshaw receives 0 votes.)  By Exercise 73, is vertical steps can occur in C(k, [I9/2]) ways, since, at any point, the number of up steps is greater than or equal to the number of down steps. Then, n — k horizontal steps can be inserted among the is vertical steps in C(n, k) ways. These n — is horizontal steps can occur in C(n — k, [(n — k)/2]) ways, since, at any point, the number of right steps is greater 
CHAPTER 6 SOLUTIONS  76.  77.  78.  87  than or equal to the number of left steps. Thus, the number of paths that stay in the first quadrant containing exactly is vertical steps is  C(k, [k/2])C(n, k)C(n — Ic, [(n — k)/2]).  Summing over all Is, we find that the total number of paths is  i C(k, [Ic/2l)C(n, k)C(n — k, [(n — k)/2]).  I:::0  Fix a starting position, and move around the table. When a handshake begins, write B; when a handshake ends, write a U. The result is a sequence of n R’s and n U ’s in which the number of R’s is always greater than or equal to the number of U ’s. Furthermore, the correspondence between such sequences and handshakes is one-to-one and onto. Since the number of sequences of n R’s and n U ’s in which the number of R’s is always greater than or equal to the number of U ’s is C,, (see Example 6.2.23), the number of ways that 2n persons seated around a circular table can shake hands in pairs without any arms crossing is also C”.  We show a one-to-one, onto correspondence between the output i1, 1'2, . . . ,1}, reversed and se- quences of n R’s and n U ’s in which the number of R’s is always greater than or equal to the number of U ’s. Since the number of such sequences is C”, the result then follows.  For each sequence of n R’s and n U ’s in which the number of R’s is always greater than or equal to the number of U ’s, under each R write the number of D’s that precede it. For example, for n : 3 we would have  RRDRDD 00 1  Then add one to each value of the resulting sequence. In our case, we obtain the sequence 112. For n : 3, the complete correspondence is  RD Sequence Numeric Sequence Numeric Sequence Reversed (Output)  RRRDDD 1 1 1 11 1 RRDRDD 112 211 RRDDRD 113 31 1 RDRRDD 122 221 RDRDRD 123 321  There are P(n, r) ways to place the r distinct objects. There is one way to place the identical objects in the remaining slots. Thus the total number of orderings is P(n, 7-).  There are C(n, n — r) : C(n, r) ways to choose positions for the n — 7- identical objects. After placing the identical objects in these positions, there are r! ways to place the distinct ob jects. Thus the number of total orderings is r!C(n, r). Therefore  P(n,r) = r!C(n,r). 
88  CHAPTER 6 SOLUTIONS  79. The Addition Principle must be applied to a family of pairwise disjoint sets. Here the sets involved are not pairwise disjoint. For example, if X is the set of hands containing clubs, diamonds, and spades and Y is the set of hands containing clubs, diamonds, and hearts, X H Y contains hands that contain clubs and diamonds.  81.  (a) (b)  (f)  If there are more tables than people, it is impossible to seat at least one person at each table.  If there are equal numbers of tables and people and there is at least one person at each table, there will be exactly one person at each table.  See Example 6.2.7.  In this case, there are two people at one table and one person at each other table. The two people to sit at one table can be chosen in C(n, 2) ways.  We prove this equation by induction on n. The Basis Step, n = 2, is part (b). Assume that the equation is true for n and that we have n + 1 people. Choose one person. Either this person sits alone or with others. If the person sits alone, the other persons can be seated at the other table in (n — 1)! ways. If this person is not alone, by the inductive hypothesis the remaining n persons can be seated in  I ®|p_a  n 1  (11-1)!  2'  1  ways. The (n + 1)st person can be added to this seating arrangement in n ways (to the right of any of the other n persons). Thus there are  1 ”‘11 _: g _ r " 1._1  ways to seat n + 1 people if the (n + 1)st person does not sit alone. Therefore the total number of seatings is  11-1  n-(n—1)!:  i:1  11-1 1 n 1 (n—1)!+n!:—_ :n!Z—,. i:1 1 1:1 1 The Inductive Step is complete. Fix n. Each seating of n persons at is round tables, with at least one person at each table, determines a unique permutation of 1, . . . ,n. If p(z', 1), . . . , p(z', e,-) are seated clockwise at table 1', z’ : 1,. ..,k, in this order, we interpret this as the permutation defined by the  mapping  p(1,2) p(1.3)  p(1, 1) p(1.2)  p(1a 61) p(1. 1)  17(1) e1 _ 1) P0761) 
CHAPTER 6  (g)  82. (a) (b) (C) (C1)-(f) (g) (h)  SOL UTIONS 89  p(k. 1) p(k, 2)  p(/6, 2) p(/9. 3)  p(k7a elc ’ 1) P(k.€Ic)  Tl elc)  —+ p(k, 1)  (This representation is called the decomposition of a permutation into its cycles.) Since all permutations are accounted for, the equation follows.  We show that 53,1 : 2 and s,,,,,_2 2 2C(n,n — 3) + 3C(n,n — 4)  for n 2 4. 53,1 = 2 by part (c). If n 2 4, there are two basic seating arrangements:  1. n — 3 tables of one person each and one table of three persons. There are 2C (n, n — 3) such seatings since we may select the n — 3 solitary persons in C(n,n — 3) ways, and then seat the remaining three persons at one table in 2! ways (using the formula from part (c)). 2. n — 4 tables of one person each and two tables of two persons each. Select the n — 4 solitary persons in C (n, n -4) ways, and then seat the remaining four persons in three ways. In this case, there are 3C(n, n — 4) seatings.  If k > n, an n-element set cannot be partitioned into is nonempty subsets.  There is one way to partition an n-element set into n nonempty subsets: Each subset must consist of one element.  There is one way to partition an n-element set into one nonempty subset: The subset is the n-element set itself.  See (g) and (h).  Let X be an n-element set and let a: E X. For each nonempty subset Y of X — {ac}, {Y, X — Y} is a partition of X. Since these are also all the partitions, Sn; : 2”“1 — 1.  A partition of an n-element set into n — 1 subsets consists of a subset containing two elements and n — 2 subsets each containing one element. The 2-element subset can be chosen in C(n, 2) ways. Therefore S,,,n_1 : C(n, 2). S,,_,,_2 : C(n, 3) + 3C(n, 4). If we partition an n-element set into n — 2 subsets, either there is a subset consisting of three elements with all other subsets consisting of one element [there are C (n, 3) of these], or there are two subsets each consisting of two elements with all other subsets consisting  of one element [there are C(n, 4) ways to choose the elements to be the doubletons and three ways to organize the four elements into doubletons]. 
90  CHAPTER 6 SOLUTIONS  Problem-Solving Corner: Combinations  1. From the following figure, we derive the formula  2.  1  E:Cw+pmKWn—k+n—nn—m:CWn+mm) k:0  };.  »__~,:__z P  Z2$mflflmwfim$fidflm+mm)  Section 6.3  2.  8.  10.  11.  13. 15.  16.  12456 3. 23456 5. 631245 6. 13245678  (For Exercise 5) After the while loop in lines 7-9 finishes, m is 2. After the while loop in lines 11-13 finishes, k is 5. At line 14, we swap 52 and 55. Now the sequence is 635421. The while loop of lines 17—22 reverses .93, . . . ,s5. The result is 631245.  12, 13, 14, 15, 16, 23, 24, 25, 26, 34, 35, 36, 45, 46, 56  12345,12346,12347,12356,12357,12367,12456,12457,12467,12567,13456,13457,1346T 13567,14567,23456,23457,23467,23567,24567,34567  123, 132, 213, 231, 312, 321  Change line 5 to while (true) { Add the following lines after line 13 to the body of the while loop at lines 11-13 if (k :2 ) return (Also, since there will now be multiple lines in the body of the while loop, enclose them in braces.)  Input: Output:  7-,n A list of all 7'—permutati0ns of {1, 2, ...,n}  lz'st_r_perms(r, n) { for 2' : 1 to 7- S,‘ = ’i r_comb(7') 
CHAPTER 6 SOLUTIONS  for z’ : 2 to C(n,r){ find the rightmost sm not at its maximum value sm : sm + 1 for j = m + 1 to 7' 5]‘ = Sj + 1 r_comb(1") } }  r_comb(7') { for 1' = 1 to 7- ti = 3i prz'ntln(t) for 1' = 2 to r! { find the largest index m satisfying tm < tm+1 find the largest index k satisfying tk > tm swap(tm, tk)  reverse the order of the elements tm+1, . . . ,t, prz'ntln(t) } } 18. Input: .91, . . .,s,, (a permutation of {1, . . .,n}) and n Output: .91, . . . , 5”, the next permutation. (The first permutation fol-  lows the last permutation.)  nea:t.perm(s,n) { so : 0 // dummy value  m=n—1 while (sm > sm+1) m:m—1 kzn while (sm > sk) k=k—1 if (m>0) swap(sm,s;c) p:m+1 q=n  while (p < q) { SW3P(5P1 511) p=p+1 q=q—1 } }  91 
92 CHAPTER 6 SOLUTIONS  20. Input: .91, . . . , s,, (a permutation of {1, . . .,n}) and n Output: .91, . . . , .9", the previous permutation. (The last permutation precedes the first permutation.)  prev_perm(s,n) { so : n + 1 dummy value // working from right, find first index where s,- > 5,-+1 i=n—1 while (5; < 5,-+1) i 2 ‘i — 1 // reverse s,~+1, . . . , 5” j : 2' + 1 k : n while (j < I9) { swap(sj, sk) ' : + 1 k = k — 1 } // if 1' > 0, swap s,- with the first 5 value after 51- that is less than 5,- if (‘i > 0) { ' 2 1' + 1 while (Sj > .9,-) J = j + 1 swap(8i7 5.7) } }  22. Input: .91, . . . , sn, n, and a string a Output: All permutations of 51, . . . , 5”, each prefixed by 04. (To list all permutations of .91, . . . ,5”, invoke this procedure with a equal to the null string.)  perm_recurs(s,n,a) { if (n :: 1) { pm'ntln(a + 51) return } for 2' : 1 to n { 0/ : oz + 5,- perm_recurs({s1, . . . ,5,--1, s,-+1, . . . , sn},n — 1, 0/) } }  Section 6.4  2. (H,2), (H,4), (H,6) 3. (H,1), (H,3), (H,5), (T,1), (T,3), (T,5) 
CHAPTER 6 SOLUTIONS  6. 7. 9.  10.  12.  18.  19.  21.  22.  24.  32.  39.  93  (1,1), (2,2), (3,3), (4,4), (5,5), (5,5) (174)) (2,4)! (374)? (414)! (574)? (674)1 (4)1)? (472)? (413)? (415)? Suppose that the experiment is: Roll three dice. An event is: The sum of the dice is 8.  Suppose that the experiment is: Roll three dice. The sample space is the set of all possible outcomes. (There are 216 possible outcomes.)  13.  03103  15. 542 16. g  OEIUV  Since an odd sum can be obtained in 18 ways,  (1,2), (1,4), (1,6), (2,1), (2,3), (2,5) (4,1), (4,3), (4,5), (5,2), (5,4), (5,6)  /\/\ ‘C23 B3 \./\/ /\/K “C20 >43 \/\/  the probability of obtaining an odd sum is fin  Since doubles can be obtained in six ways, (1,1), (2,2), (3,3), (4,4), (5,5), (6,6), the probability  of Obtaining doubles is 336.  Exactly one defective microprocessor can be obtained in 10-C (90, 3) ways. (Choose one defective  microprocessor and choose three good microprocessors.) Since four microprocessors can be chosen in C(100, 4) ways, the probability of obtaining exactly one defective microprocessor is  10 - C(90, 3) c(10o, 4) ‘  At most one defective microprocessor can be obtained in C(90, 4) + 10 - C (90, 3) ways. (Choose four good microprocessors, or choose one defective microprocessor and three good microproces- sors.) Since four microprocessors can be chosen in C(100, 4) ways, the probability of obtaining at most one defective microprocessor is  C(90, 4) + 10 - C(90, 3)  C(100,4) 3! 1 1 C(26, 13) 1 — . ———— 2 . ———— . 4 . _ 103 25 C(49,6) 7 0(31,7) 29 C(52, 13) 31 210 10 1 1 W 35. 1 — W 35. W  An equivalent problem is to count strings of three C’s and nine N ’s in which no two C’s are consecutive since we can regard the positions of the C’s as representing the chosen lockers. For example, the string NNCNNNCNNNNC represents the choice of lockers 3, 7, and 12, no two of which are consecutive. We can obtain such strings by placing the three C’s in the 10 in-between positions of the nine N ’s:  _NWN_N_N.,N__N_N_N_N_ 
94  40. 1  46.  47.  49.  50.  52.  53.  CHAPTER 6 SOLUTIONS  The number of ways of choosing the positions for the C’s is, thus, C(10, 3). Therefore the probability that no two lockers are consecutive is  C(10, 3)  C(12, 3)‘  43. A  _ C(10,3) 42 (g)? ' 38  C(12, 3) 38  If you make a random decision, you are choosing randomly between two doors—one with a goat and one with the car; therefore, the probability of winning the car is  Suppose that behind the first two doors are goats, and behind the third door is the car. Consider your three initial choices. If you initially choose door one, your switch will move you to the door with the car, and you win. Similarly, if you initially choose door two, your switch will move you to the door with the car, and you win. However, if you initially choose door three, your switch will move you to a door with a goat, and you lose. Therefore the probability of winning the car is If you make a random decision, you are choosing randomly between three doors—~two with goats and one with the car; therefore, the probability of winning the car is  Suppose that behind the first three doors are goats, and behind the fourth door is the car. There are eight equally probable outcomes. If you initially choose door one, you switch to either a door with a goat or a door with a car. Similarly, if you initially choose door two or three, you switch to either a door with a goat or a door with a car. If you initially choose door four, you switch to one of two doors, each of which hides a goat. Of the eight possibilities, three win a car. Therefore the probability of winning the car is g.  The reasoning is not correct. As a small example, suppose that the sample space consist of eight eggs: g1ag2ag31g4ag5ag5ab1ab2>  where g,- denotes a good egg and bi denotes a bad egg. Then the probability of a bad egg is 1/4. However, the set {g1, g2, g3, g4} of four eggs contains no bad eggs.  The probability that the player who chooses HT wins is 3/4. There are four ways that the sequence of tosses can start: TT, HT, TH, HH. If the sequence starts TT, the player who chooses TT wins. If the sequence starts HT, the player who chooses HT wins. However, the player who chooses HT wins in the other two cases as well. To show this we argue by contradiction. Suppose that the player who chooses TT wins. Consider the first appearance of TT. Because the sequence begins TH or HH, the first T (in TT) must be preceded by H. Therefore HT wins. Contradiction.  Section 6.5  2.  Since 1 P(2) = 13(4): P(5) = E, 
CHAPTER 6 SOLUTIONS 95  the probability of getting an even number is  3 Hm+H®+H®=§ 3. Since the probability of getting a 5 is ,—1,, the probability of not getting a 5 is 1 — {-1, = Z.  8 5% 6  1350-‘  9. The sum of 7 is obtained in six ways: (1,6), (2,5), (3,4), (4,3), (5,2), (6,1). Now 1 1  P(1,6):P(1)P(6)= 2 48.  1 1 Similarly, 1 P@®=P@®:P@®:P@m=P@D=E. Therefore the probability of the sum of 7 is  1 1 10. Doubles or a sum of 6 is obtained in 10 ways: (1,5), (2,4), (3,3), (4,2), (5,1), (1,1), (2,2), (4,4), (5,5), (6,6). Now  P(1,5) : P(1)P(5) : G)? : 3.6.  Similarly, P<3. 3) = mm) = Pu. 1) : H5, 5) = P(2, 4) 2 P(4, 2) : P(2, 2) = P(4, 4) : P(6, 6) = —.  Therefore the probability of getting doubles or the sum of 6 is  5 1 1 ) 16 + 144 ' 12. Let E1 be the event “sum of 6,” let E2 be the event “doubles,” and let E3 be the event “at  least one 2.” We want P((E1 U E2) I’) E3)  P(E3) The event (E1 U E2) 0 E3 comprises (2,4), (4,2), (2,2); therefore,  P(E1 UE2'E3) =  P((E1 u E2) n 133) = 3 .  The solution to Exercise 11 shows that  23 : E.  Therefore  mmu&mm=flE%%%3@=1 =—.  5-‘ ::|‘c‘°=|:&l°° l\3 OJ CA3 
96  13.  21.  23.  24.  26.  27.  CHAPTER 6 SOLUTIONS  Let E1 be the event “sum of 6,” let E2 be the event “sum of 8,” and let E3 be the event “at  le t o 2.” We t as ne wan P((E1 U E2) 0 E3)  The event (E1 U E2) I’) E3 comprises (2,4), (4,2), (2,6), (6,2); therefore,  P((E1 u E2) n E3) = 4 .  The solution to Exercise 11 shows that  23 P E : —. ( 3) 144 Therefore 4 P((E1 U E2) I’) E3) 111 4 P E E E : —————~—: : — = —. ( 1U 2] 3) P(E3) $14 23 C(90 10) 11,3 16. N 18. N 20. 1 — T’ ( ) ° ° C(100,10) C(10, 3)C(90, 3) + C(10, 4)C(90, 2) + C(10, 5)C(90, 1) + C(10, 6) C(100, 10) 0(4) 2) 24 The probability of all boys or all girls is 52;, so the probability of at least one boy and at least one girl is 1 2 24'  Let E be the event “exactly two girls,” and let F be the event “at least one girl.” We want to compute  _ P(E n F) P(E] F) _ P(F) . N OW C(4, 2) and 1 P(F) : 1 — P(no girls) : 1 — 5;. Therefore  P(EflF) : %§& P(F) 1-59  Let E be the event “at least one boy,” and let F be the event “at least one girl.” We want to compute  P(E) F) :  P((EnF) HF) 2 P(Efl F)  P(EflF'lF)= P(F) P(F) 
CHAPTER 6 SOLUTIONS 97 Now 2 P E F = 1 — — < n > 24, and 1 P F : 1 — —. < > 24 Therefore 2 P(E H F) 1 — P(EnF|F) 2 2132- 2 ——l1‘. ( ) 1 - 54 29. Let E be the event “at most one boy,” and let F be the event “at most one girl.” Then P(E) : P(F) = 1 — g4, and P(E I’) F) : 0. Since 5 2 P(EflF) 2 0 75 1- E1 : P(E)P(F), E and F are not independent. 30. Let E be the event “children of both sexes,” and let F be the event “at most one girl.” Then 1 P(E) 2 1 — P(F) 2 "Q: , P(Efl F) 2 P(exactly one girl) 2 Now E and F are independent if and only if P(E H F) = P(E)P(F), or n *<1_ 1)(n+1> 211 — 2n—1 211 ' This equation simplifies to 2”'1 : n + 1, whose only solution is n = 3. (By inspection, 2"'1 7E n + 1 if n : 1, 2. For n > 3, 2””1 > n + 1.) Therefore E and F are independent if and only if n : 3. C(10, 5) C(10, 4) + C(10, 5) + C(10, 6) 32. 210 33. 210 35 C(10, 0) + C(10, 1) + C(10, 2) + C(10, 3) + C(10,4) + C(10, 5) ' 210 36. Let E be the event “exactly five heads,” and let F be the event “at least one head.” We want to compute P(E H F) P F : Z: (E: > P(F) NOW 000 5) P(E H F) : P(E) : 210’ , and 1 Therefore  P(EnF): 9‘—§r%§  P<EnF> 2 P(F)  1. 1’§m' 
98  38.  39.  41.  43. 44.  CHAPTER 6 SOLUTIONS  Let E be the event “at least one head,” and let F be the event “at least one tail.” We want to compute  P(E n F) P E F = —: Now 2 P(E I’) F) = 1 — P(all heads or all tails) = 1 — -fa, and 1 P(F) : 1 — P(no tails) : 1 — E76. Therefore 2 P E I’) F 1 — p(E1F) = _.(.__,) : P(F) 1 — 5,1,  Let E be the event “at most five heads,” and let F be the event “at least one head.” We want to compute  P(E F) F) P E F : Zj. ( I ) P(F) Now P(E 0 F) = P(1 or 2 or 3 or 4 or 5 heads) C(10, 1) + C(10, 2) + C(10, 3) + C(10, 4) + C(10, 5) Z 210 ’ and 1 P(F) : 1 — P(no heads) = 1 — 2?. Therefore 0(1o,1)+c(10,2)+0(10,3)+c(10,4)+0(10,5) P(E'F):P(EnF) : 210 . P(F) 1 — 51,1,  Let H be the event “has headache,” and let F be the event “has fever.” We are given P(H) = 0.01, P(F 1 H) = 0.4, P(F) = 0.02. Using Bayes’ Theorem, we have P(F|H)P(H) _ (0.4)(0.01)  P(H|F) : P(F) 0.02 :02. P(B 1 A) = 0.01, P(B 1 D) 2 0.03, P(B 1 N) = 0.03 W P(B I A)P(A) PW B) “ P(B1A)P(A) + P(B1D)P(D) + P(B 1 N)P(N) _ (0.01)(0.55) : _ (0.01)(0.55) + (0.03)(0.1) + (0.03)(0.35) 0289473684’ Similarly,  P(D 1 B) : 0157894736, P(N 1B) = 0552631578. 
CHAPTER 6 SOLUTIONS  99  47. By Theorem 6.5.9,  48.  50.  51.  P(E1 (1 E2) = P(E1) + P(E2) — P(E1 U E2).  Since P(E1 U E2) S 1,  the result follows. The Basis Step is P(E1) 3 P(E1), which is clearly true. Assume the statement is true for n. By Theorem 6.5.9,  P(E1UE2U'--UEnUEn+1) Z P(E1UE2U'--UEH)-I-P(En+1) —P((E1LJE2LJ---UE,,)flE,,+1).  Since P((E1UE2U OE’,-,+1) 2 0, we have P(E1UE2U"'UEnUEn+1) S P(E1UE2U"'UEn)  Using the inductive assumption, we have  P(E1LJE2LJ---LJE,,LJE,,+1) 3 P(E1uE2u---uE,.)+P(E,,+1)  n+1  i P(E)-) + P(E,,+1) : Z P(E.-). i=1  i=1  I/\  Yes. Since E and F are independent, P(E H F) = P(E)P(F). Since E 0 F and E H E are mutually exclusive and E : (E H F) U (E H E),  P(E) = P(E n F) + P(E n F). Now P(E n F) = P(E) — P(E n F) = P(E) - P(E)P(F) : P(E)[1 — P(F)[: p(E)p(F). Therefore E and F are independent.  No. If the person carries a bomb on the plane the probability of a bomb on the plane is 1. The probability of two bombs on the plane is then 1 - 0.000001 : 0.000001.  Section 6.6  6! /2! 3. 12!/(4!2!)  We form strings in which no two S’s are consecutive by first placing the letters ALEPERON,  which can be done in 8'  2! ways. We then place the four S’s in the nine in-between positions 
100  11.  12. 19. 24.  .C(10+6—1,6—1)  CHAPTER 6 SOLUTIONS  _A_L_E_P_E'_R_O_Nm,  which can be done in C(9, 4) ways. Thus C(9, 4)8!  2! strings can be formed by ordering the letters SALESPERSONS if no two S’s are consecutive.  We count the number of strings of length zero, the number of strings of length one, and so on, and then sum these numbers. The number of strings of length zero is one, and the number of strings of length one is five.  There is one string of length two that uses the two O’s, and there are 5 - 4 strings of length two that do not use two O’s (formed by selecting a 2-permutation of SCHOL). Thus there are 21 strings of length two.  There are four ways to choose three letters including two O’s. There are : 3 ways to permute these letters. Thus there are 4 - 3 strings of length three that use the two O’s, and there are 5 - 4 - 3 strings of length three that do not use two O’s (formed by selecting a 3—permutation of SCHOL). Thus there are 72 strings of length three.  There are C(4, 2) 2 6 ways to choose four letters including two O’s. There are 3% = 6 ways to permute these letters. Thus there are 6 - 6 = 36 strings of length four that use the two O’s, and there are 5 - 4 - 3 - 2 strings of length four that do not use two O’s (formed by selecting a 4-permutation of SCHOL). Thus there are 156 strings of length four.  There are C(4, 3) = 4 ways to choose five letters including two O’s. There are : 60 ways to permute these letters. Thus there are 4- 60 = 240 strings of length five that use the two O’s, and there are 5 - 4- 3 - 2 - 1 strings of length four that do not use two O’s (formed by selecting a 5-permutation of SCHOL). Thus there are 360 strings of length five.  There are 3% = 360 strings of length six. Thus there are 1+5+21+72+156+360+360=975 strings that can be formed by ordering the letters SCHOOL using some or all of the letters. 9. C(4+6— 1,6— 1)  Assign each problem five points, and let 33,- denote the number of additional points that can be assigned to problem 2'. Now the question is: How many solutions are there of  12 Z: 113,; = 40? 1'21  Arguing as in Example 6.6.8, the answer is C(40 + 12 — 1,12 — 1).  410° 13. C(100+4— 1,4— 1) 16. C(9+3— 1,9) 17. C(4+3— 1,4)  C(8+2—1,8) 20. C(10+2—1,10)+C(9+2—1,9) 23. C(12+8—1,12)  C(14+2—1,14) 26. C(15+3—1,15)—C(8+3—1,8) 
CHAPTER 6 SOLUTIONS  27.  29.  30.  31. 33. 39. 40. 43.  45.  46.  101  There are C(14+3 — 1,14) solutions satisfying 0 3 :01, 1 3 :02, 0 3 :03. Of these, C(8+3 — 1, 8) have :01 2 6; C(6 + 3 — 1, 6) have :02 2 9; and there is one with :01 2 6 and :02 2 9. Thus there are  C(8+3—1,8)+C(6+3—1,6) -1 solutions with :01 2 6 or :02 2 9. Therefore there are C(14+3— 1,14) — [C(8+3— 1,8) +C(6+3—1,6) -1] of the desired type.  The problem is equivalent to solving C(21+£l32+"‘+CI3n+$l3n+1 ZM  since 0$:0,,+1:M—:01+a:2+---+:0,,.  Thus the number of solutions is  C(M+(n+1)—1,(n+1)—1):C(M+n,n).  We must count the number of solutions of iII1+:02+:03+:04+:05+:06 = 15  satisfying 0 3 50,- _<_ 9, 2' = 1, . . . ,6. There are C(15+6—1, 15) solutions with :01 2 0,1’: 1,. . . ,6. There are C(5 + 6 — 1, 5) with 3:1 2 10. There are 6C(5 + 6 — 1, 5) with some :0,- > 10. (Note  that there is no double counting, since we cannot have :0,- 2 10 and :0, 2 10, 1' 7E j.) Thus the solution is C(15 + S — 1,15) — 6C(5 + 6 — 1, 5). C(20 + 6 — 1, 20) — [6C(10 + 8 — 1,10) — C(6, 2)] 8!/(4!-2!-2!) 23. C(7+2—1,2) 36. C(5+3—1,5) 37. C(6,2)C(6,3)C(8, 2) C(20, 5)C(15, 5) [C(20, 5) — C(14, 5)][C(14, 5) + 6C(14, 4)] 42. C(15 + 5 — 1,15)C(10 + 5 — 1,10) C(12,10)  Consider the number of orderings of kn objects where there are n identical objects of each of /0 types.  The number of times the print statement is executed is 1 + 2 + + n.  Example 6.6.9 shows that this is the same as C(2 + n — 1, 2) = (n + 1)n/2. 
1 02 CHAPTER 6 SOL UTIONS  48. list_sols(n) { for 331 : 0 to n fOI‘.’Il32 =0 ton—a:1 prz'ntln(a:1, 332, n — 3:1 — 11:2)  }  49. Many partitions are not counted. For example, the partition  {{m1vm3}v{m2}1{'T4}?{'735}v{'735}a{'T7}7{'T8}!{'739v'T10}} is not counted.  51. The 10 disks can be given to Mary, Ivan, and Juan in C(10+ 3 — 1, 3 — 1) ways. If Ivan receives exactly three disks, the remaining seven disks can be given to Mary and Juan in C (7 +2— 1, 2-1) ways. Thus the probability that Ivan receives exactly three disks is  C(7+2—1,2—1) C(10+3—1,3—1)'  Section 6.7 2. 3205 — 240c4d + 720c3d2 — 1080c2d3 + 810cd4 — 243d5 4. 59136s6t6 5. C(10, 2)C(8, 3) : 10!/(2!3!5!) 7. C(5, 2) 8. C(5,2) 11. C(12 + 4 — 1,12) 12. C(12 + 3 — 1,12) + C(11 + 3 — 1,11) + C(10 + 3 — 1,10) 14. (a) C(n, k) < C(n, k + 1) if and only if  n! n! mm — k)! < (k+ 1)!(n — k -1)!  ifand only ifk+1 <n—kifand only ifk< (n—1)/2.  15. Set a 2 1 and b : -1 in the Binomial Theorem. n! + n! (k — 1)!(n — k + 1)! k!(n — I9)! (n!)k + (n!)(n — 19 + 1) k!(n—k+1)! k!(n—k+1)! _ (n!)(n+ 1) _  18. Choosing a k-element set X also selects an (n — Ic)-element set X.  17. C(n, k — 1) + C(n,k)  H  20. (n + 1)n(n — 1)/3 21. Use the fact that 192 = 2C(k,2) + C'(k,1).  23. Use Exercise 15 and equation (6.73). 
CHAPTER 6 SOLUTIONS  24. 26. 27.  29. 30.  32.  33.  103  Imitate the combinatorial proof of the Binomial Theorem. Take a = b = c = 1 in Exercise 24.  Think of C(n, k)2 as C(n, k)C(n,n — k). Let X and Y be disjoint sets each having n elements. Now, C(2n,n) is the number of ways of picking n-element subsets of X U Y. Picking an n- element subset of X LJY is the same as picking a lc-element subset of X and an (n — k)-element subset of Y.  Set as 2 1 in Exercise 28.  Inductive Step.  EkC(n + 1, k) : En: k[C(n, I9 — 1) + C(n, k)] + (n + 1)C(n + 1,n + 1) Ic=1 Ic:1 : E1 kC(n, k — 1) + i kC(n, k) Ic=1 Ic=1 n+1 n+1 n 2 Z(k — 1)C(n,lc — 1) + Z C(n, k — 1) + Z kC(n, k) Ic:1 Ic=1 Ic=1  = n2”‘1 + 2" + n2"”1 2 (n + 1)2”  We count the number of ways to choose sets A and B with A Q B Q X. Fix an integer k with 0 3 k 3 n. There are C(n, 19) ways to choose a subset A of X with k elements. After choosing such a set A, there are n — k elements not in A, and there are 2”“'“ ways to choose a subset of them to union with A to produce a set B that contains A. Thus there are C(n, k)2”"° ways to choose subsets A and B satisfying A Q B Q X in which A has is elements. Summing over all k we obtain the number of ordered pairs (A, B) satisfying A Q B Q X 2  Z C(n, k)2""°. Ic=0 Taking a = 2 and b = 1 in the Binomial Theorem, we find that this sum is equal to (a+b)” = (2 + 1)" : 3”. We use induction. The Basis Step is n 2 m:  1 C(m,m)H,,, : Hm = C(m + 1,m+ 1) (Hm+1 — ———).  m+1  Assume true for n. Then  n+1  Z C(k,m)Hk : Z C(k,m)H;c + C(n+ 1,m)H,,+1 lc:m  Ic:m 1  : C(n+1,m+ 1) <Hn+1 — ml  )4’ + 1, m)Hn+1 
104  CHAPTER 6 SOLUTIONS 1 1 + C(n + 1,m) <Hn+2 —— n _1'_ 2)  = [C(n+ 1,m+ 1) +C(n+ 1,m)]Hn+2 _ C(n+1,m+1)+C(n+1,m) _ C(n+1,m+1)  n + 2 m + 1 : C(n + 2,m + l)Hn+2 - Cm + 1) - C(n+1) = C(n + 2,m + 1)H,,+2 _ C(':n++1im) — Cm + 1) (6.1) = C(n + 2,m + 1)H,,+2 _ j——C(" + 1) Equality (6.1) follows from the formula C(n+2,m+ 1) : 3+ 2 C(n + 1,m).  +1  Section 6.8  2.  . LetA:{a:1,..  There are six possible combinations of first and last names. Each of the 18 persons is to be assigned a first and last name. By the Pigeonhole Principle, at least [18/6] = 3 of them will be assigned the same first and last names.  Professor Euclid is paid 26 times per year. Since there are 12 months, by the Pigeonhole Principle, at least [26/12] : 3 pay periods will occur in the same month.  . ,a:5o} be the set of positions for the available items. Each 33,- assumes a distinct value in {1, . . . , 115}. Let B = {$1 +4, . . . ,cc5o + 4}. The set  X={.’131,...,.’I350,.’I31-I-4,...,.’I350-I-4}  of 120 numbers can take on values from 1 to 119. By the Pigeonhole Principle at least two of these 120 elements are identical. Since the elements in A are distinct, so are the elements in B. There is an element 2:1 in A and an element in cc, + 4 in B which are identical.  . Let a,- denote the position of the ith available item. The 110 numbers  a1,...,a55; G1-|—9,...,0:55+9  have values between 1 and 109. By the second form of the Pigeonhole Principle, two must coincide. The conclusion follows.  . If any pair (P.-,P,~), (P,-,Pk), (P;c,P,-) is dissimilar, then the two dissimilar pictures together  with P1 are three mutually dissimilar pictures. If none of these pairs are dissimilar, then P,-, P,-, and Pk are three mutually similar pictures.  No. Consider five pictures P1, . . .,P5 in which P1 is similar to P2; P2 is similar to P3; P3 is similar to P4; P4 is similar to P5; P5 is similar to P1. 
CHAPTER 6 SOLUTIONS  10  15.  16.  17.  18.  19.  20.  21.  22.  23.  105  Yes, since any subset of six pictures has the given property. Let n = 2, and consider the subset {3,4, 5} of {1, 2, 3,4, 5}.  Let sci denote the longest increasing subsequence and yi denote the longest decreasing subse- quence starting at ai. Consider (bi-,ci) and (b,-,c,-). We may assume that 1' < j. If ai < a,-, {ai,:::,-} is an increasing subsequence starting at ai which is longer than cc,-. Hence bi 2 length of {ai,a:,-} > bi. If ai > a,-, {ai,y,-} is a decreasing subsequence starting at ai which is longer than yj. Hence ci 2 length of {ai, yi} > cj. Since the a;i’s are distinct, the preceding cases are the only cases. For each, we have shown that (bi, and (bi, ci) are distinct.  The number of ordered pairs (bi, ci) is m : n2 + 1, one for each i : 1, . . . ,m.  By assumption, every increasing or decreasing subsequence has length less than or equal to n. Thus13bi3nand13ci3n.  By Exercise 17, we have n2 + 1 pairs (bi,ci). By Exercise 18, these pairs can take on only n2 values. By the Pigeonhole Principle, at least two of these pairs must be identical. This  contradicts the result of Exercise 16.  If 7-i 3 8, since Ti 2 0 and si = ri, we have 0 3 si 3 8.  If 7-i > 8, since ri 3 15, we have 1 3 16—7'i < 8. Thus 1 3 si < 8.  The set {.91, . . .,s1o} is a subset of the 9-element set {0, . . . ,8}. By the second form of the Pigeonhole Principle, 51- : 5;, for j 75 I9.  Suppose that s,- : ri and 5;, = rii. Then rj = rii, so ai mod 16 : aii mod 16. Therefore 16 divides ai — aii.  If 51- : 16 — 7', and 5;, = 16 — 77,, we again find that 7', : 77, and the conclusion follows. We may suppose that sj = 73 and sii : 16-77,. Thus 7', : 16-77, so 73 +7';i = 16. By definition, aj mod 16 = r,- and aii mod 16 : mi so there are integers qi and qii satisfying ai : 16q,~ + r,- and a,,, = 16q;i + 77,. Now  a,- + a,, 16(q,- + qii) + r,- + 1",,  = 1501;‘ + ilk) + 15 = 1501:‘ + qlc + 1)-  Therefore 16 divides a,- + aii. 
106 CHAPTER 6 SOLUTIONS 25. Suppose that the numbers around the circle are 331, . . . ,a:12. We argue by contradiction. Suppose that .731 + CD2 + 1133 S 19 £62 + £83 + 1134 S 19 $610 + $611 + 9312 S 19 $611 + $612 + 031 S 19 $612 + £61 + 562 S 19-  Summing, we obtain the contradiction  12-13  234=3<  )=3(Cl31-I-E"-I-C1312)S12-19:228.  26. The sum of some four consecutive players’ numbers must be at least 26. Suppose that  C131-F5132-|—£I33+.’134 S C122-I-Cl33+Cl34-I-1125 S C1312-1-5131-1-5132-|—.’133 S  Summing, we obtain the contradiction  12-13  25 25  25  312=4(T) :4(a:1+---+5612)S12-25:300.  27. Each of the n! + 1 functions  f f2 f3 I I . is a permutation of {1, . . . ,n}. Since there are n! permutations of {1, . . . , n}, by the Pigeonhole Principle, f" 2 f’ (6.2)  for some distinct positive integers 2' and j.  Notice that if we compose each side of (6.2) with f “1, we obtain  If-13-1 : fj—1I  We may assume that 1' > j. If we compose each side of (6.2) with f ‘1 j times, we obtain  fi'j = I,  where I (as) : as for a: : 1, . . . ,n. We may take is = 1' — j to obtain the desired conclusion. 
CHAPTER 6 SOLUTIONS  29.  30.  31.  107  Suppose that the numbers around the circle are a:1,~..,a:,,+q. We argue by contradiction. Suppose that each consecutive group of lo numbers contains a zero. Then each consecutive group of k numbers sums to It — 1 or less. Thus  CI31+"'-I-Clik S k:—1 332+"'+33Ic+1 s k—1 C(3p+q-I-331-I-"'-I-.’13k_1 S k,'—1  Summing, we obtain 1917: M371 +"'+5'7p+q) S (p+q)(k‘ 1)  or p 3 (k — 1)q. Since p 2 kg > (k — 1)q, this is a contradiction.  See Section 6.11.1, pages 167-169, of U. Manber, Introduction to Algorithms, Addison-Wesley, Reading, Mass., 1989.  Suppose that it is possible to mark k squares in the upper-left, k,‘ x k subgrid and k squares in the lower-right, k X k: subgrid so that no two marked squares are in the same row, column, or diagonal of the 2k >< 2k grid. Then the 2k marked squares are contained in 2k — 1 diagonals. One diagonal begins at the top left square and runs to the bottom right square; k: — 1 diagonals begin at the It — 1 squares immediately to the right of the top left square and run parallel to the first diagonal described; and k — 1 diagonals begin at the k — 1 squares immediately under the top left square and run parallel to the others described. By the Pigeonhole Principle, some diagonal contains two marked squares. This contradiction shows that it is impossible to mark is squares in the upper-left, k X k subgrid and k squares in the lower-right, k x k subgrid so that no two marked squares are in the same row, column, or diagonal of the 2k >< 2k grid. 
108 CHAPTER 7 SOLUTIONS 
Chapter 7  Solutions to Selected Exercises  Section 7.1  2. 9.  12.  13. 15. 20.  21.  an 2 an_1 + an_2; a1 2 3, a2 2 6 3. an 2 2an_1an_2; a1 2 a2 2 1  An 2 1.10An_1 + 2000 10. A0 2 2000 11. A1 2 4200, A2 2 6620, A3 2 9282  An = 1.10A,,_1 + 2000 1.10(1.10A.._2 + 2000) + 2000 1.102A.._2 + (1.10)2000 + 2000 1.102(1.10A.._3 + 2000) + (1.10)2000 + 2000  : 1.103A,._3 + (1.102)2000 + (1.10)2000 + 2000  I I  H  : 1.10"Ao + (1.10"-1)2000 + (1.10"-2)2000 + - - - + (1.10)2000 + 2000 : (1.10")2000 + (1.10"-1)2000 + (1.10"-2)2000 + - - - + (1.10)2000 + 2000 (1.10"+1)2000 — 2000  1.10 — 1 = 20000(1.10"+1 — 1)  An = (1.03)4A,,_.1 14. A0 = 3000  A1 2 3376.53, A2 2 3800.31, A3 2 4277.28 16. An 2 (1.03)4”3000 17. 5.86  An n-bit string that does not contain the pattern 00 either begins 1 and is followed by an (n — 1)-bit string that does not contain 00, or it begins 01 and is followed by an (n — 2)-bit string that does not contain 00. Thus we obtain the recurrence relation  Sn : n—1+S -21  which is the same recurrence relation that the Fibonacci sequence f satisfies. The initial  conditions for the sequence S are S1 2 2, S2 2 3.  Since f3 2 2 and f4 2 3, the result follows.  We count the number of 11-bit strings with exactly 1' 0’s that do not contain the pattern 00. Such a string has n — 1' 1’s:  109 
110 CHAPTER 7 SOLUTIONS  _1_1_...vl,.  To avoid the pattern 00, the 0’s must be placed in the 11 — 1 + 1 spaces. This can be done in C(11 — 1' + 1,1’) ways. Thus there are  L(n+1)/21 2 C(11 + 1 -131) (7.1)  1:0 11-bit strings that do not contain the pattern 00. By Exercise 20, (7.1) is equal to f,,+2. 23. We count the number of strings not containing 010 having 1 leading 0’s. For 1 : 0, there are S,,_1 such strings. For 1 = 1, the string begins 011, so there are S,,_3 such strings. Similarly,  for 1' = 2, there are Sn_4 such strings; . . . for 1' = 11 -3, there are S1 such strings. For 1' : 11 -2, 11 — 1, or 11, there is one such string. The equation now follows.  24. The formula for 11 — 1 is Sn_1 = Sn_2 + Sn_4 + Sn_5 + ' ' - + $1 + 3. Subtracting S,,_1 from S”, we obtain Sn — S,,_1 2 Sn_1 + Sn_3 — S,,_2. Solving for S”, we obtain the desired recurrence relation.  26. We use the explicit formula for the nth Catalan number derived in Example 6.2.22 to obtain (11 + 2)C(211 + 2,11 +1) 11 + 2 (211 + 2)! (11 + 1)!(11 + 1)! 2(211 + 1)(2n)!(211 + 2) (11 + 1)11!11!(211 + 2) (411 + 2)(211)! (11 + 1)11!11! (411 + 2)C(211, 11)  (n ‘l’ 2)Cn+1 :  27. The proof is by induction on 11 with the Basis Step omitted. Assume that the inequality holds for 11. We use the formula from Exercise 26 to derive 2 4 11~1 11 4n + C” 2 2 11 + 2 11 + 2 11 (11 + 1) The last inequality is successively equivalent to 411 + 2 > 4  (11+2)112 ’ (11+1)2  C11+1 :  (211+1)(11+1)2 2 2(11+2)112 2113+5112+411+1 2 2113+4112 112+411+1 2 0, 
CHAPTER 7 SOLUTIONS 111 which is clearly true for all n _>_ 1. 28. Let b” denote the number of ways to parenthesize the product a1 *a,,+1. Then be = b1 : 1. Suppose that n > 1, 1 3 1' 3 n, and that the multiplication is carried out by multiplying a1*---aca,-, (7.2) parenthesized in some way, by a,'+1 >1: - - - ac a,,+1, (7.3)  30.  32.  parenthesized in some way. There are b,--1 ways to parenthesize (7.2) and b,,_,- ways to paren- thesize (7.3). Therefore there are b,-_1b,,_,~ ways to parenthesize the product  a1*-~->I<an+1.  if the multiplication is carried out by multiplying (7.2), parenthesized in some way, by (7.3), parenthesized in some way. Summing over all 1' we obtain  bn = bi—1bn—i-  Since the sequence {bn} satisfies the same initial condition and recurrence relation as the Cata- lan sequence {C,,}, it follows that b” 2 CT, for all n.  We assume that the paths start at (0,0) and end at (n,n). Suppose that a route first meets the diagonal at (k + 1, k + 1). It is either always below the diagonal [from (1,0) to (k + 1, k)] or always above the diagonal [from (0, 1) to (k, k + 1)]. Thus there are 2Ck such paths from (0, 0) to (k + 1,k + 1). There are C(2(n + 1 — (k + 1)),n +1 —(k + 1)) = C(2(n — k),n — k) paths from (k + 1, k + 1) to (n + 1, n + 1) (with no restrictions). Thus the number of paths that first meet the diagonal at (k + 1, k +1) is C;,C(2(n — k),n — k).  Since there are C(2(n + 1),n + 1) paths from (0, 0) to (n + 1, n + 1) (with no restrictions),  C(2(n + 1),n + 1): i 2C;cC(2(n — k),n — k). Ic=0 Thus  n—1 C(2(n + 1),n + 1) = 20,, + Z 2CkC(2(n — k), n — /9). Ic=0 Dividing by 2 and moving the last summation to the left side of the equation gives the desired result.  We assume that the paths start at (0, 0) and end at (n, Let D, denote the number of paths that first touch the diagonal at (1,1) after leaving (0, 0). Then 
112  34. 36.  38.  39.  41.  CHAPTER 7 SOLUTIONS  Since D1 is the product of the number of paths from (0,0) to (1,1) and the number of paths from (1,1) to (n,n), D1 : 2S,,_1.  If i 2 2, D,- is the product of the number of paths from (1,0) to (z',z' — 1) and the number of paths from (z',z') to (n,n), so Di = Si—1Sn—i-  Thus  Sn : 2811-1 + Z S'—1Sn—i- i=2  price : ak/(k + b), quantity : a/(k + b) We have  -9: - I pTL—1'  b b b 'Pn+1 “pnl = G — Epn — 0+ Epn—1 = l%(Pn—1 —Pn)  Now b > k, so b/k > 1. Thus |pn+1 -19”) > lpn —pn_1]. Basis Step. A(1,0) : A(0, 1) : 2 Inductive Step. A(1,n + 1) 2 A(0, A(1,n)) 2 A(0,n + 2) = n + 3  Basis Step. A(2,0) = A(1, 1) = 3 by Exercise 38. Inductive Step. Assume that the statement is true for n. Then  A(2,n + 1) = A(1,A(2,n)) 2 A(1, 3 + 2n) by the inductive assumption = 3 + 2n + 2 by Exercise 38 : 2n + 5.  Basis Step. (m : 0). A(0, n) = n + 1 > n for all n 2 0. Inductive Step. Assume that A(m, n) > n for all n 2 0. We use induction on n to prove that  A(m+ 1,n) > n for all n 2 0. Basis Step (n : 0). A(m+1,n) = A(m+ 1,0) = A(m. 1) > 1 by the original inductive assumption > 0 : n.  Inductive Step.  A(m+1,n+1)  ll  A(m,A(m + 1,n)) A(m + 1, n) by the original inductive assumption n by the present inductive assumption.  VV 
CHAPTER 7 SOLUTIONS  42.  45.  46.  48.  49.  51.  113 Now A(m+ 1,n+ 1) > A(m+ 1,n) _>_n+ 1, which completes the current inductive step. Therefore A(m + 1, n) > n for all n 2 0. Thus the original induction is complete. If n = 0, A(m, 0) = A(m — 1,1) > 1 by Exercise 41. If n > 0, A(m, n) > n 2 1 by Exercise 41. Basis Step (:1: 2 2). AO(2,2, 1) : 2- 1 : 2.  Inductive Step. Assume that the statement is true for as. Now  AO(a: + 1,2,1): AO(a:, 2, AO(a: + 1, 2, 0)) : AO(a:,2, 1) = 2. Inductive Step.  AO(a: + 1, 2, 2) = A0(a:, 2, AO(a: + 1, 2, 1)) AO(a:,2,2)  : 4  11  by Exercise 45  (a) G2 : 1 because two nodes must establish one link to share files.  Suppose that we have three nodes A, B, and C. If the following successive links are established, A<—>B, A<—>C, A<—>B,  then all nodes know all files. Since three links suflice, a3 3 3.  Suppose that we have four nodes A, B, C, and D. If the following successive links are established, A<—>B, C<—>D, AHC, B<—>D,  then all nodes know all files. Since four links suffice, a4 3 4.  Suppose that we have n 2 3 nodes. Let A and B be nodes. First A and B share files. Next, all nodes except A share files (requiring a,,_1 links). Finally, A and B again share files. At this point all nodes know all files. Thus an 3 an_1 + 2.  (b)  P1 = 1, PT, : nP,,_1  Suppose that we have n dollars. If we buy tape the first day, there are R,,_1 ways to spend the remaining money. If we buy paper the first day, there are Rn_1 ways to spend the remaining money. If we buy pens the first day, there are R,,_2 ways to spend the remaining money. If we buy pencils the first day, there are Rn_2 ways to spend the remaining money. If we buy binders the first day, there are Rn_3 ways to spend the remaining money. Thus  Rn : 2Rn—1 + 2Rrn.—2 + Rn—3- 
114  52.  54.  56.  57.  59.  60. 62.  63.  65.  CHAPTER 7 SOLUTIONS  Because of the assumptions, when the (n + 1)st line L is added, it will intersect the other n lines. If we imagine traveling along L, each time we pass through one of the original regions, we divide it into two regions. Since we pass through n + 1 regions, Rn+1 2 R” + n + 1.  5,. : [1 _ (-%)""1] A string a of length n with C(04) _<_ 2 either begins with 1 (there are S -1 of these), 01 (there are S,,_2 of these), or 001 (there are S,,_3 of these). Thus S” = Sn_1 + Sn_2 + S,,_3. Basis Steps (n : 1,2). 2f2—1=2—1=1:g1,2f3—1=4—1=3=g2 Inductive Step.  gn : 9n—1 + 9n—2 ‘l’ 1 : (2fn ’ 1) ‘l’ (2fn-1 “ 1) ‘l’ 1 : 2(fn ‘l’ fn-1)" 1 : 2fn+1 ’ 1  The problem is that the Inductive Step assumes two previous cases, but the Basis Step proves only one.  C(n + 1, k) = C(n, k — 1) + C'(n, k)  There are k" functions from X : {1, . . . ,n} onto Y = {1, . . . , I9}. We will count the number N of functions from X into, but not onto, Y. Then, the number of functions from X onto Y will be k" — N.  Let Z be a proper, nonempty subset of Y with 1' elements. There are S(n, 1') functions from X onto Z. The number of subsets of Y having 1' elements is C(k, 1'). Then, there are C(k, t')S(n, z’) functions from X onto some 1'-element subset of Y. If a function from X to Y is not onto Y, it is onto some proper nonempty subset of Y. The result follows.  (3.) L3:4,L4=7,L5:11 (b) Basis Step (n : 1, 2).  L3: L4:  4=1+3=f2+f4 7:2-l'5———f3-I-f5  Inductive Step. Assume that Ln+1 = fn + fn+2 and L,,+2 = f,,+1 + f,,+3. Now  Ln+2 ‘l’ Ln+1 : fn+1 'l” .fn+3 'l” fn ‘l’ .fn+2 2 ‘l’ fn+1) + (fn+2 + fn+3) : fn+2 ‘l’ fn+4-  Ln+3  Let X be an (n + 1)—element set and choose an element as E X. We count the number of partitions of X containing k subsets in which :1: appears as a singleton and the number of partitions of X containing kt subsets in which as appears in a subset with at least two elements.  A partition of X containing k subsets in which :1: appears as a singleton consists of {as} together with a partition of X — {IE} containing k — 1 subsets. There are S,,,;c_.1 such partitions. 
CHAPTER 7 SOLUTIONS  66.  68.  70.  71.  73.  74.  115  A partition of X containing ls subsets in which CI) appears in a subset with at least two elements can be constructed in the following way. Select a partition of X — {cc} containing k subsets. This can be done in SW, ways. Next add :1? to one of the subsets. This can be done in 19 ways. Thus there are kS,,,;, partitions of X containing 19 subsets in which as appears in a subset with at least two elements. The recurrence relation now follows.  We prove the formula by induction on n leaving the Basis Step (n : 1) to the reader.  Assume that the formula is true for n. We must prove the formula is true for n + 1. If k = 0, the formula is clearly true, so assume that k > 0. By Exercise 62,  Sn+1,lc : Sn,lc—1 + kSn,Ic 1 ‘"1 . . . is ’° . . . : W Z(—1)’(k — 1 — t)”C(k — 1,1) + 7; Z(—1)’(k — t)”C(k,t) ' 1'20 'i:0  1 19-1  Ic : % :(—1)*'(k — 1 — ¢)"c(k — 1,1‘) + Z(—1)i(k — ¢)"C(k,¢)] ‘ -i=0 1'20  ' Ic : fl k"C(k, 0) + Z{(—1)"—1(k — z')”C(k — 1,1 — 1) + (—1)*'(k — z')”C(k, 0}] ' L i=1 2 (IP11), -k”C(lc, 0) + 2k:(—1)i(k — z')"[—C(k — 1,1 — 1) + C(k, 0]] ' _ i:1 1 - n k 2' - 11 - = i -1. C(k,0)+i:Z1(—1)(k—t) C(k— 1,0]  1 1 'k"+1C<k,o> * .- ...C<k.'><k—'> 1_(k_1)!_ k +Z(—1)(k—t) “k “J  i:1  Ic : Z(_1)"(1c — t')”+1C(k, 1').  an : n(a,,_1 + 1)  1,5,2,4,3; 1,5,3,4,2; 2,5,1,4,3; 2,5,3,4,1; 3,5,1,4,2; 3,5,2,4,1; 4,5,1,3,2; 4,5,2,3,1; 1,3,2,5,4; 2,3,1,5,4; 1,4,2,5,3; 2,4,1,5,3; 1,4,3,5,2; 3,4,1,5,2; 2,4,3,5,1; 3,4,2,5,1; E5 = 16  An item in the first, third, . .. position has a larger neighbor; therefore, n cannot be in any of these positions.  The solution is similar to that of Exercise 72, which is given in the book, except that the portion following 1 must be a “fall/rise” permutation. However, the number of “fall/rise” permutations of 1,. .. ,n is equal to the number of “rise/fall” permutations of 1, . . . ,n, so the argument proceeds as in the solution to Exercise 72.  Add the recurrence relations of Exercises 72 and 7 3. 
116  CHAPTER 7 SOLUTIONS  Section 7.2  2. 9. 13.  14.  16.  17.  19.  20.  23.  26.  27.  30.  No 3. No 5. Yes; order 3 6. No 8. Yes; order 2 Yes; order 2 12. an : 2”n! an = a,,_1+n=an_2+(n—1)+n=--- 1 : a0+1+2+...+n:1+2+...+n: an : 21-ian_1 : 2n2n—1an_2 : 2n2n—12n—2an_3 : _ . . : 21'L2TL—12Tl.-2 . _ _ 21a0 : 2n+(n—~1)+---+1 Z 2TL(TL+1)/2 Solving t2 — 7t + 10 = (t — 2)(t — 5), we obtain two roots 7: = 2 and t = 5. Thus there exist  constants b and at such that an : b2" + d5". The initial conditions require that 5 : b + d and 16 = 2b + 5d. Solving these two equations simultaneously for b and d, we obtain b : 3 and d 2 2. Thus a,,=3-2”+2-5”.  The roots of t2 — 2t — 8 = 0 are 4 and -2. Thus the solution is an : b4” + d(—2)”. To satisfy the initial conditions, we must have 4 = b+d 10 : 4b—2d.  Solving, we find b = 3 and d : 1. Thus the solution is  an = 3 - 4” + (—2)".  a,,_1+1+2"‘1 (a,,_2+1+2”‘2)+1+2"‘1 2 a,,_2+2+2"‘1+2"‘2:--- = ao+n+2"‘1+2""2+---+1=n+2"—1  an 2 3” — 2n3”'1 22. an 2 6 + 9n  M n(n+ 1)  Similar to Example 7.2.13 25. 5,, — 2 + 1  Let p be the population of Utopia in 1970. Arguing as in Example 7.1.3, we find that n years after 1970, the population of Utopia is (1.05)”p. Therefore 10000 = (1.05)3°p. Solving for p, we find that the population of Utopia in 1970 was p : 2314.  T  0 31.1 S+T  33. 
CHAPTER 7 SOLUTIONS  117  34. The recurrence relation becomes b” = ,,_1 +2b -2. Solving gives an 2 bg : % [2”+1 + (—1)"]2.  35. Taking the logarithm to the base 2 of both sides of the equation, we obtain  37.  1 lg an = an_2 —lg CL,-,_1).  If we let bn = lg an, we obtain  _ _ b _2 bn _ n 1 n 2 + 2 The quadratic equation F+E 1-0 2 2 ‘  has two roots, % and -1. Thus there exist constants p and (1 such that  bn = p + q(—1)”.  Now b0:lga0 :lg8=3 and a similar calculation shows that b1 : -3. Therefore 3 = P + (I 3 _ p 2 " 2 q‘  Solving for p and q, we obtain p : 1 and q : 2. Thus 1 TL bn : — 2 -1 " (2) + ( )  an : 212" : 2l(1/2)"+2(-1)"l_  and  Subtracting the given recurrence relation from the recurrence relation for n + 1  Cn+1:2-I-fag.  i=1 gives Gwr%%=% SO %H=2%,n22  This last recurrence relation can be solved by iteration to yield  c,,+1 : 20,, : 22c,,_1 : : 2”'1c2 = 3 - 2”'1.  for n 2 2. By inspection, the formula also holds for n : 1. Thus we obtain the formula  C11. : 3'2n—2a  fornz 2. 
118  38.  40.  42.  43.  CHAPTER 7 SOLUTIONS Let S(n,m) : A(n,m) — C(n,m) + 1. [C(n,m) is the number of m—element subsets of an  n-element set.] Then S(n, n) : 1 : S(n, 0). Also  S(n—1,m—1)+S(n—1,m) = A(n—1,m—1)—C(n—1,m—1)+1  +A(n— 1,m) —C(n— 1,m) + 1 : A(n,m) — C(n,m) + 1 = S(n,m).  Since {S (n, m)} and {C(n,m)} satisfy the same recurrence relation and have the same initial conditions, they are equal. Therefore  A(n,m) : S(n,m) + C(n,m) — 1 : 2C(n,m) — 1. Show that U” — g(n) satisfies an = c1an_1 + c2an_2.  Assume that : C171 + C0  is a solution. We must have  C1’/7, -|- C0 2 7[C1(’/7, — 1) —I— C0] — 10[C1(’/7, — 2) + C0] + 167;.  The coefficient of n on the left must equal the coefficient of n on the right: C1 Z 7C1 -1001-F 16.  Thus C1 = 4. The constant on the left must equal the constant on the right:  C0 Z -701 + 7C0 + 2001 — 1000.  Thus Co = 13. Therefore g(n) = 4n + 13.  The general solution of an : 7an-1 — 10an_2 b2” + d5”. Thus the general solution of the original recurrence relation is  an = b2”+d5" +4n+13.  Assume that g(n) 2 C2712 + Cm + Co  is a solution. We must have  02712 + Cm + C0 = 2[C2(n -1)? + C1(n — 1) + Co] + 8[C2(n — 2)? + C1(n — 2) + 001+ 81n2. 
CHAPTER 7 SOLUTIONS  45. 46.  48.  49.  119  The coefficient of n2 on the left must equal the coefficient of n2 on the right: C2 = 2C2 + 8C2 + 81.  Thus C2 2 -9. The coefficient of n on the left must equal the coefficient of n on the right:  C1 2 -402 -|- 201 — 3202 -|- 801.  Thus C1 : -36. The constant on the left must equal the constant on the right:  Co I 202 — 201 + 200 -|- 3202 — 1601 +  Thus Co = -38. Therefore g(n) = —9n2 — 36n — 38.  The general solution of  an : 2an—1 ‘l’ 8an—2  an = b4” + d(—2)”.  Thus the general solution of the original recurrence relation is  an = b4" + d(—2)" — 9112 — 36n — 38.  an :b4"+dn4”+ §’~5n+ 3% an = b(1/3)" + dn(1/3)" + (5/4)n2 — (5/2)n + 25/8 We must have Co = a0 : b C1 : a1 2 b + d.  Setb:C0 andd:C1—C0. By Exercise 48, Section 7.1, we have an$a,,_1+2, n24; a4g4. Now  an--1+2San—2+2+2<"' an—i+21_<_"' a4+2(n—4) g4+2(n—4)=2n—4.  an  I/\ I/\ I/\ 
120 CHAPTER 7 SOLUTIONS 51. n T(n) Opt Moves for 3-Peg Problem 1 1 1 2 3 3 3 5 7 4 9 15 5 13 31 6 17 63 7 25 127 8 33 255 9 41 511 10 49 1023  52. We show only the inductive step. Using the recurrence relation of Exercise 50 and the inductive assumption, we have  T(n) = 2T(n — kn) + 2k" -1 2 2[(kn_;c,, + Tn-“ — 1)2'°""°" + 1] + 2*" — 1.  First suppose that  Since  it follows that  Therefore,  Also,  Now  The case  2[(kn_k,, + r,,_kn — 1)2’°""“n + 11+ 2*" — 1 2[(k,, — 1 + 7-,, — 1)2’°'-'1 + 11+ 2'°n — 1 (kn—1+r,,—1)2'°"+2+2'°" -1 : (kn +rn — 1)2’°" +1.  ‘V71. 11- kn : 2%‘ i=1  is treated similarly. (In this case, k,,_;cn = kn and 7‘,,_;cn = 0.) 
CHAPTER 7 SOLUTIONS  53.  54.  121 Since kn is the largest integer satisfying  '°"kk1 Zy:_fi{?;l5m  1:1 if we solve the equation a:(:1: + 1) 2 for as and take the floor of the positive root,we obtain  k _[t/1+8n—1J 11*“ “"-‘*5***'*-  From this formula, it is easy to see that kn 3 \/2n. Since r,, 3 kn,  T(n) 2 (kn + rn — 1)2‘°n + 1 < 2k,,2"" + 1 g 2(\/%)2*/2“ + 1 = 0(4~/E).  We call a stacking in which the disks are arranged from top to bottom in order from smallest to largest a proper stacking. We call a stacking in which the disks in arbitrary order except that the largest disk is on the bottom an arbitrary stacking.  Now consider the given problem at the point when the bottom disk first moves. There must be an empty peg for it to move to; thus, the remaining n — 1 disks must be optimally moved to a third peg in an arbitrary stacking. We first determine the minimum number of moves required to move disks from a proper stacking to another peg in an arbitrary stacking.  Our new problem is, given n disks in a proper stacking, find the minimum number of moves, which we denote .9”, to move these n disks to another peg in an arbitrary stacking. Except for the original position, arbitrary stackings are allowed.  Clearly, 51 : 1. Suppose n > 1. Consider the point at which the bottom disk is moved. One peg must be empty (to receive the largest disk), and the n — 1 smaller disks must be moved to a third peg. By definition, this move requires s,,_1 moves. Now the largest disk moves (which requires one additional move). Now the n — 1 smaller disks must be placed on top of the largest disk. We can simply peel them off one-by-one and place them on top of the largest disk. This requires n — 1 moves, which is surely optimal. Therefore,  sn=s,,_1+1+n—1.  Solving, we obtain : n(n + 1)  s,,:1+2+---+n 2  Now we can answer the original question. Consider the point at which the bottom disk first moves. There must be an empty peg for it to move to; thus, the remaining disks must be moved to a third peg, which requires n(n + 1)/2 moves. Now the largest disk moves (which requires one additional move). Finally, the smallest n — 1 disks must be optimally moved and properly stacked on top of the largest disk. This can be done by reversing the first n(n + 1) / 2 moves. [If there were some way to move the smallest n — 1 disks and properly stack them on top of the 
122  CHAPTER 7 SOLUTIONS  largest disk in fewer than n(n + 1) / 2, we could reverse this technique and obtain a method of moving from a proper stacking to an arbitrary stacking in fewer than n(n + 1) / 2 moves.] Thus optimum number of moves is  n(n+1) +1+n(n+1)  = 1 1. 2 2 n(n+ )+  Section 7.3  2. At line 2, since 1 > j (1 > 5) is false, we proceed to line 4 where we set k to 3. At line 5, since  key (’P’) is not equal to 53 (’J’), we proceed to line 7. At line 7, key < 5;, (’P’ < ’J’) is false, so at line 10, we set 1 to 4. We then invoke this algorithm with 1' = 4, j = 5 to search for key in  S4 = ,MI, 85 = [X].  At line 2, since 1 > j (4 > 5) is false, we proceed to line 4 where we set k to 4. At line 5, since key (’P’) is not equal to .94 (’M’), we proceed to line 7. At line 7, key < 3;, (’P’ < 'M’) is false, so at line 10, we set 1' to 5. We then invoke this algorithm with 1 = j = 5 to search for key in  S5 = [X].  At line 2, since 1 > j (5 > 5) is false, we proceed to line 4 where we set k to 5. At line 5, since key (’P’) is not equal to s5 (’X’), we proceed to line 7. At line 7, key < an, (’P’ < ’X’) is true, so at line 8, we set 3’ to 4. We then invoke this algorithm with 1' : 5, j : 4 to search for key in an empty list.  At line 2, since 1 > j (5 > 4) is true, we return 0 to signal an unsuccessful search.  At line 2, since 1' > 3' (1 > 5) is false, we proceed to line 4 where we set k to 3. At line 5, since key (’C’) is not equal to 53 (’J’), we proceed to line 7. At line 7, key < 3;, (’C’ < ’J’) is true, so at line 8, we set j to 2. We then invoke this algorithm with 1 = 1, j = 2 to search for key in  .91 2 '0', .92 : '0'.  At line 2, since 1' > 3’ (1 > 2) is false, we proceed to line 4 where we set k to 1. At line 5, since key (’C’) is equal to .91 (’ C’ ), we return 1, the index of key in the sequence .9.  . We give a proof using induction. We omit the Basis Step.  Assume that a.- S a,-+1 for all 1' < n. We must prove the inequality for 11.  Using (7.3.2) and the inductive assumption, we have an : 1 + “Ln/21 S 1 + “L(n+1)/21 = “n+1-  We use induction on n. The Basis Step (11 = 1) is omitted. Inductive Step. Suppose that 11 > 1 and CL), : [lg k] + 2 for all k < 11. If n is odd, 
CHAPTER 7 SOLUTIONS  7.  123 an : 1 + ah,/2) : 1 + a(,,_1)/2 1 + I_lg(n — 1)/2] + 2 3+ I_lg(n — 1) — 1] 3+ [lg(n -1)] — 1 2 + L1g(n — 1)] : 2+ [lgnj  by the inductive assumption  I I  I {  L~’6-1J=l58J—1  ifj is Odd, 1182'] = 1180’ - 1)J-  The case when n is even is treated similarly.  (8)  (b)  We use induction on the size n of the sequence to prove that b2'nary_search2 is correct when the input is a sequence of size n. The Basis Step is n 2 0. In this case, the sequence is empty, 1' > j, and the algorithm correctly returns 0 to indicate that key is not found. Now assume that if a sequence of length less than n is input to b2'nary_search2, the al- gorithm returns the correct value. Suppose that a sequence of length n > 0 is input to bz'nary_search2. Since 1' 3 j, the algorithm proceeds to the line where it computes k. If key is at index k, the algorithm correctly returns k. If key is not at index k, since the sequence is sorted, key, if present, is either in .9,-, . . . ,s;,_1 or sk+1, . . . ,5,-, but not both. The algorithm then executes  k1 = b2‘nary_search2(s,z', k — 1, key)  If key is present in .9,-, . . . , s;,_1, by the inductive assumption, bz'nary_search2 returns the index where it is located. If key is not present in .9,-, . . . , s;,_1, by the inductive assumption, bz'nary_search2 returns 0. The value returned is stored in k1. The algorithm then executes  k2 : bz'nary_search2(s, k + 1,3’, key)  If key is present in s;,+1, . . . , 5,, by the inductive assumption, bmary_search2 returns the index where it is located. If key is not present in s;,+1, . . . , .9,-, by the inductive assumption, bz'nary_search2 returns 0. The value returned is stored in k2. It follows that if key is present in 5,-,...,sk_1 or sk+1,...,s,-, it is at index k1 + k2. If key is not present in 5,-,...,s,-, k1 + k2 = 0. Since the algorithm returns k1 + k2, it follows that the algorithm is correct. We define the worst-case time required by the algorithm to be the number of times the algorithm is invoked in the worst case for a sequence containing n items. Let let an denote the worst-cast time. Suppose that n is 0, that is, 2' > j. In this case, there is one invocation; so a0 = 1. Now suppose that n > 1. In the worst case, the item will not be found at the line  if (ke =: 5k) so the algorithm will be invoked twice more: k1 : bz'nary_search2(s,t', k — 1, key) k2 = bz'nary-search2(s, k + 1,3‘, key)  By definition, the first invocation will require a total of aL(,,_1)/2) invocations, and the second invocation will require a total of at”/2] invocations. Thus we obtain the recurrence relation an = 1 + Gun-1)/21 + “Ln/21' 
124  CHAPTER 7 SOLUTIONS  We use strong induction to show that an 3 3n + 1  for all n 2 0, thus proving that an = O(n). The Base Case, n : 0, is readily verified. Now assume that n > 0. By the inductive assumption, aL(,,_1)/2] 3 3[(n — 1)/2] + 1 and at”/2] 5 3[n/2] + 1.  Now  11  an 1 + Gun-1>/21 + “W21 1 + 3L(n — 1)/2] + 1 + 3[n/2] + 1 3 + 3(L(n - 1)/21 + Ln/21)  3+3(n—1)=3n<3n+1.  I/\  I I  We conclude by using strong induction to show that an 2 n  for all n 2 0, thus proving that an 2 Q(n) and, therefore, an = ®(n). The Base Case, n : 0, is readily verified. Now assume that n > 0. By the inductive assumption,  a|_(n—1)/2] Z [(71 -1)/21 and am/21 2 [71/21-  Now an = 1 + Gun-1)/21 + “Ln/2] 2 1 + L(n - 1)/21+ Ln/21 = 1 + (n — 1) 2 n. 1 1 1 9 9 3 3 7 3 7 9 Merge Merge  one-element two-element  arrays arrays 
CHAPTER 7 SOLUTIONS  12.  13. 15.  16.  17.  23.  24.  25. 26.  27.  125  We give a recursive description. We assume that the input consists of the integers from 1 to n. Let m : [(n+ 1)/2].  Set 51 =1,s2 23,53 =5,...,s,,, :2m—1 and sm+1 = 2,sm+2 2 4, . . .,s,, = 2[n/2]. Now arrange 51, . . . , sm to produce worst—case behavior for me7'ge_s0rt and arrange sm+1, . . . ,5"  to produce worst—case behavior for me7'ge_s07't. Seven, which occurs for an already sorted array. Basis Step. a1 : 0 < 2 = 2a1 + 2 : a2. Inductive Step. Assume that the inequality holds for I: < n. Now  “n+1 = “L(n+1)/21 +“L(n+2)/2J +71  2 “Ln/21 + “L(n+1)/21 + " * 1 = an-  The last inequality in the proof of Theorem 7.3.10 gives an 3 2n lgn + 2n + 1 for all n. If 3 3 lgn (or, equivalently, if 8 3 n), 2n + 1 3 3n 3 nlg n. Therefore if 8 3 n, an 3 2nlgn + 2n + 1 3 3nlgn. The cases 1 3 n < 7 can be checked directly.  Sequences of length m and n, where m 3 n, require, at the minimum, m — 1 comparisons for merging. Thus if b” denotes the least number of comparisons used by mergesort, bn satisfies  bn = bl”/2] + bL(n+1)/2] + — 1.  This recurrence relation can be estimated in the same way as the one for the worst—case time; therefore, the best—case time is @(nlg  If n = 1, a” = a; thus, a is returned. For n > 1, ifn is even, m : Ln/2] = 11/2 and a” : amam. If n is odd, m = (n — 1)/2 and a" = amama.  If n is odd, m : (n — 1)/2. If n > 1, after am is computed in line 5, line 6 is executed to compute amam and line 10 is then executed to compute amama. Thus bn : b(,,_1)/2 + 2. If n is even, m : n / 2 and line 6 is executed to compute amam. In this case, line 10 is not executed, SO bn : bn/2 + 1.  b1 :0, b2:1, b3:2, b4:2 Assume that n : 2'“. Now  bn:b2t—1+1:b2t—2+2=---:b1+k:0+k:lgn.  b7=4,b3=3 
126  28.  29.  30.  31.  32.  CHAPTER 7 SOLUTIONS  We use induction on n to prove that lgn _<_ b,, 3 2lgn,  from which we deduce bn : ®(lg n). The Basis Step (11 : 1) is omitted.  Assume that n > 1. If n is even, we have bu:nfl+1g1+2gg=1+2myn—ug2gn  and n b”: T,/2+131+lg§=1+(lgn)—1=lgn.  If 11 is odd, we have  -1 bn=qm”fl+2g2+2g"2 =2+pgm—1n—2g2gn and b" :b(,,_1)/2+2_>_2+lgn—1 :2+[lg(n—1)] -1 = 1+lg(n—1)Zlgn. The last inequality is equivalent to 1 > lg n ’ n -1 or 2 3 L n — 1  which is easily seen to be true for 11 > 1.  If 1 = 3’, there is only one element in the array, which is both largest and smallest. In this case, the algorithm simply returns these values.  If 1 < j, the algorithm divides the array into two nearly equal parts at line 7. At lines 8 and 9, the algorithm recursively finds that largest and smallest elements in each of the parts. The overall largest element is the larger of the largest in each of the parts (computed at line 11 or 13), and the overall smallest element is the smaller of the smallest in each of the parts (computed at line 15 or 17).  For input of size 1, 1 : j; no comparisons are made since the algorithm returns at line 5. Thus bl : 0.  For input of size 2, no comparisons are made during the recursive calls at lines 8 and 9 (since each involves input of size 1). There is one comparison at line 10 and one at line 14. Thus b2 = 2.  4  At lines 8 and 9, ah,/2] +aL(,,+1)/2] comparisons are made. At lines 10 and 14, two comparisons are made. 
CHAPTER 7 SOLUTIONS  127  33. If n : 2", the recurrence relation becomes bzk : 2b2t_1 + 2. Now  bn : bzk : 2b2)c—1 + 2 : 2[2b2k—2 + + 2 22b2»._2 +22+2 2 2‘°b2o+2‘°+2‘°-1+---+2  = 2‘°+2‘°'1+--.+2:2‘°+1—2=2.2’°—2=2n—2  H  l i  34. We give only the Inductive Step.  40.  41.  42.  45. 47.  Assume that bk = 2k — 2, for I: < n. The inductive assumption gives  : 2[n/2] -2 2[(n + 1)/2] — 2.  bin/2] bL(n+1)/2J =  Ifn is even, Ln/2] = n/2 = [(n + 1)/2], so bn : 2[2(n/2) — 2] + 2 : 2n — 2. If n is odd, Ln/2] : (n -1)/2 and [(n + 1)/2] = (n + 1)/2, so  bn:[2(n—1)/2-2]+[2(n+1)/2-2]+2:2n—2.  If n = 1, there is nothing to sort so the algorithm simply returns. If n > 1, the elements 51, . . . ,s,,_1 are sorted as a result of the recursive call. To sort the entire array, the nth element 5", stored in the variable temp, is compared to each of the preceding elements which are moved up one position successively as long as they are greater than temp. The index 1' runs down the list. As soon as an element less than or equal to temp is found (pointed to by z’), the loop is exited and temp is stored at position 1' + 1. If there is no element less than or equal to temp, i is 0 and temp is stored at position 1.  The worst—case behavior occurs when the items are in reverse order.  n(n — 1)  2 46. b,, = (1 +lgn)(2+ lgn)/2  b1:0,b2:1,b3:3 43. bn:bn..1+n—1 44. bn: bn = 1 + [lgnj +bL,,/2J,b1 = 1,b2 = 3,b3 : 3 An arbitrary value of n falls between two powers of 2, say 2'“ < n g 2'“. This inequality implies that k — 1 < lgn 3 Is. Since the sequence b is nondecreasing, b2k—1 3 b” 3 bzk.  Now  _ (1 + k)(2 + k) < (2 + lgn)(3 + lgn) _ 2 — 2 Similarly, b,, : O((lg n)2). Therefore bn : ®((lg n)2).  bn 3 bgk = O((lg n)2). 
128  50. 55.  58.  60. 63.  65.  66.  68.  69.  CHAPTER 7 SOLUTIONS  b1 : 1, ()2 = 2, b3 = 3, 51. bn Z bn_1 + 1 52. bn I TL 53.  Similar to the proof for Exercise 47 57. bn : bL(1+n)/2] + btn/2] + n  Let ck = bzk. Then ck : 2Ck—1 + 3. If n : 2", bn : ck:2c;c—1+3:2(2ck—2+3)+3:  = 2'°co+3(2'°'1+2’°'2+---+1)=2‘°-0+3(2‘°—1) = 3(n—1).  Use the method of Exercise 58. 61. bn : n(1 + lg n)  Use Exercise 60 to show that if n is a power of 2, bn = nlg n. Now let n be arbitrary. Choose is so that 2'“ < n 3 2k“. By Exercise 62, bn _<_ b2t+1. Now  122.... = 2'°+1(k + 1) g 2'°+1(k + k) : 4(2'°k) g 4n lgn. an 3 at” J+ aL(,,+1)/21+ 2 +1g([n/2] [(n + 1)/2]). If n is even, Ln/2] [(n + 1)/2] = n2/4. Ifn is odd, Ln/2] [(n +1)/2] = [(n -1)/2][(n + 1)/2] = (n2 -1)/4 _<_ n2/4. Thus we can write  n2 an S at"/21+ aL(n+1)/21+ 2 -Fig? : at”/2] + aL(n+1)/21+ 21gn.  Let n = 2'“ and use induction on Is. Basis Step. Ifk:0, b1 20:4-1—21g1—4 Inductive Step.  2b2x+2(k+1)=2[4-2'°—2k—4]+2(k+1) 4-2’“+1—2(k+1)—4  b2k+1 Z  Inductive Step. bn = bin/2] + bL(n+1)/21 + 218" S bL(n+1)/2] + bL(n+2)/2] + 2180‘ + 1) = bn+1 Choose 19 with 2" < n _<_ 2"“. Then  angbngbzmri:4-2k+1—2(k+1)—4§8-2'“£811. 
Chapter 8  Solutions to Selected Exercises  Section 8.1  2. The following undirected graph models the tournament:  Snow Pheasants  Skyxcmpera Thug  3. The following simple, directed graph models the tournament:  Snow Pheasants  Skyscmpcrs Tuna  6. There are vertices of odd degree {b, d}. 7.. There are vertices of odd degree {b, d}. 9. (a, c, f, e, c, b,e, d, b, a) 10. (a, b, c,e, b, d,e, f, C,g,h,’i,f, h,e,g,d, a)  12. V : {v1,v2,v3,v4,v5}. E : {e1,e2,e3,e4,e5,e5,e7,eg}. There are no parallel edges, no loops, and no isolated vertices. G is simple. e1 is incident on 122 and 124.  13. V = {v1,v2,v3}. E is empty. There are no parallel edges and no loops. G is simple. e1 does not exist. All vertices are isolated.  15. n(n — 1)/2  129 
130 CHAPTER 8 SOLUTIONS  16- V1 = {v1,v2,U3.v4}, V5 = 925106.127}-  U1 U5 02 U6 U3 U7 v4  18. The graph is bipartite. V1 = {121,123,124,125,12g,129,121o}, V2 = {122,125, 127}. 19. The graph is bipartite. V1 = {Gre, Buf, Sho, Dou, Mud}, V5 : {She, W01", Gas, G1'l,Lan}. 21. Not bipartite 22. Not bipartite 25. mn  26. Example 8.1.12 is bipartite, but Examples 8.1.13 and 8.1.14 are not bipartite. K1 is not bipartite because there is no way to partition the vertices into two nonempty subsets.  28. (c, a, b, e, d) 29. (a, c, d, e, b)  30. The vertices are mathematicians, and an edge connects two mathematicians if they co-authored  a paper. The Erdés number of mathematician m is the length of a shortest path from m to Erdés.  31. Yes 33. One class.  1 2  4 5  34. No. If similarity is defined solely by the dissimilarity function, in the graph of Figure 8.1.8, 121 is similar to 123 and 123 is similar to 125, but 121 is not similar to 125.  , ,10——-/11 071 1¢’——i~1f’ 0 0 «” * /1?/I 01f—’——0f’ 0 ——  41. n2”'1 (There are 2” vertices and each is incident on n edges. Since n2” counts each edge twice, the formula follows.)  3  O0  42. n!2” (The result can be proved by induction on n.) 44.  11 01 11 01 11 01 011 001  10 00 10 — 00 10 00 010 000  —-l-——o—-»— ———o——— ———o——— ——-—o—r—— ——-—o-———  10 oo 10 00 110 100 11 10 V  11 01 11 01 111 101 
CHAPTER 8 SOLUTIONS  47. 5  51. 33:1 ——>w=a:+5  /  y:2 —+z:y+2  52-5821 a:m+y V  y:2 b:y+z a::a+b+c  z:3 c=a:+z —>c=c+1  Section 8.2  [O  . Simple path—yes; cycle—no; simple cycle—no 3. Simple path—no; cycle—no; simple cyc1e—no 5. Simple path—no; cycle—no; simple cycle—no 6. Simple pathano; cycle—yes; simple cycle~no 8. Simple path—yes; cycle—no; simple cycle—no  9. Simple path—yes; cycle—no; simple cyclekno  11. There is no such graph since there are always an even number of vertices of odd degree.  II  14. No such graph exists. One-half the sum of the degrees (: number of edges) is 5, not 4.  15. 17.  131 
132  18.  20.  21.  23.  25.  26.  29. 30. 32. 33. 35. 36. 38. 40.  41.  CHAPTER 8 SOLUTIONS  No such graph exists. Suppose, by way of contradiction, that there is such a graph with vertices a and b of degree 2 and c, d, and e of degree 4. Since c is of degree 4, it is incident on a, b, d, and e. Similarly, d is incident on a, b, c, and e, and e is incident on a, b, c, and d. But now a has degree at least 3. Contradiction.  (a,b,c.d.e),(a.b.c,d.f,e),(a,b,c,g.f,e),(a,b,c,g,f,d,e),(a,b,g,f,e),(a.b,g,c,d,eL (a,b,9,f,d,e), (a,b,g,c,d,f,e)  NJ\“L_l\~<__P  The second is a simple path. Neither is a cycle or a simple cycle.  6(v1) = 2,6(v2) = 2,6(v3) : 3,6(v4) = 6,6(v5) : 2,6(v5) : 3,(5(v7) : 4,6(U1(]) : 2  4, 6(’U3) : 4,6(’U9) :  There are six subgraphs, the following five subgraphs and the original graph itself.  21 22  /V/W  "1 "2 "1 "2 "1 "2 "1 ‘"2  The following are the subgraphs with no edges: G1 = ({v1},0), G2 = ({v2},0), G3 : ({v3}»0)a (74 ==({v1aU2}a@)» C?5 ::({"11U3}a0)1(;5:: ({v2.v3},@),<?7 = ({v1,v2.v3},@)~'ThB other subgraphs are  U1 U1 U1 U1 6% X2 6/ W2 123 U2 . U3 U2 . G8 G9 G 10  and G itself.  62  123 11  (vi,vs,v2,v4,vs,v3,v2,v1,v4,v3,v1) There is no Euler cycle since there are vertices of odd degree. (a, b, d, c, b, f, g,j, f, e,j, h, c, 1', d, e, 1', h, a) (a, b, c, b, d,e,h, f,z',j,k,z',h,g, f,e,g,d, c, a) When n is odd Both m and n must be even. When n is even  There are zero vertices of even degree, and zero is even.  (daaabadaeabacaeahagadafagajahaiae) 
CHAPTER 8 SOLUTIONS  43  44.  46.  48. 49.  51.  52. 54.  56. 60.  133  (b,c,d,g,b,a,f.g,i.f); (c,h,e) Let G be a connected graph with n vertices 121, . . . ,12,, of odd degree. There are paths with no repeated edges from 121 to 122, 123 to 124, and so on, such that every edge in G is in exactly one of the paths. False. Consider the cycle (a, b, c, a) for the graph b  a . d c The graph of Exercise 26  No. Let the vertices of a graph be the squares of the chessboard. Insert an edge between two vertices if a knight can make a move between the corresponding squares. The degrees of the vertices that correspond to the border squares next to the corner squares have degree 3. Since there are eight of these, there is no Euler cycle.  Let H be one of the connected subgraphs in the partition. Let 12 be a vertex in H. Let C be the component to which 12 belongs. We show that H = C. Let 112 be a vertex in H. Since H is connected, there is a path from 12 to 112 in H. Therefore 112 is in C. Let 112 be a vertex in C. Then there is a path from 12 to 112 (110191, ' ' ' 5,011):  with 120 = 12, 12,, : 112, in C. The edge (120,121) must belong to H since vertex 120 is in H. Thus vertex 121 is in H. Continuing in this way, we see that 112 is in H. Therefore the vertex sets of H and C are equal.  Similarly, the edges sets of H and C are equal. Therefore the subgraphs of the partition are components.  There is a path P from 12 to 112. Change the orientation of each edge in P.  Let G be a simple, bipartite graph having the maximum number of edges with disjoint vertex sets having is and n — k vertices. Then G has k(n — k) edges. The maximum of the integer- valued function f(k) = k(n — 19) occurs when k = 11/2, if n is even, and when k = (n — 1)/2 or k = (n + 1) /2, if n is odd. Thus the maximum number of edges is [n2/4] = n2/4, if n is even, and [n2/4] : [(n — 1)/2][(n + 1)/2], if n is odd.  K6 If (bg1>bg1> . . .12“)  11-1:  b‘,2’b§2’ . . . b£f_’,, . . .) is a directed Euler cycle in G, b‘,1’b§1’ . . . b§,1l,b£,23,b§,33, . . .  is a de Bruijn sequence. 
134  CHAPTER 8 SOLUTIONS  62. We first show that if G is a connected bipartite graph, then every closed path in G has even  length. Suppose that the disjoint vertex sets are V1 and V2. Let  P:(120,121,...,12,,)  be a closed path from 1211 to 12”. Suppose that 120 6 V1. Then 121 6 V2, 122 6 V1,. . .. Notice that if 1' is odd, 12,- 6 V2, and if 1' is even, 12,- 6 V1. Since 12,, 6 V1, it follows that n is even. Thus P has even length.  We conclude by showing that if every closed path in a connected graph G has even length, then G is bipartite.  Choose a vertex 12 in G. Let V1 denote the set of vertices 112 in G that are reachable from 12 on a path of even length. Let V2 denote the set of vertices 112 in G that are reachable from 12 on a path of odd length. Notice that since G is connected, every vertex in G is either in V1 or V2. We claim that V1 and V2 are disjoint. To show this, we argue by contradiction. Suppose that some vertex 112 belongs to both V1 and V2. Then there is a path P; of odd length and a path P6 of even length from 12 to 112. Let Po be the path from 112 to 12 obtained by reversing the order of the vertices. Then P6 followed by P0 is a closed path of odd length from 12 to 12. This contradiction shows that V1 and V2 are disjoint. Now let e be an edge incident on vertices :13 and 3;. Suppose that :1: belongs to V1. Then there is a path P of even length from 12 to cc. Now P followed by y is a path of odd length from 12 to y. Thus y is in V2. Therefore G is bipartite.  63. n(n — 1)'° [Choose (12o,121, . . . ,12;,) with 12,--1 7E 12,-.]  65.  66.  (a) pm : (n — 1)""1 — p,,,_1. The first term counts the number of paths of length m — 1 that start with 12, and the last term counts the number of paths of length m — 1 that start with 12 and end with 112. A path of length m — 1 that starts with 12 and does not end with 112 can be extended to a path of length m that starts with 12 and ends with 112.  (b)  (n —1>'"“1—1<n ~ 12"” —pm—2l = (n - 12"“ — (n — 1)“ +p...-2  = (n — 1)'”'1 - (n — 1)'”“2 + - - - + (-1)'”(n — 1) + (—1)'”“p1 = (n — 1)'”'1 — (n — 1)'”'2 + - - - + (—1)'"(n — 1) + (—1)'”+1 -(n - 1)” - (-1)'”“ —(n — 1) — 1 (n — 1)” + (—1)'”+‘ T17...”  There is one path of length 1, (12,112), from 12 to 112.  There are n — 2 paths of length 2, (12, $1,112), from 12 to 112 since vertex 5131 can be chosen in n — 2 ways. (Vertex 5131 must be different from 12 and 112.) 
CHAPTER 8 SOLUTIONS  67.  69.  71.  72.  74.  135  There are (n — 2)(n — 3) paths of length 3, (v,:01,:02,w), from v to 11) since vertex :01 can be chosen in n — 2 ways, and vertex :02 can be chosen in n — 3 ways. (Vertex :01 must be different from v and w, and vertex :02 must be different from v, w, and :01.)  In general, there are (n — 2)(n — 3) - - - (n —— k) paths of length 10, (1), :01, . . . ,a:k_1, w), from v to 11) since vertex :01 can be chosen in n — 2 ways, vertex :02 can be chosen in n — 3 ways, and so on. The result now follows.  The number of simple paths of length 0 is n; the number of simple paths of length 1 is n(n — 1); the number of simple paths of length 2 is n(n — 1)(n -2); and so on. Thus the number of simple paths is  n+n(n—1)+n(n—1)(n—2)+---+n(n—1)---1=n!§%. k:0 '  Now  11-1 1  ” 1 : n!e—1—n! E F. lc=n+1 . Since, for n 2 2, W 1 1 1 n‘ — — + kglk! n+1 (n+1)(n+2) 1 1 g 1 _ _ .. : : <1 n+n2+ 1—% 11-1‘ ’  the result follows. The result is true by inspection for n = 1.  A connected graph with one vertex, consists of the vertex, say 12, and none or more loops incident on ’U. An Euler cycle consists of a cycle that traverses each loop once.  A connected graph with two vertices, say ’U and w, each of which has even degree, consists of 2k edges incident on v and w, k 2 1, none or more loops incident on v, and none or more loops incident on '11). An Euler cycle consists of a path that begins at v, traverses all of the loops incident on v, traverses one edge from v to w, traverses all of the loops incident on w, traverses one edge from w to v, and traverses all remaining edges incident on v and w. This path will end at 12 since there are an even number of edges incident on v and 11).  diameter : n. The diameter is the maximum time for two processors to communicate. 1, since dist(v, w) : 1 for every pair of distinct vertices in K”  First we show that, if n mod 4 = 1, kz"’3 2 
136  76.  77.  78.  CHAPTER 8 SOLUTIONS  Suppose that n mod 4 : 1. In particular, n is odd. Since every vertex has degree I9, /9 must be even. (If It is odd, we obtain a contradiction to the theorem that states that there are an even number of vertices of odd degree). We show that (n — 3) / 2 is an odd integer and, consequently,  -3 -1 " +1=" .  k> ‘2 2  Since nmod4 = 1, we may write n : 4q+1. Thus n—3 = 4q—2 and (n—3)/2 = 2q— 1, which is an odd integer. Therefore  regardless of the value of n mod 4.  Now suppose that G is not connected. Let C1 and C2 be components. Since every vertex has degree is, C1 and C2 each have at least lc + 1 vertices. Thus G has at least 2(k + 1) 2 n + 1 vertices, which is a contradiction.  We prove the result by induction on n. We omit the Basis Step (n : 1).  Assume that the result is true for n. Let G be an (n+ 1)-vertex dag with the maximum number of edges. By Exercise 74, G has a vertex v with no out edges. In fact, there must be edges of the form (11), v) for all 11) 7E 1); otherwise, G would not have the maximum number of edges. This accounts for n edges.  Let G’ be the graph obtained from G by eliminated v and the n edges incident on v. G’ is an n-vertex dag and since G has the maximum number of vertices, G’ must also have the maximum number of vertices. By the inductive assumption, G’ has n(n — 1) /2 vertices. Thus G has  n(n—1) n_ (n+1)n 2 ‘ 2 vertices.  Let I (P,,) denote the number of independent sets in P”. Note that I (P1) = 2 and I (P2) 2 3. Now suppose that n > 2. Let 1) be a vertex of degree 1 in P". An independent set P” that contains ’U consists of v and an independent set of Pn_2, and there are I (Pn_2) such independent sets. An independent set of P” that does not contain 1) is an independent set of P,,_1, and there are I (P,,_1) such independent sets. Therefore  I(P,,) : I(P,,_1) + I(P,,_2).  Since {I (P,,)} satisfies the same initial conditions and recurrence relation as {f,,+2}, I (P,,) f,,+2 for all n.  (a) Let 1) and 11) be nonadjacent vertices in G. Let {$131, . . . ,a:;c}  denote the vertices adjacent to 1). Then the mapping N (cc,-) 2 y,-, where y,- is adjacent to .'1:,- and w, is a bijection to the set of vertices adjacent to 11). Therefore 6(1)) : 6(w). 
CHAPTER 8 SOLUTIONS  137  (b) Let V1 denote the set of vertices of degree 11. Suppose that 71 is nonempty. By part (a), every vertex in V1 is adjacent to every vertex in 71. Since no vertex is adjacent to all other vertices, [V1] 3 2 and I71] 3 2. Let 121 and 1121 be distinct vertices in V1, and let 122 and 1122 be distinct vertices in |V1|. Now 121 adjacent to 122 and 1122 and 1121 adjacent to 122 and 1122, which is a contradiction since there are two vertices (122 and 1122) adjacent to both 121 and 1121.  Section 8.3  10.  11.  13.  14.  16.  (a$b!c,d3e,f)n$p1m3[) k;$j70?(':1h3g3a)  We would have to eliminate one edge at f, three edges at c, one edge at b, one edge at 1', three edges at j, and three edges at m, leaving 15 edges. Since there are 16 vertices, a Hamiltonian cycle would have 16 edges.  . Suppose that the graph has a Hamiltonian cycle. Since each vertex in a cycle has degree 2,  we would have to include the edges (a, b), (a, f), (f, g), (b, c), (c, d), (d,e), (e, h), and (g,h). Since these edges already form a cycle, there is no Hamiltonian cycle.  (a, b.c,g,l,m. 1", (1119, 11,1’, f,e, tn, 0,15. 8, h,d, a)  There is no Hamiltonian cycle. We would have to eliminate two edges at c, three edges at e, and one edge at f, leaving six edges. Since there are seven vertices, a Hamiltonian cycle would have seven edges.  K3  We begin the Hamiltonian cycle at row 1, column 1 and proceed along the first row to column m— 1. Then we go down to row 2 and move back along row 2 to column 1. Then we go down to row 3 and along row 3 to column m — 1. Then we go down to row 4 and back to column 1 along row 4. We continue this serpentine path until we arrive at the last row. If n is odd, we finish in column 1. We then take the edge from row n, column 1 to row n, column m and proceed up column m to row 1. We then follow the edge from row 1, column m to row 1, column 1 finishing the cycle. If n is odd, we ended our path at row n, column m — 1. We then move along row n to column m, up column m to row 1, and along the edge from row 1, column m to row 1, column 1 to finish the cycle.  Choose any vertex 12 to start. After arriving at a vertex, move to a not-yet-visited vertex (except when returning to 12 for the nth and last move). Since the degree of every vertex is n — 1 and there are n moves, such moves are always possible.  The five edges of smallest weight have weights 3, 4, 4, 5, 5. Thus the shortest Hamiltonian cycle has a weight of at least 21. However, three of these edges (those with weights 3, 4, 4) are incident on vertex c. Thus the edges of weight 3, 4, 4 cannot all be in a Hamiltonian cycle. If 
138  17.  19.  20.  22.  23.  26.  29.  CHAPTER 8 SOLUTIONS  we replace an edge of weight 4 with an edge of minimum replacement weight 6, we can conclude that the shortest Hamiltonian cycle has weight at least  3+6+4+5+5:23.  Since the given Hamiltonian cycle has weight 23, we conclude that it is minimal.  (e,d, a, b, c, e) G12 0 1 Cf: 1 0 G3: 00 01 G’1’: 11 10 G2: 00 01 11 10 G§: 10 11 01 00 G3: 000 001 011 010 Gg: 110 111 101 100 G3: 000 001 011 010 110 111 101 100 Q5}: 100 101 111 110 010 011 001 000 05: 0000 0001 0011 0010 0110 0111 0101 0100 Cg; 1100 1101 1111 1110 1010 1011 1001 1000 G4: 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111  1110 1010 1011 1001 1000  Let C be a Hamiltonian cycle in G. Consider a traversal of C. When we traverse an edge from a vertex 121 in V1 to a vertex 02 in 16, this uniquely associates one vertex U2 with 01. Since C traverses all vertices |V1] = ll/5|.  Let each vertex of a graph represent a permutation. Put an edge between two vertices p and q if and only ifp, 75 q,- for all 1' : 1,2,...,n.  (n:1)1 (n:2) 12 21  (n = 3) Consider a graph with six vertices representing the permutations and with an edge between two vertices if the permutations differ in each coordinate. A solution to the problem is a Hamiltonian path in the graph. There is no solution for n : 3 because the graph is not connected.  (n : 4) 1234 3412 4321 1432 2341 4132 3241 4123 3214 1423 2314 1243 2134 3421 4312 2431 1342 4231 3142 4213 3124 2413 1324 2143  No. Consider Figure 8.3.5. 27. Yes, (v1,v2,v5,v4,v3).  No. Suppose the graph has a Hamiltonian path. First note that the path must either start or end at either a or c. If not, we must use edges (a, b), (a, d), (b, c), and (c, d), which make a cycle. Similarly, the path must start or end at either 3' or l. Suppose that the path starts at a. The path begins with either (a, b) or (a, d). By symmetry, we may assume that the path begins with (a, d). 
CHAPTER 8 SOLUTIONS  30.  32.  33.  35.  36.  139  First suppose that the path ends at l. Since the path does not end at c, it must include edges (b, c) and (c, d). Also, since the path does not end at 3', it must include edges (2', j) and (j, k). The path must include either (b, e) or (b, f). If (b, e) is in the path, then (f, e) and (f, 1') must be in the path. Since the path ends at l, it must contain (l, k). If (b, f) is in the path, then (f, e) and (e,t') must be in the path. Again, since the path ends at l, it must contain (l, k). In either case, h must have degree one, which is a contradiction. Therefore the path cannot end at l.  Now suppose that the path ends at j. Since the path does not end at c, it must include edges (b, c) and (c, d). Also, since the path does not end at l, it must include edges (’i,l) and (k,l). Arguing as in the previous case, we find that either e or f connects to z’. Since the path ends at j, it must include (j, k). Again, h must have degree one, which is a contradiction. Therefore the path cannot end at 37.  Now suppose that the path begins at c. By symmetry, we may assume that the path begins with (c, d). Since the path does not end at a, it must include edges (d, a) and (a, b). Now the argument is exactly as in the preceding paragraphs; again a contradiction is reached. The proof is complete.  No. We would have to eliminate at least one edge at f, at least three edges at c, at least one edge at b, at least one edge at 1', at least three edges at j, at least three edges at m, and at least one edge at p leaving 14 edges. Since there are 16 vertices, a Hamiltonian path would have 15 edges.  Yes?(a'5b3c3j1(£,m7k,d)e’f3[’g7h) Yes? (a’b$c!g’l7m3r$q7p,k?j1f$e7(':,n!01t,S7h5d)  The graph contains a Hamiltonian path for all m and n. Start in the upper-left corner. Continue right until reaching the end of this row. Drop down to the next row. Continue left until reaching the end of this row. Drop down to the next row. Now repeat, continue right until reaching the end of this row . . . Continue until all vertices have been visited.  For all n  Section 8.4  2.  7.  8.  11; (a, b, c,g) 3. 10; (a, b, c, d, z) 5. 10; (h, f, c, d)  Change line 8 of Algorithm 8.4.1 to while (T -1: 0) {  Input: A connected, weighted graph with n vertices in which all weights are positive (if there is no edge between 2' and j, set ’U)(’i,j) : oo) Output: diSt(’i, j), the length of a shortest path from 1' to j for all 1'  and j 
140  all_paths(w,n) { for j : 1 to n for k 2 1 to n dist(j, k) = w(j, /9) for 1' = 1 to n for j : 1 to n for k = 1 to n if (dist(j,i) + dist(z', k) < dist(j, 19)) dist(j, k) = dist(j, 1') + dist(z', I9)  10. False  Section 8.5  2. Relative to the ordering a, b, c, d, e, f, g, the adjacency matrix is  OOOOOIOO O0!-*C>r—‘Ot\:> OOHOIQHO  3. Relative to the ordering a, b, c, d, e, the adjacency matrix is  ©©©P-‘G ©©®©r—I  >—»r—IOOO >—*@>—*t\D©®©  l—‘©P—‘©@ ©P-‘@*—‘P—‘P—‘©  GP-‘P—‘©© >—‘©>—*©©©©  ©>-‘C?-‘©©©  CHAPTER 8 SOLUTIONS  5. Every entry is one except along the main diagonal, which consists of zeros. 
CHAPTER 8 SOLUTIONS 141  6. If V1 : {a, b} and V2 : {c, d, e} are the vertex sets and the ordering is a, b, c, d, e, the adjacency matrix is  0 0 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0  8. Relative to the orderings cc1,a:2,a:3,a:4,a:5,a:5,:c7,a:3,a:9,a:10,a:11 and a, b, c, d,e,f,g, the adja- cency matrix is  1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 1 0 0  9. Relative to the orderings 331,332, 333,934 and a, b, c, d, e the adjacency matrix is  1000 1000 0110 0011 0101 (1111000000 1000111000 11.0100100110 0010010101 0001001011 (111000 000111 12.100100 010010 001001 14. 15. G. C G C b E b ab 1b a[ 17. O 
142  18  20.  25.  26.  29.  30.  CHAPTER 8 SOLUTIONS  (For Exercise 15) The first matrix is relative to the ordering a, c, f and the second is relative to the ordering b, d, e.  0 1 1 1 0 1 1 1 0  [OP-dl\D  1 0 1  c>r—tt\D  93 21. The graph is not connected.  a. c d b C The vertex corresponding to the row of zeros is an isolated vertex.  Use the fact that  dn+1 an-{*1 0111+] drn an an 0 1 1 1 1 - an dn an 1 0 1 1 1 : A"+1 : - - 1 1 0 1 1 - 1 1 1 0 1 CL,-L+1 CL,-L+1 d1-,+1 an an dn 1 1 1 1 0  We solve the second—order linear homogeneous recurrence relation (see Exercise 29) an : 3an—1 + 4an—2  by the method of Section 7.2.  Solving the equation t2 — 3t — 4 = 0  for t, we obtain t : 4 and t 2 -1. Thus the solution is of the form an : b4” + d(—1)". The initial conditions give the equations  : a1:4b—d 3 Z a2:16b+d.  Solving for b and d, we obtain b = 1/5 and d = -1 / 5. Therefore  :§_(‘1)":1  5 5 5  an [4” + (—1)”+1]. 
CHAPTER 8 SOLUTIONS 143 Section 8.6 2. The graphs are isomorphic: f(a) : 1, f(b) : 3, f(c) : 5, f(d) = 7, f(e) : 2, f(f) : 4. f(9) = 6- 9((w. 12)) = (f(rv).f(y))- 3. The graphs are not isomorphic since G1 has a simple cycle of length 3 and G2 does not. 5. The graphs are isomorphic: f(a) = 3, f(b) = 4, f(c) : 1, f(d) : 5, f(e) : 2. g((a:,y)) = (f(5v). f(y))- 6. The graphs are isomorphic: f(a) = 1, f(b) = 5, f(c) = 6, f(d) : 2, f(e) : 3, f(f) 2 7, f(9) =8. f(h) =4, f(%') =9. f(f) =10. f(k)=11, N) = 12- 9((6v,y)) = (f(w).f(y))- 8. The graphs are not isomorphic. The edge (1,4) in G2 has 6(1) 2 3 and 6(4) = 3 but there is no such edge in G1 (see also Exercise 15). 9. The graphs are not isomorphic. G1 has two simple cycles of length 3, but G2 has only one simple cycle of length 3 (see also Exercise 14). 11. Extend the definition in Example 8.6.3 as follows: f (12) = 121122 . . .12;,, where 12,- is the 1'th coordinate determined as the members of a 15,- Gray code. Note that if (12,112) is an edge in M, the strings 121122 . . .121, and 11211122 . . .1121, will differ in exactly one bit. So, (12,112) is an edge of the (t1 + t2 + - - - + tk)-cube. Define g on the edges of M by g((12,112)) : (121122 . . .12;c11211122 . . .112k). f and g define an isomorphism from M onto the subgraph (V, E) of the (t1 + t2 + - - - +t;c)—cube where V = {f(12) [12 is a vertex in M}, E = {f(e)|e is an edge in M}. 13. Suppose that G1 and G2 are isomorphic. We use the notation of Definition 8.6.1. Suppose that G1 has n vertices 121,... ,12,, of degree k and that G2 has m vertices of degree /1. By Example 8.6.8, f(121), . . . , f(12,,) each have degree It in G2. Therefore m 2 n. By symmetry, m 3 n. Thus m = n. 14. We use the notation of Definition 8.6.1. Suppose that G1 is connected. We must show that G2 is connected. Let 12’ and 112’ be distinct vertices in G2. Then there exist vertices 12 and 112 in G1 with f(12) : 12’ and f(112) = 112’. Since G1 is connected, there exists a path (120,121, . . . ,12,,) in G1 with 120 = 12 and 12,, : 112. Now (f(12o), f(121), . . . , f(12n)) is a path in G2 from 12’ to 112’. Therefore G2 is connected. 16. Let (12,112) be an edge in G1 with 6(1)) :1’ and 6(112) = 37. Example 8.6.8 shows that 6(f(12)) :1’ and 6(f(112)) = j. Now the edge (f(12), f(112)) has the desired property in G2. 19. Not an invariant 
144  20. 22.  23.  27.  28.  30.  31. 34. 35. 37. 38.  CHAPTER 8 SOL UTIONS  Invariant  IIIIIIYIITNNIJNIZIM  O—O—0—o——0o—o—~I—-o>—{—<'  Suppose that G is not connected. Let C be a component of G and let V1 be the set of vertices in G that belong to C. Let V5 be the set of vertices in G not in V1. In G, for every 121 6 V1 and 125 6 V5, there is an edge e incident on 121 and 125. Thus, in G there is a path from 12 to 112 if 12 6 V1 and 112 6 V5. Suppose that 12 and 112 are in V1. Choose a: 6 V5. Then (12, 93,112) is a path from 12 to 112. Similarly if 12 and 112 are in V5, there is a path from 12 to 112. Thus G is connected.  Suppose that G1 and G5 are isomorphic. We use the notation of Definition 8.6.1. We construct an isomorphism for G1 and G5. The function f is unchanged. Let (12,112) be an edge in G1. Set  9((v.w)) = (f(v), f(w))-  It can be verified that the functions f and g provide an isomorphism of G1 and  If (T1 and ‘G’; are isomorphic, by the preceding result, 3} : G1 and E : G5 are isomorphic. Yes f(1) = w. f(2) = «'6. f(3) = 1/,f(4)= zr f(5) = 1/, f(6) = 56 f(1)=ai f(2)=b, .f(3):c2.f(4):d1.f(5):c1.f(6):b f(a) = 1. f(b) = 2, f(c) = 3. f(d) = 4, f(e) = 5. f(f) = 3, f(g) = 2 See [Hell]. 
CHAPTER 8 SOLUTIONS  Section 8.7  2. 3.  J  5. Remove (g, e) and (a, c) to obtain a graph homeomorphic to  b f 9 a c d 7 . Planar a b e d  8. Not planar. The following graph is homeomorphic to K3_3.  a b h d 6 9  C  145  11. Let G be a graph having four or fewer vertices. By Exercise 10, the planarity of G is not affected by deleting loops or parallel edges; so we can assume that G has neither loops nor  parallel edges. Now G is a subgraph of K4 and, since K4 is planar, so is G.  13. Since every cycle has at least three edges, each face is bounded by at least three edges. Thus the number of edges that bound faces is at least 3f. In a planar graph, each edge belongs to  at most two bounding cycles. Therefore 2e 2 3f : 3(e — v + 2). Thus 31) — 6 2 e.  14. K33  16. Suppose that G and G are both planar. Let ’U denote the number of vertices in G. Let e (respectively, 6) denote the number of edges in G (respectively, G). If either G or G is not 
146  17.  19.  20.  21.  23.  24.  26.  27.  29.  CHAPTER 8 SOLUTIONS  connected, add just enough edges, preserving planarity, to connect it. Let the connected graphs so obtained be denoted G* (with e* edges) and @ with E edges). Using Exercise 13, we obtain  12(12 — 1)  2 =e+E§e*+E7g2(312—6).  Thus 122—1312+24 $0.  The roots of the equation obtained by replacing 3 by 2 are  13:l:\/fi a:=j—, 2 SO 13 12_<_-—i;/—fi<11.  See Amer. Math. Mo., April 1983, pages 287~288.  Pick a city in each country. Draw a line through the common border between two cities in countries sharing a common border. This can be done with no lines crossing.  Color D, say, red. Now B and C must be different colors and different from red. A—red, B—green, C—blue, D—red, E—green, F—blue, G—green  Color L red. Now G needs a different color—say blue. Now K needs a color different from L and G-say yellow. Now J needs a fourth color.  A—blue, B-green, C—red, D—yellow, Ewgreen, F—red, G—yellow, H—green, I~yellow, J—green, Kablue, L—red  Suppose that G’ can be colored with n colors. If we eliminate edges from G’ to obtain G, G is colored with n colors.  Each face is bounded by three edges and each edge is in a boundary for two faces.  Suppose that G has a vertex of degree 3. Then, we find the configuration  '01 '02  113  Consider the map G’ obtained from G by removing vertex 12 and the three edges incident on 12. By assumption, G’ can be colored with four colors. Now 121, 122, and 123 require at most three colors. Color 12 with the fourth color. Now G is colored with four colors—a contradiction. 
CHAPTER 8 SOLUTIONS  147  30. If G has a vertex 12 of degree 4, we find the configuration  32.  121 122  124 123  Consider the graph G’ obtained from G by removing vertex 12 and the four edges incident on 12. By assumption, G’ can be colored with four colors. Show that if 121, 122, 123, and 124 use three or fewer colors, we get an immediate contradiction.  Suppose that 121, 122, 123, and 124 require four colors and that 12,- is colored C,-. Consider the subgraph G’1 of G’ consisting of all simple paths starting at 121 whose vertices are alternately colored C1 and C3. If G’1 does not include 123, we may change each C1 to C3 and each C3 to C1 in G’1 and produce a coloring of G’ with four colors. If this is done, we can then color G with four colors.  Suppose that G5 includes 123. Consider the subgraph G5 of G’ consisting of all simple paths starting at 122 whose vertices are alternately colored C2 and C4. Show that G5 cannot include 124. We may change each C2 to C4 and each C4 to C2 in G5 and produce a coloring of G’ with four colors. If this is done, we can then color G with four colors.  Deduce that G cannot have a vertex of degree 4.  Use the methods of Exercise 29-31.  Section 8.8  2.  R 1.3 R B 4 1 3 2 2 4 W nG W G 3 R 2 B R DB 2 4 3 4 1 3 W G W IG 
148 CHAPTER 8 SOLUTIONS  2 O G R B O 1 1 3 2 4 W 4 G W 3 G G1 G2 (0) R B R 2 B 1 2 4 3 1 4 W G W 3 G G3 G4  (d) Note that G; and Gj have edges in common for 1 = 1, j = 3; 1 = 1, j: 4; 1 = 3, j: 4; 1': 2, j: 3; and 1' 2 2, j : 4. Thus the only solution is G1, G2.  9. We cannot select the edge incident on R and B for, if we do, there is no way to make the degree of R : 2. Similarly, we cannot select the edge incident on B and G for, if we do, there is no way to make the degree of B = 2. Since we must have an edge labeled 4, we must select the 
CHAPTER 8 SOLUTIONS 149  loop incident on W. This means we cannot select any of the edges incident on W and G. Now, G cannot have degree 2. Thus, no subgraph satisfies (8.8.1) and (8.8.2).  11. There are six choices for the top and, having chosen the top, there are four choices for the front for a total of 6 - 4 : 24 choices.  12. By Exercise 11, there are 24 orientations of one cube. Thus there are 244 = 331,776 stackings.  1 1 v4 4 4 H1 H2  14. Let  '01  be subgraphs of the graph representing the four cubes in the puzzle such that the intersection of the edge sets and the intersection of the vertex sets are empty.  We can use H1 to construct front and back sides of the stack with the front having color 121 and back having color 122. This is possible since the edges incident on 121 and 122 contain all the labels 1, 2, 3, and 4. Similarly, H2 can be used to construct the left and right sides of the stack with the left color 123 and the right color 124.  Any solution is of this form, for if a solution exists, let 121, 122, 123, and 124 be the colors of the front, back, left, and right faces of the solution stack. Then 121 and 122 appear on opposite faces of all four cubes, and 123 and 124 appear on the other opposite faces of all four cubes. Thus H1 and H2 exist in the graph, as shown previously, representing the solution stack.  4 4 R G W 1 1 H  H1 2 17.  R B : 1.2 W G  18. There is no solution.  16.  20. Let H1 and H2 be a solution to the modified version as in, for example, the solution to Exercise 16. We construct subgraphs G1 and G2 as follows. We let the vertex set of G1 be {R, B, G, W}. 
150 CHAPTER 8 SOLUTIONS  We let the edge set of G1 be the set of edges labeled 1, 2 from H1 and the edges labeled 3, 4 from H2. We let the vertex set of G2 be {R, B, G, W}. We let the edge set of G2 be the set of edges labeled 3, 4 from H1 and the edges labeled 1, 2 from H2.  21. Yes. See the graph of Exercise 9. 
Chapter 9  Solutions to Selected Exercises  Section 9.1  2. This graph is a not tree because, if v is the upper-left vertex and w is the bottom, middle vertex, there are two simple paths from v to w.  3. This graph is a not tree because, if v is the left, middle vertex and w is the left, bottom vertex, there is no simple path from v to w.  5. If either m or n, or both, equals 1 6. n = 1,2 9. 4 10. 5  12' Hospital ABC Dr. A Dr. B Dr. Z a m b n z k Patients 15. LAP 16. DEAL 19. 010000001111 20. 0111000100111100010  22. Overhead in decoding, memory addressing capability, compatibility with other systems, amount of memory available  23. See G. Williams and R. Meyer, “The Panasonic and Quasar hand-held computers: beginning a new generation of consumer computers,” BYTE, 6 (January 1981), 3445.  151 
152  29  30.  31.  33.  34. 36.  37.  39.  CHAPTER 9 SOLUTIONS  The proposed code is ambiguous. For example, 01 could represent EA or C’. A terminal vertex has degree 1.  Since K33 and K5 contain cycles, a tree cannot contain a subgraph homeomorphic to either; thus, a tree is planar.  Consider the tree to be rooted. Color the vertices on even levels one color and those on odd levels another color.  a—5, b—4, c—5, d—4, e—3, f~4, g—3, h—4, 1P4, 37-5  In this solution, we call a simple path in a tree from the root to a terminal vertex a drop. Also, we let ecc(v) denote the eccentricity of the vertex 1).  Let c be a center of a tree T. Root T at c. Notice that if ecc(c) : L, the height of T is L.  We first show that no vertex on level 2 or greater can be a center. For suppose that there is a center c’ on level two or greater. Then ecc(d) : L. A simple path starting at c’ of length L must pass through c. But now any simple path starting at the parent of c’ has length at most L — 1. This contradicts the definition of “center.”  Notice that no vertex different from c on a drop whose length is less than L can be a center. Thus the only possible centers besides c are the children of c which lie on drops of length L. It is easy to see that if c has at least two children each lying on a drop of length L, then c is the unique center. If c has a unique child c’ lying on a drop of length L, c and c’ are the only centers.  In the solution to Exercise 36, we showed that all centers are on level 0 or level 1. Therefore the centers are adjacent.  In the following tree, (a, b) and (a, b, a, b) are distinct paths from a to b.  o-———o  a b  Section 9.2  2.  3.  Aphrodite, Uranus  Aphrodite, Kronos, Atlas, Prometheus 
CHAPTER 9 SOLUTIONS  5.  6.  8. 9. 11. 12.  14.  20.  23.  24.  26.  28. 29.  31.  32.  34.  153  Zeus, Poseidon, Hades  I Aphroditc Eros  Ancestors of c: b, a. Ancestors of j: e,c, b, a. Children of d: h, z’. Child of e: j. Siblings of f: e,g. Sibling of h: 1'.  Terminal vertices: j, f, g, h,’i 15. I C j One is the ancestor of the other.  Li I  No such graph exists. A terminal vertex has degree 1.  18. They are siblings. 19. It is the root.  b,o  21. It is a terminal vertex.  In this case, if the edge is (12,11)), we would have the cycle (12, w, v).  The graph is not a tree since, according to Definition 9.1.1, a tree is a simple graph satisfying: If v and w are vertices, there is a unique simple path from 12 to w.  n—m  No. Consider the paths (a, c, d, b) and (a, e,d, c, f, b) in the graph a c d b  6 f First, suppose that T is a tree. By Theorem 9.2.3b, T is connected. Suppose that for some vertex pair v,w, when edge (v,w) is added, at least two cycles are created. Then there must be at least two distinct simple paths from ’U to U) to account for the distinct cycles. But this contradicts the definition of a tree.  Now suppose that T is connected and when an edge is added between any two vertices, exactly one cycle is created. It follows that if ’U and w are vertices in T, there is a unique simple path from v to 11). For if there were no simple path from v to w, inserting an edge between 1) and w 
154 CHAPTER 9 SOLUTIONS  would not create a cycle. If there were two or more simple paths between 1) and U), inserting an edge between 12 and 11) would create two or more cycles. Thus T is a tree by the definition of tree.  35. Let 1) be a vertex of degree at least 2 in a tree G and let P = (120, . . . , 12”) be a simple path of maximum length passing through 1). Since G is a tree, P is not a cycle and, since 12 has degree at least 2, ’U 7E 120 and ’U yé on. If removing v and all edges incident on 12 leaves a connected graph, then there is a simple path, distinct from P, from U0 to 12”. Since G is a tree, this is impossible. Therefore ’U is an articulation point.  Section 9.3  2. 3. 5.  21 N  8. The cycle (a, b, c, d,e,f,g, h,z',j, k,l)  12. False. Consider K4. A breadth-first search spanning tree will produce a tree whose root has degree 3. Thus it cannot produce the tree (a, b, c, d).  14. If T is a tree, every vertex ordering with the same initial vertex produces the same spanning tree, namely T itself. 
CHAPTER 9 SOLUTIONS  15.  17.  18. 20.  21. 24.  25.  155 If T is a tree, every vertex ordering with the same initial vertex produces the same spanning tree, namely T itself.  First show that the graph T constructed is a tree. Now use induction on the number of iterations of the loop to show that T contains all of the vertices of G.  If the edge is not contained in a cycle of G  Input: A connected graph G with vertices ordered U1, . . . , v,,; and d Output: d(v,-) = length of a shortest path from 121 to 12,- short_paths(V, E, d) { S 2 (U1) V’ : set consisting of U1 E’ = (D d(’U1) 1‘ 0  while (true) { for each an E S, in order for each y E V — V’, in order if ((:::,y) is an edge) { add edge (:12, y) to E’ and y to V’ d(y) = d(a:) + 1  if (no edges were added) return T S = children of S ordered consistently with the original vertex ordering  } }  Both algorithms find simple paths from v in increasing order of length.  The fundamental cycle matrix relative to the orderings (a, b, a), (b, d, c, b), (b, c, f, b), (d, e, c, d), (c, f,e,c), (c, e,g,d, c), (c, f,g,d, c) and e2, e3, e5, e12, e13, em, en, e1, e4, e5, e7, eg, 69 is  1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1  The fundamental cycle matrix relative to the orderings (a, b, d, e,a), (a,b,d,e,a)’, (b, c, d, b), (d,e, f, d), and e3, e4, e2, e9, e1, e5, e5, e7, egg is  1 0 0  CJHOCJ OO>—»r-—- c)>—»»—A+—A CJHOCJ >—»o»—A>—» HOOD  0 0 1  ©©©  1 0 0 
156 CHAPTER 9 SOLUTIONS  27. Modify Algorithm 9.3.7 as follows. Change the line return T to  if (lV’| == n) return true else return false  If the graph is connected, the value true is returned; otherwise, the value false is returned.  28. Modify Algorithm 9.3.10 as follows. Change the line return true to print solution  Delete the line return false.  Section 9.4  2. 3. 5.  W  Li  7  6. Suppose that the start vertex is 1, and that the vertices are added in the order 1,2, . . .,n. When 2' is 1 and j is 1, the innermost line (line 11) of the nested for loops is executed n times. When 1' is 2, the innermost line of the nested for loops is executed n times for each of the values j : 1, 2. When 1' is 3, the innermost line of the nested for loops is executed n times for each of the values j : 1, 2, 3; and so on. Thus line 11 is executed  n(n — 1)  n+2n+3n+---+(n—1)n=n[1+2+3+---+(n—1)]= 2 n:®(n3)  times. No input requires more than ®(n3) time since the nested for loops take at most O(n3) time to execute. Therefore the worst-case time is @(n3).  8. The body of the last for loop executes n — 1 times the first time, n — 2 times the second time, and so on. This time dominates, so the worst-case time is  (n—1)+(n—2)+---1=@—§E:@(n2).  9. The argument is similar to the proof of Theorem 9.4.5.  11. Yes 
CHAPTER 9 SOLUTIONS  12.  15.  17.  18. 21.  22. 24.  25.  26. 28.  157  Suppose that the weight of each edge in K” is equal to 2. Suppose that some algorithm does not examine edge e. Let T denote the minimal spanning tree output by the algorithm. If e is in T, alter the input by changing the weight of e to 3. If e is not in T, alter the input by changing the weight of e to 1. Rerun the algorithm. Notice that since the algorithm does not examine e, it will still output T. However, for the modified input, T is not a minimal spanning tree. This is a contradiction. Therefore every minimal spanning tree algorithm examines every edge in K”.  True  The proof is similar to the proof of Theorem 9.4.5. Let G, be the graph produced at the ith iteration. Use induction to show that G, contains a minimal spanning tree.  Change oo in line 6 to -00. Change < to > in line 10.  (For Exercise 1) If we break ties by picking the smallest vertices, Kruskal’s Algorithm picks, successively, (2,3), (3,5), (3,4), (1,2).  Argue as in the proof of Theorem 9.4.5.  The algorithm picks one 10—cent stamp and six 1-cent stamps to make 16 cents postage, but two 8-cent stamps is optimal.  We use induction on n to show that the greedy solution and any optimal solution to the n—cent problem are identical. The statement is clearly true for n : 1, 2, 3, 4, 5, 25.  Suppose that 5 < n < 25. Let S be an optimal solution to the n-cent problem. We must use a 5-cent stamp; for otherwise, we could replace five 1-cent stamps with one 5-cent stamp. Now S with a 5-cent stamp removed is an optimal solution to the (n — 5)-cent problem; for otherwise, an optimal solution to the (n — 5)-cent problem together with a 5-cent stamp would be smaller than S. By the inductive assumption, S, with a 5-cent stamp removed, is the greedy solution. Therefore S is the greedy solution.  Suppose that n > 25. Let S be an optimal solution to the n-cent problem. We must use a 25-cent stamp since we can make at most 24 cents postage optimally using only 5-cent and 1-cent stamps. Now S with a 25-cent stamp removed is an optimal solution to the (n -25)-cent problem. By the inductive assumption, it is the greedy solution. Therefore S is the greedy solution.  a1 : 11, a2 2 5. For n : 15, the greedy method gives 11, 1, 1, 1, 1, but 5, 5, 5 is better. The set {1, 5,11} shows that the condition is not sufficient. For n = 15, the greedy algorithm gives one 11-cent stamp and four 1-cent stamps, but three 5-cent stamps is optimal.  The set { 1, 5, 10, 20, 25,40} shows that the condition is not necessary. (The example is due to Stephen B. Maurer, Amer. Math. Mo., 101 (5), 419.) The greedy algorithm is optimal for these denominations; however, the condition fails for 1' : 5: 25 2 2 - 20 — 10 is false.  We can use induction to prove that the greedy algorithm is optimal for the set {1, 5, 10, 20, 25, 40}.  We verify directly the cases 1 3 n 3 214. Now suppose that n > 214. Let S be an optimal solution for n. We claim that S contains a 40-cent stamp. If not, S contains at most four 1—cent stamps (since five 1—cent stamps could be replaced by one 5-cent stamp). For the same reason, 
158 CHAPTER 9 SOLUTIONS  S contains at most one 5~cent stamp, at most one 10-cent stamp, at most one 20-cent stamp, and at most seven 25-cent stamps. But now S can make at most  4-1+1-5+1-10+1-20+7-252214  cents postage. This contradiction shows that S contains a 40-cent stamp.  Now let G” be the greedy solution for n—cents postage, and let S’ be S with one 40-cent stamp removed. Then S’ is optimal for (n — 40)-cents postage. By the inductive assumption, lG,,_4ol : IS’). Therefore  lGnl = 1 + lGn—4ol = 1 +15’! = ISL and the greedy solution is optimal for n-cents postage.  30. Let a1 = 1, a2 = 5, and a3 = 6. The greedy algorithm is optimal for n = 1, . . . ,9, but not optimal for n : 10.  Section 9.5  2. Input: root, the root of an n—vertex binary search tree; key, a value to find; and n Output: The vertex containing key, or null if key is not in the tree  bst-search(root,n, key) { ptr : mot while (ptr -1 = null) if (ptr contains key) return ptr else if (ptr contains a value greater than key) ptr : left child of ptr else ptr : rigt child of ptr return null  3. Input: s1,...,sn;n Output: A binary search tree T of minimum height that stores the input  optz'mal_bst(s,n) { sort s1,...,s,, return o_bst(s,1,n)  } 
CHAPTER 9 SOLUTIONS 159  o_bst(s,z',j) { if (1 > 3') return null m = W + J’)/2] T’ : optz'mal_bst(s,2',m — 1) T” = optz'mal_bst(s,m + 1,j) let T be the tree whose root contains sm let the left subtree of T be T’ let the right subtree of T be T” return T  }  6. There is no such graph. The existence of such a graph would contradict Theorem 9.5.6.  7.  9. Input: An integer n > 1 Output: A full binary tree T with n terminal vertices  full_b2'nary_tree(n) { T = a rooted tree with one vertex  forz':1ton—1{ let 1) be a terminal vertex give ’U two children  }  return T  }  10. Input: A word 11) to insert in a binary search tree T Output: The updated binary search tree T  bst_recurs(w, T) if (T 2: null) { let T be the tree with one vertex, root store 11) in root return T } s : word in T’s root if (11) < .9) if (T has no left child) give T a left child and store 11) in it 
1 60 CHAPTER 9 SOL UTIONS  else { left = left child of T bst-recurs(w, left) } else if (T has no right child) give T a right child and store 11; in it else { right : right child of T bst_recurs(w, right)  }  return T  12. Input: The root root of a nonempty binary tree in which data are stored Output: true, if the binary tree is a binary search tree; false, if the binary tree is not a binary search tree. If the binary tree is a binary search tree, the algorithm sets small to the smallest value in the tree and large to the largest value in the tree.  ls_bst(root, small, large) { if (root has no children) { small : value of root large = value of root return true } lchlld :: left child of root rvchlld 2 right child of root if (ls_bst(lchlld, small_left, large_left) /\ ls_bst(rchlld, small-rz'ght, large_rz'ght)) { val : value of root if (large_left > val V small_rz'ght < val) return false small : small_left large : large_rz'ght return true } else return false  13. We prove the result using induction on n.  Basis Step (n = 1). In this case, the tree consists of three vertices—the root and its two children. ThusI:0, E=2,andE=2=0+2-1=I+2n. 
CHAPTER 9 SOLUTIONS  15.  19.  20.  22.  161  Inductive Step. Assume that the equation is true for n. Let T be a tree with n + 1 internal vertices. Let T’ be the tree obtained from T by deleting two sibling terminal vertices and the edges incident on them. Let p denote the (former) parent of the deleted siblings. The resulting tree T’ has n internal vertices. Let I’ and E’ denote the internal and external path lengths for T’. By the inductive assumption, E’ : I’ + 2n.  If len denotes the length of the simple path from the root to p in T, the external path length in T is obtained from the external path length in T’ by adding 2(len + 1), to account for the two new paths to the children of p, and by subtracting len, to account for the loss of the path to the former terminal p; thus,  E=E’+2(len+1)—len:I’+2n+len+2.  The internal path length in T’ is obtained from the internal path length in T by subtracting len to account for the loss of the path to p; thus,  E:I’+2n+len+2=I—len+2n+len+2=I+2(n+1).  Balanced 16. Not balanced  If the balanced trees of heights h — 1 and h — 2 with the minimum number of vertices are found, the required tree of height h can be formed by attaching these two trees as right and left subtrees of a new root. Thus Nh : Nh_1 + Nh—2 + 1.  Let Sh = N}, -I’ 1. Then 8h=Nh+1=1+Nh—1+Nh—2+1 =5h—1+5h—2a  by Exercise 19. Now so 2 N0 + 1 : 2, 51 = N1 + 1 = 3 (Exercise 18). Thus {sh} satisfies the same recurrence relation as the Fibonacci sequence. Since so 2 f3 and 51 = f4, it follows that 5;, : fh+3, h 2 0. Therefore Nh : sh — 1 : fh+3 — 1.  We prove that n < 2"“ using induction on n. Taking lg of both sides gives the desired result. We omit the Basis Step (n = 1).  Assume that the result is true for binary trees with less than n vertices. Let T be an n-vertex binary tree. Let nL be the number of vertices in T’s left subtree, and let mg be the number of vertices in T’s right subtree. Let h; be the height of T’s left subtree, and let hg be the height of T’s right subtree. Note that 1 + hL S h and 1 + hg 3 h. By the inductive assumption, nL < 2"L+1 and ma < 2"R+1. Now  n=1+nL+nR<1+2"L+1+2"R+1g1+2"+2"=1+2-2"=1+2"+1.  Section 9.6  2.  Preorder: ABCDEF Inorder: CBEFDA Postorder: CFEDBA 
162  3.  12.  13.  ABHIKLMJCDEFG ILKMHJBADFEGC LMKIJHBFGEDCA  Preorder: Inorder: Postorder:  Preorder: Inorder: Postorder:  ABCDEFG DCBAEFG DCBGFEA  Prefix: /*—ACD+A—BD Postfix; AC—D*ABD—+/  /\ “/ \D A/ \_ /E [E  Prefix: —+*AB*CD—/AB+DE Postfix: AB*CD*+AB/DE+- -  /‘\ /\ //\+ /X/X/X/X  Prefix: ++—*AB/CDE/— — —ABC*DD++ABC Postfix: AB*CD/—E+AB—C—DD*—AB+C+/+  /*\E / \  */ \/ /E/E /E A /\  A B Prefix: —A+BC Usual Infix: A—(B+C) Parened Infix: (A—(B+C)) /\ [E Prefix: —/A*B+CDE Usual Infix: A/(B*(C+D))—E  Parened Infix: ((A/(B*(C+D)))—E)  CHAPTER 9 SOLUTIONS 
CHAPTER 9 SOLUTIONS 163  15. Prefix: *—+AB—*C'D/EFA Usual Infix: (A+B—(C*D—E/F))*A Parened Infix; (((A+B)—((C*D)—(E/F)))*A)  17. 0 18. -16 20. 16 21. —-6  Because of the preorder listing, A is the root. If A had a left child, the inorder listing would not begin with A. Since A has no left child, the preorder listing tells us that the right child of A is B. The argument that the tree is correct continues in this way.  24. Input: pr, the preorder list, and in, the inorder list Output: mot, the root of the binary tree with the given preorder and inorder lists  make_tree(pr, in) { if (W! == 0) return null ch = first character in pr Create a vertex 1) store ch in v mot = 12 
164 CHAPTER 9 SOLUTIONS  choose strings st] and st? such that in 2 st] + ch + st2 // + is concatenation let pr’ be the substring of pr obtained by omitting eh choose strings st1’ and st2’ such that pr’ 2 st] + st2’, where st1’ (respectively, st2’) is a permutation of st] (respectively, st2) left subtree of root 2 malce_tree(st1’, st] ) right subtree of root 2 malce_tree(st2’, st2) return root  }  26. Not necessarily. Consider P1 2 ABCDEF and P2 2 DBCAEF.  27. Input: pt, the root of a binary tree Output: contents of the terminal vertices from left to right  prlnt_termtnals(pt) { if (pt 22 null) return if (pt is a terminal) { print contents of pt return } left 2 left child of pt prz'nt_terminals(left) right 2 right child of pt prz'nt_term2'nals(m'ght)  29. Input: pt, the root of a binary tree Output: initialize each vertex to the number of its descendants  deseendants(pt) { , if (pt 22 null) return numb_dese 2 0 left 2 left child of pt if (left -12 null) { deseendants(left) numb-dese 2 1 + contents(left) } right 2 right child of pt if (right -12 null) { deseendants(m'ght) numb_desc 2 numb_desc + 1 + contents(m'ght)  }  contents(pt) 2 numb_desc 
CHAPTER 9 SOLUTIONS 165  31. Input: pt, the root of a binary tree that represents an expression Output: the fully parenthesized infix form of the expression  prlnt_e:z:press2'on(pt) if (pt :2 null) return if (pt is a terminal) { prlnt(contents(pt)) return } W'nt(“(”) left = left child of pt prlnt-ea:presslon(left) prlnt(contents(pt)) right : right child of pt prz'nt_ea:press2'on(rz'ght) print(‘‘)’’)  32. Input: pt, the root of a Huffman coding tree, and a string a Output: The characters and their codes. Each code is prefixed by a. To print just the codes, invoke this procedure with a set to the null string.  hufi"man(pt, a) if (pt is a terminal) { prz'nt(character stored in pt) prlnt(a) return } left 2 left child of pt hufi"man(left, oz + 1) // + is concatenation right 2 right child of pt hufl"man(m'ght, 04 + 0) }  34. First, note that any subset of n — 1 vertices is a vertex cover. Second, note that any subset V’ of n — 2 edges is not a vertex cover. [If v and w are distinct vertices not in V’, then edge (1), w) violates the condition that either 1) or w is in V’ .]  35. No. Exercise 34 shows that even if all edges are present, n — 1 vertices suffice for a cover.  37. Let E’ be an edge disjoint set for G, and let V’ be a vertex cover of G. We define a function f from E’ to V’ in the following way: Let e = (v,w) E E’. Then either 1) or w is in V’ . Choose one of v or 11) that is in V’ , but not both, and let f (e) denote the chosen vertex. The function f is one-to-one because the set E’ is an edge disjoint set. Therefore |E’| 3 [W]. 
166 CHAPTER 9 SOLUTIONS  38. The graph  A.  has the desired property since it is impossible to put more than one edge in an edge disjoint set and a single vertex is not a vertex cover.  Section 9.7  2. A tree of height one has at most three terminal nodes. Since four outcomes are possible, the decision tree must have height at least two. Thus at least two weighings are required to solve the problem of Exercise 1.  3. In the following figure, if the coins in the left pan weigh less than the coins in the right pan, we go to the left child. If the coins in the left pan weigh more than the coins in the right pan, we go to the right child. If the coins in the left pan weigh the same as the coins in the right pan, we go to the middle child.  clcgca - c4c5c.,  c1c., : C205 C7 C1 c104 : CQC5 c1:c-, C3:C7 c,,:c-, C"*L c8:c, 07!” C4-C7 c3:c7 c1.c7 01.14 05.11 C3.L Ca.” C2,L C4,” C'8.L C8,” C'4.L 02.11 C82L C3,” 05,14 01,11  5. If we weigh four coins against four coins and they balance, the problem does not reduce to the problem of finding the bad coin from among four coins, but rather to the problem of finding the bad coin from among four coins and eight good coins. This latter problem can be solved in at most two weighings.  6. Four weighings are required in the worst case. We prove this result by considering several cases.  Suppose that we begin by weighing four coins against four coins. If they balance, in two additional weighings, we can account for at most nine outcomes. Since ten outcomes are possible with five coins, we cannot identify the bad coin in at most three weighings in this case.  Similarly, if we begin by weighing three coins against three coins, two coins against two coins, or one coin against one coin, at least four weighings are required in the worst case.  Suppose that we begin by weighing five coins against five coins. Consider one of the instances in which they do not balance: ‘ 
CHAPTER 9 SOLUTIONS  11.  167  0102030405 ' 06070809010  \  In two more weighings, we can account for at most nine outcomes, but there are ten C1,L, C2,L, C3,L, C4,L, C5,L, C5,H, C7,H, C3,H, C9,H, C10,H.  Therefore, if we begin by weighing five coins against five coins, at least four weighings are required in the worst case.  Similarly, if we begin by weighing six coins against six coins, at least four weighings are required in the worst case.  We conclude that the 13-coins puzzle requires at least four weighings in the worst case. In fact, the puzzle can be solved in at most four weighings: Begin by weighing four coins against four coins. If they do not balance, proceed as in the solution to the 12-coins puzzle (see Exercise 4). If they balance, five coins remain. We can identify a bad coin among five in at most three weighings (see Example 9.7.1).  If there is an algorithm that solves the puzzle in k < n weighings, the algorithm can be described by a decision tree of height I9. Every internal vertex of this tree has at most three children; thus, there can be at most 3'“ terminal vertices. But there are 2((3” — 3) / 2) = 3" — 3 possible outcomes and 3” — 3 > 3'“ for n 2 2, k < n, which is a contradiction.  Input: Output:  01, G2, G3, 04 a1, a2, a3, a4 (in increasing order)  8071-4(a1,a2,a3.G4) // sort a1 and a2 if (a1 > a2) swap(a1, a2) // sort a3 and a4 if (a3 > a4) swap(a3, a4) // find largest if (a2 > a4) swap(a2, a4) // find smallest if (a1 > a3) swap(a1, a3) // sort G2 and a3 if (a2 > a3) swap(a2, a3) }  There are 6! = 720 possible outcomes to the problem of sorting six items. To accommodate 720 vertices, we must have a tree of height at least 10 since 29 < 720 < 210. Thus we need 10 comparisons in the worst case. 
168  13.  14.  CHAPTER 9 SOLUTIONS  To sort six items using at most 10 comparisons, we first sort five items using at optimal sort (see Exercise 10). This requires at most seven comparisons. We then find the correct position for the sixth item using binary search. This last step requires at most three comparisons.  ./“\.. ./”\ xx /1 xx /x ../\1\../\.../\. ../\.1\../\../\.  2’°—1 16. is  Section 9.8  2. 3.  11.  12.  14.  15.  Not isomorphic. Tree T2 has a vertex of degree 4 (1124), but T1 has no vertex of degree 4.  1S0m0I‘phiC- f(v1) = M3, f(v2) = U251 f(v3) = we. f(v4) = U22, f(v5) = M1, f(U6) : W4-  Not isomorphic. Vertex 1210 in T1 must be mapped to vertex 1124 in T2 since these are the only vertices of degree 4. The vertices adjacent to 1210 have degree 1, 1, 2, 3, while the vertices adjacent to 1124 have degree 1, 2, 3, 2.  Isomorphic. f(121) : 1127, f(122) : 1124, f(123) = 1125, f(124) = 11210, f(125) 2 1123, f(125) 2 U22, f(v7)=U)91 f(1)s) = U111, f(v9) =U)1, f(v10) = “)8: f(v11) :'U)5a f(v12) = 1012-  Not isomorphic as rooted trees. The root of T1 has degree 3, but the root of T1 has degree 1.  They are isomorphic as free trees (see the solution to Exercise 3). Isomorphic. f (12,-) : 112,-, 1' : 1,. . . ,5. Also, they are isomorphic as free trees.  Isomorphic. f(12,-) = 112,-, 1' 2 trees.  1, . . .,6. Also, they are isomorphic as rooted trees and as free  Not isomorphic. The root of T1 has no right child, but the root of T2 has a right child. They are not isomorphic as rooted trees, but they are isomorphic as free trees.  _L ._._.m_.m_.nJmmJ_n_l_L  +~>s 
CHAPTER 9 SOLUTIONS 17.  «AM  /\  km&%x KM ®@  KMVQ/k 
170  23.  24.  26.  CHAPTER 9 SOLUTIONS  “M lfib  For Exercise 9, there are 10 spanning trees obtained by replacing the left triangle by  and by replacing the leftmost figure by  l< it C T? 3  Let bk denote the number of comparisons when two k-vertex isomorphic binary trees are input to Algorithm 9.8.13. We use induction on Is to show that  bk = 6k+2. (9.1)  If k: = 0, the trees are empty. In this case, there are two comparisons at line 1 after which the procedure returns. Thus (9.1) is correct for Is : 0.  Assume that b,‘ Z 61' + 2  for 1' < Is. There are four comparisons at lines 1 and 3. Let L denote the number of vertices in the left subtree (of either tree) and R denote the number of vertices in the right subtree (of either tree). By the inductive assumption, line 9 requires bL+bR :(6L+2)+(6R+2) comparisons. Thus the total number of comparisons is 4+6L+2+6R+2:6(1+L+R) +2 :6k+2.  The inductive step is complete.  Input: n Output: an n-vertex random binary tree 
CHAPTER 9 SOLUTIONS 171  mnd_bt'n_tree(n) { if (n :2 0) return null let it be a random integer between 0 and n — 1 inclusive T1 = mnd_bz'n_tree(k) T2 : mnd_bz'n_tree(n — 1 — k) let T be the binary tree with left subtree T1 and right subtree T2 return T  27. The hint provides a one-to-one correspondence between n-edge ordered trees and strings of n zeros and n ones in which, reading from the left, the number of ones is always greater than or equal to the number of zeros. The number of such strings is C”, since these strings also encode paths in an n x n grid from the lower-left corner to the upper-right corner that never go above the diagonal from the lower-left corner to the upper-right corner (see Example 7.1.7). The encoding is obtained by interpreting a one as a move right and a zero as a move up.  Section 9.9  2. The second player always wins. If the first player leaves { 1, 3} or {0, 3}, leave one. If the first player leaves {2, 3}, leave {2, 2}. After the first player moves, the second player can leave one. Part of the tree is  3. The tree is the same as Figure 9.9.1. The terminal vertices are assigned values as in Figure 9.9.2 with 0 and 1 interchanged. After applying the minimax procedure, the root receives the value 1; thus the first player will always win. The optimal strategy is to first leave {2, 2}. If the second player leaves only one pile, take it; otherwise, leave {1,1}.  5. The tree is the same as in Exercise 1. The terminal vertices are assigned values as in the hint for Exercise 1 with 0 and 1 interchanged. After applying the minimax procedure, the root receives the value 1; thus the first player will always win. The optimal strategy is take 2. No matter how many player 2 chooses, player 1 can take the rest.  6. Figure 9.9.2 
17 2 CHAPTER 9 SOLUTIONS  8. The strategy for winning play is: Play nim’ exactly like nim unless the move would leave an odd number of singleton piles and no other pile. In this case, leave an even number of piles.  10.  11. The value of the root is 10. 13. The value of the root is 9. l6.4—-222 l7.l—120 20. No. Assign a larger value to a winning position.  21. Input: the root pt of a game tree, the level pt_level of pt, the maxi- mum level n to which the search is to be conducted, and an evaluation function E Output: the game tree with the values of the vertices stored in the vertices  mz'm'maa:(pt, pt-level, n, E) { if (pt_level 22 n) { contents(pt) 2 E(pt)  return } let cl, . . . , ck be the children of pt for 1' 2 1 to k {  m1Im'ma:1:(c,-,pt-level + 1, n, E) e,- 2 contents(c,-)  } if (pt is a box vertex) contents (pt) 2 max{e1, . . . , ek} else contents(pt) 2 min{e1, . . . , ek}  24. We first obtain the values 9, 6, 7 for the children of the root. Thus we order the children of the root 9, 7, 6 and use alpha-beta pruning to obtain 
CHAPTER 9 SOLUTIONS 173  El 1/ 0 6 O 1/ E! E I E I 1/ 1/ 1/  0 O 0 0 9 O 9 O 00 O O  EEEIEEIIIIEJEIIIII  29—30. It is possible to always force a draw in Mu Torere, see P. D. Straflin, Jr., “Position graphs for Pong Hau K’i and Mu Torere,” Math. Mag., 68 (1995), 382-386, and “Corrected figure for position graphs for Pong Hau K’i and Mu Torere,” Math. Mag., 69 (1996), 65. 
174 CHAPTER 10 SOLUTIONS 
Chapter 10  Solutions to Selected Exercises  Section 10.1 2. (a, d)—1, (b, d)—2, (e,c)—2, (e,z)—1. The value of the flow is 5. 3. (a, b)—3, (a,d)—1, (d, c)—0, (d,f)w1, (c, e)A1, (g,z)—2, (c, z)—2. The value of the flow is 6.  6. Make the capacities of (A, z), (B,z), and (C, 2), 4, 3, and 4, respectively.  8. 1000 4000  9. Replace each undirected edge by two directed edges each having weight equal to the weight of the undirected edge.  11. n2 — 3n + 3. To prove this, we sum the in and out degrees of the vertices and then divide by 2. The source has n — 1 out edges. The sink has n — 1 in edges. All other vertices have n — 2  175 
176 CHAPTER 10 SOLUTIONS  out edges (since an edge cannot go to itself or the source) and n — 2 in edges (since an edge cannot come from itself or the sink). Since there are n — 2 vertices besides the sink and source, the sum of the in and out degrees is  (n—1)+(n—1)+(n—2)[(n—2)+(n—2)]=2n2—6n+6.  We obtain n2 — 3n + 3 by dividing by 2.  Section 10.2  2. 2 3. 1 4000,4000 3000,2000 00,6000 yoo,0 00,4000 2000,2000 co. 6000 4000, 4000 cc. 6000 00,0 oo,4000 y 3000.2000 00,6000 00,0 2000,2000 4000,4000 ' :2 3,3 d 4,3 f 3,3 4,3 a 1,0 2 2,2 5,2 b 2,2 e ' 1.01 3,2 b 4,4 c 4,4 A 
CHAPTER 1 0 SOLUTIONS 177  101 3,2 5 4,4 c 44 A 22 32 8,0 44 42 20 d 55 d’ 53 B 33 a 2 W2 3,0 7,7 5,5 44.0 4,4 2,2 103 52 6 2,2 f 62 C  12' (av b)_102 (aa .f)—11v (aaj)“1a (bac)"6a (bag)"9a (fa b)—51 (f1g)§61 g)_1a (cad)_8a (ca h)_2v (gac)' 4: (ga h)‘12v (d1e)_8! (han)—6: ( 1m)A2a (man)—2a (e7z)—8> z)‘61 (naz)_8' other edges have flow equal to 0.  14. 8 15. 
178 CHAPTER 10 SOLUTIONS  18' (av w1)”37 (aw w2)_31 (aa 793)‘-3» (wla b)—37 (792: b)_31 (703: d)‘3v (bu A)—4v (bu c)_2a (da c)—3a (C: A)’ 2, (c,B)—3, (A,z)-6, (B,z)~3  Section 10.3  2. 9; not minimal 3. 15; not minimal 5. P = {a,w1, 102,103, b, d}  6. P : {a,A—6:00,B—6:15,A—6:15,B—6:30,A—6:30}  8. P:{a} 9. P.={a,b} 11. P:-{a}  P : {aw/wla/W23/w31b1c1d1eaf)A9BaC}  14. P = {a,A—7:00,C—7:15,A—7:15,C—7:30, A—7:30,C—7:45}  15. P : {a, b, d,e,g}  19. Use Exercise 18 and imitate the proofs of Theorems 10.3.7 and 10.3.9.  21. The argument is similar to that of Exercise 19.  22. Modify Algorithm 10.2.4. 
CHAPTER 10 SOLUTIONS  Section 10.4  2. A minimal cut is P : {a}.  4. Filling the maximum number of jobs  5. J1—C,J2—-A,J5—D  7. There is not a complete matching because there are fewer persons than jobs.  8.  179 
180  12.  14.  15.  16. 18.  19.  CHAPTER 10 SOLUTIONS  (b) The maximum number of committees that can be represented (c) All committees are represented. (e) Yes Let V = {v1, . . . ,v,,,} and W = {w1, . . . ,u),,} be the disjoint vertex sets. Order the vertices  ’U1,...,’Um,’U)1,...,’U)n.  Each row has exactly one label and each column has at most one label.  Among all labelings in which every column has at most one label, the maximum number of rows are labeled.  See A. Tucker, Applied (Jombinatorics, Wiley, New York, 1980, page 348.  See 0. L. Liu, Introduction to Combinatorial Mathematics, McGraw—Hill, New York, 1968.  False. Consider  Y  Problem-Solving Corner: Matching  1. 
Chapter 11  Solutions to Selected Exercises  Section 11.1  2. 51:1 51:2 a:_1 V 51:2 1 1 0 1 0 1 0 1 0 0 0 0 11 :5: 11 V 12 a 3. 9:1 9:2 9:3 (:01 /\ 332) V 933 1 1 1 1 1 1 0 1 1 0 1 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 1  181 
182 CHAPTER 1 1 SOL UTIONS  5. 9:1 9:2 3:3 1:4 V 11:2) /\ (T5 V 934)) /\ (932 V 1:4) 1 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 6. 3:1 3:2 9:3 51:4 ((581 /\ 51:2)/\(a:—3 V 184)) V (1131 /\ 9:2) 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0  8. If as : 0, the output of the AND gate is 0 regardless of the value of the other input. Thus the output of the NOT gate is 1. Therefore, y = 1.  9. Suppose that as : 1 and y = 0. Then the input to the AND gate is 1,0. Thus the output of the AND gate is 0. Since this is then NOTed, y : 1. Contradiction. Similarly, if as : 1 and y : 1,  we obtain a contradiction.  ll. 1 12. 1 14. 1 
CHAPTER 11 SOLUTIONS 183  15. (For Exercise 10) 9:1 and 332 are Boolean expressions by (11.1.2); 331 A932 is a Boolean expression by (11.1.3d); 9:1 /\ 3:2 is a Boolean expression by (11.1.3b).  17. Is a Boolean expression 18. Is a Boolean expression 20. Is a Boolean expression 21. The circuit for Exercise 10 is Exercise 1. The solution to Exercise 1 gives the logic table. 23. A B  26. A/\(Bv(C/\§)) 27. (A/\(BvC))vD  29. A/\((BvE)v(C/\(AvDvU)))/\B  31. A B C Av(B/\C) ,1 1 1 1 1 E} 1 1 0 1 §_/C 1 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 0 0 1 1 0 0 0 0 32. A B C (X/\B)v(C/\A) X_{ 1 1 1 1 j_. 1 1 0 0 C_/A 1 0 1 1 1 0 0 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 0 
1 84 CHAPTER 1 1 SOL UTI ON S  34.  A/\((B/\C/\fi)v((B/\C) D)v(§/x5/\D))/\(Bv5)  oc>oo>~r—«r—t>—‘ooc>o>—w—-o—A>—-to  OC>OOOOOOr—Ir—tv—tr—A>—ap—A>-ar—tfi; 00>-*r—‘OO>—*r—‘OO>-*r—*OOr—‘r—‘C) cg»-op—ao»—no»—acp>—»o+—-or—aOr—n@ c>oc><:<:oc>c>oo>~c>o>~»—»—A<  cqjfil} B _.4—4  Section 11.2  2.  3:1 9:2 (931 /\ 332) V 331 (931 V 2:2) /\ 3:1 1 1 1  CC?-‘>-‘ GI»-‘G  1 0 0  ©©P—‘  S D—‘ S to  (331 Va:_2) (:r:_1/\:t:3) a:_1/\ (332 V583)  0  ©r—4c>r—IO>—»O>—»§  V 0 0 0 0 1 1 1 0  OOOOr—‘>dr—‘r-' o©>—»r—4c>o>—»>—» O>-‘HP-‘CDOCJ  5. The Boolean expression for the second circuit can be transformed to the Boolean expression 
CHAPTER 1 1  10.  12. 13. 15. 19.  SOLUTIONS 185  for the first circuit  (:01 V :03) /\ (:02 V :03) /\ (:02 V 2:4) /\ (221 V :04) 2 (223 V (:01 /\ :02)) /\ (:04 V (:02 /\ :01)) : ($1 /\ $2) V ($3 /\ $4)  8. «'61 «'62 «'61 V («'61 /\ 562) :01 :02 :01 /\ 5 (:0—1 V :02) 1 1 1 1 1 0 0 1 0 1 1 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0  The left expression can be transformed into the right expression by successive applications of the distributive and commutative laws:  (:01 V :02) /\ (:03 V :04) 2 ((:01 V 1:2) /\ :03) V ((:01 V :02) /\ :04) (:01 /\ :03) V (:02 /\ :03) V (:01 /\ :04) V (:02 /\ :04)  ($3 /\ $1) V ($3 /\ $2) V ($4 /\ $1) V ($4 /\ IE2)  False. Take :01 2 1, :02 2 0. False. Take :01 2 :02 2 :03 2 1. False. Take :01 2 :03 2 1 and :02 2 :04 2 0.  (For Exercise 28, Section 11.1)  535%  22.  23  A —J—4  Section 11.3  3.  If (S, +, -,’ , 1, 8) is a Boolean algebra, then :0 + :0’ 2 1. In this case, we must have lcm(:0,8/:0) 2 8, for :0 2 1,2,4,8.  However, for :0 2 4, lcm(4,8/4) 2 lcm(4, 2) 2 4. Therefore, this system is not a Boolean algebra. 
186  10. 12. 13. 16.  17. 19.  20.  CHAPTER 11 SOLUTIONS  In this solution, we denote the 0 (respectively, 1) of a Boolean algebra by m (respectively, M). Every Boolean algebra has at least two elements since m and M are distinct. Thus n 2 2.  Suppose that n > 2 and that S” is a Boolean algebra. Then n 2 n - M 2 min{n, M}. Thus M 2 n. For any as E S”, we have M 2 as + as’ 2 max{a:,a:’}. It follows that if as 2 M, then as’ 2 M. Therefore, if as 2 M, :1? 2 (cc’)’ 2 M’. This says that M’ is not unique. Contradiction. If n 2 2, we may take m 2 1, M 2 2, 1’ 2 2, and 2’ 2 1, and show that S” is a Boolean algebra.  ) ) (c) XLJ(XnY) 2X, Xn(XLJY) 2X (d) 7 = X (e) E 2 U. U 2 (1) (1) my =Yn7, XnY27LJ7 (:v’y’)’ = so + 1/ If my 2 acz and a:’y 2 a:’z, then y 2 z. Ifccy21,thena:212y. as 2 1 if and only if y 2 (cc +3/)(a:’ +y) for ally. (For the dual of Exercise 8) a:y+a:0 2 a:y+0 by 11.3.6b 2 say by 11.3.1d a:(a: + my 2 (ma: + a:y)y by 11.3.10 2 (a:+a:y)y by 11.3.6a 2 y(a: + yat) by 11.3.1b 2 ya: + y(ya:) by 11.3.1c 2 ya:+ (yy)a: by 11.3.1a 2 ya: + ya: by 11.3.6a 2 ya: by 11.3.6a 2 say by 11.3.1b  If my 2 0 and as + y 2 1, then y 2 cc’. The dual of Theorem 11.3.4 is Theorem 11.3.4. (Forpart c) a:(a:+y)2(a:+0)(a:+y)2a:+0y2a:+y02a:+02ac  (For part d) We have  a:+a:' by 11.3.1b by 11.3.1e.  a:’+a: 2 = 1  Dually, a:’::: 2 0. By Theorem 11.3.4, (cc’)’ 2 cc. 
CHAPTER 1 1  22.  24.  SOLUTIONS 187  Since 11.3.1a—e hold for all sets, they hold for S. We need only note that (1) and U are present and that S is closed under taking unions, intersections, and complements.  First notice that the proof of the absorption laws [Theorem 11.3.6(c)] does not use the associative laws. Therefore, the absorption laws follow from the definition of Boolean algebra (Definition 11.3.1) without the associative laws.  Weshowthat a+(b+c) :(a+b)+c  by showing that each side of the preceding equation is equal to ((a + b) + c)(a + (b + c)). Throughout the proof we make implicit use of the commutative laws, and we use the equations  a(a+ (b+ c)) 2 a, a((a+b) +c) : a,  b(a+ (b+c)) = b, b((a+b) +c) = b,  c(a+(b+c) =c, C((a+b)+c) =c.  The first equation follows immediately from the absorption laws. To prove the second equation, we first use the distributive law and then the absorption laws to obtain  b(a+(b+c))=ba+b(b+c):ba+b=b.  The proof of the third equation is similar to the proof of the second equation, and the proofs of the last three equations are similar to the proofs of the first three equations.  We have  distributive law 4th equation distributive law 5th and 6th equations.  ((a+b)+c)a+((a+b)+c)(b+c) a+((a+b)+c)(b+c) a+(((a+b)+c)b+((a+b)+c)c) : a+(b+c)  ((a+b) +c)(a+ (b+c)) :  l I  I I  Also  distributive law 3rd equation distributive law 1st and 2nd equations.  ((a+b)+c)(a+(b+c)) = (a+b)(a+(b+c))+c(a+(b+c)) (a+b)(a+(b+c))+c (a(a+(b+c))+b(a+ (b+c)))+c  = (a+b)+c  I I  I I  Therefore, the associative law holds for +. By duality, the associative law holds for -. 
188  Section 11.4  In these hints, a /\ b is written ab.  2.,  12.  13.  . ccyzVa:y§Va:’y‘z VTy§VT’y‘z VT’y‘  a:’y’VT’y’  1 >  y 1  . ccyz V :1:y§V ccyiv Tyz VTQE  NI  . my? V xyz V my? V Tyz V Ty? V Tyz  . ccyiv Tyz Viyi Viyz  wccyz V wa:’y‘z V wig? V ‘ccyz V 'u7Tyz my V Ty  ccyz V ccyz V my? V my? V my?  15. "'-  16.  18. ‘-  19. 21.  24.  26.  27.  wccyz V wiyz V «may? V may? V wccyz V 'u7a:yz V Wccyz V 'u7Tyz V 'u7Tf]z V wig?  TL  22  E > 53>  CHAPTER 11  SOL UTIONS  Let f: Z5‘ —-> Z2. Let A1, . . . , ,A;c denote the elements A,- of Z5‘ for which f(A,-) : 0. For each  A,-=(a1,...,an), set m,-=y1V...Vyn where  Then f(.’Il31,...,.’,'l3,-L) :m1/\m2/\.../\m;c.  (For Exercise 13) (as V g V §)(a: V y V §)(a: V y V z)  Iff(a:1,...,a:n) = m1V...Vmk, then f(a:1,...,a:,,) :W1W2- - -’7n—k. Sinceeachmi : ylyg---yn, where each yj is either ccj or a:_,~, W = mvfiv . . . Vy_n. Thus f(a:1, . . . ,:::n) is expressed as the  conjunction of maxterms. 
CHAPTER 1 1  29.  SOLUTIONS 189  If j > k, then some term ml does not occur in the expansion m1 V . .. V mk. Choose 33,- E Z2 so that m; = 1. Show that mi 2 0 for 2' : 1,...,n. Conclude that j 3 k. Similarly, j 2 k. Therefore, 3’ = 19.  Give a similar argument to show that each m, is equal to some ml.  Section 11.5  9°.“:4>9°  10. 11.  16. 18. 19.  21.  A combinatorial circuit consisting only of OR gates would output 0 when all inputs are 0. A combinatorial circuit consisting only of NOT gates would have as many outputs as inputs. 661/=(9cTy)T(5vT1/) False. Take cc : 1 and y = z = 0. :91 = fl, 2/2 = T1 V7 ya = m—2:c3(:v—1vT§)a:1  9:1/\a:2 (:01/\a:2)VT§ ((:t:1/\ar:2)Vi:E;')/\a:1/\a:2/\TE3'/\:t:4 T5/\Cb‘4  91 = 92 = 93 = 94 I  See the solution to Exercise 15.  mu/=((:vTcv)T(yTy))T((wTrc)T(yTy))  331 $62 331 L932 1 0  ®®P—‘>—‘  0 0 1 0 0 1  (For Exercise 3) Write my V as? V T? : :1:(y V E) V my = T V y V E V as V y, which gives  “$0?  y—a-  $>£D*~  »:> 
190 CHAPTER 11 SOLUTIONS 24. See the solution to Exercise 23. 26. The standard multiplication algorithm gives {I32 {I31 92 91 $6291 $6191 $6292 $192 Z4 Z3 Z2 21 This computation can be performed by the following circuit 131 \ Z1 2111 l '} i Z2 12 Half Adder .92 Half Adder \ C 2:4 29. 00101 30. 100101010 32. The simplest approach is to simply rewrite each of the properties in 11.3.1 using the star  35.  operator. Notice that in some cases the dual properties can be given in one star expression. For example,  w*((y*z)*(y*z)) :((6v*y)*(0=*y))*z is sufficient to prove both associative laws.  J. G. P. Nicod in “A reduction in the number of primitive propositions of logic,” Proceedings of the Cambridge Philosophical Society, 19 (1916), 32-40, has shown that the following single axiom is suflicient to establish all of the properties of a Boolean algebra  (a*(b*c))*((d*(d*d))*((e*b)*((a*e)*(a*e)))) :1.  We use induction on the number n of occurrences of <—> in B(a:,y) to prove parts a and b simultaneously. For the Basis Step, suppose that there are 0 occurrences of <—> in B(cc,y). If B(:c,y) contains an even number of a:’s, then either B(a:,y) = 0, B(a:,y) : 1, or B(:c,y) : y. In all cases, B(T,y) = B(cc,y) for all as and g. If B(cc,y) contains an odd number of a:’s, then B(a:, y) : so. In this case, B(T, y) = B(cc,y) for all as and y. 
CHAPTER 11 SOLUTIONS 191  Now suppose that there are n occurrences of <—> in B(a:,y). Then B(a:,y) = (B1(a:,y) ¢—> B2(a:, y)), where each of B1(a:, y) and B2(a:, y) contains fewer than n occurrences of <—>.  Suppose first that B(a:, y) contains an even number of a:’s. If B1(a:, y) contains an even number of a:’s, so does B2(a:, y). By the inductive assumption,  B(T,11) = (B1(T,11) <-> B2(T,11)) = (B1(cv,11) <—> B2(w,11)) = B(:v,11)- If B1(a:, y) contains an odd number of a:’s, so does B2(a:, y). By the inductive assumption,  B(i,11) = (B1(T,11) <—> B2(E.11)) = (B1(rv,11) <-> B2(:v.11)) = (B1(w,11) <-> B2(w,11)) = B(6v,11)-  Now suppose that B(cc,y) contains an odd number of a:’s. Then one of B1(a:,y) or B2(a:,y) contains an odd number of a:’s. We may assume that B1(a:, y) contains an odd number of w’s. Then B2(a:, y) contains an even number of a:’s. By the inductive assumption,  B(T,11) = (B1(T,11) <-> B2(E,11)) = (B1(:c,11) <—> B2(w,11)) = B(w,11)-  The Inductive Step is complete, and parts a and b are proved.  Using parts a and b, we may show that there is no Boolean expression using only <—> that computes the function  cv11f(~'v.11) 11 0 10 1 01 0 00 0  For suppose that there is a Boolean function B(a:, y) using only the <—> operator with f (cc, y) : B(a:, g). If B(a:, y) contains an even number of cc’s, part a tells us that we must have B(0, 0) : B(1, 0), which is not the case. If B(:::, y) contains an odd number of a:’s, part b tells us that we must have B (0, 1) = B(1, 1), which is not the case. Therefore {<—>} is not functionally complete. 
192  CHAPTER 12 SOLUTIONS 
Chapter 12  Solutions to Selected Exercises  Section 12.1  193 
194 CHAPTER 12 SOLUTIONS  7. I = {a, b}; C’) : {0,1}, 5 = {A,B,C}; initial state = A  S\I a b a b A A B 0 1 B A C 0 1 C C A 1 0  8. I : {a, b}; O : {0, 1, 2}; S : {(70, 01,02}; initial state : ao  S\I a b 0'0 0'1 0'0 01 01 00 02 01 00  OIOOQ »—-»—atoc-  10. I = {a, b, C}; C’) = {0, 1,2}; 5 = {A,B,C, D}; initial state = B  S\I a b c a b c A B A C 1 0 2 B A D D 2 0 0 C A C D 0 1 2 D D C A 2 2 0 12. 0100 13. 0101100 15. 121121 16. 011 18. 20210  19. 010000000001  22. 
CHAPTER 12 SOLUTIONS 195  23.  25.  26.  29. Suppose that such a finite-state machine M exists and has m states. Let X and Y each be 1 followed by m + 2 0’s. Then the sequence  00,00,...,00,00,00,...,00  g  m‘4:2 m‘—'}—3 is input to M. The product of X and Y is 1 followed by 2m + 4 0’s. The output is  0,0,...,0,1,0. my \ 2m+4  After 11 is input, a sequence of m + 1 00’s is input and the output is 0 each time. Since there are only m states, we must return to a state that we previously visited. That is, the path in the transition diagram contains a cycle. Since the input is constant (00), we must remain on this cycle. Therefore, we continue outputting 0’s and we never output 1. 
196 CHAPTER 12 SOLUTIONS Section 12.2  2. All incoming edges to 00 output 0, all incoming edges to 01 output 1, and all incoming edges to 02 output 0; hence, the finite-state machine is a finite-state automaton.  1 b/O  ‘*9 9 
CHAPTER 12 SOLUTIONS  11.  12.  14.  19.  22.  197  1,7,9  The following must hold for all states 0: All entries in the output table corresponding to occurrences of a in the next-state table must be identical.  Not accepted 15. Accepted 17. Accepted  If a string a, which ends bb is input, no matter which state we are in prior to bb, we will end at state 02, as can be seen by checking the three possibilities. Since 02 is accepting, a is accepted.  Suppose that 0! is accepted by Figure 12.2.5. We end in state 02. Thus the last character in a is b. There is at least one character before b. If the last two characters are ab and we are in state a just before the a, by checking the three possibilities for 0, we can show that we will not end in 02. Therefore, the last two characters are bb. 
198 CHAPTER 12 SOLUTIONS  Two or more a's  23_ 25. 
CHAPTER 12 SOLUTIONS  33.  34.  199  If a string consisting only of b’s is input to either finite-state automaton, it is accepted. If a string contains an a, in either finite-state automaton we move to a nonaccepting state. In neither finite-state automaton is there an edge from a nonaccepting state to an accepting state. Thus once an a is encountered, both finite-state automata reject the string. Therefore, the set of strings accepted by each finite-state automaton is the same—name1y, the set of strings over {a, b} that do not contain an a.  If L is empty, the finite-state automaton  -CE?  accepts L. If L consists of the null string, the finite-state automaton  G G o-..  accepts L.  If L consists of one nonnull string 331932 . . .a:;,, the finite-state automaton  where . _ CL if .737; = b g1 — b if :13,‘ : a accepts L. If L : {s1, . . . , 5”}, we have shown how to construct finite-state automata that accept L, : {s,-}, i = 1,... ,n. Exercise 37 shows how to construct a finite-state automaton that accepts  L=L1UL2U...UL,,.  36. The argument is similar to that given in Exercise 37.  37. Suppose that 331 . . .33” 6 L1. Then there exist states 510, . . .  ,s1,, satisfying  810 Z 01; f1(S1,,'_.1,$l31') Z 811' for ‘i 2 1, . . . ,n; 81" 6 A1. 
200  39.  CHAPTER 12 SOLUTIONS Define 820 = 02; 821' = f2(S2,,'_1,£I3,') for ‘i : 1,. . . ,n; S,‘ # (31,-, 82,‘) fOI‘ ‘i = 0, . . . ,’/7,. Now so = 0; f(5i—1a5’7i) : (51ia52i) f01” 1 = 1» - - ‘an; 511 : (51na 5211) E  Thus L1 Q Ac(A). Similarly, L2 Q Ac(A). Therefore, L1 U L2 Q A similar kind of argument may be used to show that Ac(A) Q L1 U L2. Use Exercises 36 and 37.  Section 12.3  11.  13.  14.  16. 17. 19.  $°.°°.‘”!°  None 3. Context-sensitive  5. Regular, context-free, context-sensitive None 0 => AB => aAB => aABb => aBAb => abAb => abab 0 => AAB => AaaB => ABaaB => ABaab => ABBaab => aaBBaab => aabBaab => aabbaab  <S>¢a<A>=>ab<B>=>aba<S>=>abaa<A>=>abaab<B> =>abaabb<A > =>abaabba < S > =>abaabbab< S > =>abaabbabb< S > =>abaabbabba  The productions a —-> ba, A —-> bA, and 0 —-> b generate any number of b’s. If these are omitted, the only derivations possible are  a => aA => aaa => => (aa)”a => (aa)”aA => (aa)”+1.  An accepted string is of the form :1;1:1;2...a:,,, where 331 : b*a and cc2,...,a:,, are any of ab*a, (bb)*, or bab*a.  S—+aS, S—->bS, S—>bA, A->a S—~>aS, S—>bA, A—>bA, A—>aB, B—->aB, B—->bB, B—>a, B——>b,A—>a  <digit> 0|1|2|3|4l5]6l7l8]9 <nonzero digit> : 1l2l3|4|5|6]7]8|9 <integer> : <signed integer> I <unsigned integer>  H  <signed integer> <unsigned integer> <digit string> 2::  +<unsigned integer> I —< unsigned integer> <digit> I <nonzero digit><digit string> <digit> I <digit><digit string>  H 
CHAPTER 12 SOLUTIONS 201  20. <float number> 2:: . <integer> I <integer> .| <integer> . <integer>  22. <BOOL> :2: 0| 1 |X1 |X2l |Xn|(<BOOL>) | < BOOL >| <BOOL> v <BOOL> | <BOOL> /\ <BOOL>  23. S—>aS,S—->bS,S—->)\  26. This grammar does generate L. Every string that the grammar generates is in L, since anytime an a is generated, a b is generated and vice versa.  To show that every string 5 E L is generated, we argue by induction on the length of .9. If the length of 5 is 0, 5 is generated. Suppose that s E L and that 5 starts with a. (The argument is similar if 5 starts with b.)  Suppose first that 5 ends with b. Then 5 = atb, where t is a string shorter than 5 and t E L. By the inductive assumption, S =,‘» t. But now  S => aSb => atb : 5 is a derivation of 5. Therefore 5 is in the language generated by the grammar.  Suppose that 5 ends with a. Then 5 = tu, where t and u are each shorter strings than 5 and t,u E L. By the inductive assumption, S => t and S =:» u. But now  S => SS => tu : s is a derivation of .9. Again 5 is in the language generated by the grammar. 27. This grammar does not generate L; aabb is a counterexample. 29. This grammar does not generate L; aabbbbaa is a counterexample. 30. This grammar does not generate L; abba is a counterexample.  34. The language is generated by the context-free language S—->AC, C—->cC, C—>c, A—->aAb, A->ab  36. S —+ —AD+SDS+DA—|s A —+ +SD—ADA—DS+ I a D —> Did + —> + _ _, _  a and s are ignored when drawing the figure.  Section 12.4  2. 
202  7. I : {a,b}, S 2 {A, B,C}, A : {A,C}, initial state = A  S\I a b A {A,C} {B} B {C} {BaC} C 0 0  8. I : {a, b}, 5 = {ao,a1,a2,03}, A = {a3}, initial state : 00  S\I 00 01 02 03  a b {U0} {0o.01} {U2} 0 0 {U3} 0 0  10. I = {a,b}, 5 = {a0,a1,a2,03}, A = {a3}, initial state : 00  5\1 00 U1 02 03  a b 0 {U1} {U2} 0 (0 {U3}  {U3} {U3}  CHAPTER 12 SOLUTIONS 
CHAPTER 12 SOLUTIONS  12.  13. 15.  16.  18. 19.  22.  23.  25.  203  (For Exercise 1, Section 12.3)  b  Yes. The path (0, 0, 0, C, C, C, F) represents bbabbb and ends at an accepting state.  The string a is of the form b"ab'”, where n 2 0 and m 2 1. A path representing this string terminating at F is (a”+1C"‘F). Any path starting at 0 terminating at F is of the form (a”+1C'”F) and thus represents b”ab'”, where n 2 0 and m 2 1.  No. For the first three characters, aaa, either we follow the path (a,a,a,C) or the path (0, 0, 0, 0). From C, on the first path, the next two moves are determined and we remain at C. But now we cannot move on the final a. From the last a on the second path, the next move is determined and we move to D. But now we cannot move on the next b.  {a”b'”ln21,m20}LJ{ba”b'”|n21,m20}  To reach 03 on a path from 00, we must have ended bab. Any string that ends bab is accepted, since we can remain at 00 until we encounter the final bab, at which time we move successively to 01, 02, and 03. 
204 CHAPTER 1 2 SOL UTIONS  26. ‘  28.  29. Use Exercise 36, Section 12.2.  Section 12.5 
CHAPTER 12 SOLUTIONS 205  9. Exercise 19, Section 12.2, shows that Figure 12.5.4 accepts precisely the strings over {a, b} that end bb. We may now use Example 12.5.7 to conclude that Figure 12.5.5 accepts precisely the strings over {a, b} that start bb.  12. 
206 CHAPTER 12 SOLUTIONS  13.  15. To find the nondeterministic finite-state automaton that accepts Ac(A)+, allow an edge in A that terminates on an accepting state to optionally return to the starting state:  16. 
CHAPTER 12 SOLUTIONS 207  18.  O.  19. Allow an edge in A1 that terminates on an accepting state in A1 to terminate optionally on the starting state in A2. The accepting states of the nondeterministic finite—state automaton are the accepting states of A2:  21. See the hint for Exercise 19.  23. Allow any terminating production, alternatively, to return to the start:  <S> ::= b<S> I a<A> I a<S> I a <A> 2:: a<S> I b<B> <B> 2:: b<A> I a<S> I b<S> I b  I  24. Replace any terminating production of L1 with the starting symbol of L2: 
208 CHAPTER 12 SOLUTIONS  <S> ::: b<S> | a<A> | a<a> <A> ::= a<S> | b<B> <B> :::: b<A> | a<S> | b<a> <a> ::: b<0> I a<C> <C> ::= b<C> | b  26. Use Exercises 35-37, Section 12.2, and the methods of Exercises 23 and 24. 27. Consider  L1 2 {a”b”c'°ln,k€{1,2,...}} L2 : {a'°b"c”ln,kE{1,2,...}}. 
Chapter 13  Solutions to Selected Exercises  Section 13.1  2. Some pair is equal.  3- {(1,1),(1,1)=(1a1)a(1,1)}  5. Modify Algorithm 13.1.2 as follows.  Add the parameters a:1,y1,a:2,y2 in which the 33- and y-coordinates of a closest pair will be returned.  Add the lines  331 2 cc-coordinate of first member of closest pair yl : y-coordinate of first member of closest pair 332 : a:—coordinate of second member of closest pair y2 = y-coordinate of second member of closest pair  after the line directly find the distance 6 between a closest pair Replace the lines 6L : 7'ec_cl_pa2'7'(p,i, k) 63 2 rec_cl_paz'r(p, k + 1, j) by  5L = T€C—Cl—Pa1T(Pa1.k,931L,y1L,932L,?J2L) (512 = 7"€C—0l—Pa17‘(P7 19 + 1, J. 93112, y1R. 513212, 1/2R)  if ((5L < 63) { 331 = Slim 91 : 91L 502 : 3»‘2L 92 = 92L 6 = 6L }  209 
210 CHAPTER 13 SOLUTIONS  else { $61 = $613 91 = 9112 $82 = $6212 92 = 9212 6 2 53 }  Replace the line 6 : min{6,dist(v;c,v_.,)}  by if (diSt(’();c,’U3) < (5) { (5 = dist(v;c,v3) 3:1 : v;c.a: 91 = 1219-?! 11:2 = v3.9: 1'/2 : Us-y } 6. Input: 3:1, . . . ,a:n,n  Output: the distance between a closest pair  one-dz'm_cl_paz'r(a:,n) { sort 3:1, ...,a:n dist = oo for 1' : 2 to n dist Z II1iI1{ dist, '58,‘ — 535-1,} return dist  l  9. No. There could be points (11 and Q2 with Q2 closer to p than ql, yet the y—coordinate of Q2 exceeds the y-coordinate of (11. 
CHAPTER 13 SOLUTIONS  11. find_all(p, n) { 6 2 closest_pa,2'r(p, n) // original function if (6 > 0) { sort p1,. ..,pn by as-coordinate rec_find_all(p, 1, n, 6) } }  rec_find_all(p,t',j, 6) { if (j -1‘ < 3) { sort pi, . . . , pj by y-coordinate directly find and output all pairs within 6 of each other return  } k = [(1 +J')/2J l : pkg: rec_find_all(p, 1', k, 6) 7‘ec_find_all(p, k + 1, j, 6)  merge pi, . . . , pk and p;c+1,...,pj by y-coordinate t = 0 for k :1 toj if (pk.a:> l -6)/\pk.a: < l+6){ t : t + 1 ’Ut :plc }  for k 2 1 to t — 1 for 5 = 16+ 1 to min{t,k+7} if (dist(v;c,vs) : 6) println (oh, 123)  12. find_all_26(p,n) { 6 : closest_paz'r(p, n) // original function  if (6 > 0) { sort p1,. . . , pm by as-coordinate rec_find-all_2delta(p, 1, n, 6) }  }  rec_find_all_26(p,i,j, 6) if (j —z' < 3) { sort pi, . . . , pj by y-coordinate directly find and output all pairs less than 26 apart return  }  211 
2 12 CHAPTER 1 3 SOL UTIONS  '6 = [(1 + J’)/ 21 l = pkg) rec_find_all_26(p, 1, k, 6) rec_find_all_26(p, is + 1,3’, 6)  merge p,-, . . . , pk and pk+1, . . . , p,- by y-coordinate t: 0 for k :1 toj if(p;c.:0>l—26/\p;c.a: <l+26){ t: t + 1 'Ut =PIc }  for 10 : 1 to t — 1 for s : k + 1 to min{t,k+ 31} if (dist(vk,v3) < 26) pr1ntln(v;c, vs)  14. Consider points p,- : (1, (1 — l)100) for 1 : 1 to 31 and p32 = (1, 32).  The closest pair is p1, p32 and 6 : 32. After the closest-pair algorithm is called, the points are sorted by y-coordinate: p1,p2, . . . ,p32. The only pair less than 26 is p1, p32, which is not found by algorithm exercise 14.  15. Replace the code that stores all points in the vertical strip for the initial value of 6 with code that finds the first eight points in the strip (or less if there are less than eight points in the strip). After comparing each point to the next seven points in the strip, store an additional point in the strip (if any) using the updated value of 6.  Section 13.2  2. We use the sa.me notation as in the proof of Theorem 13.2.5. If p1,p0,p2 make a left turn, :01 = 3:0, and ya > y1, then :02 < 930. Thus  CF0SS(Po.P1.P2) = (1/2 — yo)(5'31 ‘ $0) — (91 - 1/0)(932 - 500) = -(1/1 - 1/o)(~’82 — 1150) < 0.  Therefore if p1,po,p2 make a left turn, :01 : :00, and ya > 111, then cross(po,p1,p2) < 0. In a similar way, we can show that if p1,p0,p2 make a left turn, :01 : :00, and ya < y1, then cross(po,p1,p2) < 0. Thus if p1,p0,p2 make a left turn and :01 : :00, then cross(po,p1,p2) < 0.  Similarly, we can show that if p1, pg, pg make a right turn and :01 = :00, then cross(po, p1, p2) > 0, and if p1,p0,p2 are collinear and :01 = :00, then cross(po,p1,p2) : 0.  5' (211): (971): (1113): (10:17): (3:11) 
CHAPTER 13 SOLUTIONS 213  6. The idea is to insert the added point into the convex hull so that the sorted order, determined by the angle from the horizontal, is maintained. The correct position can be determined and the point can be inserted in worst-case time ®(n). Next the portion of Graham’s algorithm following the sort step can be run, which takes time ®(n). Thus the convex hull of S’ can be found in time ®(n). This technique works unless the added point (1 is below pl or on the same level and left of pl, in which case, the points are no longer sorted with respect to pl. This problem can be overcome by comparing (1 to pl. If (1 is above or at the same level and to the right of pl, we insert (1 in sorted order determined by the angle from the horizontal with respect to pl, and then run the last for loop exactly as in the original algorithm. If q is below or at the same level and to the left of pl, we insert (1 in sorted order determined by the angle from the horizontal with respect to pm”, a point on the convex hull with maximum y-coordinate. We then run the last for loop, with suitable modifications, with pm” as the base point.  9. @(n2), which occurs when all the points are on the convex hull. 
214 APPENDIX SOLUTIONS 
Appendix  Solutions to Selected Exercises  AppendixA 577 —1—6—9 —8—24 3'(-710 -1) 4' 0-4 2) 6'(14 -12 -2)  46 -35 9 8 5 -11 -6 7. < ) 10. -18 -20 11. < ) -14 16 0 ( 23 _2) 18 -8  2a+4c+e 2b+4d+f 13 6a+9c+3e 6b+9d+3f  a—c+6c b—d+6f  15.a::1,y:—2, z=8  15. ct: = 38/5, y = 0, z = —81/5, 11) : -304/5 2 1 1 -1 1 -1 2 1  19.Let a b A_<c d).  Suppose that AB : I2 for some 2 x 2 matrix  f B: 6 . (9 h) ae+bg af+bh wAB_ 1 0 ce+dg cf+dh M _ 0 1 '  (ad— bc)(eh — fg) : (ae+ bg)(cf + dh) — (af + bh)(ce + dg) 2 1 - 1 — 0 - 0 = 1.  We have  Now  215 
216  21.  APPENDIX SOL UTIONS  Thus ad — bc 7E 0.  If s : ad — bc 7E 0, setting —b/5 a/5  d/5 —c/5  we obtain AB : I2 = BA.  Let  A = (Chi): B = (hm), AB = (On), BTAT = (duv), AT = (021). BT = (bép), (AB)T 2 (09)-  Then Ic Ic dug : Z :3: Z arvgbgu : Czw. 23:1 23:1  Appendix B  2.  15. 17. 23. 29. 33.  38.  39.  8a:—4b_7a:+b_ 16cc—8b_7cc+b_9a:—9b  4_ 96“ 2 4 4 4 4  3. —2a + 14b 5  563:2 — 2033b — 4b2 9  5"+4-5":5"(1+4):5"-5=5"+1  9. 81-1 10. 81 12. 1 13. 1  :c2+;c—12 18. 6a:2+a:—12 20. :c2—8:c+16 21. 9a;2+24a:+16 3:2 — a2 24. 4:8 — 9 26. (ct: — 5)(a: + 2) 27. (:1: + 3)? (2: + 9)(a: — 9) 30. (:1: + 2b)(a: — 2b) 32. (39: + 5)(2a: — 3) (2a; — 3)? 35. (3a + 2b)(3a — 2b) 36. 2(3:1: — 5)(2a: — 5) +(n+1)2 : (n+1)- +(n+1)] : (n+1) Ln(2n+1)(;|—6(n+1)] ‘: (R 11, : (n + 1) _ (n+1)(n+2)(2n+3) _ 6 n 1 n(2n+3)+1 2n2+3n+1  2n+ 1 + (2n+ 1)(2n+3) (2n+ 1)(2n+3)  (n+1)(2n+1) W n+1 (2n+1)(2n+3) _ 2n+3  (2n + 1)(2n + 3) 
APPENDIX SOLUTIONS 217 41. 2r(n — 1)r”'1 — r2(n — 2)r"'2 : 2(n —1)r" — (n — 2)r” = [2(n — 1) — (n — 2)]r" : nr” 43. (3a:—2)(2a: — 1) : 0, cc: §,§ 44 $2 —(—4):l:\/(—4)7—4-2-1 : 4:l:\/§ : 4:|:2\/2 : 24‘/2 ' 2- 2 4 4 2 46. —9>a: 47. —}—§<:c 49. We have  50.  (1+aa:)(1+a:) = 1+aa:+a:+aa:2 = 1+(a+1):1:+am2 Z 1+(a+1)a:  because am? 2 0.  We may multiply 5 -25>225— (3)2 2” ' ‘ ‘ 2  <2)“ <:>"”<2>><;>"*<:>=  by  to obtain  <%)"~  52. The given inequality is equivalent to 0 < 411 + 1, which is true for all n 2 1. 53. 6112 + 411+ 1 3 6112 + 4112 +112 : 11112 55. -7 56. 1 58. 1000 60. 4.906890596 61. 15.84962501 63. —4.736965594 65. —0.603845495 66. 99.4300753 69. 1.336810137 70. 2069864223 Appendix C 2. First large is set to 8 and 1 is set to 2. Since 1 3 n is true, the body of the while loop executes.  Since s,~ > large is false, the value of large does not change. 1 is set to 3 and the while loop executes again.  Since s.- > large is false, the value of large does not change. 1 is set to 4 and the while loop executes again.  Since 51 > large is false, the value of large does not change. 1 is set to 5 and the while loop executes again.  Since 1 3 n is false, the while loop terminates. The value of large is 8, the largest element in the sequence. 
218  11.  12.  14.  APPENDIX SOLUTIONS  First large is set to 1 and ‘l is set to 2. Since 1' 3 n is true, the body of the while loop executes. Since s,- > large is false, the value of large does not change. ‘l is set to 3 and the while loop executes again.  Since 51- > large is false, the value of large does not change. i is set to 4 and the while loop executes again.  Since s,- > large is false, the value of large does not change. i is set to 5 and the while loop executes again.  Since ‘l 3 n is false, the while loop terminates. The value of large is 1, the largest element in the sequence.  . First as is set to 4. Since b > as is false, as : b is not executed. Since c > as is false, as = c also is  not executed. Thus as is the largest of the numbers a, b, and c.  . First as is set to 8. Since b > as is false, as : b is not executed. Since c > as is false, as = c also is  not executed. Thus as is the largest of the numbers a, b, and c.  ma:1:(a, b) { if (a > b) return a else return b }  swap(a,b) { temp = a a 2 b b : temp  }  negatives(s,n) { for 1' : 1 to n if (5; < 0) println(s,~)  }  find_val(s,n, val) { for i : 1 to n if (si :: val) prlntln(2')  }  alternate(s,n) { i : 1 while (1 3 n) { prz'ntln(s,-) ‘l = i + 2 } }