# Solutions Manual (odd) For Discrete Mathematics And Its Applications (7th Edition)

### Solutions%20Manual%20(odd)%20for%20Discrete%20Mathematics%20and%20Its%20Applications%20(7th%20Edition)

### Solutions%20Manual%20(odd)%20for%20Discrete%20Mathematics%20and%20Its%20Applications%20(7th%20Edition)

User Manual:

Open the PDF directly: View PDF .

Page Count: 576

Download | |

Open PDF In Browser | View PDF |

Student's Solutions Guide to accompany .:..· ~' ··Discrete· . : ...·.Mathematics· . ' . and Its Applications SEVENTH EDITION Prepared by Jerrold Grossman . Student's Solutions Guide to accompany Discrete Mathematics and Its Applications Seventh Edition Kenneth H. Rosen Monmouth University (and formerly AT&T Laboratories) Prepared by Jerrold W. Grossman Oakland University ~~onnect Learn • Succeed" The McGrow·Hill Companies ~~onnect learn • Succeed' Student's Solutions Guide to accompany DISCRETE MATHEMATICS AND ITS APPLICATIONS, SEVENTH EDITION KENNETH H. ROSEN Published by McGraw-Hill Higher Education, an imprint of The McGraw-Hill Compames, Inc., 1221 Avenue of the Americas, New York, NY 10020. Copyright© 2012 and 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Pnnted in the United States of America. No part of this publication may be reproduced or distributed many form or by any means, or stored ma database or retrieval system, without the prior written consent of The McGraw-Hill Companies, Inc., including, but not limited to, network or other electronic storage or transm1ss10n, or broadcast for distance leammg. 1234567890QDB~DB10987654321 ISBN: 978-0-07-735350-6 MHID: 0-07-735350-1 www.mhhe.com Preface This Student's Solutions Guide for Discrete Mathematics and Its Applications, seventh edition, contains several useful and important study aids. • SOLUTIONS TO ODD-NUMBERED EXERCISES The bulk of this work consists of solutions to all the odd-numbered exercises in the text. These are not just answers, but complete, worked-out solutions, showing how the principles discussed in the text and examples are applied to the problems. I have also added bits of wisdom, insights, warnings about errors to avoid, and extra comments that go beyond the question as posed. Furthermore, at the beginning of each section you will find some general words of advice and hints on approaching the exercises in that section. • REFERENCES FOR CHAPTER REVIEWS Exact page references, theorem and example references, and answers are provided as a guide for all the chapter review questions in the text. This will make reviewing for tests and quizzes particularly easy. • A GUIDE TO WRITING PROOFS Near the end of this book is a section on writing proofs, a skill that most students find difficult to master. Proofs are introduced formally in Chapter 1 (and proofs by mathematical induction are studied in Chapter 5), but exercises throughout the text ask for proofs of propositions. Reading this section when studying Sections 1.6-1.8, and then periodically thereafter, will be rewarded, as your proof-writing ability grows. • REFERENCES AND ADVICE ON THE WRITING PROJECTS Near the end of this book you will find some general advice on the Writing Projects given at the end of each chapter. There is a discussion of various resources available in the mathematical sciences (such as Mathematical Reviews and the World Wide Web), tips on doing library research, and some suggestions on how to write well. In addition, there is a rather extensive bibliography of books and articles that will be useful when researching these projects. We also provide specific hints and suggestions for each project, with pointers to the references; these can be found in the solutions section of this manual, at the end of each chapter. • SAMPLE CHAPTER TESTS Near the end of this book you will find a sequence of 13 chapter tests, comparable to what might be given in a course. You can take these sample tests in a simulated test setting as practice for the real thing. Complete solutions are provided, of course. • PROBLEM-SOLVING TIPS AND LIST OF COMMON MISTAKES People beginning any endeavor tend to make the same kinds of mistakes. This is especially true in the study of mathematics. I have included a detailed list of common misconceptions that students of discrete mathematics often have and the kinds of errors they tend to make. Specific examples are given. It will be useful for you to review this list from time to time, to make sure that you are not falling into these common traps. Also included in this section is general advice on solving problems in mathematics, which you will find helpful as you tackle the exercises. • CRIB SHEETS Finally, I have prepared a set of 13 single-page "crib sheets," one for each chapter of the book. They provide a quick summary of all the important concepts, definitions, and lll theorems in the chapter. There are at least three ways to use these. First, they can be used as a reference source by someone who wants to brush up on the material quickly or reveal gaps in old knowledge. Second, they provide an excellent review sheet for studying for tests and quizzes, especially useful for glancing over in the last few minutes. And third, a copy of this page (augmented by your own notes in the margins) is ideal in those cases where an instructor allows the students to come to a test with notes. Several comments about the solutions in this volume are in order. In many cases, more than one solution to an exercise is presented, and sometimes the solutions presented here are not the same as the answers given in the back of the text. Indeed, there is rarely only one way to solve a problem in mathematics. You may well come upon still other valid ways to arrive at the correct answers. Even if you have solved a problem completely, you will find that reviewing the solutions presented here will be valuable, since there is insight to be gained from seeing how someone else handles a problem that you have just solved. Exercises often ask that answers be justified or verified, or they ask you to show or prove a particular statement. In all these cases your solution should be a proof, i.e., a mathematical argument based on the rules of logic. Such a proof needs to be complete, convincing, and correct. Read your proof after finishing it. Ask yourself whether you would understand and believe it if it were presented to you by your instructor. Although I cannot personally discuss with you my philosophy on learning discrete mathematics by solving exercises, let me include a few general words of advice. The best way to learn mathematics is by solving problems, and it is crucial that you first try to work these exercises independently. Consequently, do not use this Guide as a crutch. Do not look at the solution (or even the answer) to a problem before you have worked on it yourself. Resist the temptation to consult the solution as soon as the going gets rough. Make a real effort to work the problem completely on your own-preferably to the point of writing down a complete solution-before checking your work with the solutions presented here. If you have not been able to solve a problem and have reached the point where you feel it necessary to look at the answer or solution, try reading it only casually, looking for a hint as to how you might proceed; then try working on the exercise again, armed with this added information. As a last resort, study the solution in detail and make sure you could explain it to a fellow student. I want to thank Jerry Grossman for his extensive advice and assistance in the preparation of this entire Guide, Paul Lorczak, Suzanne Zeitman, and especially Georgia Mederer for doublechecking the solutions, Ron Marash for preparing the advice on writing proofs, and students at Monmouth College and Oakland University for their input on preliminary versions of these solutions. A tremendous amount of effort has been devoted to ensuring the accuracy of these solutions, but it is possible that a few scattered errors remain. I would appreciate hearing about all that you find, be they typographical or mathematical. You can reach me using the Reporting of Errata link on the companion website's Information Center at www.mhhe.com/rosen. One final note: In addition to this Guide, you will find the companion website created for Discrete Mathematics and Its Applications an invaluable resource. Included here are a Web Resources Guide with links to external websites keyed to the textbook, numerous Extra Examples to reinforce important topics, Interactive Demonstration Applets for exploring key algorithms, Self Assessment question banks to gauge your understanding of core concepts, and many other helpful resources. See the section titled "The Companion Website" on page xvi of the textbook for more details. The address is www.mhhe.com/rosen. Kenneth H. Rosen iv Contents Preface iii CHAPTER 1 The Foundations: Logic and Proofs 1.1 Propositional Logic 1 8 1.2 Applications of Propositional Logic 1.3 Propositional Equivalences 11 1.4 Predicates and Quantifiers 17 1.5 Nested Quantifiers 23 1.6 Rules of Inference 32 1. 7 Introduction to Proofs 36 Proof Methods and Strategy 40 1.8 Guide to Review Questions for Chapter 1 44 Supplementary Exercises for Chapter 1 45 48 Writing Projects for Chapter 1 CHAPTER 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 2.1 Sets 50 2.2 Set Operations 53 Functions 59 2 .3 68 2.4 Sequences and Summations Cardinality of Sets 75 2.5 2.6 Matrices 79 83 Guide to Review Questions for Chapter 2 Supplementary Exercises for Chapter 2 84 Writing Projects for Chapter 2 87 CHAPTER 3 Algorithms 3.1 Algorithms 88 3.2 The Growth of Functions 97 3.3 Complexity of Algorithms 103 Guide to Review Questions for Chapter 3 107 Supplementary Exercises for Chapter 3 108 112 Writing Projects for Chapter 3 CHAPTER 4 Number Theory and Cryptography 4.1 Divisibility and Modular Arithmetic 113 116 4.2 Integer Representations and Algorithms 4.3 Primes and Greatest Common Divisors 122 130 4.4 Solving Congruences 4.5 Applications of Congruences 137 Cryptography 140 4.6 Guide to Review Questions for Chapter 4 142 Supplementary Exercises for Chapter 4 143 Writing Projects for Chapter 4 147 v 1 50 88 113 CHAPTER 5 CHAPTER 6 CHAPTER 7 CHAPTER 8 Induction and Recursion 5.1 Mathematical Induction 149 Strong Induction and Well-Ordering 161 5.2 5.3 Recursive Definitions and Structural Induction 5.4 Recursive Algorithms 176 Program Correctness 182 5.5 Guide to Review Questions for Chapter 5 183 Supplementary Exercises for Chapter 5 185 Writing Projects for Chapter 5 195 Counting 6.1 The Basics of Counting 197 The Pigeonhole Principle 206 6.2 6.3 Permutations and Combinations 211 Binomial Coefficients and Identities 6.4 216 6.5 Generalized Permutations and Combinations 6.6 Generating Permutations and Combinations Guide to Review Questions for Chapter 6 230 Supplementary Exercises for Chapter 6 231 237 Writing Projects for Chapter 6 Discrete Probability 7.1 An Introduction to Discrete Probability Probability Theory 242 7.2 7.3 Bayes' Theorem 247 7.4 Expected Value and Variance 250 Guide to Review Questions for Chapter 7 255 Supplementary Exercises for Chapter 7 256 261 Writing Projects for Chapter 7 149 167 197 220 227 239 239 Advanced Counting Techniques 8.1 Applications of Recurrence Relations 262 Solving Linear Recurrence Relations 272 8.2 8.3 Divide-and-Conquer Algorithms and Recurrence Relations 8.4 Generating Functions 286 8.5 Inclusion-Exclusion 298 8.6 Applications of Inclusion-Exclusion 300 Guide to Review Questions for Chapter 8 304 Supplementary Exercises for Chapter 8 305 Writing Projects for Chapter 8 310 CHAPTER 9 9.1 9.2 9.3 9.4 Relations Relations and Their Properties 312 n-ary Relations and Their Applications Representing Relations 322 Closures of Relations 325 Vl 262 282 312 320 9.5 Equivalence Relations 329 Partial Orderings 337 9.6 345 Guide to Review Questions for Chapter 9 Supplementary Exercises for Chapter 9 347 351 Writing Projects for Chapter 9 CHAPTER 10 Graphs 10.1 Graphs and Graph Models 352 10.2 Graph Terminology and Special Types of Graphs 355 10.3 Representing Graphs and Graph Isomorphism 361 10.4 Connectivity 368 10.5 Euler and Hamilton Paths 375 10.6 Shortest-Path Problems 381 10.7 Planar Graphs 385 10.8 Graph Coloring 389 Guide to Review Questions for Chapter 10 393 Supplementary Exercises for Chapter 10 395 Writing Projects for Chapter 10 401 352 Trees CHAPTER 11 11.1 Introduction to Trees 403 11.2 Applications of Trees 408 11.3 Tree Traversal 417 Spanning Trees 421 11.4 11.5 Minimum Spanning Trees 427 Guide to Review Questions for Chapter 11 Supplementary Exercises for Chapter 11 Writing Projects for Chapter 11 434 403 429 430 CHAPTER 12 Boolean Algebra 12.1 Boolean Functions 436 12.2 Representing Boolean Functions 440 12.3 Logic Gates 443 12.4 Minimization of Circuits 445 Guide to Review Questions for Chapter 12 453 Supplementary Exercises for Chapter 12 454 Writing Projects for Chapter 12 456 436 CHAPTER 13 Modeling Computation 13.1 Languages and Grammars 457 Finite-State Machines with Output 464 13.2 469 13.3 Finite-State Machines with No Output Language Recognition 474 13.4 Turing Machines 478 13.5 482 Guide to Review Questions for Chapter 13 483 Supplementary Exercises for Chapter 13 Writing Projects for Chapter 13 487 457 Vll APPENDIXES Appendix 1 Appendix 2 Appendix 3 489 Axioms for the Real Numbers and the Positive Integers 489 Exponential and Logarithmic Functions Pseudocode 491 491 A Guide to Proof-Writing 492 References and Advice on Writing Projects 503 Sample Chapter Tests with Solutions 511 Common Mistakes in Discrete Mathematics Solving Problems in Discrete Mathematics List of Common Mistakes 541 540 540 551 Crib Sheets Vlll Section 1.1 Propositional Logic 1 CHAPTERl The Foundations: Logic and Proofs SECTION 1.1 Propositional Logic Manipulating propositions and constructing truth tables are straightforward. A truth table is constructed by finding the truth values of compound propositions from the inside out; see the solution to Exercise 31, for instance. This exercise set also introduces fuzzy logic. 1. Propositions must have clearly defined truth values, so a proposition must be a declarative sentence with no free variables. a) This is a true proposition. b) This is a false proposition (Tallahassee is the capital). c) This is a true proposition. d) This is a false proposition. e) This is not a proposition (it contains a variable; the truth value depends on the value assigned to x). f) This is not a proposition, since it does not assert anything. 3. a) Mei does not have an MP3 player. b) There is pollution in New Jersey. c) 2+1#3 d) It is not the case that the summer in Maine is hot and sunny. In other words, the summer in Maine is not hot and sunny, which means that it is not hot or it is not sunny. It is not correct to negate this by saying "The summer in Maine is not hot and not sunny." [For this part (and in a similar vein for part (b)) we need to assume that there are well-defined notions of hot and sunny; otherwise this would not be a proposition because of not having a definite truth value.] 5. a) Steve does not have more than 100 GB free disk space on his laptop. (Alternatively: Steve has less than or equal to 100 GB free disk space on his laptop.) b) Zach does not block e-mails and texts from Jennifer. (Alternatively, and more precisely: Zach does not block e-mails from Jennifer, or he does not block texts from Jennifer. Note that negating an "and" statement produces an "or" statement. It would not be correct to say that Zach does not block e-mails from Jennifer, and he does not block texts from Jennifer. That is a stronger statement than just the negation of the given statement.) c) 7·11·13#999. d) Diane did not ride her bike 100 miles on Sunday. 7. a) This is false, because Acme's revenue was larger. b) Both parts of this conjunction are true, so the statement is true. c) The second part of this disjunction is true, so the statement is true. d) The hypothesis of this conditional statement is false and the conclusion is true, so by the truth-table definition this is a true statement. (Either of those conditions would have been enough to make the statement true.) 2 Chapter 1 The Foundations: Logic and Proofs e) Both parts of this biconditional statement are true, so by the truth-table definition this is a true statement. 9. This is pretty straightforward, using the normal words for the logical operators. a) Sharks have not been spotted near the shore. b) Swimming at the New Jersey shore is allowed, and sharks have been spotted near the shore. c) Swimming at the New Jersey shore is not allowed, or sharks have been spotted near the shore. d) If swimming at the New Jersey shore is allowed, then sharks have not been spotted near the shore. e) If sharks have not been spotted near the shore, then swimming at the New Jersey shore is allowed. f) If swimming at the New Jersey shore is not allowed, then sharks have not been spotted near the shore. g) Swimming at the New Jersey shore is allowed if and only if sharks have not been spotted near the shore. h) Swimming at the New Jersey shore is not allowed, and either swimming at the New Jersey shore is allowed or sharks have not been spotted near the shore. Note that we were able to incorporate the parentheses by using the word "either" in the second half of the sentence. 11. a) Here we have the conjunction p A q. b) Here we have a conjunction of p with the negation of q, namely p A --.q. Note that "but" logically means the same thing as "and." c) Again this is a conjunction: --.p A --.q. d) Here we have a disjunction, p V q. Note that V is the inclusive or, so the "(or both)" part of the English sentence is automatically included. e) This sentence is a conditional statement, p -> q. f) This is a conjunction of propositions, both of which are compound: (p V q) A (p-> --.q). g) This is the biconditional p f-+ q. 13. a) This is just the negation of p, so we write --.p. b) This is a conjunction ("but" means "and"): p A --.q. c) The position of the word "if" tells us which is the antecedent and which is the consequence: p d) -ip - t --.q e) The sufficient condition is the antecedent: p -> -> q. q. f)qA--.p g) ''Whenever" means "if": q -> p. 15. a) "But" is a logical synonym for "and" (although it often suggests that the second part of the sentence is likely to be unexpected). So this is r A --.p. b) Because of the agreement about precedence, we do not need parentheses in this expression: --.p A q A r. c) The outermost structure here is the conditional statement, and the conclusion part of the conditional statement is itself a biconditional: r -> ( q f-+ --.p) . d) This is similar to part (b): --.q A --.p A r. e) This one is a little tricky. The statement that the condition is necessary is a conditional statement in one direction, and the statement that this condition is not sufficient is the negation of the conditional statement in the other direction. Thus we have the structure (safe -> conditions) A--.( conditions -> safe). Fleshing this out gives our answer: (q -> (--.r A --.p)) A --.( (--.r A --.p) -> q). There are some logically equivalent correct answers as well. f) We just need to remember that "whenever" means "if" in logic: (p A r) -> --.q. 17. In each case, we simply need to determine the truth value of the hypothesis and the conclusion, and then use Section 1.1 Propositional Logic 3 the definition of the truth value of the conditional statement. The conditional statement is true in every case except when the hypothesis (the "if" part) is true and the conclusion (the ''then" part) is false. a) Since the hypothesis is true and the conclusion is false, this conditional statement is false. b) Since the hypothesis is false and the conclusion is true, this conditional statement is true. c) Since the hypothesis is false and the conclusion is false, this conditional statement is true. Note that the conditional statement is false in both part (b) and part ( c); as long as the hypothesis is false, we need look no further to conclude that the conditional statement is true. d) Since the hypothesis is false, this conditional statement is true. 19. a) Presumably the diner gets to choose only one of these beverages, so this is an exclusive or. b) This is probably meant to be inclusive, so that long passwords with many digits are acceptable. c) This is surely meant to be inclusive. If a student has had both of the prerequisites, so much the better. d) At first glance one might argue that no one would pay with both currencies simultaneously, so it would seem reasonable to call this an exclusive or. There certainly could be cases, however, in which the patron would pay a portion of the bill in dollars and the remainder in euros. Therefore, an inclusive or seems better. 21. a) If this is an inclusive or, then it is allowable to take discrete mathematics if you have had calculus or computer science or both. If this is an exclusive or, then a person who had both courses would not be allowed to take discrete mathematics-only someone who had taken exactly one of the prerequisites would be allowed in. Clearly the former interpretation is intended; if anything, the person who has had both calculus and computer science is even better prepared for discrete mathematics. b) If this is an inclusive or, then you can take the rebate, or you can sign up for the low-interest loan, or you can demand both of these incentives. If this is an exclusive or, then you will receive one of the incentives but not both. Since both of these deals are expensive for the dealer or manufacturer, surely the exclusive or was intended. c) If this is an inclusive or, you can order two items from column A (and none from B), or three items from column B (and none from A), or five items (two from A and three from B). If this is an exclusive or, which it surely is here, then you get your choice of the two A items or the three B items, but not both. d) If this is an inclusive or, then lots of snow, or extreme cold, or a combination of the two will close school. If this is an exclusive or, then one form of bad weather would close school but if both of them happened then school would meet. This latter interpretation is clearly absurd, so the inclusive or is intended. 23. a) If the wind blows from the northeast, then it snows. ["Whenever" means ''if."] b) If it stays warm for a week, then the apple trees will bloom. [Sometimes word order is flexible in English, as it is here. Other times it is not-"The man bit the dog" does not have the same meaning as "The dog bit the man."] c) If the Pistons win the championship, then they beat the Lakers. d) If you get to the top of Long's Peak, then you must have walked eight miles. [The necessary condition is the conclusion.] e) If you are world famous, then you will get tenure as a professor. [The sufficient condition is the antecedent.] f) If you drive more than 400 miles, then you will need to buy gasoline. [The word ''then" is sometimes omitted in English sentences, but it is still understood.] g) If your guarantee is good, then you must have bought your CD player less than 90 days ago. [Note that "only if" does not mean "if"; the clause following the "only if" is the conclusion, not the antecedent.] h) If the water is not too cold, then Jan will go swimming. [Note that "unless" really means "if not." It also can be taken to mean "or."] Chapter 1 4 The Foundations: Logic and Proofs 25. In each case there will be two statements. It is being asserted that the first one holds true if and only if the second one does. The order doesn't matter, but often one order is more colloquial English. a) You buy an ice cream cone if and only if it is hot outside. b) You win the contest if and only if you hold the only winning ticket. c) You get promoted if and only if you have connections. d) Your mind will decay if and only if you watch television. e) The train runs late if and only if it is a day I take the train. 27. Many forms of the answers for this exercise are possible. a) One form of the converse that reads well in English is "I will ski tomorrow only if it snows today." We could state the contrapositive as ''If I don't ski tomorrow, then it will not have snowed today." The inverse is "If it does not snow today, then I will not ski tomorrow." b) The proposition as stated can be rendered "If there is going to be a quiz, then I will come to class." The converse is "If I come to class, then there will be a quiz." (Or, perhaps even better, "I come to class only if there's going to be a quiz.") The contrapositive is "If I don't come to class, then there won't be a quiz." The inverse is "If there is not going to be a quiz, then I don't come to class.'' c) There is a variable ("a positive integer") in this sentence, so technically it is not a proposition. Nevertheless, we can treat sentences such as this in the same way we treat propositions. Its converse is "A positive integer is a prime if it has no divisors other than 1 and itself." (Note that this can be false, since the number 1 satisfies the hypothesis but not the conclusion.) The contrapositive of the original proposition is "If a positive integer has a divisor other than 1 and itself, then it is not prime." (We are simplifying a bit here, replacing ''does not have no divisors" by "has a divisor." Note that this is always true, assuming that we are talking about positive divisors.) The inverse is "If a positive integer is not prime, then it has a divisor other than 1 and itself." 29. A truth table will need 2n rows if there are n variables. a)2 1 =2 b)2 4 =16 d)2 4 =16 c)2 6 =64 31. To construct the truth table for a compound proposition, we work from the inside out. In each case, we will show the intermediate steps. In part ( d), for example, we first construct the truth table for p V q, then the truth table for p /\ q, and finally combine them to get the truth table for (p V q) -+ (p /\ q). For parts (a) and (b) we have the following table (column three for part (a), column four for part (b)). P 'P p/\-ip pV-ip T F F T F F T T For part ( c) we have the following table. v -iq p q -iq T T F F T F T F F T F T T T F T p (p v -iq) -+ q T F T F For part ( d) we have the following table. p q pVq p /\ q T T F F T F T F T T T F T F F F (p v q) -+ T F F T (p /\ q) 5 Propositional Logic Section 1.1 For part ( e) we have the following table. This time we have omitted the column explicitly showing the negations of p and q. Note that this true proposition is telling us that a conditional statement and its contrapositive always have the same truth value. p q p-+ q T T F F T F T F T F T T •q -+ (p-+ q) 'P f--7 T F T T (•q -+ •p) T T T T For part ( f) we have the following table. The fact that this proposition is not always true tells us that knowing a conditional statement in one direction does not tell us that the conditional statement is true in the other direction. p q T T F F T F T F p --'> q q-+ p T F T T (p-+ q) T T F T -+ (q-+ p) T T F T 33. To construct the truth table for a compound proposition, we work from the inside out. In each case, we will show the intermediate steps. In part (a), for example, we first construct the truth table for p V q, then the truth table for p EB q, and finally combine them to get the truth table for (p V q) -+ (p EB q). For parts (a), (b), and ( c) we have the following table (column five for part (a), column seven for part (b), column eight for part ( c)). (pV q) EB (p/\ q) p q pVq (pV q) -+ (p EB q) p /\ q (p EB q) -+ (p /\ q) pEB q T T F F T F T F F T T F T T T F F T T T T F F T T F F F F T T F For part ( d) we have the following table. p q 'P p f--7 q --- •P ,_. q (p ,_. q) EB (•P ,_. q) T T F F T F T F F F T T T F F T F T T F T T T T For part ( e) we need eight rows in our truth table, because we have three variables. p f--7 q (p ,_. q) EB (•p ,_. •r) p q r •P ,_. •r •r 'P T F F F T F F F T T F T T T F T T For part (f) we have the following table. T T T T F F F F T T F F T T F F T T F F F F T T F T F T F T F F T F T F F T F T p q •q p EB q p EB •q T T F F T F T F F T F T F T T F T F F T T T F F T T F (p EB q) -+ T F F T (p EB •q) The Foundations: Logic and Proofs Chapter 1 6 35. The techniques are the same as in Exercises 31-34. For parts (a) and (b) we have the following table (column four for part (a), column six for part (b)). p q •q T T F F T F T F F T F T p ---+ •q -.p 'P F F T T F T T T +-+ q F T T F For parts (c) and (d) we have the following table (columns six and seven, respectively). p q T T F F T F T F p ---+ q -.p 'P F F T T T F T T ---+ (p---+ q) q v (•p---+ q) (p---+ q) /\ (•p---+ q) T T T T T T T F T F T F For parts ( e) and ( f) we have the following table (this time we have not explicitly shown the columns for negation). Column five shows the answer for part (e), and column seven shows the answer for part (f). p q T T F F T F T F p +-+ T F F T q 'P +-+ (p q +-+ q) v (•p +-+ q) •P T T T T F T T F +-+ (•p •q T F F T +-+ -.q) +-+ (p +-+ q) T T T T 37. The techniques are the same as in Exercises 31-36, except that there are now three variables and therefore eight rows. For part (a), we have p q r •q •q Vr T T T T F F F F T T F F T T F F T F T F T F T F F F T T F F T T T F T T T F T T p q r -.p q ---+ r T T T T F F F F T T F F T T F F T F T F T F T F F F F F T T T T T F T T T F T T p ---+ ( •q V r) T F T T T T T T For part (b), we have Parts ( c) and ( d) we can combine into a single table. -.p ---+ ( q ---+ T T T T T F T T r) Section 1.1 Propositional Logic 7 p q r p ____, q •p 'P ____, r (p ____, q) V (•p ____, r) (p ____, q) A (•p ____, r) T T T T F F T T T T T F F F F F T F T F T F T T T T F T T T T T T T T T T T T T T T T T T T F F F F F T T F F F T F F F T F T F For part ( e) we have p q r T T T T F T T F F T T T F F F F F p F T F T •q T T F F F T T F F F F T T T T T F 39. This time the truth table needs 24 p q r F F F F F F F q F F Finally, for part ( f) we have p q r •P T T T F T T F F T F T F T F F F F T T T F T F T F F T T F F F T T T T T T T T T F <,--+ •p •q <,--+ F F T T T T T T T F F T T T •q q ,,._, r (•P ,,__, •q) ,,__, (q ,,__, r) T T F F F T T T F F F T T T F F = 16 rows. Note the systematic order in which we list the possibilities. s p <,--+ T T T F F T F F T T F F F T T T T F T F T F T F F F F F T F T T F F F F T F T F F F T T F T T T T F T T (p ,,._, q) V (•q ,,._, r) T T F F T T T T F F F F F •q ,,._, r F F T T T T F q r ,,._, s (p ,,._, q) ,,._, (r ,,._, s) T T F F F F T T T F T T F F F F F F T T F F F F F T T T T T F F F F T T T T T T F F 41. The first clause (p V q V r) is true if and only if at least one of p, q, and r is true. The second clause ( •p V •q V •r) is true if and only if at least one of the three variables is false. Therefore both clauses are true, and therefore the entire statement is true, if and only if there is at least one T and one F among the truth values of the variables, in other words, that they don't all have the same truth value. Chapter 1 8 The Foundations: Logic and Proofs = 111 1111; bitwise AND= 000 0000; bitwise XOR = 1111111 OR = 1111 1010; bitwise AND= 1010 0000; bitwise XOR = 0101 1010 43. a) bitwise OR b) bitwise c) bitwise OR= 10 01111001; bitwise AND= 00 0100 0000; bitwise XOR= 10 00111001 d) bitwise OR= 1111111111; bitwise AND= 00 0000 0000; bitwise XOR= 1111111111 45. For "Fred is not happy," the truth value is 1 - 0.8 = 0.2. For "John is not happy,'' the truth value is 1- 0.4 = 0.6. 47. For "Fred is happy, or John is happy,'' the truth value is max(0.8, 0.4) = 0.8. For ''Fred is not happy, or John is not happy," the truth value is max(0.2, 0.6) Exercise 45). = 0.6 (using the result of 49. One great problem-solving strategy to try with problems like this, when the parameter is large ( 100 statements here) is to lower the parameter. Look at a simpler problem, with just two or three statements, and see if you can figure out what's going on. That was the approach used to discover the solution presented here. a) Some number of these statements are true, so in fact exactly one of the statements must be true and the other 99 of them must be false. That is what the 99th statement is saying, so it is true and the rest are false. b) The 10oth statement cannot be true, since it is asserting that all the statements are false. Therefore it must be false. That makes the first statement true. Now if the 99th statement were true, then we would conclude that statements 2 through 100 were false, which contradicts the truth of statement 99. So statement 99 must be false. That means that statement 2 is true. We continue in this way and conclude that statements 1 through 50 are all true and statements 51 through 100 are all false. c) If there are an odd number of statements, then we'd run into a contradiction when we got to the middle. If there were just three statements, for example, then statement 3 would have to be false, making statement 1 true, and now the truth of statement 2 would imply its falsity and its falsity would imply its truth. Therefore this situation cannot occur with three (or any odd number of) statements. It is a logical paradox, showing that in fact these are not statements after all. SECTION 1.2 Applications of Propositional Logic Applications of propositional logic abound in computer science, puzzles, and everyday life. For example, much of the operation of our legal system is based on conditional statements. Boolean searches are increasingly important in using the Web (see Exercises 13-14 for example). 1. Recall that '' q unless •p" is another way to state p _, q. In this problem, •P is a, so p is •a; and q is •e. Therefore the statement here is •a _, •e. This could also be stated equivalently as e _, a (if you can edit, then you must be an administrator). 3. Recall that p only if q means p _, q. In this case, if you can graduate then you must have fulfilled the three listed requirements. Therefore the statement is g _, (r /\ (•m) /\ (•b)). Notice that in everyday life one might actually say "You can graduate if you do these things," but logically that is not what the rules really say. 5. This is similar to Exercise 3. If you are eligible to be President, then you must satisfy the requirements: e _, (a/\ (b V p) /\ r). Notice that it is only the requirement of being native-born that can be overridden by having parents who were citizens, so b V p is grouped as one of the three conditions. Section 1.2 Applications of Propositional Logic 9 7. a) Since "whenever" means "if," we have q---+ p. b) Since "but" means "and," we have q /\ 'P. c) This sentence is saying the same thing as the sentence in part (a), so the answer is the same: q---+ p. d) Again, we recall that "when" means "if" in logic: •q---+ •p. 9. Let m, n, k, and i represent the propositions ''The system is in multiuser state," "The system is operating normally," "The kernel is functioning,'' and "The system is in interrupt mode," respectively. Then we want to make the following expressions simultaneously true by our choice of truth values for m, n, k, and i: m ,,_.. n, n ---+ k, -,kV i, -im ---+ i, -,i In order for this to happen, clearly i must be false. In order for •m ---+ i to be true when i is false, the hypothesis •m must be false, so m must be true. Since we want m ,,_.. n to be true, this implies that n must also be true. Since we want n ---+ k to be true, we must therefore have k true. But now if k is true and i is false, then the third specification, •kV i is false. Therefore we conclude that this system is not consistent. 11. Let s be "The router can send packets to the edge system"; let a be "The router supports the new address space"; let r be "The latest software release is installed." Then we are told s ---+ a, a ---+ r, r ---+ s, and •a. Since a is false, the first conditional statement tells us that s must be false. From that we deduce from the third conditional statement that r must be false. If indeed all three propositions are false, then all four specifications are true, so they are consistent. 13. This is similar to Example 6, about universities in New Mexico. To search for beaches in New Jersey. we could enter NEW AND JERSEY AND BEACHES. If we enter (JERSEY AND BEACHES) NOT NEW, then we'll get websites about beaches on the isle of Jersey, except for sites that happen to use the word "new" in a different context (e.g., a recently opened beach there). If we were sure that the word "isle" was in the name of the location, then of course we could enter ISLE AND JERSEY AND BEACHES. 15. There are many correct answers to this problem, but all involve some sort of double layering, or combining a question about the kind of person being addressed with a question about the information being sought. One solution is to ask this question: "If I were to ask you whether the right branch leads to the ruins, would you say 'yes'?" If the villager is a truth-teller, then of course he will reply "yes" if and only if the right branch leads to the ruins. Now let us see what the liar says. If the right branch leads to the ruins, then he would say "no" if asked whether the right branch leads to the ruins. Therefore, the truthful answer to your convoluted question is "no." Since he always lies, he will reply "yes." On the other hand, if the right branch does not lead to the ruins, then he would say "yes'' if asked whether the right branch leads to the ruins; and so the truthful answer to your question is "yes"; therefore he will reply "no." Note that in both cases, he gives the same answer to your question as the truth-teller; namely, he says "yes" if and only if the right branch leads to the ruins. A more detailed discussion can be found in Martin Gardner's Scientific American Book of Mathematical Puzzles and Diversions (Simon and Schuster, 1959), p. 25; reprinted as Hexafiexagons and Other Mathematical Diversions: The First Scientific American Book of Puzzles and Games (University of Chicago Press, 1988). 17. The question was "Does everyone want coffee?" If the first professor did not want coffee, then he would know that the answer to the hostess's question was "no." Therefore we-and the hostess and the remaining professors-know that the first professor does want coffee. The same argument applies to the second professor, so she, too, must want coffee. The third professor can now answer the question. Because she said "no,'' we conclude that she does not want coffee. Therefore the hostess knows to bring coffee to the first two professors but not to the third. 10 Chapter 1 The Foundations: Logic and Proofs 19. If A is a knight, then he is telling the truth, in which case B must be a knave. Since B said nothing, that is certainly possible. If A is a knave, then he is lying, which means that his statement that at least one of them is a knave is false; hence they are both knights. That is a contradiction. So we can conclude that A is a knight and B is a knave. 21. If A is a knight, then he is telling the truth, in which case B must be a knight as well, since A is not a knave. (If p V q and •p are both true, then q must be true.) Since B said nothing, that is certainly possible. If A is a knave, then his statement is patently true, but that is a contradiction to the behavior of knaves. So we can conclude that A is a knight and B is a knight. 23. If A is a knight, then he should be telling the truth, but he is asserting that he is a knave. So that cannot be. If A is a knave, then in order for his statement to be false, B must be a knight. So we can conclude that A is a knave and B is a knight. 25. Neither the knight nor the knave would say that he is the knave, so B must be the spy. Therefore C is lying and must be the knave, and A is therefore the knight (and told the truth). 27. We know that B is not the knight, because if he were, then his assertion that A is telling the truth would mean that there were two knights. Clearly C is not the knight, because he claims he is the spy. Therefore A is the knight. That means that B was telling the truth, so he must be the spy. And C is the knave, who falsely asserts that he is the spy. 29. We can tell nothing here; each of the six permutations is possible. The knight will always say that he is the knight; the knave will always lie, so he might also say that he is the knight; and the spy may lie and say that he is the knight. 31. If there were a solution, then whoever is the knave here is speaking the truth when he says that he is not the spy. Because knaves always lie, we get a contradiction. Therefore there are no solutions. 33. Because of the first piece of information that Steve has, let's assume first that Fred is not the highest paid. Then Janice is. Therefore Janice is not the lowest paid, so by the second piece of information that Steve has, Maggie is the highest paid. But that is a contradiction. Therefore we know that Fred is the highest paid. Next let's assume that Janice is not the lowest paid. Then our second fact implies that Maggie is the highest paid. But that contradicts the fact that Fred is the highest paid. Therefore we know that Janice is the lowest paid. So it appears that the only hope of a consistent set of facts is to have Fred paid the most, Maggie next, and Janice the least. (We have just seen that any other assumption leads to a contradiction.) This assumption does not contradict either of our two facts, since in both cases, the hypothesis is false. 35. Let's use the letters B, C, G, and H for the statements that the butler, cook, gardner, and handyman are telling the truth, respectively. We can then write each fact as a true proposition: B -+ C; •(CA G), which is equivalent to ·CV --,Q (see the discussion of De Morgan's law in Section 1.3); •( •G A ·H), which is equivalent to G V H; and H -+ ·C. Suppose that B is true. Then it follows from the first of our propositions that C must also be true. This tells us (using the second proposition) that G must be false, whence the third proposition makes H true. But now the fourth proposition is violated. Therefore we conclude that B cannot be true. If fact, the argument we have just given also proves that C cannot be true. Therefore we know that the butler and the cook are lying. This much already makes the first, second, and fourth propositions true, regardless of the truth of G or H. Thus either the gardner or the handyman could be lying or telling the truth; all we know (from the third proposition) is that at least one of them is telling the truth. Section 1.3 Propositional Equivalences 11 37. If the first sign were true, then the second sign would also be true. In that case, we could not have one true sign and one false sign. Rather, the second sign is true and the first is false; there is a lady in the second room and a tiger in the first room. 39. The given conditions imply that there cannot be two honest senators. Therefore, since we are told that there is at least one honest senator, there must be exactly 49 corrupt senators. 41. a) The output of the OR gate is q V •r. Therefore the output of the AND gate is p /\ (q V •r). Therefore the output of this circuit is •(P /\ (q V •r)). b) The output of the top AND gate is (•p) /\ (•q). The output of the bottom AND gate is p /\ r. Therefore the output of this circuit is ( (•p) /\ (•q)) V (p /\ r). 43. We have the inputs come in from the left, in some cases passing through an inverter to form their negations. Certain pairs of them enter OR gates, and the outputs of these and other negated inputs enter AND gates. The outputs of these AND gates enter the final OR gate. SECTION 1.3 Propositional Equivalences The solutions to Exercises 1-10 are routine; we use truth tables to show that a proposition is a tautology or that two propositions are equivalent. The reader should do more than this, however; think about what the equivalence is saying. See Exercise 11 for this approach. Some important topics not covered in the text are introduced in this exercise set, including the notion of the dual of a proposition, disjunctive normal form for propositions, functional completeness, satisfiability, and two other logical connectives, NAND and NOR. Much of this material foreshadows the study of Boolean algebra in Chapter 12. 1. First we construct the following truth tables, for the propositions we are asked to deal with. pVF pVT p /\ p p p/\ T pt\ F pVp T T T T F T F F T F F F The first equivalence, p /\ T p, is valid because the second column p /\ T is identical to the first column p. Similarly, part (b) comes from looking at columns three and one. Since column four is a column of F's, and column five is a column of T's, part ( c) and part ( d) hold. Finally, the last two parts follow from the fact that the last two columns are identical to the first column. T F = Chapter 1 12 The Foundations: Logic and Proofs 3. We construct the following truth tables. p q pVq qVp p/\ q q /\p T T T T T T T T F T F F F T T T F F F F F F F F Part (a) follows from the fact that the third and fourth columns are identical; part (b) follows from the fact that the fifth and sixth columns are identical. 5. We construct the following truth table and note that the fifth and eighth columns are identical. p q r qVr p/\(qVr) p /\ q p /\ r (p/\q) V (p/\r) T T T T F F F F T T F F T T F F T F T F T F T F T T T F T T T F T T T F F F F F T T F F F F F F T F T F F F F F T T T F F F F F 7. De Morgan's laws tell us that to negate a conjunction we form the disjunction of the negations, and to negate a disjunction we form the conjunction of the negations. a) This is the conjunction "Jan is rich, and Jan is happy." So the negation is "Jan is not rich, or Jan is not happy." b) This is the disjunction '"Carlos will bicycle tomorrow, or Carlos will run tomorrow." So the negation is ''Carlos will not bicycle tomorrow, and Carlos will not run tomorrow." We could also render this as ''Carlos will neither bicycle nor run tomorrow.'' c) This is the disjunction ''Mei walks to class, or Mei takes the bus to class." So the negation is ''Mei does not walk to class, and Mei does not take the bus to class." (Maybe she gets a ride with a friend.) We could also render this as ''Mei neither walks nor takes the bus to class." d) This is the conjunction ''Ibrahim is smart, and Ibrahim is hard working." So the negation is "Ibrahim is not smart, or Ibrahim is not hard working.'' 9. We construct a truth table for each conditional statement and note that the relevant column contains only T's. For parts (a) and (b) we have the following table (column four for part (a), column six for part (b)). E____!l_ T T F T F T F F p /\ q (p /\ q) T F F F --+ p T T T T p vq T T T F p --+ (p v q) T T T T For parts ( c) and ( d) we have the following table (columns five and seven, respectively). P q TT TF F T F F 'P P-+ q F F T F T T T T 'P -+ (p-+ q) T T T T P /\ q T F F F (p /\ q) -+ (p--+ q) T T T T For parts (e) and (f) we have the following table. Column five shows the answer for part (e), and column seven shows the answer for part ( f). Section 1.3 13 Propositional Equivalences p p q T T T F T F F F T F T T ---'> q •(p ---'> q) •(p ---'> F q) ---'> p •(p •q ---'> q) T T T F T T T F F T T F T T T ---'> -,q 11. Here is one approach: Recall that the only way a conditional statement can be false is for the hypothesis to be true and the conclusion to be false; hence it is sufficient to show that the conclusion must be true whenever the hypothesis is true. An alternative approach that works for some of these tautologies is to use the equivalences given in this section and prove these "algebraically." We will demonstrate this second method in some of the solutions. a) If the hypothesis is true, then by the definition of /\ we know that p is true. Hence the conclusion is also true. For an algebraic proof, we exhibit the following string of equivalences, each one following from one of the laws in this section: (p /\ q) ---+ p = -, (p /\ q) V p = (•p V •q) V p = (•q V •p) V p = •q V (•P V p) = •q V T T. The first logical equivalence is the first equivalence in Table 7 (with p /\ q playing the role of p, and p playing the role of q ); the second is De Morgan's law; the third is the commutative law; the fourth is the associative law; the fifth is the negation law (with the commutative law); and the sixth is the domination law. = b) If the hypothesis p is true, then by the definition of V, the conclusion p V q must also be true. c) If the hypothesis is true, then p must be false; hence the conclusion p ---+ q is true, since its hypothesis is false. Symbolically we have •p---+ (p---+ q) = ••p V (•P V q) = p V (•p V q) = (p V •p) V q =TV q = T. d) If the hypothesis is true, then by the definition of /\ we know that q must be true. This makes the conclusion p ---+ q true, since its conclusion is true. e) If the hypothesis is true, then p what we wanted to show. ---+ q must be false. But this can happen only if p is true, which is precisely f) If the hypothesis is true, then p what we wanted to show. ---+ q must be false. But this can happen only if q is false, which is precisely 13. We first construct truth tables and verify that in each case the two propositions give identical columns. The fact that the fourth column is identical to the first column proves part (a), and the fact that the sixth column is identical to the first column proves part {b). p q p /\ q T T T F F T F F Alternately, we can argue as follows. T F F F p v (p /\ q) T T F F p vq T T T F p /\ (p v q) T T F F a) If p is true, then p V (p /\ q) is true, since the first proposition in the disjunction is true. On the hand, if p is false, then both parts of the disjunction are false. Hence p V (p /\ q) always has the same value as p does, so the two propositions are logically equivalent. b) If p is false, then p /\ (p V q) is false, since the first proposition in the conjunction is false. On the hand, if p is true, then both parts of the conjunction are true. Hence p /\ (p V q) always has the same value as p does, so the two propositions are logically equivalent. other truth other truth 15. We need to determine whether we can find an assignment of truth values to p and q to make this proposition false. Let us try to find one. The only way that a conditional statement can be false is for the hypothesis to be true and the conclusion to be false. Hence we must make •P false, which means we must make p true. Furthermore, in order for the hypothesis to be true, we will need to make q false, so that the first part of the conjunction will be true. But now with p true and q false, the second part of the conjunction is false. 14 Chapter 1 The Foundations: Logic and Proofs Therefore the entire hypothesis is false, so this assignment will not yield a false conditional statement. Since we have argued that no assignment of truth values can make this proposition false, we have proved that this proposition is a tautology. (An alternative approach would be to construct a truth table and see that its final column had only T's in it.) This tautology is telling us that if we know that a conditional statement is true, and that its conclusion is false, then we can conclude that its antecedent is also false. 17. The proposition -.(p f--7 q) is true when p and q do not have the same truth values, which means that p and q have different truth values (either p is true and q is false, or vice versa). These are exactly the cases in which p f--7 -.q is true. Therefore these two expressions are true in exactly the same instances, and therefore are logically equivalent. 19. The proposition -.p f--7 q is true when -.p and q have the same truth values, which means that p and q have different truth values (either p is true and q is false, or vice versa). By the same reasoning, these are exactly the cases in which p f--7 --iq is true. Therefore these two expressions are true in exactly the same instances, and therefore are logically equivalent. 21. This is essentially the same as Exercise 17. The proposition -i(p f--7 q) is true when p f--7 q is false. Since p f--7 q is true when p and q have the same truth value, it is false when p and q have different truth values (either p is true and q is false, or vice versa). These are precisely the cases in which -.p f--7 q is true. 23. We'll determine exactly which rows of the truth table will have F as their entries. In order for (p _, r) I\ ( q _, r) to be false, we must have at least one of the two conditional statements false, which happens exactly when r is false and at least one of p and q is true. But these are precisely the cases in which p V q is true and r is false, which is precisely when (p V q) _, r is false. Since the two propositions are false in exactly the same situations, they are logically equivalent. 25. We'll determine exactly which rows of the truth table will have Fas their entries. In order for (p _, r)V(q _, r) to be false, we must have both of the two conditional statements false, which happens exactly when r is false and both p and q are true. But this is precisely the case in which p I\ q is true and r is false, which is precisely when (p I\ q) _, r is false. Since the two propositions are false in exactly the same situations, they are logically equivalent. 27. This fact was observed in Section 1.1 when the biconditional was first defined. Each of these is true precisely when p and q have the same truth values. 29. We will show that if p _, q and q _, r are both true, then p _, r is true. Thus we want to show that if p is true, then so is r. Given that p and p _, q are both true, we conclude that q is true; from that and q _, r we conclude that r is true, as desired. This can also be done with a truth table. 31. To show that these are not logically equivalent, we need only find one assignment of truth values to p, q, and r for which the truth values of (p _, q) _, r and p _, (q _, r) differ. One such assignment is F for all three. Then (p _, q) _, r is false and p _, (q _, r) is true. 33. To show that these are not logically equivalent, we need only find one assignment of truth values to p, q, r, and s for which the truth values of (p _, q) _, (r _, s) and (p _, r) _, (q _, s) differ. Let us try to make the first one false. That means we have to make r _, s false, so we want r to be true and s to be false. If we let p and q be false, then each of the other three simple conditional statements (p _, q, p _, r, and q _, s) will be true. Then (p-t q) _, (r _, s) will be T-t F, which is false; but (p-t r) _, (q _, s) will be T-t T, which is true. Section 1.3 Propositional Equivalences 15 35. We apply the rules stated in the preamble. a) pV-.qV-.r b) (pVqVr)/\s c) (p/\T)V(q/\F) 37. If we apply the operation for forming the dual twice to a proposition, then every symbol returns to what it originally was. The /\ changes to the V, then changes back to the /\. Similarly the V changes to the /\, then back to the V. The same thing happens with the T and the F. Thus the dual of the dual of a proposition s, namely (s*)*, is equal to the original proposition s. 39. Let p and q be two compound propositions involving only the operators /\, V, and -, ; we can also allow them to involve the constants T and F. We want to show that if p and q are logically equivalent, then p* and q* are logically equivalent. The trick is to look at 'P and -.q. They are certainly logically equivalent if p and q are. Now if p is a conjunction, say r /\ s, then 'P is logically equivalent, by De Morgan's law, to -.r V -.s; a similar statement applies if p is a disjunction. If r and/or s are themselves compound propositions, then we apply De Morgan's laws again to "push" the negation symbol -, deeper inside the formula, changing /\ to V and V to /\. We repeat this process until all the negation signs have been "pushed in" as far as possible and are now attached to the atomic (i.e., not compound) propositions in the compound propositions p and q. Call these atomic propositions p 1 , p 2 , etc. Now in this process De Morgan's laws have forced us to change each /\ to V and each V to /\. Furthermore, if there are any constants T or F in the propositions, then they will be changed to their opposite when the negation operation is applied: -.T is the same as F, and -.F is the same as T. In summary, 'P and -.q look just like p* and q*, except that each atomic proposition p, within them is replaced by its negation. Now we agreed that 'P -.q; this means that for every possible assignment of truth values to the atomic propositions p 1 , P2, etc., the truth values of 'P and -.q are the same. But assigning T to Pi is the same as assigning F to 'Pi , and assigning F to p, is the same as assigning T to 'Pi . Thus, for every possible assignment of truth values to the atomic propositions, the truth values of p* and q* are the same. This is precisely what we wanted to prove. = 41. There are three ways in which exactly two of p, q, and r can be true. We write down these three possibilities as conjunctions and join them by V to obtain the answer: (p /\ q /\ -.r) V (p /\ -.q /\ r) V (-.p /\ q /\ r). See Exercise 42 for a more general result. 43. Given a compound proposition p, we can construct its truth table and then, by Exercise 42, write down a proposition q in disjunctive normal form that is logically equivalent to p. Since q involves only -, , /\, and V, this shows that -, , /\, and V form a functionally complete collection of logical operators. 45. Given a compound proposition p, we can, by Exercise 43, write down a proposition q that is logically equivalent to p and uses only ' , /\, and V. Now by De Morgan's law we can get rid of all the /\ 's by replacing each occurrence of P1 /\ P2 /\ · · · /\ Pn with the equivalent proposition -.(-.pi V 'P2 V · · · V 'Pn). 47. The proposition -.(p /\ q) is true when either p or q, or both, are false, and is false when both p and q are true; since this was the definition of p I q, the two are logically equivalent. 49. The proposition -.(p V q) is true when both p and q are false, and is false otherwise; since this was the definition of p l q, the two are logically equivalent. 51. A straightforward approach, using the results of Exercise 50, parts (a) and (b), is as follows: (p ----+ q) = (-.p V q) =((pl p) V q) =(((pl p) l q) l ((pl p) l q)). If we allow the constant F in our expression, then a simpler answer is Fl ((Fl p) l q). 53. This is clear from the definition, in which p and q play a symmetric role. 16 Chapter 1 The Foundations: Logic and Proofs 55. A truth table for a compound proposition involving p and q has four lines, one for each of the following combinations of truth values for p and q: TT, TF, FT, and FF. Now each line of the truth table for the compound proposition can be either T or F. Thus there are two possibilities for the first line; for each of those there are two possibilities for the second line, giving 2 · 2 = 4 possibilities for the first two lines; for each of those there are two possibilities for the third line, giving 4 · 2 = 8 possibilities for the first three lines; and finally for each of those, there are two possibilities for the fourth line, giving 8 · 2 = 16 possibilities altogether. This sort of counting will be studied extensively in Chapter 6. 57. Let do, me, and in stand for the propositions "The directory database is opened,'' "The monitor is put in a closed state," and "The system is in its initial state,'' respectively. Then the given statement reads -iin ___, (do ___, me). By the third line of Table 7 (twice), this is equivalent to in V (-ido V me). In words, this says that it must always be true that either the system is in its initial state, or the data base is not opened, or the monitor is put in a closed state. Another way to render this would be to say that if the database is open, then either the system is in its initial state or the monitor is put in a closed state. 59. Disjunctions are easy to make true, since we just have to make sure that at least one of the things being "or-ed" is true. In this problem, we notice that 'P occurs in four of the disjunctions, so we can satisfy all of them by making p false. Three of the remaining disjunctions contain r, so if we let r be true, those will be taken care of. That leaves only p V --.q V s and q V --.r V --.s , and we can satisfy both of those by making q and s both true. This assignment, then, makes all nine of the disjunctions true. 61. a) With a little trial and error we discover that setting p = F and q = F produces (FVT) /\ (TVF) /\ (TVT), which has the value T. So this compound proposition is satisfiable. (Note that this is the only satisfying truth assignment.) b) We claim that there is no satisfying truth assignment here. No matter what the truth values of p and q might be, the four implications become T ___, T, T ___, F, F ___, T, and F ___, F, in some order. Exactly one of these is false, so their conjunction is false. c) This compound proposition is not satisfiable. In order for the first clause, p +-+ q, to be true, p and q must have the same truth value. In order for the second clause, (--.p) +-+ q, to be true, p and q must have opposite truth values. These two conditions are incompatible, so there is no satisfying truth assignment. 63. This is done in exactly the same manner as was described in the text for a 9 x 9 Sudoku puzzle, with the variables indexed from 1 to 4, instead of from 1 to 9, and with a similar change for the propositions for the 2 X 2 blocks: /\~=O /\~=O /\!=l v;=l V~=l p(2r + i, 2s + j, n). 65. We just repeat the discussion in the text, with the roles of the rows and columns interchanged: To assert that column j contains the number n, we form v;= 1 p(i,j,n). To assert that column j contains all 9 numbers, we form the conjunction of these disjunctions over all nine possible values of n, giving us /\~=l Vi=l p( i, j, n). To assert that every column contains every number, we take the conjunction of /\~=l 1 p(i,j,n) over all nine columns. This gives us /\~= 1 /\~= 1 v;= 1 p( i, j, n). Vi= Section 1.4 Predicates and Quantifiers 17 SECTION 1.4 Predicates and Quantifiers The reader may find quantifiers hard to understand at first. Predicate logic (the study of propositions with quantifiers) is one level of abstraction higher than propositional logic (the study of propositions without quantifiers). Careful attention to this material will aid you in thinking more clearly, not only in mathematics but in other areas as well, from computer science to politics. Keep in mind exactly what the quantifiers mean: Yx means "for all x" or "for every x," and ::Jx means "there exists an x such that" or "for some x." It is good practice to read every such sentence aloud, paying attention to English grammar as well as meaning. It is very important to understand how the negations of quantified statements are formed, and why this method is correct; it is just common sense, really. The word "any" in mathematical statements can be ambiguous, so it is best to avoid using it. In negative contexts it almost always means "some" (existential quantifier), as in the statement "You will be suspended from school if you are found guilty of violating any of the plagiarism rules" (you don't have to violate all the rules to get into trouble-breaking one is sufficient). In positive contexts, however, it can mean either "some" (existential quantifier) or "every" (universal quantifier), depending on context. For example, in the sentence "The fraternity will be put on probation if any of its members is found intoxicated," the use is existential (one drunk brother is enough to cause the sanction); but in the sentence "Any member of the sorority will be happy to lead you on a tour of the house," the use is universal (every member is able to be the guide). Another interesting example is an exercise in a mathematics textbook that asks you to show that "the sum of any two odd numbers is even." The author clearly intends the universal interpretation here-you need to show that the sum of two odd numbers is always even. If you interpreted the question existentially, you might say, "Look, 3 + 5 = 8, so I've shown it is true--you said I could do it for any numbers, and those are the ones I chose.'' 1. a) T, since 0 :::; 4 b) T, since 4 :::; 4 c) F, since 6 i 4 3. a) This is true. b) This is false, since Lansing, not Detroit, is the capital. c) This is false (but Q(Boston, Massachusetts) is true). d) This is false, since Albany, not New York, is the capital. 5. a) There is a student who spends more than five hours every weekday in class. b) Every student spends more than five hours every weekday in class. c) There is a student who does not spend more than five hours every weekday in class. d) No student spends more than five hours every weekday in class. (Or, equivalently, every student spends less than or equal to five hours every weekday in class.) 7. a) This statement is that for every x, if x is a comedian, then x is funny. In English, this is most simply stated, "Every comedian is funny." b) This statement is that for every x in the domain (universe of discourse), x is a comedian and x is funny. In English, this is most simply stated, "Every person is a funny comedian." Note that this is not the sort of thing one wants to say. It really makes no sense and doesn't say anything about the existence of boring comedians; it's surely false, because there exist lots of x for which C(x) is false. This illustrates the fact that you rarely want to use conjunctions with universal quantifiers. c) This statement is that there exists an x in the domain such that if x is a comedian then x is funny. In English, this might be rendered, "There exists a person such that ifs/he is a comedian, then s/he is funny." Note that this is not the sort of thing one wants to say. It really makes no sense and doesn't say anything about the existence of funny comedians; it's surely true, because tbere exist lots of x for which C(x) is false (recall Chapter 1 18 The Foundations: Logic and Proofs the definition of the truth value of p -+ q). This illustrates the fact that you rarely want to use conditional statements with existential quantifiers. d) This statement is that there exists an x in the domain such that x is a comedian and x is funny. In English, this might be rendered, ''There exists a funny comedian" or "Some comedians are funny" or "Some funny people are comedians." 9. a) We assume that this sentence is asserting that the same person has both talents. Therefore we can write 3x(P(x) /\ Q(x)). b) Since "but" really means the same thing as "and" logically, this is 3x(P(x) /\ •Q(x)) c) This time we are making a universal statement: Vx(P(x) V Q(x)) d) This sentence is asserting the nonexistence of anyone with either talent, so we could write it as -,::Jx(P(x) V Q(x)). Alternatively, we can think of this as asserting that everyone fails to have either of these talents, and we obtain the logically equivalent answer 'v'x•(P(x) V Q(x)). Failing to have either talent is equivalent to having neither talent (by De Morgan's law), so we can also write this as Vx((•P(x)) /\ (•Q(x)). Note that it would not be correct to write Vx((•P(x)) V (•Q(x)) nor to write 'v'x•(P(x) /\ Q(x)). 11. a) T, since 0 = 02 d) F, since -1-=/:- (-1) 2 b) T, since 1 = 12 e) T (let x = 1) c) F, since 2 f 22 f) F (let x = 2 ) 13. a) Since adding 1 to a number makes it larger, this is true. b) Since 2 · 0 = 3 · 0, this is true. c) This statement is true, since 0 = -0. d) This is true for the nonnegative integers but not for the negative integers. For example, 3(-2) 'f:_ 4(-2). Therefore the universally quantified statement is false. 15. Recall that the integers include the positive and negative integers and 0. a) This is the well-known true fact that the square of a real number cannot be negative. b) There are two real numbers that satisfy n 2 = 2, namely ±J2, but there do not exist any integers with this property, so the statement is false. c) If n is a positive integer, then n 2 ;:::: n is certainly true; it's also true for n = 0; and it's trivially true if n is negative. Therefore the universally quantified statement is true. d) Squares can never be negative; therefore this statement is false. 17. Existential quantifiers are like disjunctions, and universal quantifiers are like conjunctions. See Examples 11 and 16. a) We want to assert that P(x) is true for some x in the universe, so either P(O) is true or P(l) is true or P(2) is true or P(3) is true or P(4) is true. Thus the answer is P(O) V P(l) V P(2) V P(3) V P(4). The other parts of this exercise are similar. Note that by De Morgan's laws, the expression in part (c) is logically equivalent to the expression in part (f), and the expression in part (d) is logically equivalent to the expression in part (e). b) P(O) /\ P(l) /\ P(2) /\ P(3) /\ P(4) c) •P(O) V ·P(l) V ·P(2) V ·P(3) V ·P(4) d) ·P(O) /\ ·P(l) /\ ·P(2) /\ ·P(3) /\ ·P(4) e) This is just the negation of part (a): •(P(O) V P(l) V P(2) V P(3) V P(4)) f) This is just the negation of part (b): •(P(O) /\ P(l) /\ P(2) /\ P(3) /\ P(4)) Section 1.4 Predicates and Quantifiers 19 19. Existential quantifiers are like disjunctions, and universal quantifiers are like conjunctions. See Examples 11 and 16. a) We want to assert that P(x) is true for some x in the universe, so either P(l) is true or P(2) is true or P(3) is true or P(4) is true or P(5) is true. Thus the answer is P(l) V P(2) V P(3) V P(4) V P(5). b) P(l) /\ P(2) /\ P(3) /\ P( 4) /\ P(5) c) This is just the negation of part (a): •(P(l) V P(2) V P(3) V P(4) V P(5)) d) This is just the negation of part (b): •(P(l) /\ P(2) /\ P(3) /\ P(4) /\ P(5)) e) The formal translation is as follows: (((1 =I- 3) -+ P(l)) /\ ((2 =I- 3) -+ P(2)) /\ ((3 =I- 3) -+ P(3)) /\ ((4 =I- 3) -+ P(4)) /\ ((5 =I- 3) -+ P(5))) V (•P(l) V -.P(2) V -.P(3) V -.P(4) V ·P(5)). However, since the hypothesis x =I- 3 is false when x is 3 and true when x is anything other than 3, we have more simply (P(l) /\ P(2) /\ P(4) /\ P(5)) V (•P(l) v-.P(2) v-.P(3) V •P(4) V •P(5)). Thinking about it a little more, we note that this statement is always true, since if the first part is not true, then the second part must be true. 21. a) One would hope that if we take the domain to be the students in your class, then the statement is true. If we take the domain to be all students in the world, then the statement is clearly false, because some of them are studying only other subjects. b) If we take the domain to be United States Senators, then the statement is true. If we take the domain to be college football players, then the statement is false, because some of them are younger than 21. c) If the domain consists of just Princes William and Harry of Great Britain (sons of the late Princess Diana), then the statement is true. It is also true if the domain consists of just one person (everyone has the same mother as him- or herself). If the domain consists of all the grandchildren of Queen Elizabeth II of Great Britain (of whom William and Harry are just two), then the statement is false. d) If the domain consists of Bill Clinton and George W. Bush, then this statement is true because they do not have the same grandmother. If the domain consists of all residents of the United States, then the statement is false, because there are many instances of siblings and first cousins, who have at least one grandmother in common. 23. In order to do the translation the second way, we let C(x) be the propositional function "x is in your class." Note that for the second way, we always want to use conditional statements with universal quantifiers and conjunctions with existential quantifiers. a) Let H (x) be "x can speak Hindi." Then we have 3x H (x) the first way, or 3x (C (x) /\ H (x)) the second way. b) Let F(x) be "x is friendly." Then we have 't:/x F(x) the first way, or 't:/x(C(x)-+ F(x)) the second way. c) Let B(x) be "x was born in California." Then we have 3x-.B(x) the first way, or 3x(C(x) /\ -.B(x)) the second way. d) Let M(x) be "x has been in a movie." Then we have 3xM(x) the first way, or 3x(C(x) /\ M(x)) the second way. e) This is saying that everyone has failed to take the course. So the answer here is 't:/x -.L(x) the first way, or 't:/x(C(x)-+ -.L(x)) the second way, where L(x) is "x has taken a course in logic programming." 25. Let P(x) be "x is perfect"; let F(x) be "x is your friend"; and let the domain (universe of discourse) be all people. a) This means that everyone has the property of being not perfect: 't:/x •P(x). Alternatively, we can write this as --,::Jx P(x), which says that there does not exist a perfect person. b) This is just the negation of "Everyone is perfect": --,\:/x P( x). c) If someone is your friend, then that person is perfect: 't:/x(F(x) statement with universal quantifiers. -+ P(x)). Note the use of conditional 20 Chapter 1 The Foundations: Logic and Proofs d) We do not have to rule out your having more than one perfect friend. Thus we have simply :Jx(F(x)/\P(x)). Note the use of conjunction with existential quantifiers. e) The expression is Vx(F(x) /\ P(x)). Note that here we did use a conjunction with the universal quantifier, but the sentence is not natural (who could claim this?). We could also have split this up into two quantified statements and written (Vx F(x)) /\(\Ix P(x)). f) This is a disjunction. The expression is (--NxF(x)) V (:Jx....,P(x)). 27. In all of these, we will let Y(x) be the propositional function that x is in your school or class, as appropriate. a) If we let V(x) be "x has lived in Vietnam," then we have :lx V(x) if the universe is just your schoolmates, or :Jx(Y(x) /\ V(x)) if the universe is all people. If we let D(x, y) mean that person x has lived in country y, then we can rewrite this last one as :Jx(Y(x) /\ D(x, Vietnam)). b) Ifwe let H(x) be "x can speak Hindi," then we have :Jx-,H(x) ifthe universe is just your schoolmates, or 3x(Y(x) /\ -iH(x)) if the universe is all people. If we let S(x, y) mean that person x can speak language y, then we can rewrite this last one as 3x(Y(x) /\ -,S(x, Hindi)). c) If we let J(x), P(x), and C(x) be the propositional functions asserting x 's knowledge of Java, Prolog, and C++, respectively, then we have :Jx(J(x) /\P(x) /\C(x)) if the universe is just your schoolmates, or :Jx(Y(x) /\ J(x) /\ P(x) /\ C(x)) if the universe is all people. If we let K(x, y) mean that person x knows programming language y, then we can rewrite this last one as 3x(Y(x) /\ K(x, Java)/\ K(x, Prolog) /\ K(x, C++ )) . d) If we let T(x) be "x enjoys Thai food," then we have VxT(x) if the universe is just your classmates, or Vx(Y(x) -+ T(x)) if the universe is all people. If we let E(x, y) mean that person x enjoys food of type y, then we can rewrite this last one as Vx(Y(x) -+ E(x, Thai)). e) If we let H (x) be "x plays hockey,'' then we have 3x -,H (x) if the universe is just your classmates, or :Jx(Y(x) /\ -iH(x)) if the universe is all people. If we let P(x, y) mean that person x plays game y, then we can rewrite this last one as :Jx(Y(x) /\ -iP(x, hockey)). 29. Our domain (universe of discourse) here is all propositions. Let T(x) mean that x is a tautology and C(x) mean that x is a contradiction. Since a contingency is just a proposition that is neither a tautology nor a contradiction, we do not need a separate predicate for being a contingency. a) This one is just the assertion that tautologies exist: :Jx T(x). b) Although the word "all" or "every" does not appear here, this sentence is really expressing a universal meaning, that the negation of a contradiction is always a tautology. So we want to say that if x is a contradiction, then -ix is a tautology. Thus we have Vx(C(x) -+ T(-,x)). Note the rare use of a logical symbol (negation) applied to a variable ( x); this is purely a coincidence in this exercise because the universe happens itself to be propositions. c) The words "can be" are expressing an existential idea-that there exist two contingencies whose disjunction is a tautology. Thus we have :Jx:Jy( -iT(x) /\ -iC(x) /\ -iT(y) /\ -iC(y) /\ T(x Vy)). The same final comment as in part (b) applies here. Also note the explanation about contingencies in the preamble. d) As in part (b ), this is the universal assertion that whenever x and y are tautologies, then so is x /\ y; thus we have Vx\ly((T(x) /\ T(y)) -+ T(x /\ y)). 31. In each case we just have to list all the possibilities, joining them with V if the quantifier is :J, and joining them with /\ if the quantifier is V. a) Q(O, 0,0) /\ Q(O, 1, 0) b) Q(O, 1, 1) V Q(l, 1, 1) V Q(2, 1, 1) c) -iQ(O, 0, 0) V -iQ(O, 0, 1) d) -iQ(O, 0, 1) V -iQ(l, 0, 1) V -iQ(2, 0, 1) 33. In each case we need to specify some predicates and identify the domain (universe of discourse). a) Let T(x) be the predicate that x can learn new tricks, and let the domain be old dogs. Our original statement is :Jx T(x). Its negation is -,::Jx T(x), which we must to rewrite in the required manner as Vx -iT(x). Section 1.4 Predicates and Quantifiers 21 In English this reads "Every old dog is unable to learn new tricks" or "All old dogs can't learn new tricks." (Note that this does not say that not all old dogs can learn new tricks-it is saying something stronger than that.) More colloquially, we can say "No old dogs can learn new tricks." b) Let C(x) be the predicate that x knows calculus, and let the domain be rabbits. Our original statement is --.3x C(x). Its negation is, of course, simply 3x C(x). In English this reads "There is a rabbit that knows calculus.'' c) Let F(x) be the predicate that x can fly, and let the domain be birds. Our original statement is l::/x F(x). Its negation is --.1::/x F(x) (i.e., not all birds can fly), which we must to rewrite in the required manner as 3x --.F (x) . In English this reads "There is a bird who cannot fly." d) Let T(x) be the predicate that x can talk, and let the domain be dogs. Our original statement is --.3xT(x). Its negation is, of course, simply 3xT(x). In English this reads "There is a dog that talks." e) Let F(x) and R(x) be the predicates that x knows French and knows Russian, respectively, and let the domain be people in this class. Our original statement is --.3x(F(x) /\ R(x)). Its negation is, of course, simply 3x(F(x) /\ R(x)). In English this reads "There is someone in this class who knows French and Russian." 35. a) As we saw in Example 13, this is true, so there is no counterexample. b) Since 0 is neither greater than nor less than 0, this is a counterexample. c) This proposition says that 1 is the only integer-that every integer equals 1. If is obviously false, and any other integer, such as -111749, provides a counterexample. 37. In each case we need to make up predicates. The answers are certainly not unique and depend on the choice of predicate, among other things. a) l::/x((F(x,25000) V S(x,25)) _, E(x)), where E(x) is "Person x qualifies as an elite flyer in a given year," F(x, y) is "Person x flies more than y miles in a given year,'' and S(x, y) is "Person x takes more than y flights in a given year" b) l::/x(((M(x)/\T(x, 3))V(•M(x)/\T(x, 3.5))) _, Q(x)), where Q(x) is "Person x qualifies for the marathon," l'vf(x) is "Person x is a man,'' and T(x, y) is "Person x has run the marathon in less than y hours" c) M _, ((H(60) V (H(45) /\ T)) /\ l::/yG(B,y)), where Mis the proposition ''The student received a masters degree," H(x) is "The student took at least x course hours," T is the proposition "The student wrote a thesis," and G(x, y) is "The person got grade x or higher in his course y" d) 3x ((T(x, 21) /\ G(x, 4.0)), where T(x, y) is "Person x took more than y credit hours" and G(x,p) is "Person x earned grade point average p" (we assume that we are talking about one given semester) 39. In each case we pretty much just write what we see. a) If there is a printer that is both out of service and busy, then some job has been lost. b) If every printer is busy, then there is a job in the queue. c) If there is a job that is both queued and lost, then some printer is out of service. d) If every printer is busy and every job is queued, then some job is lost. 41. In each case we need to make up predicates. The answers are certainly not unique and depend on the choice of predicate, among other things. a) (3x F(x, 10)) _, 3x S(x), where F(x, y) is "Disk x has more than y kilobytes of free space,'' and S(x) is "Mail message x can be saved" b) (3xA(x)) _, l::/x(Q(x) _, T(x)), where A(x) is ''Alert xis active," Q(x) is "Message xis queued," and T(x) is "Message x is transmitted" c) l::/x((x -1- main console)_, T(x)), where T(x) is "The diagnostic monitor tracks the status of system x" d) l::/x(•L(x) _, B(x)), where L(x) is "The host of the conference call put participant x on a special list'' and B(x) is "Participant x was billed" 22 Chapter 1 The Foundations: Logic and Proofs 43. A conditional statement is true if the hypothesis is false. Thus it is very easy for the second of these propositions to be true-just have P(x) be something that is not always true, such as "The integer x is a multiple of 2.'' On the other hand, it is certainly not always true that if a number is a multiple of 2, then it is also a multiple of 4, so if we let Q(x) be "The integer xis a multiple of 4,'' then \ix(P(:r) _, Q(x)) will be false. Thus these two propositions can have different truth values. Of course, for some choices of P and Q, they will have the same truth values, such as when P and Q are true all the time. 45. Both are true precisely when at least one of P(x) and Q(x) is true for at least one value of x in the domain (universe of discourse). 47. We can establish these equivalences by arguing that one side is true if and only if the other side is true. For both parts, we will look at the two cases: either A is true or A is false. a) Suppose that A is true. Then the left-hand side is logically equivalent to \:/xP(x), since the conjunction of any proposition with a true proposition has the same truth value as that proposition. By similar reasoning the right-hand side is equivalent to \ixP(x). Therefore the two propositions are logically equivalent in this case; each one is true precisely when P(x) is true for every x. On the other hand, suppose that A is false. Then the left-hand side is certainly false. Furthermore, for every x, P(x) A A is false, so the right-hand side is false as well. Thus in all cases, the two propositions have the same truth value. b) This problem is similar to part (a). If A is true, then both sides are logically equivalent to 3xP( x). If A is false, then both sides are false. 49. We can establish these equivalences by arguing that one side is true if and only if the other side is true. For both parts, we will look at the two cases: either A is true or A is false. a) Suppose that A is true. Then for each x, P(x) _,A is true, because a conditional statement with a true conclusion is always true; therefore the left-hand side is always true in this case. By similar reasoning the right-hand side is always true in this case (here we used the fact that the domain is nonempty). Therefore the two propositions are logically equivalent when A is true. On the other hand, suppose that A is false. There are two sub cases. If P( x) is false for every x, then P( x) _, A is vacuously true (a conditional statement with a false hypothesis is true), so the left-hand side is vacuously true. The same reasoning shows that the right-hand side is also true, because in this subcase 3xP(x) is false. For the second subcase, suppose that P(x) is true for some x. Then for that x, P(x) _,A is false (a conditional statement with a true hypothesis and false conclusion is false), so the left-hand side is false. The right-hand side is also false, because in this subcase :3xP(.r) is true but A is false. Thus in all cases, the two propositions have the same truth value. b) This problem is similar to part (a). If A is true, then both sides are trivially true, because the conditional statements have true conclusions. If A is false, then there are two subcases. If P( x) is false for some x, then P(x) _,A is vacuously true for that x (a conditional statement with a false hypothesis is true), so the left-hand side is true. The same reasoning shows that the right-hand side is true, because in this subcase \ixP(x) is false. For the second subcase, suppose that P(x) is true for every x. Then for every x, P(x) _,A is false (a conditional statement with a true hypothesis and false conclusion is false), so the left-hand side is false (there is no x making the conditional statement true). The right-hand side is also false, because it is a conditional statement with a true hypothesis and a false conclusion. Thus in all cases, the two propositions have the same truth value. 51. We can show that these are not logically equivalent by giving an example in which one is true and the other is false. Let P(x) be the statement "x is odd" applied to positive integers. Similarly let Q(x) be ''x is even." Then since there exist odd numbers and there exist even numbers, the statement 3xP(x) A 3xQ(x) is true. On the other hand, no number is both odd and even, so 3x(P(x) A Q(x)) is false. Section 1.5 Nested Quantifiers 23 53. a) This is certainly true: if there is a unique x satisfying P(x), then there certainly is an x satisfying P(x). b) Unless the domain (universe of discourse) has fewer than two items in it, the truth of the hypothesis implies that there is more than one x such that P(x) holds. Therefore this proposition need not be true. (For example, let P(x) be the proposition x 2 2:: 0 in the context of the real numbers. The hypothesis is true, but there is not a unique x for which x 2 2:: 0.) c) This is true: if there is an x (unique or not) such that P(x) is false, then we can conclude that it is not the case that P(x) holds for all x. 55. A Prolog query returns a yes/no answer if there are no variables in the query, and it returns all values that make the query true if there are. a) b) c) d) One of the facts was that Chan was the instructor of Math 273, so the response is yes. None of the facts was that Patel was the instructor of CS 301, so the response is no. Prolog returns the names of the people enrolled in CS 301, namely juana and kiko. Prolog returns the names of the courses Kiko is enrolled in, namely math273 and cs301. e) Prolog returns the names of the students enrolled in courses which Grossman is the instructor for (which is just CS 301), namely juana and kiko. 57. Following the idea and syntax of Example 28, we have the following rule: sibling(X, Y) :- mother(M,X), mother(M,Y), father(F,X), father(F,Y). Note that we used the comma to mean "and"; X and Y must have the same mother and the same father in order to be (full) siblings. 59. a) This is the statement that every person who is a professor is not ignorant. In other words, for every person, if that person is a professor, then that person is not ignorant. In symbols: Vx(P(x) ---+ •Q(x)). This is not the only possible answer. We could equivalently think of the statement as asserting that there does not exist an ignorant professor: --,:Jx(P(x) /\ Q(x)). b) Every person who is ignorant is vain: Vx(Q(x)---+ R(x)). c) This is similar to part (a): Vx(P(x)---+ ·R(x)). d) The conclusion (part ( c)) does not follow. There may well be vain professors, since the premises do not rule out the possibility that there are vain people besides the ignorant ones. 61. a) This is asserting that every person who is a baby is necessarily not logical: Vx(P(x)---+ •Q(x)). b) c) d) e) If a person can manage a crocodile, then that person is not despised: Vx(R(x)---+ •S(x)). Every person who is not logical is necessarily despised: Vx(•Q(x)---+ S(x)). Every person who is a baby cannot manage a crocodile: Vx(P(x)---+ ·R(x)). The conclusion follows. Suppose that x is a baby. Then by the first premise, x is illogical, and hence, by the third premise, x is despised. But the second premise says that if x could manage a crocodile, then x would not be despised. Therefore x cannot manage a crocodile. Thus we have proved that babies cannot manage crocodiles. SECTION 1.5 Nested Quantifiers Nested quantifiers are one of the most difficult things for students to understand. The theoretical definition of limit in calculus, for example, is hard to comprehend because it has three levels of nested quantifiers. Study the examples in this section carefully before attempting the exercises, and make sure that you understand the solutions to the exercises you have difficulty with. Practice enough of these until you feel comfortable. The effort will be rewarded in such areas as computer programming and advanced mathematics courses. Chapter 1 24 The Foundations: Logic and Proofs 1. a) For every real number x there exists a real number y such that x is less than y. Basically, this is asserting that there is no largest real number-for any real number you care to name, there is a larger one. b) For every real number x and real number y, if x and y are both nonnegative, then their product is nonnegative. Or, more simply, the product of nonnegative real numbers is nonnegative. c) For every real number x and real number y, there exists a real number z such that xy = z. Or, more simply, the real numbers are closed under multiplication. (Some authors would include the uniqueness of z as part of the meaning of the word closed.) 3. It is useful to keep in mind that x and y can be the same person, so sending messages to oneself counts in this problem. a) Formally, this says that there exist students x and y such that x has sent a message to y. In other words, there is some student in your class who has sent a message to some student in your class. b) This is similar to part (a) except that x has sent a message to everyone, not just to at least one person. So this says there is some student in your class who has sent a message to every student in your class. c) Note that this is not the same as part (b). Here we have that for every x there exists a y such that x has sent a message to y. In other words, every student in your class has sent a message to at least one student in your class. d) Note that this is not the same as part (c), since the order of quantifiers has changed. In part (c), y could depend on x; in other words, the recipient of the messages could vary from sender to sender. Here the existential quantification on y comes first, so it's the same recipient for all the messages. The meaning is that there is a student in your class who has been sent a message by every student in your class. e) This is similar to part ( c), with the role of sender and recipient reversed: every student in your class has been sent a message from at least one student in your class. Again, note that the sender can depend on the recipient. f) Every student in the class has sent a message to every student in the class. 5. a) This simply says that Sarah Smith has visited www. att. com. b) To say that an x exists such that x has visited www. imdb. org is just to say that someone (i.e., at least one person) has visited www. imdb. org. c) This is similar to part (b). Jose Orez has visited some website. d) This is asserting that a y exists that both of these students has visited. In other words, Ashok Puri and Cindy Yoon have both visited the same website. e) When there are two quantifiers of opposite types, the sentence gets more complicated. This is saying that there is a person ( y) other than David Belcher who has visited all the websites that David has visited (i.e., for every website z, if David has visited z, then so has this person). Note that it is not saying that this person has visited only websites that David has visited (that would be the converse conditional statement)-this person may have visited other sites as well. f) Here the existence of two people is being asserted; they are said to be unequal, and for every website z, one of these people has visited z if and only if the other one has. In plain English, there are two different people who have visited exactly the same websites. 7. a) Abdallah Hussein does not like Japanese cuisine. b) Note that this is the conjunction of two separate quantified statements. Some student at your school likes Korean cuisine, and everyone at your school likes Mexican cuisine. c) There is some cuisine that either Monique Arsenault or Jay Johnson likes. d) Formally this says that for every x and z, there exists a y such that if x and z are not equal, then it is not the case that both x and z like y. In simple English, this says that for every pair of distinct students at Section 1.5 Nested Quantifiers 25 your school, there is some cuisine that at least one them does not like. e) There are two students at your school who have exactly the same tastes (i.e., they like exactly the same cuisines). f) For every pair of students at your school, there is some cuisine about which they have the same opinion (either they both like it or they both do not like it). 9. We need to be careful to put the lover first and the lovee second as arguments in the propositional function L. a) 'VxL(x, Jerry) b) Note that the "somebody" being loved depends on the person doing the loving, so we have to put the universal quantifier first: 'Vx3yL(x, y). c) In this case, one lovee works for all lovers, so we have to put the existential quantifier first: 3y'VxL(x, y). d) We could think of this as saying that there does not exist anyone who loves everybody ( -i3x'VyL(x, y) ), or we could think of it as saying that for each person, we can find a person whom he or she does not love ('Vx3y-iL(x, y). These two expressions are logically equivalent. e) 3x-iL(Lydia, x) f) We are asserting the existence of an individual such that everybody fails to love that person: 3x'Vy-iL(y, x). g) In Exercises 52-54 of Section 1.4, we worked with a notation for the existence of a unique object satisfying a certain condition. Employing that device, we could write this as 3!x'VyL(y, x). In Exercise 52 of the present section we will discover a way to avoid this notation in general. What we have to say is that the x asserted here exists, and that every z satisfying this condition (of being loved by everybody) must equal x. Thus we obtain 3x('VyL(y, x) /\ 'Vz(('VwL(w, z)) -> z = x)). Note that we could have used y as the bound variable where we used w; since the scope of the first use of y had ended before we came to this point in the formula, reusing y as the bound variable would cause no ambiguity. h) We want to assert the existence of two distinct people, whom we will call x and y, whom Lynn loves, as well as make the statement that everyone whom Lynn loves must be either x or y: 3x3y(x =/=- y/\L(Lynn,x)/\ L(Lynn, y) /\ 'Vz(L(Lynn, z)-> (z = x V z = y))). i) 'VxL(x, x) (Note that nothing in our earlier answers ruled out the possibility that variables or constants with different names might be equal to each other. For example, in part (a), x could equal Jerry, so that statement includes as a special case the assertion that Jerry loves himself. Similarly, in part (h), the two people whom Lynn loves either could be two people other than Lynn (in which case we know that Lynn does not love herself), or could be Lynn herself and one other person.) j) This is asserting that the one and only one person who is loved by the person being discussed is in fact that person: 3x'Vy(L(x, y) +-+ x = y). 11. a) We might want to assert that Lois is a student and Michaels is a faculty member, but the sentence doesn't really say that, so the simple answer is just A(Lois, Professor Michaels). b) To say that every student (as opposed to every person) has done this, we need to restrict our universally quantified variable to being a student. The easiest way to do this is to make the assertion being quantified a conditional statement. As a general rule of thumb, use conditional statements with universal quantifiers and conjunctions with existential quantifiers (see part (d), for example). Thus our answer is 'Vx(S(x) -> A(x,Professor Gross)). c) This is similar to part (b): 'Vx(F(x)-> (A(x,Professor Miller) V A(Professor Miller,x))). Note the need for parentheses in these answers. d) There is a student such that for every faculty member, that student has not asked that faculty member a question. Note how we need to include the Sand F predicates: 3x(S(x) /\ 'Vy(F(y)-> -,A(x, y))). We could also write this as 3x(S(x) /\ -i3y(F(y) /\ A(x, y))). e) This is very similar to part (d), with the role of the players reversed: 3x(F(x) /\ 'Vy(S(y)-> -iA(y,x))). 26 Chapter 1 The Foundations: Logic and Proofs f) This is a little ambiguous in English. If the statement is that there is a very inquisitive student, one who has gone around and asked a question of every professor, then this is similar to part ( d), without the negation: 3x(S(x) /\ \:/y(F(y) ---> A(x, y))). On the other hand, the statement might be intended as asserting simply that for every professor, there exists some student who has asked that professor a question. In other words, the questioner might depend on the questionee. Note how the meaning changes with the change in order of quantifiers. Under the second interpretation the answer is \fy(F(y)---> 3x(S(x) /\ A(x, y))). The first interpretation is probably the intended one. g) This is pretty straightforward, except that we have to rule out the possibility that the askee is the same as the asker. Our sentence needs to say that there exists a faculty member such that for every other faculty member, the first has asked the second a question: 3x(F(x) /\ \fy((F(y) /\ y -:f x)---> A(x, y))). h) There is a student such that every faculty member has failed to ask him a question: 3x(S(x) /\ \fy(F(y)---> --.A(y, x))). 13. Be careful to put in parentheses where needed; otherwise your answer can be either ambiguous or wrong. a) Clearly this is simply --.M(Chou, Koko). b) We can give two answers, which are equivalent by De Morgan's law: --.(M(Arlene, Sarah)VT(Arlene, Sarah)) or --.M(Arlene, Sarah)/\ --.T(Arlene, Sarah). c) Clearly this is simply --.M(Deborah, Jose). d) Note that this statement includes the assertion that Ken has sent himself a message: \fx M(x, Ken). e) We can write this in two equivalent ways, depending on whether we want to say that everyone has failed to phone Nina or to say that there does not exist someone who has phoned her: \fx --.T(x, Nina) or --.3x T(x, Nina). f) This is almost identical to part (d): Vx(T(x,Avi) V M(x,Avi)). g) To get the "else" in there, we have to make sure that y is different from x in our answer: 3x\fy(y M(x, y)). h) This is almost identical to part (g): 3x\fy(y :f- x---> (M(x, y) V T(x, y))). #x i) We need to assert the existence of two distinct people who have sent e-mail both ways: 3x3y(x # ---> y /\ M(x, y) /\ M(y, x)). j) Only one variable is needed: 3x M(x, x). k) This poor soul (x in our expression) did not receive a message or a phone call (i.e., did not receive a message and did not receive a phone call) from any person y other than possibly himself: 3x\fy(x -:f y ---> (--.M(y,x) f\--.T(y,x))). 1) Here y is "another student": \:/x3y(x -:f y /\ (M(y, x) V T(y, x))). rn) This is almost identical to part (i): 3x3y(x -:f y /\ M(x, y) /\ T(y, x)). n) Note how the "everyone else" means someone different from both x and y in our expression (and note that there are four possibilities for how each such person z might be contacted): 3x3y(x # y /\ Vz((z # x /\ z :fy)---> (M(x, z) V M(y, z) V T(x, z) V T(y, z)))). 15. The answers presented here are not the only ones possible; other answers can be obtained using different predicates and different variables, or by varying the domain (universe of discourse). a) \:/xN(x, discrete mathematics), where N(x, y) is "x needs a course in y" and the domain for x is computer science students and the domain for y is academic subjects b) 3xO(x,personal computer), where O(x,y) is "x owns y," and the domain for xis students in this class c) \:/x3yP(x,y), where P(x,y) is "x has taken y"; x ranges over students in this class, and y ranges over computer science courses d) 3x3yP(x, y), with the environment of part (c) (i.e., the same definition of P and the same domain) Section 1.5 Nested Quantifiers 27 e) Vx\lyP(x,y), where P(x,y) is "x has been in y"; x ranges over students in this class, and y ranges over buildings on campus f) 3x3y\lz(P(z,y)--+ Q(x,z)), where P(z,y) is ''z is in y" and Q(x,z) is "x has been in z"; x ranges over students in this class, y ranges over buildings on campus, and z ranges over rooms g) Vx\ly3z(P(z, y) /\ Q(x, z)), with the environment of part (f) 17. a) We need to rule out the possibility that the user has access to another mailbox different from the one that is guaranteed: Vu3m(A(u, m) /\ Vn(n -1- m --+ ·A(u, n))), where A(u, m) means that user u has access to mailbox m. b) 3p\le(H(e)--+ S(p,running))-+ S(kernel,working correctly), where H(e) means that error condition e is in effect and S(x,y) means that the status of xis y. Obviously there are other ways to express this with different choices of predicates. Note that "only if" is the converse of "if,'' so the kernel's working properly is the conclusion, not the hypothesis. c) Vu\ls(E(s, .edu)--+ A(u,s)), where E(s,x) means that websites has extension x, and A(u,s) means that user u can access website s d) This is tricky, because we have to interpret the English sentence first, and different interpretations would lead to different answers. We will assume that the specification is that there exist two distinct systems such that they monitor every remote server, and no other system has the property of monitoring every remote system. Thus our answer is 3x3y(x -1- y /\ Vz((Vs M(z, s)) f-7 (z = x V z = y))), where M(a, b) means that system a monitors remote server b. Note that the last part of our expression serves two purposes-it says that x and y do monitor all servers, and it says that no other system does. There are at least two other interpretations of this sentence, which would lead to different legitimate answers. 19. a) Vx\ly((x < 0) /\ (y < 0)--+ (x + y < 0)) b) What does "necessarily" mean in this context? The best explanation is to assert that a certain universal conditional statement is not true. So we have ---,\fx\ly((x > 0) /\ (y > 0)--+ (x - y > 0)). Note that we do not want to put the negation symbol inside (it is not true that the difference of two positive integers is never positive), nor do we want to negate just the conclusion (it is not true that the sum is always nonpositive). We could rewrite our solution by passing the negation inside, obtaining 3x3y((x > 0) /\ (y > 0) /\ (x - y:::; 0)). + y 2 2: (x + y) 2 ) Vx\ly (lxyl = lxllYI) c) Vx\ly (x 2 d) 21. Vx3a3b3dd ((x > 0) --+ x = a 2 +b 2 +c 2 +d 2 ), where the domain (universe of discourse) consists of all integers 23. a) Vx\ly((x < 0) /\ (y < 0)--+ (xy > 0)) b)Vx(x-x=O) c) To say that there are exactly two objects that meet some condition, we must have two existentially quantified variables to represent the two objects, we must say that they are different, and then we must say that an object meets the conditions if and only if it is one of those two. In this case we have Vx3a3b (a -1- b /\ Vc(c 2 Xf-7 (c=aVc=b))). d) \Ix ((x < 0) --+ 3y (x 0 = y 2 )) = where the domain (universe of discourse) consists of all real numbers 25. a) This says that there exists a real number x such that for every real number y, the product xy equals y. That is, there is a multiplicative identity for the real numbers. This is a true statement, since x = 1 is the identity. b) The product of two negative real numbers is always a positive real number. c) There exist real numbers x and y such that x 2 exceeds y but x is less than y. This is true, since we can take x = 2 and y = 3, for instance. 28 Chapter 1 The Foundations: Logic and Proofs d) This says that for every pair of real numbers x and y , there exists a real number z that is their sum. In other words, the real numbers are closed under the operation of addition, another true fact. (Some authors would include the uniqueness of z as part of the meaning of the word closed.) 27. Recall that the integers include the positive and negative integers and 0. a) The import of this statement is that no matter how large n might be, we can always find an integer m bigger than n 2 . This is certainly true; for example, we could always take m = n 2 + 1. b) This statement is asserting that there is an n that is smaller than the square of every integer; note that n is not allowed to depend on m, since the existential quantifier comes first. This statement is true, since we could take, for instance, n = -3, and then n would be less than every square, since squares are always greater than or equal to 0. c) Note the order of quantifiers: m here is allowed to depend on n. Since we can take m = -n, this statement is true (additive inverses exist for the integers). d) Here one n must work for all m. Clearly n = 1 does the trick, so the statement is true. e) The statement is that the equation n 2 + m 2 = 5 has a solution over the integers. This is true; in fact there are eight solutions, namely n = ±1, m = ±2, and vice versa. f) The statement is that the equation n 2 + m 2 = 6 has a solution over the integers. There are only a small finite number of cases to try, since if lml or lnl were bigger than 2 then the left-hand side would be bigger than 6. A few minutes reflection shows that in fact there is no solution, so the existential statement is false. g) The statement is that the system of equations {n + m = 4, n - m = 1} has a solution over the integers. By algebra we see that there is a unique solution to this system, namely n = 2 ~, m = 1 ~ . Since there do not exist integers that make the equations true, the statement is false. h) The statement is that the system of equations {n + m = 4, n - m = 2} has a solution over the integers. By algebra we see that there is indeed an integral solution to this system, namely n = 3, m = 1. Therefore the statement is true. i) This statement says that the average of two integers is always an integer. If we take m = 1 and n = 2, for example, then the only p for which p = ( m + n) /2 is p = which is not an integer. Therefore the statement is false. q, 29. a) P(l, 1) /\ P(l, 2) /\ P(l, 3) /\ P(2, 1) /\ P(2, 2) /\ P(2, 3) /\ P(3, 1) /\ P(3, 2) /\ P(3, 3) b) P(l, 1) V P(l, 2) V P(l, 3) V P(2, 1) V P(2, 2) V P(2, 3) V P(3, 1) V P(3, 2) V P(3, 3) c) (P(l, 1) /\ P(l, 2) /\ P(l, 3)) V (P(2, 1) /\ P(2, 2) /\ P(2, 3)) V (P(3, 1) /\ P(3, 2) /\ P(3, 3)) d) (P(l, 1) V P(2, 1) V P(3, 1)) /\ (P(l, 2) V P(2, 2) V P(3, 2)) /\ (P(l, 3) V P(2, 3) V P(3, 3)) Note the crucial difference between parts ( c) and ( d). 31. As we push the negation symbol toward the inside, each quantifier it passes must change its type. For logical connectives we either use De Morgan's laws or recall that •(p----+ q) p /\ --.q. = a) --.\fx3y\fz T(x, y, z) =3x--.3y\fz T(x, y, z) =3x\fy---,\fzT(x,y,z) = 3x\fy3z--.T(x, y, z) b) --.(\fx3y P(x, y) V \fx3y Q(x, y)) =--.\fx3y P(x, y) /\ --.\fx3y Q(x, y) =3x--.3yP(x,y) /\ 3x--.3yQ(x,y) = 3x\fy--.P(x, y) /\ 3x\fy---, Q(x, y) c) Section 1.5 29 Nested Quantifiers -,'tfx3y(P(x, y) /\ 3z R(x, y, z)) =3x-,3y(P(x, y) /\ 3z R(x, y, z)) =3x'tly •(P(x, y) /\ 3z R(x, y, z)) = 3x't/y(•P(x, y) V -,3z R(x, y, z)) = 3x't/y(•P(x,y) V'tfz-,R(x,y,z)) d) •'tlx3y(P(x,y)-+ Q(x,y)) =3x-,3y(P(x,y)-+ Q(x,y)) =3x'Vy•(P(x,y)-+ Q(x,y)) = 3x't/y(P(x, y) /\ •Q(x, y)) 33. We need to use the transformations shown in Table 2 of Section 1.4, replacing -,'tj by 3-,, and replacing -,3 by \;/-,. In other words, we push all the negation symbols inside the quantifiers, changing the sense of the quantifiers as we do so, because of the equivalences in Table 2 of Section 1.4. In addition, we need to use De Morgan's laws (Section 1.3) to change the negation of a conjunction to the disjunction of the negations and to change the negation of a disjunction to the conjunction of the negations. We also use the double negation law. a) 3x3y •P(x, y) b) 3y'tlx•P(x,y) c) We can think of this in two steps. First we transform the expression into the equivalent expression 3y3x•(P(x,y) V Q(x,y)), and then we use De Morgan's law to rewrite this as 3y3x(•P(x,y) /\ •Q(x,y)). d) First we apply De Morgan's law to write this as a disjunction: (•3x3y•P(x,y)) V (•V'x't/yQ(x,y)). Then we push the negation inside the quantifiers, and note that the two negations in front of P then cancel out (••P(x,y) P(x,y)). So our final answer is (V'x't/yP(x,y)) V (3x3y•Q(x,y)). e) First we push the negation inside the outer universal quantifier, then apply De Morgan's law, and finally push it inside the inner quantifiers: 3x-,(3y't/zP(x,y,z) /\ 3z't/yP(x,y,z)) = 3x(•3y't/zP(x,y,z) V -,3z't/yP(x,y,z)) = 3x(V'y3z-,P(x,y,z) VV'z3y•P(x,y,z)). = 35. If the domain (universe of discourse) has at least four members, then no matter what values are assigned to x, y, and z, there will always be another member of the domain, different from those three, that we can assign to w to make the statement true. Thus we can use a domain such as United States Senators. On the other hand, for any domain with three or fewer members, if we assign all the members to x, y, and z (repeating some if necessary), then there will be nothing left to assign to w to make the statement true. For this we can use a domain such as your biological parents. 37. In each case we need to specify some predicates and identify the domain (universe of discourse). a) To get into the spirit of the problem, we should let T(x,y) be the predicate that x has taken y, where x ranges over students in this class and y ranges over mathematics classes at this school. Then our original statement is V'x3y3z(y =f. z /\ T(x,y) /\ T(x,z) /\ V'w(T(x,w) -+ (w = y V w = z))). Here y and z are the two math classes that x has taken, and our statement says that these are different and that if x has taken any math class w, then w is one of these two. We form the negation by using Table 2 of Section 1.4 and De Morgan's law to push the negation symbol that we place before the entire expression inwards, to achieve 3x't/y't/z(y = z V •T(x, y) V •T(x, z) V 3w(T(x, w) /\ w =f. y /\ w =f. z)). This can also be expressed as 3x't/y't/z(y =f. z-+ (•T(x,y) V •T(x,z) V 3w(T(x,w) /\ w =f. y /\ w =f. z))). Note that we formed the negation of a conditional statement by asserting that the hypothesis was true and the conclusion was false. In simple English, this last statement reads "There is someone in this class for whom no matter which two distinct math courses you consider, these are not the two and only two math courses this person has taken." b) Let V (x, y) be the predicate that x has visited y, where x ranges over people and y ranges over countries. The statement seems to be asserting that the person identified here has visited country y if and only if Chapter 1 30 The Foundations: Logic and Proofs y is not Libya. So we can write this symbolically as :3x\iy(V(x, y) +---+ y =I- Libya). One way to form the negation of P +---+ Q is to write P +---+ -,Q; this can be seen by looking at truth tables. Thus the negation is \ix:3y(V(x, y) +---+ y = Libya). Note that there are two ways for a biconditional to be true; therefore in English this reads "For every person there is a country such that either that country is Libya and the person has visited it, or else that country is not Libya and the person has not visited it." More simply, ''For every person, either that person has visited Libya or else that person has failed to visit some country other than Libya." If we are willing to keep the negation in front of the quantifier in English, then of course we could just say "There is nobody who has visited every country except Libya," but that would not be in the spirit of the exercise. c) Let C ( x, y) be the predicate that x has climbed y, where x ranges over people and y ranges over mountains in the Himalayas. Our statement is -,::Jx\iy C(x, y). Its negation is, of course, simply :3x\iy C(x, y). In English this reads "Someone has climbed every mountain in the Himalayas." d) There are different ways to approach this, depending on how many variables we want to introduce. Let M(x, y, z) be the predicate that x has been in movie z with y, where the domains for x and y are movie actors, and for z is movies. The statement then reads: \ix((:3z lvl(x, Kevin Bacon, z))v(:3y:3zi:3z 2 (M(x, y, z1)/\ M(y, Kevin Bacon, z 2 )))). The negation is formed in the usual manner: :3x((Vz -,Af(x, Kevin Bacon, z)) /\ (\iy\iz 1\iz 2 (-,M(x, y, z 1) V -,Af(y, Kevin Bacon, z 2 ) ))) . In simple English this means that there is someone who has neither been in a movie with Kevin Bacon nor been in a movie with someone who has been in a movie with Kevin Bacon. 39. a) Since the square of a number and its additive inverse are the same, we have many counterexamples, such as x = 2 and y = - 2. b) This statement is saying that every number has a square root. If x is negative (like x = -4), or, since we are working in the domain of the integers, x is not a perfect square (like x = 6 ), then the equation y 2 = x has no solution. c) Since negative numbers are not larger than positive numbers, we can take something like x = 17 and y = -1 for our counterexample. 41. We simply want to say that a certain equation holds for all real numbers: \ix\iy\iz((x · y) · z = x · (y · z)). 43. We want to say that for each pair of coefficients (the m and the b in the expression mx + b ), as long as m is not 0, there is a unique x making that expression equal to 0. So we write \im\ib(m =I- 0-+ :3x(mx + b = O/\ \iw(mw + b = 0-+ w = x))). Notice that the uniqueness is expressed by the last part of our proposition. 45. This statement says that every number has a multiplicative inverse. a) In the universe of nonzero real numbers, this is certainly true. In each case we let y b) Integers usually don't have inverses that are integers. If we let x = 3, = 1/ x. then no integer y satisfies xy = 1. Thus in this setting, the statement is false. c) As in part (a) this is true, since 1/x is positive when x is positive. 47. We use the equivalences explained in Table 2 of Section 1.4, twice: -,::Jx\iyP(x, y) =\fx-,\fyP(x, y) =\ix::Jy-,P(x, y) 49. a) We prove this by arguing that whenever the first proposition is true, so is the second; and that whenever the second proposition is true, so is the first. So suppose that \ixP(x) /\ :3xQ(x) is true. In particular, P always holds, and there is some object, call it y, in the domain (universe of discourse) that makes Q true. Now to show that the second proposition is true, suppose that x is any object in the domain. By our assumptions, P(x) is true. Furthermore, Q(y) is true for the particular y we mentioned above. Therefore P(x) /\ Q(y) is Section 1.5 Nested Quantifiers 31 true for this x and y. Since x was arbitrary, we have showed that \/x3y(P(x) /\ Q(y)) is true, as desired. Conversely, suppose that the second proposition is true. Letting x be any member of the domain allows us to assert that there exists a y such that P(x) /\ Q(y) is true, and therefore Q(y) is true. Thus by the definition of existential quantifiers, 3xQ(x) is true. Furthermore, our hypothesis tells us in particular that \/xP(x) is true. Therefore the first proposition, \/xP(x) /\ 3xQ(x) is true. b) This is similar to part (a). Suppose that \/xP(x)V3xQ(x) is true. Thus either P always holds, or there is some object, call it y, in the domain that makes Q true. In the first case it follows that P(x) V Q(y) is true for all x, and so we can conclude that \/x3y(P(x) V Q(y)) is true (it does not matter in this case whether Q(y) is true or not). In the second case, Q(y) is true for this particular y, and so P(x) V Q(y) is true regardless of what x is. Again, it follows that \/x3y(P(x) V Q(y)) is true. Conversely, suppose that the second proposition is true. If P( x) is true for all x, then the first proposition must be true. If not, then P( x) fails for some x, but for this x there must be a y such that P(x) V Q(y) is true; hence Q(y) must be true. Therefore 3yQ(y) holds, and thus the first proposition is true. 51. This will essentially be a proof by (structural) mathematical induction (see Sections 5.1-5.3), where we show how a long expression can be put into prenex normal form if the subexpressions in it can be put into prenex normal form. First we invoke the result of Exercise 45 from Section 1.3 to assume without loss of generality that our given proposition uses only the logical connectives V and --, . Then every proposition must either be a single propositional variable (like P), the disjunction of two propositions, the negation of a proposition, or the universal or existential quantification of a predicate. (There is a small technical point that we are sliding over here; disjunction and negation need to be defined for predicates as well as for propositions, since otherwise we would not be able to write down such things as \/x(P(x) /\ Q(x)). We assume that all that we have done for propositions applies to predicates as well.) Certainly every proposition that involves no quantifiers is already in prenex normal form; this is the base case of our induction. Next suppose that our proposition is of the form QxP(x), where Q is a quantifier. Then P(x) is a shorter expression than the given proposition, so (by the inductive hypothesis) we can put it into prenex form, with all of its quantifiers coming at the beginning. Then Qx followed by this prenex form is again in prenex form and is equivalent to the original proposition. Next suppose that our proposition is of the form --,p. Again, we can invoke the inductive hypothesis and assume that P is already in prenex form, with all of its quantifiers coming at its front. We now slide the negation symbol past all the quantifiers, using the equivalences in Table 2 of Section 1.4. For example, --,\fx3yR(x, y) becomes 3x\fy--,R(x, y), which is in prenex form. Finally, suppose that our given proposition is a disjunction of two propositions, P V Q, each of which can (again by the inductive hypothesis) be assumed to be in prenex normal form, with their quantifiers at the front. There are several cases. If only one of P and Q has quantifiers, then we invoke the result of Exercise 46 of Section 1.4 to bring the quantifier in front of both. We then apply our process to what remains. For example, P V \/xQ(x) is equivalent to \/x(P V Q(x)), and then P V Q(x) is put into prenex form. Another case is that the proposition might look like 3xR(x) V 3xS(x). In this case, by Exercise 45 of Section 1.4, the proposition is equivalent to 3x(R(x) V S(x)). Once again, by the inductive hypothesis we can then put R(x) V S(x) into prenex form, and so the entire proposition can be put into prenex form. Similarly, using Exercise 48 of the present section we can transform \/xR(x) V\/xS(x) into the equivalent \/x\/y(R(x) VS(y)); putting R(x) V S(y) into prenex form then brings the entire proposition into prenex form. Finally, if the proposition is of the form \/xR(x) V 3xQ(x), then we invoke Exercise 49b of the present section and apply the same construction. Note that this proof actually gives us the process for finding the proposition in prenex form equivalent to the given proposition-we just work from the inside out, dealing with one logical operation or quantifier at a Chapter 1 32 The Foundations: Logic and Proofs time. Here is an example: 't:/xP(x) V -dx(Q(x) V 't:/yR(x, y)) ='t:/xP(x) V -dx't:/y(Q(x) V R(x, y)) ='t:/xP(x) V Vx:ly•(Q(x) V R(x, y)) :::::: 't:/x't:/z(P(x) V 3y•(Q(z) V R(z, y))) :::::: 't:/x't:/z:Jy(P(x) V •(Q(z) V R(z, y))) SECTION 1.6 Rules of Inference This section lays the groundwork for understanding proofs. You are asked to understand the logical rules of inference behind valid arguments, and you are asked to construct some highly stylized proofs using these rules. The proofs will become more informal in the next section and throughout the remainder of this book (and your mathematical studies). 1. This is modus ponens. The first statement is p ____, q, where p is "Socrates is human" and q is "Socrates is mortal." The second statement is p. The third is q. Modus ponens is valid. We can therefore conclude that the conclusion of the argument (third statement) is true, because the hypotheses (the first two statements) are true. 3. a) This is the addition rule. We are concluding from p that p V q must be true, where p is "Alice is a mathematics major" and q is ''Alice is a computer science major." b) This is the simplification rule. We are concluding from p A q that p must be true, where p is "Jerry is a mathematics major" and q is "Jerry is a computer science major." c) This is modus ponens. We are concluding from p ____, q and p that q must be true, where p is "it is rainy" and q is ''the pool will be closed.'' d) This is modus tollens. We are concluding from p ____, q and •q that •p must be true, where p is "it will snow today'' and q is ''the university will close today." e) This is hypothetical syllogism. We are concluding from p ____, q and q ____, r that p ____, r must be true, where p is "I will go swimming," q is ''I will stay in the sun too long," and r is "I will sunburn." 5. Let w be the proposition "Randy works hard," let d be the proposition "Randy is a dull boy," and let j be the proposition "Randy will get the job." We are given premises w, w ____, d, and d ____, •j. We want to conclude •j. We set up the proof in two columns, with reasons, as in Example 6. Step 1. w 2. w----; d 3. d 4. d----; · j 5. · j Reason Hypothesis Hypothesis Modus ponens using (2) and (3) Hypothesis Modus ponens using (3) and (4) 7. First we use universal instantiation to conclude from "For all x, if x is a man, then x is mortal" the special case of interest, "If Socrates is a man, then Socrates is mortal." Then we use modus ponens to conclude that Socrates is mortal. Section 1.6 Rules of Inference 33 9. a) Because it was sunny on Tuesday, we assume that it did not rain or snow on Tuesday (otherwise we cannot do anything with this problem). If we use modus tollens on the universal instantiation of the given conditional statement applied to Tuesday, then we conclude that I did not take Tuesday off. If we now apply disjunctive syllogism to the disjunction in light of this conclusion, we see that I took Thursday off. Now use modus ponens on the universal instantiation of the given conditional statement applied to Thursday; we conclude that it rained or snowed on Thursday. One more application of disjunctive syllogism tells us that it rained on Thursday. b) Using modus tollens we conclude two things-that I did not eat spicy food and that it did not thunder. Therefore by the conjunction rule of inference (Table 1), we conclude "I did not eat spicy food and it did not thunder." c) By disjunctive syllogism from the first two hypotheses we conclude that I am clever. The third hypothesis gives us no useful information. d) We can apply universal instantiation to the conditional statement and conclude that if Ralph (respectively, Ann) is a CS major, then he (she) has a PC. Now modus tollens tells us that Ralph is not a CS major. There are no conclusions to be drawn about Ann. e) The first two conditional statements can be phrased as "If x is good for corporations, then x is good for the U.S." and "If x is good for the U.S., then x is good for you." If we now apply universal instantiation with x being "for you to buy lots of stuff,'' then we can conclude using modus ponens twice that for you to buy lots of stuff is good for the U.S. and is good for you. f) The given conditional statement is "For all x, if x is a rodent, then x gnaws its food." We can form the universal instantiation of this with x being a mouse, a rabbit, and a bat. Then modus ponens allows us to conclude that mice gnaw their food; and modus tollens allows us to conclude that rabbits are not rodents. We can conclude nothing about bats. 11. We are asked to show that whenever p 1 , p 2 , ... , Pn are true, then q--+ r must be true, given that we know that whenever P1 , P2 , ... , Pn and q are true, then r must be true. So suppose that p 1 , p 2 , ... , Pn are true. We want to establish that q --+ r is true. If q is false, then we are done, vacuously. Otherwise, q is true, so by the validity of the given argument form, we know that r is true. 13. In each case we set up the proof in two columns, with reasons, as in Example 6. a) Let c(x) be ''x is in this class," let j(x) be "x knows how to write programs in JAVA," and let h(x) be "x can get a high paying job." We are given premises c(Doug), j(Doug), and Vx(j(x) to conclude 3x(c(x) /\ h(x)). Step 1. Vx(j(x)--+ h(x)) 2. j (Doug) --+ h(Doug) 3. j(Doug) 4. h(Doug) 5. c(Doug) 6. c(Doug) /\ h(Doug) 7. 3x(c(x) /\ h(x)) --+ h(x)), and we want Reason Hypothesis Universal instantiation using (1) Hypothesis Modus ponens using (2) and (3) Hypothesis Conjunction using (4) and (5) Existential generalization using (6) b) Let c(x) be "x is in this class," let w(x) be "x enjoys whale watching," and let p(x) be "x cares about ocean pollution." We are given premises 3x(c(x) /\ w(x)) and Vx(w(x) --+ p(x)), and we want to conclude 3x (c( x) /\ p( x)) . In our proof, y represents an unspecified particular person. Chapter 1 34 Step 1. 3x(c(x) /\ w(x)) 2. 3. 4. 5. 6. 7. 8. 9. c(y)Aw(y) w(y) c(y) \lx(w(x) _.., p(x)) w(y) _.., p(y) p(y) c(y) /\ p(y) 3x(c(x) /\p(x)) The Foundations: Logic and Proofs Reason Hypothesis Existential instantiation using ( 1) Simplification using (2) Simplification using (2) Hypothesis Universal instantiation using (5) Modus ponens using (3) and (6) Conjunction using (4) and (7) Existential generalization using (8) c) Let c(x) be "xis in this class," let p(x) be "x owns a PC," and let w(x) be "x can use a word processing program." We are given premises c(Zeke), \lx(c(x) _.., p(x)), and \lx(p(x) _.., w(x)), and we want to conclude w(Zeke). Step 1. \lx(c(x) _, p(x)) 2. c(Zeke) _.., p(Zeke) 3. c(Zeke) 4. p(Zeke) 5. \lx(p(x) _, w(x)) 6. p(Zeke) _, w(Zeke) Reason 7. w(Zeke) Modus ponens using (4) and (6) Hypothesis Universal instantiation using (1) Hypothesis Modus ponens using (2) and (3) Hypothesis Universal instantiation using (5) d) Let j(x) be "x is in New Jersey," let f(x) be "x lives within fifty miles of the ocean,'' and let s(x) be "x has seen the ocean." We are given premises Vx(j(x) _, f(x)) and 3x(j(x) /\ •s(x)), and we want to conclude 3x(f (x) /\ •s( x)) . In our proof, y represents an unspecified particular person. Step 1. 3x(j(x) /\ •s(x)) 2. j(y) /\ •s(y) 3. j(y) 4. \lx(j(x) _, f(x)) 5. j(y) _, f(y) 6. f(y) 7. •s(y) 8. f(y) /\ •s(y) 9. 3x(f(x) /\ •s(x)) Reason Hypothesis Existential instantiation using (1) Simplification using (2) Hypothesis Universal instantiation using (4) Modus ponens using (3) and (5) Simplification using (2) Conjunction using (6) and (7) Existential generalization using (8) 15. a) This is correct, using universal instantiation and modus ponens. b) This is invalid. After applying universal instantiation, it contains the fallacy of affirming the conclusion. c) This is invalid. After applying universal instantiation, it contains the fallacy of denying the hypothesis. d) This is valid by universal instantiation and modus tollens. 17. We know that some x exists that makes H (x) true, but we cannot conclude that Lola is one such x. Maybe only Suzanne is happy and everyone else is not happy. Then 3x H(x) is true, but H(Lola) is false. 19. a) This is the fallacy of affirming the conclusion, since it has the form "p _.., q and q implies p." b) This reasoning is valid; it is modus tollens. c) This is the fallacy of denying the hypothesis, since it has the form "p _, q and •P implies •q ." Section 1.6 Rules of Inference 35 21. Let us give an argument justifying the conclusion. By the second premise, there is some lion that does not drink coffee. Let us call him Leo. Thus we know that Leo is a lion and that Leo does not drink coffee. By simplification this allows us to assert each of these statements separately. The first premise says that all lions are fierce; in particular, if Leo is a lion, then Leo is fierce. By modus ponens, we can conclude that Leo is fierce. Thus we conclude that Leo is fierce and Leo does not drink coffee. By the definition of the existential quantifier, this tells us that there exist fierce creatures that do not drink coffee; in other words, that some fierce creatures do not drink coffee. 23. The error occurs in step (5), because we cannot assume, as is being done here, that the c that makes P true is the same as the c that makes Q true. 25. We are given the premises Vx(P(x) ---+ Q(x)) and •Q(a). We want to show •P(a). Suppose, to the contrary, that •P(a) is not true. Then P(a) is true. Therefore by universal modus ponens, we have Q(a). But this contradicts the given premise •Q(a). Therefore our supposition must have been wrong, and so •P(a) is true, as desired. 27. We can set this up in two-column format. Step 1. 'v'x(P(x) /\ R(x)) 2. P(a) /\ R(a) 3. P(a) 4. 'v'x(P(x)---+ (Q(x) /\ S(x))) 5. Q(a) /\ S(a) 6. S(a) 7. R(a) 8. R(a)/\S(a) 9. 'v'x(R(x) /\ S(x)) Reason Premise Universal instantiation using (1) Simplification using (2) Premise Universal modus ponens using (3) and (4) Simplification using (5) Simplification using (2) Conjunction using (7) and (6) Universal generalization using (5) 29. We can set this up in two-column format. The proof is rather long but straightforward if we go one step at a time. Step Reason 1. 3x•P(x) Premise Existential instantiation using ( 1) 2. ·P(c) Premise 3. 'v'x(P(x) V Q(x)) 4. P(c) V Q(c) Universal instantiation using (3) 5. Q(c) Disjunctive syllogism using (4) and (2) Premise 6. 'v'x(•Q(x) V S(x)) Universal instantiation using (6) 7. •Q(c) V S(c) 8. S(c) Disjunctive syllogism using (5) and (7), since ••Q(c) Q(c) Premise 9. 'v'x(R(x)---+ •S(x)) Universal instantiation using (9) 10. R(c)---+ •S(c) = 11. ·R(c) 12. 3x·R(x) Modus tollens using (8) and (10), since ••S(c) Existential generalization using ( 11) = S(c) 31. Let p be "It is raining"; let q be "Yvette has her umbrella"; let r be "Yvette gets wet." Then our assumptions are •p V q, •q V •r, and p V •r. Using resolution on the first two assumptions gives us •p V •r. Using resolution on this and the third assumption gives us •r, so Yvette does not get wet. 36 Chapter 1 The Foundations: Logic and Proofs 33. Assume that this proposition is satisfiable. Using resolution on the first two clauses allows us to conclude q V q; in other words, we know that q has to be true. Using resolution on the last two clauses allows us to conclude •q V •q; in other words, we know that •q has to be true. This is a contradiction. So this proposition is not satisfiable. 35. This argument is valid. We argue by contradiction. Assume that Superman does exist. Then he is not impotent, and he is not malevolent (this follows from the fourth sentence). Therefore by (the contrapositives of) the two parts of the second sentence, we conclude that he is able to prevent evil, and he is willing to prevent evil. By the first sentence, we therefore know that Superman does prevent evil. This contradicts the third sentence. Since we have arrived at a contradiction, our original assumption must have been false, so we conclude finally that Superman does not exist. SECTION 1.7 Introduction to Proofs This introduction applies jointly to this section and the next (1.8). Learning to construct good mathematical proofs takes years. There is no algorithm for constructing the proof of a true proposition (there is actually a deep theorem in mathematical logic that says this). Instead, the construction of a valid proof is an art, honed after much practice. There are two problems for the beginning student-figuring out the key ideas in a problem (what is it that really makes the proposition true?) and writing down the proof in acceptable mathematical language. Here are some general things to keep in mind in constructing proofs. First, of course, you need to find out exactly what is going on-why the proposition is true. This can take anywhere from ten seconds (for a really simple proposition) to a lifetime (some mathematicians have spent their entire careers trying to prove certain conjectures). For a typical student at this level, tackling a typical problem, the median might be somewhere around 15 minutes. This time should be spent looking at examples, making tentative assumptions, breaking the problem down into cases, perhaps looking at analogous but simpler problems, and in general bringing all of your mathematical intuition and training to bear. It is often easiest to give a proof by contradiction, since you get to assume the most (all the hypotheses as well as the negation of the conclusion), and all you have to do is to derive a contradiction. Another thing to try early in attacking a problem is to separate the proposition into several cases; proof by cases is a valid technique, if you make sure to include all the possibilities. In proving propositions, all the rules of inference are at your disposal, as well as axioms and previously proved results. Ask yourself what definitions, axioms, or other theorems might be relevant to the problem at hand. The importance of constantly returning to the definitions cannot be overstated! Once you think you see what is involved, you need to write down the proof. In doing so, pay attention both to content (does each statement follow logically? are you making any fallacious arguments? are you leaving out any cases or using hidden assumptions?) and to style. There are certain conventions in mathematical proofs, and you need to follow them. For example, you must use complete sentences and say exactly what you mean. (An equation is a complete sentence, with "equals" as the verb; however, a good proof will usually have more English words than mathematical symbols in it.) The point of a proof is to convince the reader that your line of argument is sound, and that therefore the proposition under discussion is true; put yourself in the reader's shoes, and ask yourself whether you are convinced. Most of the proofs called for in this exercise set are not extremely difficult. Nevertheless, expect to have a fairly rough time constructing proofs that look like those presented in this solutions manual, the textbook, or other mathematics textbooks. The more proofs you write, utilizing the different methods discussed in this Section 1. 7 Introduction to Proofs 37 section, the better you will become at it. As a bonus, your ability to construct and respond to nonmathematical arguments (politics, religion, or whatever) will be enhanced. Good luck! 1. We must show that whenever we have two odd integers, their sum is even. Suppose that a and b are two odd integers. Then there exist integers s and t such that a = 2s + 1 and b = 2t + 1. Adding, we obtain a+ b = (2s + 1) + (2t + 1) = 2(s + t + 1). Since this represents a+ b as 2 times the integer s + t + 1, we conclude that a + b is even, as desired. 3. We need to prove the following assertion for an arbitrary integer n: "If n is even, then n 2 is even." Suppose that n is even. Then n = 2k for some integer k. Therefore n 2 = (2k ) 2 = 4k 2 = 2(2k 2 ). Since we have written n 2 as 2 times an integer, we conclude that n 2 is even. 5. We can give a direct proof. Suppose that m + n is even. Then m + n = 2s for some integer s. Suppose that n + p is even. Then n + p = 2t for some integer t. If we add these [this step is inspired by the fact that we want to look at m + p], we get m + p + 2n = 2s + 2t. Subtracting 2n from both sides and factoring, we have m + p = 2s + 2t - 2n = 2(s + t - n). Since we have written m + p as 2 times an integer, we conclude that m + p is even, as desired. 7. The difference of two squares can be factored: a 2 - b2 = (a+ b)(a - b). If we can arrange for our given odd integer to equal a + b and for a - b to equal 1, then we will be done. But we can do this by letting a and b be the integers that straddle n/2. For example, if n = 11, then we take a = 6 and b = 5. Specifically, if n = 2k + 1, then we let a = k + 1 and b = k. Here, then, is our proof. Since n is odd, we can write n = 2k + 1 for some integer k . Then (k + 1) 2 - k 2 = k 2 + 2k + 1 - k 2 = 2k + 1 = n. This expresses n as the difference of two squares. 9. The proposition to be proved here is as follows: If r is a rational number and i is an irrational number, then s = r + i is an irrational number. So suppose that r is rational, i is irrational, and s is rational. Then by Example 7 the sum of the rational numbers s and -r must be rational. (Indeed, ifs= a/b and r = c/d, where a, b, c, and d are integers, with b =/=- 0 and d =/=- 0, then by algebra we see that s + (-r) = (ad-be)/ (bd) , so that patently s + (-r) is a rational number.) But s + (-r) = r + i - r = i, forcing us to the conclusion that i is rational. This contradicts our hypothesis that i is irrational. Therefore the assumption that s was rational was incorrect, and we conclude, as desired, that s is irrational. 11. To disprove this proposition it is enough to find a counterexample, since the proposition has an implied universal quantification. We know from Example 10 that J2 is irrational. If we take the product of the irrational number J2 and the irrational number J2, then we obtain the rational number 2. This counterexample refutes the proposition. 13. We give an proof by contraposition. The contrapositive of this statement is "If l/x is rational, then x is rational" so we give a direct proof of this contrapositive. Note that since 1/x exists, we know that x =/=- 0. If l/x is rational, then by definition 1/x = p/q for some integers p and q with q =/=- O. Since 1/x cannot be 0 (if it were, then we'd have the contradiction 1 = x · 0 by multiplying both sides by x), we know that p =/=- 0. Now x = 1/(1/x) = l/(p/q) = q/p by the usual rules of algebra and arithmetic. Hence x can be written as the quotient of two integers with the denominator nonzero. Thus by definition, x is rational. 15. We will prove the contrapositive (that if it is not true that x 2: 1 or y 2: 1, then it is not true that x + y 2: 2), using a direct argument. Assume that it is not true that x 2: 1 or y 2: 1. Then (by De Morgan's law) x < 1 and y < 1. Adding these two inequalities, we obtain x proof is complete. +y < 2. This is the negation of x + y 2: 2, and our 38 Chapter 1 The Foundations: Logic and Proofs 17. a) We must prove the contrapositive: If n is odd, then n 3 + 5 is even. Assume that n is odd. Then we can write n = 2k+l for some integer k. Then n 3 +5 = (2k+1) 3 +5 = 8k 3 +12k 2 +6k+6 = 2(4k 3 +6k 2 +3k+3). Thus n 3 + 5 is two times some integer, so it is even. b) Suppose that n 3 + 5 is odd and that n is odd. Since n is odd, and the product of odd numbers is odd, in two steps we see that n 3 is odd. But then subtracting we conclude that 5, being the difference of the two odd numbers n 3 + 5 and n 3 , is even. This is not true. Therefore our supposition was wrong, and the proof by contradiction is complete. 19. The proposition we are trying to prove is "If 0 is a positive integer greater than 1, then 02 > 0 ." Our proof is a vacuous one, exactly as in Example 5. Since the hypothesis is false, the conditional statement is automatically true. 21. The proposition we are trying to prove is "If a and b are positive real numbers, then (a+ b) 1 2'. a 1 + b1 ." Our proof is a direct one. By the definition of exponentiation, any real number to the power 1 is itself. Hence (a+ b) 1 = a+ b = a 1 + b1 . Finally, by the addition rule, we can conclude from (a+ b) 1 = a 1 + b1 that (a+ b) 1 2 a 1 + b1 (the latter being the disjunction of (a+ b) 1 = a 1 + b1 and (a+ b) 1 > a 1 + b1 ). One might also say that this is a trivial proof, since we did not use the hypothesis that a and b are positive (although of course we used the hypothesis that they are numbers). 23. We give a proof by contradiction. If there were nine or fewer days on each day of the week, this would account for at most 9 · 7 = 63 days. But we chose 64 days. This contradiction shows that at least ten of the days must be on the same day of the week. 25. One way to prove this is to use the rational root test from high school algebra: Every rational number that satisfies a polynomial with integer coefficients is of the form p / q, where p is a factor of the constant term of the polynomial, and q is a factor of the coefficient of the leading term. In this case, both the constant and the leading coefficient are 1, so the only possible values for p and q are ±1. Therefore the only possible rational roots are ±1/(±1), which means that 1 and -1 are the only possible rational roots. Clearly neither of them is a root, so there are no rational roots. Alternatively, we can follow the hint. Suppose by way of contradiction that a/b is a rational root, where a and b are integers and this fraction is in lowest terms (that is, a and b have no common divisor greater than 1 ). Plug this proposed root into the equation to obtain a 3 /b3 + a/b + 1 = 0. Multiply through by b3 to obtain a 3 + ab 2 + b3 = 0. If a and b are both odd, then the left-hand side is the sum of three odd numbers and therefore must be odd. If a is odd and b is even, then the left-hand side is odd+ even+ even, which is again odd. Similarly, if a is even and b is odd, then the left-hand side is even+ even+ odd, which is again odd. Because the fraction a/b is in simplest terms, it cannot happen that both a and b are even. Thus in all cases, the left-hand side is odd, and therefore cannot equal 0. This contradiction shows that no such root exists. 27. We must prove two conditional statements. First, we assume that n is odd and show that 5n + 6 is odd (this is a direct proof). By assumption, n = 2k + 1 for some integer k. Then 5n + 6=5(2k+1) + 6 = lOk + 11 = 2(5k + 5) + 1. Since we have written 5n + 6 as 2 times an integer plus 1, we have showed that 5n + 6 is odd, as desired. Now we give an proof by contraposition of the converse. Suppose that n is not odd-in other words, that n is even. Then n = 2k for some integer k. Then 5n + 6 = lOk + 6 = 2(5k + 3). Since we have written 5n + 6 as 2 times an integer, we have showed that 5n + 6 is even. This completes the proof by contraposition of this conditional statement. Section 1.7 Introduction to Proofs 39 29. This proposition is true. We give a proof by contradiction. Suppose that m is neither 1 nor -1. Then mn has a factor (namely lml) larger than 1. On the other hand, mn = 1, and 1 clearly has no such factor. Therefore we conclude that m = 1 or m = -1. It is then immediate that n = 1 in the first case and n = -1 in the second case, since mn = 1 implies that n = 1/m. 31. Perhaps the best way to do this is to prove that all of them are equivalent to x being even, which one can discover easily enough by trying a few small values of x. If x is even, then x = 2k for some integer k. Therefore 3x + 2 = 3 · 2k + 2 = 6k + 2 = 2(3k + 1), which is even, since it has been written in the form 2t, where t = 3k+l. Similarly, x+5 = 2k+5 = 2k+4+1=2(k+2)+1, so x+5 is odd; and x 2 = (2k) 2 = 2(2k 2), so x 2 is even. For the converses, we will use a proof by contraposition. So assume that x is not even; thus x is odd and we can write x = 2k + 1 for some integer k. Then 3x + 2=3(2k+1) + 2 = 6k + 5 = 2(3k + 2) + 1, which is odd (i.e., not even), since it has been written in the form 2t + 1, where t = 3k + 2. Similarly, x+5 = 2k+1+5 = 2(k+3), so x+5 is even (i.e., not odd). That x 2 is odd was already proved in Example 1. This completes the proof. 33. It is easiest to give proofs by contraposition of (i) --+ (ii), (ii) --+ (i), (i) --+ (iii) , and (iii) --+ (i). For the first of these, suppose that 3x + 2 is rational, namely equal to p / q for some integers p and q with q -=I- 0. Then we can write x = ( (p/ q) - 2) /3 = (p - 2q) / (3q), where 3q -=I- 0. This shows that x is rational. For the second conditional statement, suppose that x is rational, namely equal to p/q for some integers p and q with q -=I- 0. Then we can write 3x + 2 = (3p + 2q) / q, where q -=I- 0. This shows that 3x + 2 is rational. For the third conditional statement, suppose that x/2 is rational, namely equal to p/q for some integers p and q with q -=I- 0 . Then we can write x = 2p / q, where q -=I- 0 . This shows that x is rational. And for the fourth conditional statement, suppose that xis rational, namely equal to p/q for some integers p and q with q -=I- 0. Then we can write x/2 = p/(2q), where 2q -=I- 0. This shows that x/2 is rational. 35. The steps are valid for obtaining possible solutions to the equations. If the given equation is true, then we can conclude that x = 1 or x = 6, since the truth of each equation implies the truth of the next equation. However, the steps are not all reversible; in particular, the squaring step is not reversible. Therefore the possible answers must be checked in the original equation. We know that no other solutions are possible, but we do not know that these two numbers are in fact solutions. If we plug in x = 1 we get the true statement 2 = 2; but if we plug in x = 6 we get the false statement 3 = -3. Therefore x = 1 is the one and only solution of -./x + 3 = 3 - x. 37. Suppose that we have proved p 1 --+ p 4 --+ p2--+ p5--+ p3--+ p 1 . Imagine these conditional statements arranged around a circle. Then to prove that each one of these propositions (say Pi) implies each of the others (say p 1 ), we just have to follow the circle, starting at Pi, until we come to Pj , using hypothetical syllogism repeatedly. 39. We can give a very satisfying proof by contradiction here. Suppose instead that all of the numbers a 1 , a 2 , ... , an are less than their average, which we can denote by A. In symbols, we have a, < A for all i. If we add these n inequalities, we see that a1 + a2 + · · · + an < nA . By definition, A = a1 + a2 + · · · + an . n The two displayed formulae clearly contradict each other, however: they imply that nA < nA. Thus our assumption must have been incorrect, and we conclude that at least one of the numbers a, is greater than or equal to their average. 40 Chapter 1 The Foundations: Logic and Proofs 41. We can prove that these four statements are equivalent in a circular way: (i) --> (ii) --> (iii) --> (iv) --> ( i). For the first, we want to show that if n is even, then n + 1 is odd. Assume that n is even. Then n = 2k for some integer k. Thus n + 1 = 2k + 1, so by definition n + 1 is odd. This completes the first proof. Next we give a direct proof of (ii) --> (iii). Suppose that n + 1 is odd, say n + 1 = 2k + 1. Then 3n + 1 = 2n + (n + 1) = 2n + 2k + 1 = 2(n + k) + 1. Since this shows that 3n + 1 is 2 times an integer plus 1, we conclude that 3n+ 1 is odd, as desired. For the next proof, suppose that 3n+ 1 is odd, say 3n+ 1=2k+1. Then 3n = (3n + 1) - 1 = (2k + 1) - 1 = 2k. Therefore by definition 3n is even. Finally, we must prove that if 3n is even, then n is even. We will do this using a proof by contraposition. Suppose that n is not even. Then n is odd, so we can write n = 2k + 1 for some integer k. Then 3n = 3(2k + 1) = 6k + 3 = 2(3k + 1) + 1. This exhibits 3n as 2 times an integer plus 1, so 3n is odd, completing the proof by contraposition. SECTION 1.8 Proof Methods and Strategy The preamble to the solutions for Section 1. 7 applies here as well, so you might want to reread it at this time. In addition, the section near the back of this Guide, entitled "A Guide to Proof- Writing," provides an excellent tutorial, with many additional examples. Don't forget to take advantage of the many additional resources on the website for this text, as well. If you are majoring in mathematics, then proofs are the bread and butter of your fleld. Most likely you will take a course devoted entirely to learning how to read and write proofs, using one of the many textbooks available on this subject. For a review of many of them (as well as reviews of hundreds of mathematics books), see this site provided by the Mathematical Association of America: mathdl.maa.org/MathDL/19/. 1. We give an exhaustive proof-just check the entire domain. For n = 1 we have 12 + 1 = 2 2: 2 = 2 1 . For n = 2 we have 22 + 1 = 5 2 4 = 22 . For n = 3 we have 32 + 1 = 10 2 8 = 23 • For n = 4 we have 42 + 1 = 17 2: 16 = 24 . Notice that for n 2 5, the inequality is no longer true. 3. Following the hint, we consider the two cases determined by the relative sizes of x and y. First suppose that x 2 y. Then by definition max(x, y) = x and min(x, y) = y. Therefore in this case max(x, y) + min(x, y) = .r + y, exactly as desired. For the second (and final) case, suppose that x < y. Then max(x,y) = y and min(x, y) = x. Therefore in this case max(x, y) + min(x, y) = y + x = x + y, again the desired conclusion. Hence in all cases, the equality holds. 5. Because Ix - YI = IY - xi, the values of x and y are interchangeable. Therefore, without loss of generality, we can assume that x 2 y. In this case, Ix - YI = x - y, so the first expression gives us x+y-(x-y) 2 and indeed y is the smaller. Similarly, the second expression gives us x+y+(x-y) x+y+x-y 2 2 2x = 2 =x, and indeed x is the larger. 7. There are several cases to consider. If x and y are both nonnegative, then lxl + IYI = x+y = lx+yl. Similarly, if both are negative, then lxl + IYI = (-x) + (-y) = -(x + y) = Ix+ YI, since x + y is negative in this case. The complication (and strict inequality) comes if one of the variables is nonnegative and the other is negative. By the symmetry of the roles of x and y here (strictly speaking, by the commutativity of addition), we can assume without loss of generality that it is x that is nonnegative and y that is negative. So we have x 2: 0 and y < 0. Section 1.8 Proof Methods and Strategy 41 Now there are two subcases to consider within this case, depending on the relative sizes of the nonnegative numbers x and -y. First suppose that x 2 -y. Then x + y 2 0. Therefore Ix + YI = x + y, and this quantity is a nonnegative number smaller than x (since y is negative). On the other hand lxl + IYI = x + IYI is a positive number bigger than x. Therefore we have Ix+ YI < x < lxl + IYI, as desired. Finally, consider the possibility that x < -y. Then Ix+ YI= -(x + y) = (-x) + (-y) is a positive number less than or equal to -y (since -x is nonpositive). On the other hand lxl + IYI = lxl + (-y) is a positive number greater than or equal to -y. Therefore we have Ix+ YI :S: -y :S: lxl + IYI, as desired. 9. We want to find consecutive squares that are far apart. If n is large enough, then (n + 1) 2 will be much bigger than n 2 , and that will do it. Let's take n = 100. Then 100 2 = 10000 and 101 2 = 10201, so the 201 consecutive numbers 10001, 10002, ... , 10200 are not perfect squares. The first 100 of these will satisfy the requirements of this exercise. Our proof was constructive, since we actually exhibited the numbers. 11. We try some small numbers and discover that 8 = 23 and 9 = 32 . In fact, this is the only solution, but the proof of this fact is not trivial. 13. One way to solve this is the following nonconstructive proof. Let x = 2 (rational) and y = J2 (irrational). If xY = 2v'2 is irrational, we are done. If not, then let x = 2v'2 and y = J2/ 4; x is rational by assumption, and y is irrational (if it were rational, then J2 would be rational). But now xY = (2v'2)v'2/ 4 = 2v'2·(VZ)/ 4 = 2 1 / 2 = J2, which is irrational, as desired. 15. a) This statement asserts the existence of x with a certain property. If we let y = x, then we see that P(x) is true. If y is anything other than x, then P(y) is not true. Thus x is the unique element that makes P true. b) The first clause here says that there is an element that makes P true. The second clause says that whenever two elements both make P true, they are in fact the same element. Together this says that P is satisfied by exactly one element. c) This statement asserts the existence of an x that makes P true and has the further property that whenever we find an element that makes P true, that element is x. In other words, x is the unique element that makes P true. Note that this is essentially the same as the definition given in the text, except that the final conditional statement has been replaced by its contrapositive. 17. The equation la - cl = lb- cl is equivalent to the disjunction of two equations: a - c = b- c or a - c = -b + c. The first of these is equivalent to a = b, which contradicts the assumptions made in this problem, so the original equation is equivalent to a - c = -b + c. By adding b + c to both sides and dividing by 2, we see that this equation is equivalent to c = (a + b) /2. Thus there is a unique solution. Furthermore, this c is an integer, because the sum of the odd integers a and b is even. 19. We are being asked to solve n = (k - 2) + (k + 3) for k. Using the usual, reversible, rules of algebra, we see that this equation is equivalent to k = (n - 1) /2. In other words, this is the one and only value of k that makes our equation true. Since n is odd, n - 1 is even, so k is an integer. 21. If x is itself an integer, then we can take n = x and E = 0. No other solution is possible in this case, since if the integer n is greater than x, then n is at least x + 1, which would make E 2 1. If x is not an integer, then round it up to the next integer, and call that integer n. We let E = n - x. Clearly 0 :S: E < 1, this is the only E that will work with this n, and n cannot be any larger, since E is constrained to be less than 1. Chapter 1 42 The Foundations: Logic and Proofs 23. If x = 5 and y = 8, then the harmonic mean is 2·5·8/(5+8) ~ 6.15, and the geometric mean is J5-8 ~ 6.32. If x = 10 and y = 100, then the harmonic mean is 2·10·100/(10+100) ~ 18.18, and the geometric mean is v'lO · 100 ~ 31.62. We conjecture that the harmonic mean of x and y is always less than their geometric mean if x and y are distinct positive real numbers (clearly if x = y then both means are this common value). So we want to verify the inequality 2xy/(x + y) < JXY. Multiplying both sides by (x + y)/(2v'xfj) gives us the equivalent inequality JXY < (:r + y)/2, which is proved in Example 14. 25. The key point here is that the parity (oddness or evenness) of the sum of the numbers written on the board never changes. If j and k are both even or both odd, then their sum and their difference are both even, and we are replacing the even sum j + k by the even difference IJ - kl , leaving the parity of the total unchanged. If j and k have different parities, then erasing them changes the parity of the total, but their difference Jj - kl is odd, so adding this difference restores the parity of the total. Therefore the integer we end up with at the end of the process must have the same parity as 1+2 + · · · + (2n). It is easy to compute this sum. If we add the first and last terms we get 2n + 1; if we add the second and next-to-last terms we get 2 + (2n - 1) = 2n + 1; and so on. In all we get n sums of 2n + 1, so the total sum is n(2n two odd numbers and therefore is odd, as desired. + 1). If n is odd, this is the product of 27. Without loss of generality we can assume that n is nonnegative, since the fourth power of an integer and the fourth power of its negative are the same. To get a handle on the last digit of n, we can divide n by 10, obtaining a quotient k and remainder l, whence n = lOk + l, and l is an integer between 0 and 9, inclusive. Then we compute n 4 in each of these ten cases. We get the following values, where ?? is some integer that is a multiple of 10, whose exact value we do not care about. (10k + 0) 4 = 10000k4 = 10000k4 (10k + 1) 4 (10k + 2) 4 4 +0 3 = 10000k + ?? . k + ?? . k 2 + ?? . k + 1 = 10000k4 + ?? . k 3 + ?? . k 2 + ?? . k + 16 (10k + 3) 4 = 10000k 4 + ?? . k 3 + ?? . k 2 + ?? . k + 81 (10k + 4) 4 = 10000k 4 +??. k 3 + ?? . k 2 +??. k + 256 (10k + 5) 4 = 10000k4 + ?? . k 3 + ?? . k 2 + ?? . k + 625 (10k + 6) 4 = 10000k 4 + ?? . k 3 + ?? . k 2 + ?? . k + 1296 + 7) 4 = 10000k4 + ?? . k 3 + ?? . k 2 + ?? . k + 2401 (10k + 8) 4 = 10000k 4 + ?? . k 3 + ?? . k 2 + ?? . k + 4096 (10k + 9) 4 = 10000k 4 + ?? . k 3 + ?? . k 2 + ?? . k + 6561 (lOk Since each coefficient indicated by ?? is a multiple of 10, the corresponding term has no effect on the ones digit of the answer. Therefore the ones digits are 0, 1, 6, 1, 6, 5, 6, 1, 6, 1, respectively, so it is always a 0 , 1 , 5 , or 6 . 29. Because n 3 n2 + n3 31. Since 54 = > 100 for all n > 4, we need only note that n = 1, n = 2, n = 3, and n = 4 do not satisfy 100. = 625, for there to be positive integer solutions to this equation both x and y must be less than 5. This means that each of x 4 and y 4 is at most 44 = 256, so their sum is at most 512 and cannot be 625. 33. We give a proof by contraposition. Assume that it is not the case that a ::; ijn or b ::; ijn or c ::; ijn. Then it must be true that a > ifi1 and b > -ifii, and c > ijn. Multiplying these inequalities of positive numbers together we obtain abc < ( ijri,) 3 = n, which implies the negation of our hypothesis that n = abc. Section 1.8 Proof Methods and Strategy 43 35. The idea is to find a small irrational number to add to the smaller of the two given rational numbers. Because we know that J2 is irrational, we can use a small multiple of v'2. Here is our proof: By finding a common denominator, we can assume that the given rational numbers are a/b and c/b, where b is a positive integer and a and c are integers with a < c. In particular, (a+ 1)/b:::; c/b. Thus x = (a+ ~J2)/b is between the two given rational numbers, because 0 < J2 < 2. Furthermore, x is irrational, because if x were rational, then 2(bx - a) = v'2 would be as well, in violation of Example 10 in Section 1. 7. 37. a) Without loss of generality, we may assume that the x sequence is already sorted into nondecreasing order, since we can relabel the indices. There are only a finite number of possible orderings for the y sequence, so if we can show that we can increase the sum (or at least keep it the same) whenever we find Yi and y1 that are out of order (i.e., i < j but Yi > y 1 ) by switching them, then we will have shown that the sum is largest when the y sequence is in nondecreasing order. Indeed, if we perform the swap, then we have added XiYJ +x1 yi to the sum and subtracted XiYi +x1 y1 . The net effect, then, is to have added XiYJ +x1 yi -XiYi -x1 y 1 = (x 1 -xi)(Yi -yj), which is nonnegative by our ordering assumptions. b) This is similar to part (a). Again we assume that the x sequence is already sorted into nondecreasing order. If the y sequence is not in nonincreasing order, then Yi < y1 for some i < j. By swapping Yi and Yj we increase the sum by XiYJ + x 1 yi - XiYi - x 1 y1 = (x 1 - xi)(Yi - y1 ), which is nonpositive by our ordering assumptions. 39. In each case we just have to keep applying the function f until we reach 1, where J(x) = 3x + 1 if x is odd and f(x) = x/2 if x is even. a) f(6) = 3, f(3) = 10, f(lO) = 5, f(5) = 16, f(16) = 8, f(8) = 4, f(4) = 2, f(2) = 1. We abbreviate this to 6 _.., 3 _.., 10 _.., 5 _.., 16 _.., 8 _.., 4 _.., 2 _.., 1. b) 7 _.., 22 _.., 11 _.., 34 _.., 17 _.., 52 _.., 26 _.., 13 _.., 40 _.., 20 _.., 10 _.., 5 _.., 16 _.., 8 _.., 4 _.., 2 _.., 1 c) 17 _.., 52 _.., 26 _.., 13 _.., 40 _.., 20 _.., 10 _.., 5 _.., 16 _.., 8 _.., 4-* 2 _.., 1 d) 21 _.., 64 _.., 32 _.., 16 _.., 8 _.., 4 _.., 2 _.., 1 41. We give a constructive proof. Without loss of generality, we can assume that the upper left and upper right corners of the board are removed. We can place three dominoes horizontally to fill the remaining portion of the first row, and we can place four dominoes horizontally in each of the other seven rows to fill them. 43. The number of squares in a rectangular board is the product of the number of squares in each row and the number of squares in each column. We are given that this number is even, so there is either an even number of squares in each row or an even number of squares in each column. In the former case, we can tile the board in the obvious way by placing the dominoes horizontally, and in the latter case, we can tile the board in the obvious way by placing the dominoes vertically. 45. We follow the suggested labeling scheme. Clearly we can rotate the board if necessary to make the removed squares be 1 and 16. Square 2 must be covered by a domino. If that domino is placed to cover squares 2 and 6, then the following domino placements are forced in succession: 5-9, 13-14, and 10-11, at which point there is no way to cover square 15. Otherwise, square 2 must be covered by a domino placed at 2-3. Then the following domino placements are forced: 4-8, 11-12, 6-7, 5-9, and 10-14, and again there is no way to cover square 15. 47. Remove the two black squares adjacent to one of the white corners, and remove two white squares other than that corner. Then no domino can cover that white corner, because neither of the squares adjacent to it remains. Chapter 1 44 The Foundations: Logic and Proofs 49. a) It is not hard to find the five patterns: 1 EE 4 5 qpLfb b) It is clear that the pattern labeled 1 and the pattern labeled 2 will tile the checkerboard. It is harder to find the tiling for patterns 3 and 4, but a little experimentation shows that it is possible. It remains to argue that pattern 5 cannot tile the checkerboard. Label the squares from 1 to 64, one row at a time from the top, from left to right in each row. Thus square 1 is the upper left corner, and square 64 is the lower right. Suppose we did have a tiling. By symmetry and without loss of generality, we may suppose that the tile is positioned in the upper left corner, covering squares 1, 2, 10, and 11. This forces a tile to be adjacent to it on the right, covering squares 3, 4, 12. and 13. Continue in this manner and we are forced to have a tile covering squares 6, 7, 15, and 16. This makes it impossible to cover square 8. Thus no tiling is possible. GUIDE TO REVIEW QUESTIONS FOR CHAPTER 1 1. a) See p. 3. b) This is not a boring course. 2. a) See pp. 4, 6, and 9. b) Disjunction: 'TU go to the movies tonight or I'll finish my discrete mathematics homework." Conjunction: "I'll go to the movies tonight and I'll finish my discrete mathematics homework." Exclusive or: "I'll go to the movies tonight or I'll finish my discrete mathematics homework, but not both." Conditional statement: "If I'll go to the movies tonight, then I'll finish my discrete mathematics homework." Biconditional: "I'll go to the movies tonight if and only if I'll finish my discrete mathematics homework." b) Seep. 8. c) Converse: "If I go for a walk in the woods tomorrow, then it will be sunny." Contrapositive: "If I don't go for a walk in the woods tomorrow, then it will not be sunny.'' 3. a) See p. 6. 4. a) See p. 25. b) using truth tables; symbolically, using identities in Tables 6-8 in Section 1.3; by giving a valid argument about the possible truth values of the propositional variables involved c) Use the fact that r ---; -iq = -,r V -iq, or use truth tables. Supplementary Exercises 45 5. a) Each line of the truth table corresponds to exactly one combination of truth values for the n atomic propositions involved. We can write down a conjunction that is true precisely in this case, namely the conjunction of all the atomic propositions that are true and the negations of all the atomic propositions that are false. If we do this for each line of the truth table for which the value of the compound proposition is to be true, and take the disjunction of the resulting propositions, then we have the desired proposition in its disjunctive normal form. See Exercise 42 in Section 1.3. b) See Exercise 43 in Section 1.3. c) See Exercises 50 and 52 in Section 1.3. 6. See pp. 40 and 42. The negation of VxP(x) is 3x-,P(x), and the negation of 3xP(x) is Vx•P(x). 7. a) In the second, x can depend on y. In the first, the same x must "work" for every y. b) See Example 4 in Section 1.5. 8. See pp. 69-70. This is a valid argument because it uses the valid rule of inference called modus tollens. 9. This is a valid argument because it uses the universal modus ponens rule of inference. Therefore if the premises are true, the conclusion must be true. 10. a) See pp. 82, 83, and 86. b) For a direct proof, the hypothesis implies that n = 2k for some k, whence n + 4 = 2(k + 2), so n + 4 is even. For a proof by contraposition, suppose that n + 4 is odd; hence n + 4 = 2k + 1 for some k. Then n = 2(k - 2) + 1, so n is odd, hence not even. For a proof by contradiction, assume that n = 2k and n + 4 = 21+1 for some k and l. Subtracting gives 4 = 2(1 - k) + 1, which means that 4 is odd, a contradiction. 11. a) See p. 87. b) Suppose that 3n + 2 is odd, so that 3n + 2 = 2k + 1 for some k. Multiply both sides by 3 and subtract 1, obtaining 9n+5 = 6k+2 = 2(3k+ 1). This shows that 9n+5 is even. We prove the converse by contraposition. Suppose that 3n + 2 is not odd, i.e., that it is even. Then 3n + 2 = 2k for some k. Multiply both sides by 3 and subtract 1, obtaining 9n + 5 = 6k - 1 = 2(3k - 1) + 1. This shows that 9n + 5 is odd. 12. No-we could add to these p2 --> p3 and p 1 --> p 4 , for example. 13. a) Find a counterexample, i.e., an object c such that P(c) is false. b) n = 1 is a counterexample. 14. See p. 96. 15. See p. 99. 16. See Example 4 in Section 1.8. SUPPLEMENTARY EXERCISES FOR CHAPTER 1 1. a) q--> p (note that "only if" does not mean "if") b) q /\ p c) •q V •P (assuming inclusive use of the English word "or" is intended by the speaker) d) q '"'"'p (this is another way to say "if and only if" in English words) 3. We could use truth tables, but we can also argue as follows. a) Since q is false but the conditional statement p b) The disjunction says that either --> q is true, we must conclude that p is also false. p or q is true. Since p is given to be false, it follows that q must be true. 46 Chapter 1 The Foundations: Logic and Proofs 5. The inverse of p -+ q is •p -+ •q. Therefore the converse of the inverse is •q -+ •p. Note that this is the same as the contrapositive of the original statement. The converse of p-+ q is q-+ p. Therefore the converse of the converse is p -+ q, which was the original statement. The contrapositive of p -+ q is •q -+ •p. Therefore the converse of the contrapositive is •p -+ •q, which is the same as the inverse of the original statement. 7. The straightforward approach is to use disjunctive normal form. There are four cases in which exactly three of the variables are true. The desired proposition is (p/\q/\r/\•s) V (p/\q/\•r/\s) V (p/\•q/\r/\s) V (•p/\q/\r/\s). 9. Translating these statements into symbols, using the obvious letters, we have •t -+ •g, •g -+ •q, r -+ q, and •t /\ r. Assume the statements are consistent. The fourth statement tells us that •t must be true. Therefore by modus ponens with the first statement, we know that •g is true, hence (from the second statement) that •q is true. Also, the fourth statement tells us that r must be true, and so again modus ponens (third statement) makes q true. This is a contraction: q /\ •q. Thus the statements are inconsistent. 11. We make a table of the eight possibilities for p, q, and r, showing the truth values of the four propositions. p .q r •(p-+ (q /\ r)) pV •q (p/\r)V(q-+p) •r T T T T T T F T F T F T T T F T T T T F T T T T T F T F F F F T T F F F F T F F T F F F T F T F T F F F F T T T If we look at the first row of the table, we see that if the student rejects the first proposition, accepts the second, rejects the third, and accepts the fourth, then the resulting commitments are consistent, because the second and fourth propositions and the negations of the first and third propositions are all true in this case in which p, q, and r are all true. Similarly, looking at the sixth row of the table, where p and r are false but q is true, we see that a student who accepts the third proposition and rejects the other three also wins. Scanning the entire table, we see that the winning answers are reject-accept-reject-accept, accept-accept-accept-accept, acceptaccept-reject-accept, reject-reject-reject-reject, reject-reject-accept-reject, and reject-accept-accept-accept. 13. Aaron must be a knave, because a knight would never make the false statement that all of them are knaves. If Bohan is a knight, then he would be speaking the truth if Crystal is a knight, so that is one possibility. On the other hand, Bohan might be a knave, in which case his statement is already false, regardless of Crystal's identity. In this case, if Crystal were also a knave, then Aaron would have told the truth, which is impossible. So there are two possibilities for the ordered triple (Aaron, Bohan, Crystal), namely (knave, knight, knight) and (knave, knave, knight). 15. We are told that exactly one of these people committed the crime, and exactly one (the guilty party) is a knight. We look at the three cases to determine who the knight is. If Amy were the knight, then her protestations of innocence would be true, but that cannot be, since we know that the knight is guilty. If Claire were the knight, then her statement that Brenda is not a normal is true; and since Brenda cannot be the knight in this situation, Brenda must be a knave. That means that Brenda is lying when she says that Amy was telling the truth; therefore Amy is lying. This means that Amy is guilty, but that cannot be, since Amy isn't the knight. So Brenda must be the knight. Amy is an innocent normal who is telling the truth when she says she is innocent; Brenda is telling the truth when she says that Amy is telling the truth; and Claire is a normal who is telling the truth when she says that Brenda is not a normal. So Brenda committed the crime. Supplementary Exercises 47 17. The definition of valid argument is an argument in which the truth of all the premises forces the truth of conclusion. In this example, the two premises can never be true simultaneously, because they are contradictory, irrespective of the true status of the tooth fairy. Therefore it is (vacuously) true that whenever both of the premises are true, the conclusion is also true (irrespective of your luck at finding gold at the end of the rainbow). Because the premises are not both true, we cannot conclude that the conclusion is true. 19. This is done in exactly the same manner as was described in the text for a 9 x 9 Sudoku puzzle (Section 1.3), with the variables indexed from 1 to 16, instead of from 1 to 9, and with a similar change for the propositions for the 4 x 4 blocks: /\;=0 /\;=0 /\~6=1 v;=l v~=l p( 4r + i, 4s + j, n). 21. a) F, since 4 does not di vi de 5 b) T, since 2 di vi des 4 c) F, by the counterexample in part (a) d) T, since 1 divides every positive integer e) F, since no number is a multiple of all positive integers (No matter what positive integer n one chooses, if we take m = n + 1, then P( m, n) is false, since n + 1 does not divide n.) f) T, since 1 divides every positive integer 23. The given statement tells us that there are exactly two elements in the domain. Therefore if we let the domain be anything with size other than 2 the statement will be false. 25. For each person we want to assert the existence of two different people who are that person's parents. The most elegant way to do so is Vx3y3z(y =I z /\ Vw(P(w, x) <---+ (w = y V w = z))). Note that we are saying that w is a parent of x if and only if w is one of the two people whose existence we asserted. 27. To express the statement that exactly n members of the domain satisfy P, we need to use n existential quantifiers, express the fact that these n variables all satisfy P and are all different, and express the fact that every other member of the domain that satisfies P must be one of these. a) This is a special case, however. To say that there are no values of x that make P true we can simply write --,::JxP(x) or Vx--,P(x). b) This is the same as Exercise 52 in Section 1.5, because 31 xP(x) is the same as 3!xP(x). Thus we can write 3x(P(x) /\ Vy(P(y)---> y = x)). c) Following the discussion above, we write :3x1:3x2(P(x1) /\P(x 2 ) /\x 1 =I x2 /\ Vy(P(y)---> (y = x1 Vy= x2))). d) We expand the previous answer to one more variable: :3x 1:3x 2:3x 3 (P(x 1) /\ P(x 2 ) /\ P(x 3 ) /\ x 1 =I x 2 /\ x 1 =I X3 /\ X2 =fa X3 /\ Vy(P(y)---> (y = X1 Vy= X2 Vy= x3))). 29. Suppose that 3x(P(x)---> Q(x)) is true. Then for some x, either Q(x) is true or P(x) is false. If Q(x) is true for some x, then the conditional statement VxP(x)---> 3xQ(x) is true (having true conclusion). If P(x) is false for some x, then again the conditional statement VxP(x) ---> 3xQ(x) is true (having false hypothesis). Conversely, suppose that 3x(P(x)---> Q(x)) is false. That means that for every x, the conditional statement P(x) ---> Q(x) is false, or, in other words, P(x) is true and Q(x) is false. The latter statement implies that 3xQ(x) is false. Thus VxP(x) ---> 3xQ(x) has a true hypothesis and a false conclusion and is therefore false. 31. No. For each x there may be just one y making P(x, y) true, so that the second proposition will not be true. For example, let P( x, y) be x + y = 0, where the domain (universe of discourse) is the integers. Then the first proposition is true, since for each x there exists a y, namely -x, such that P(x, y) holds. On the other hand, there is no one x such that x + y = 0 for every y. 33. Let T(s,c,d) be the statement that students has taken class c in department d. Then, with the domains (universes of discourse) being the students in this class, the courses at this university, and the departments in the school of mathematical sciences, the given statement is VsVd::lcT(s, c, d). Chapter 1 48 The Foundations: Logic and Proofs 35. Let T(x, y) mean that student x has taken class y, where the domain is all students in this class. We want to say that there exists exactly one student for whom there exists exactly one class that this student has taken. So we can write simply :3!x:3!y T(x. y). To do this without quantifiers, we need to expand the uniqueness quantifier using Exercise 52 in Section 1.5. Doing so, we have :3x\fz((:3y\fw(T(z,w) +-+ w = y)) +-+ z = x). 37. By universal instantiation we have P(a) Q(a) and Q(a) •Q(a). and again by modus tollens we conclude •P(a). ft -+ R(a). By modus tollens we then conclude fi is rational, then x is rational, assuming throughout that x 2'. 0. = p / q is rational, q -j. 0. Then x = ( fi) 2 = p 2 / q2 is also rational ( q2 is again nonzero). 39. We give a proof by contraposition that if Suppose that -+ 41. We can give a constructive proof by letting m = 10500 + 1. Then m 2 = (10 500 + 1) 2 > (10 500 ) 2 = 10 1000. 43. The first three positive cubes are 1, 8, and 27. If we want to find a number that cannot be written as the sum of eight cubes, we would look for a number that is 7 more than a small multiple of 8. Indeed, 23 will do. \Ve can use two S's but then would have to use seven l's to reach 23, a total of nine numbers. Clearly no smaller collection will do. This counterexample disproves the statement. 45. The first three positive fifth powers are 1, 32, and 243. If we want to find a number that cannot be written as the sum of 36 fifth powers, we would look for a number that is 31 more than a small multiple of 32. Indeed, 7 · 32 - 1 = 223 will do. We can use six 32's but then would have to use 31 l's to reach 223, a total of 37 numbers. Clearly no smaller collection will do. This counterexample disproves the statement. WRITING PROJECTS FOR CHAPTER 1 Books and articles indicated by bracketed symbols below are listed near the end of this manual. You should also read the general comments and advice you will find there about researching and writing these essays. 1. An excellent website for this is www. paradoxes. co. uk. It includes a bibliography. 2. Search your library's on-line catalog for a book with the word fuzzy in the title. You might find [BaGo], [DuPr], [Ka], [Ko3], or [McFr], for example. 3. Look for this article (available on the Web): Marques-Silva, J. (2008) Practical Applications of Boolean Satisfiability. Also try a book published by the American Mathematical Society, the proceedings of a workshop on this topic: Satisfiability Problem: Theory and Applications. 4. A Web search for ''solving sudoku" should get you more than enough sources. 5. Even if you can't find a set, you may find some articles about it in materials for high school students and teachers, such as old issues of Mathematics Teacher. published by the National Council of Teachers of Mathematics. This journal, and possibly even copies of the game, may exist in the education library at your school (if there is one). The company that currently produces it has a website: wffnproof. com. 6. Martin Gardner and others have written some books that annotate Carroll's writings quite extensively. Lewis Carroll has become a cult figure in certain circles. See also [Cal], [Ca2], and [Ca3], for original material. 7. A textbook on logic programming and/or the language PROLOG, such as [Ho2] or [Sal], would be a logical place to start. Many bookstores have huge computer science sections, so that source should not be ignored. Writing Projects 49 8. A course on computational logic at Stanford in 2005-2006 had a Web page with class notes: logic. stanford. edu/classes/cs157 /2005fall/cs157 .html. Enderton's book on logic [En] would be a possible choice for background information. 9. There are books on this subject, such as [Du]. 10. A place to start might be a recent article on this topic in Science [Re]. As always, a Web search will also turn up more information. 11. There is an excellent article on this by Keith Devlin, writing for the Mathematical Association of America (MAA); see www.maa.org/devlin/devlin_05_03 .html. 12. The well-known on-line encyclopedia made up of articles by contributors is usually quite good, with accurate information and useful links and cross-references. See their article on Chomp: en. wikipedia. org/wiki/Chomp. 13. The references given in the text are the obvious place to start. The mathematics education field has bought into P6lya's ideas, especially as they relate to problem-solving. See what the National Council of Teachers of Mathematics (www.nctm.org) has to say about it. 14. The classic work in this field is [GrSh]. Chapter 2 50 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices CHAPTER2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices SECTION 2.1 Sets This exercise set (note that this is a "set" in the mathematical sense!) reinforces the concepts introduced in this section-set description, subset and containment, cardinality, power set, and Cartesian product. A few of the exercises (mostly some of the even-numbered ones) are a bit subtle. Keep in mind the distinction between "is an element of" and "is a subset of." Similarly, there is a big difference between 0 and { 0}. In dealing with sets, as in most of mathematics, it is extremely important to say exactly what you mean. 1. a) {1,-1} b) {1,2,3,4,5,6,7,8,9,10,11} c) {O, 1, 4, 9, 16, 25, 36, 49, 64, 81} d) 0 ( v'2 is not an integer) 3. Recall that one set is a subset of another set if every element of the first set is also an element of the second. We just have to apply this definition here. a) Because every nonstop flight is a flight, every element in the first set is also an element of the second, so the first set is a subset of the second. Because there are flights that do have intermediate stops (say, from New York to Atlanta with a stop in Detroit), the second set is not a subset of the first. b) Because there is certainly at least one person who speaks English but not Chinese, and vice versa, neither set is a subset of the other. c) Every flying squirrel is a living creature that can fly, so the first set is a subset of the second. Because birds, for instance, are leaving creatures that can fly but are not flying squirrels, the second set is not a subset of the first. 5. a) Yes; order and repetition do not matter. b) No; the first set has one element, and the second has two elements. c) No; the first set has no elements, and the second has one element (namely the empty set). 7. a) Since 2 is an integer greater than 1, 2 is an element of this set. b) Since 2 is not a perfect square ( 12 < 2, but n 2 > 2 for n > 1 ), 2 is not an element of this set. c) This set has two elements, and as we can clearly see, one of those elements is 2. d) This set has two elements, and as we can clearly see, neither of those elements is 2. Both of the elements of this set are sets; 2 is a number, not a set. e) This set has two elements, and as we can clearly see, neither of those elements is 2. Both of the elements of this set are sets; 2 is a number, not a set. f) This set has just one element, namely the set { {2}}. So 2 is not an element of this set. Note that {2} is not an element either, since {2} =f. { {2}}. 9. a) This is false, since the empty set has no elements. b) This is false. The set on the right has only one element, namely the number 0, not the empty set. c) This is false. In fact, the empty set has no proper subsets. Section 2.1 Sets 51 d) This is true. Every element of the set on the left is, vacuously, an element of the set on the right; and the set on the right contains an element, namely 0, that is not in the set on the left. e) This is false. The set on the right has only one element, namely the number 0, not the set containing the number 0. f) This is false. For one set to be a proper subset of another, the two sets cannot be equal. g) This is true. Every set is a subset of itself. 11. a) T (in fact x is the only element) b) T (every set is a subset of itself) d) T (in fact, {x} is the only element) c) F (the only element of {x} is a letter, not a set) e) T (the empty set is a subset of every set) f) F (the only element of {x} is a letter, not a set) 13. The four months whose names don't contain the letter R form a subset of the set of twelve months, as shown here. January February March Apnl September November 0 ctober December 15. We put the subsets inside the supersets. We also put dots in certain regions to indicate that those regions are not empty (required by the fact that these are proper subset relations). Thus the answer is as shown. u 1 7. We need to show that every element of A is also an element of C. Let x E A. Then since A ~ B, we can conclude that x E B. Furthermore, since B ~ C, the fact that x E B implies that x E C, as we wished to show. 19. The cardinality of a set is the number of elements it has. The number of elements in its elements is irrelevant. a) 1 b) 1 21. a) {0,{a}} c) 2 d) 3 b) {0, {a}, {b}, {a,b}} c) {0,{0},{{0}},{0,{0}}} 23. a) Since the set we are working with has 3 elements, the power set has 23 =8 elements. b) Since the set we are working with has 4 elements, the power set has 24 = 16 elements. c) The power set of the empty set has 2° = 1 element. The power set of this set therefore has 21 In particular, it is { 0, { 0}}. (See Example 14.) = 2 elements. 25. We need to prove two things, because this is an "if and only if" statement. First, let us prove the "if" part. We are given that A ~ B. We want to prove that the power set of A is a subset of the power set of B, which means that if C ~ A then C ~ B. But this follows directly from Exercise 17. For the "only if" part, we are given that the power set of A is a subset of the power set of B. We must show that every element of A is also an element of B. So suppose a is an arbitrary element of A. Then {a} is a subset of A, so it is an element of the power set of A. Since the power set of A is a subset of the power set of B, it follows that {a} is an element of the power set of B, which means that {a} is a subset of B. But this means that the element of {a}, namely a, is an element of B, as desired. 52 Chapter 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 27. In each case we need to list all the ordered pairs, and there are 4 x 2 = 8 of them. a) {(a,y), (a,z), (b,y), (b,z), (c,y), (c,z), (d,y), (d,z)} b) {(y,a), (y,b),(y,c), (y,d),(z,a), (z,b),(z,c), (z,d)} 29. This is the set of triples (a, b, c), where a is an airline and b and c are cities. For example, (American, Rochester Hills Michigan, Middletown New Jersey) is an element of this Cartesian product. A useful subset of this set is the set of triples (a, b, c) for which a flies between band c. For example, (Delta, Detroit, New York) is in this subset, but the triple mentioned earlier is not. 31. By definition, 0 x A consists of all pairs (x, a) such that x E 0 and a E A. Since there are no elements x E 0 , there are no such pairs, so 0 x A = 0 . Similar reasoning shows that A x 0 = 0. 33. Recall that A 2 = A x A. Therefore here we must list all the ordered pairs of elements of A. a) {(0,0), (0,1),(0,3),(1,0), (1,1),(1,3), (3,0),(3,1),(3,3)} b) {(1,1),(1,2),(1,a),(1,b),(2,1), (2,2),(2,a),(2,b),(a,1),(a,2),(a,a),(a,b),(~ 1), (~2), (b,a), (~b)} 35. The Cartesian product Ax B has mn elements. (This problem foreshadows the general discussion of counting in Chapter 5.) To see that this answer is correct, note that for each a E A there are n different elements b E B with which to form the pair (a, b). Since there are m different elements of A, each leading to n different pairs, there must be mn pairs altogether. 37. The Cartesian product Ax A has m 2 elements. (This problem foreshadows the general discussion of counting in Chapter 6.) To see that this answer is correct, note that for each a E A there are m different elements b EA (including a itself) with which to form the pair (a,b). Since there are m different elements of A, each leading to m different pairs, there must be m 2 pairs altogether. Similarly, for each of the m 2 choices of a and b, there are m choices of c with which to form the triple (a, b, c) in A 3 , so A 3 has m 3 elements. Continuing in this way, we see that An has m n elements. 39. The only difference between Ax Bx C and (Ax B) x C is parentheses, so for all practical purposes one can think of them as essentially the same thing. By Definition 9, the elements of A x B x C consist of 3-tuples (a, b, c), where a E A, b E B, and c E C. By Definition 8, the elements of (Ax B) x C consist of ordered pairs (p, c), where p E A x B and c E C, so the typical element of (A x B) x C looks like ((a, b), c). A 3-tuple is a different creature from a 2-tuple, even if the 3-tuple and the 2-tuple in this case convey exactly the same information. To be more precise, there is a natural one-to-one correspondence between Ax B x C and (Ax B) x C given by (a, b, c) +---+ ((a, b), c). 41. a) Every real number has its square not equal to -1. Alternatively, the square of a real number is never -1. This is true, since squares of real numbers are always nonnegative. b) There exists an integer whose square is 2. This is false, since the only two numbers whose squares are 2, namely J2 and -J2, are not integers. c) The square of every integer is positive. This is almost true, but not quite, since 02 f 0. d) There is a real number equal to its own square. This is true, since x = 1 (as well as x = 0) fits the bill. 43. In each case we want the set of all values of x in the domain (the set of integers) that satisfy the given equation or inequality. a) The only integers whose squares are less than 3 are the integers whose absolute values are less than 2. So the truth set is {x E Z I x 2 < 3} = {-1,0,1}. Section 2.2 53 Set Operations b) All negative integers satisfy this inequality, as do all nonnegative integers other than 0 and 1. So the truth set is {x E Z x 2 > x} = Z- {O, 1} = { ... ,-2,-1,2,3,4, ... }. c) The only real number satisfying this equation is x = -1/2. Because this value is not in our domain, the truth set is empty: {x E Z 2x + 1 = O} = 0. J J 45. First we prove the statement mentioned in the hint. The "if" part is immediate from the definition of equality. The "only if" part is rather subtle. We want to show that if {{a},{a,b}} = {{c},{c,d}}, then a= c and b = d. First consider the case in which a I- b. Then { {a}, {a, b}} has exactly two elements, both of which are sets; exactly one of them contains one element, and exactly one of them contains two elements. Thus {{c}, {c, d}} must have the same property; hence c cannot equal d, and so {c} is the element containing one element. Hence {a} = {c}, and so a = c. Also in this case the two-element elements {a, b} and {c, d} must be equal, and since b I- a = c, we must have b = d. The other possibility is that a = b. Then {{a},{a,b}} ={{a}}, a set with one element. Hence {{c},{c,d}} must also have only one element, which can only happen when c = d and the set is { {c}} . It then follows that a = c, and hence b = d, as well. Now there is really nothing else to prove. The property that we want ordered pairs to have is precisely the one that we just proved is satisfied by this definition. Furthermore, if we look at the proof, then it is clear how to "recover" both a and b from { {a}, {a, b}} . If this set has two elements, then a is the unique element in the one-element element of this set, and b is the unique member of the two-element element of this set other than a. If this set has only one element, then a and b are both equal to the unique element of the unique element of this set. 47. We can do this recursively, using the idea from Section 5.4 of reducing a problem to a smaller instance of the same problem. Suppose that the elements of the set in question are listed: A= {a 1 , a 2 , a 3 , ... , a,,}. First we will write down all the subsets that do not involve a,,. This is just the same problem we are talking about all over again, but with a smaller set---one with just n - 1 elements. We do this by the process we are currently describing. Then we write these same subsets down again, but this time adjoin a,, to each one. Each subset of A will have been written down, then-first all those that do not include a,,, and then all those that do. For example, using this procedure the subsets of {p, d, q} would be listed in the order 0, {p} , {d} , {p,d}, {q}, {p,q}, {d,q}, {p,d,q}. An alternative solution is given in the answer key in the back of the textbook. SECTION 2.2 Set Operations Most of the exercises involving operations on sets can be done fairly routinely by following the deEnitions. It is important to understand what it means for two sets to be equal and how to prove that two given sets are equal-using membership tables, using the definition to reduce the problem to logic, or showing that each is a subset of the other; see, for example, Exercises 5-24. It is often helpful when looking at operations on sets to draw the Venn diagram, even if you are not asked to do so. The symmetric difference is a fairly important set operation not discussed in the section; it is developed in Exercises 32-43. Two other new concepts, multisets and fuzzy sets, are also introduced in this set of exercises. Chapter 2 54 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 1. a) the set of students who live within one mile of school and walk to class (only students who do both of these things are in the intersection) b) the set of students who either live within one mile of school or walk to class (or, it goes without saying, both) c) the set of students who live within one mile of school but do not walk to class d) the set of students who live more than a mile from school but nevertheless walk to class 3. a) We include all numbers that are in one or both of the sets, obtaining {O, 1, 2, 3, 4, 5, 6}. b) There is only one number in both of these sets, so the answer is { 3}. c) The set of numbers in A but not in B is {1, 2, 4, 5}. d) The set of numbers in B but not in A is {O, 6}. 5. By definition A is the set of elements of the universal set that are not in A. Not being in A means being in A. Thus A is the same set as A. We can give this proof in symbols as follows: A = { x I •X E A} = { x I ••X E A} = { x I x E A} = A. 7. These identities are straightforward applications of the definitions and are most easily stated using set-builder notation. Recall that T means the proposition that is always true, and F means the proposition that is always false. a) AU U = { x I x E A V x E U} = { x I x E A V T} = { x I T} = U b) An 0 = { x Ix EA/\ x E 0} = { x Ix EA /\ F} = { x IF}= 0 9. a) We must show that every element (of the universal set) is in AU A. This is clear, since every element is either in A (and hence in that union) or else not in A (and hence in that union). b) We must show that no element is in An A. This is clear, since An and not in A at the same time, obviously an impossibility. A consists of elements that are in A 11. These follow directly from the corresponding properties for the logical operations or and and. a) AU B = { x I x E A V x E B} = { x I x E B V x E A} = B U A b) An B = { x Ix EA/\ x EB}= { x Ix EB /\ x EA}= B n A 13. We will show that these two sets are equal by showing that each is a subset of the other. Suppose x E An (AU B). Then x EA and x EAU B by the definition of intersection. Since x EA, we have proved that the left-hand side is a subset of the right-hand side. Conversely, let x E A. Then by the definition of union, x E AU B as well. Since both of these are true, x E An (AU B) by the definition of intersection, and we have shown that the right-hand side is a subset of the left-hand side. 15. This exercise asks for a proof of one of De Morgan's laws for sets. The primary way to show that two sets are equal is to show that each is a subset of the other. In other words, to show that X = Y, we must show that whenever x E X, it follows that x E Y, and that whenever x E Y, it follows that x E X. Exercises 5- 7 could also have been done this way, but it was easier in those cases to reduce the problems to the corresponding problems of logic. Here, too, we can reduce the problem to logic and invoke De Morgan's law for logic, but this problem requests specific proof techniques. a) This proof is similar to the proof of the dual property, given in Example 10. Suppose x E AU B. Then x rf_ AU B. which means that x is in neither A nor B. In other words, x rf- A and x rf_ B. This is equivalent to saying that x E A and x E B. Therefore x E An B' as desired. Conversely, if x E An B' then x E A and x E B. This means x rf- A and x rf- B, so x cannot be in the union of A and B . Since x rf- A U B, we conclude that x E A U B, as desired. Section 2.2 55 Set Operations b) The following membership table gives the desired equality, since columns four and seven are identical. A E 1 1 1 0 0 0 AUE --1 1 1 0 1 0 AUE --0 0 0 1 A E AnE --0 0 0 1 - 0 0 1 1 0 1 0 1 17. This exercise asks for a proof of a generalization of one of De Morgan's laws for sets from two sets to three. a) This proof is similar to the proof of the two-set property, given in Example 10. Suppose x E An B n C. Then x ~ An B n C, which means that x fails to be in at least one of these three sets. In other words, x ~ A or x r:f. E or x r:f. C. This is equivalent to saying that x E A or x E E or x E C. Therefore x E AU E U C, as desired. Conversely, if x E AUE UC, then x E A or x E E or x E C. This means x r:f. A or x r:f. E or x r:f. C, so x cannot be in the intersection of A, E and C. Since x r:f. A n E n C, we conclude that x E A n E n C, as desired. b) The following membership table gives the desired equality, since columns five and nine are identical. A E c AnEnC AnEnC 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 A E c AUE UC 0 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 1 19. a) This is clear, since both of these sets are precisely { x I x E A /\ x r:f. E}. b) One approach here is to use the distributive law; see the answer section for that approach. Alternatively, we can argue directly as follows. Suppose x E (An E) U (An E). Then we know that either x E An E or x E An B (or both). If either case, this forces x E A. Thus we have shown that the left-hand side is a subset of the right-hand side. For the opposite direction, suppose x E A. There are two cases: x E E and x r:f. E. In the former case, x is then an element of An E and therefore also an element of (An E) U (An E). In the latter cases, x E E and therefore x is an element of An E and therefore also an element of (An E) U (An E). 21. There are many ways to prove identities such as the one given here. One way is to reduce them to logical identities (some of the associative and distributive laws for V and /\). Alternately, we could argue in each case that the left-hand side is a subset of the right-hand side and vice versa. Another method would be to construct membership tables (they will have eight rows in order to cover all the possibilities). Here we choose the second method. First we show that every element of the left-hand side must be in the right-hand side as well. If x E AU (EU C), then x must be either in A or in EU C (or both). In the former case, we can conclude that x E AUE and thus x E (AUE) UC, by the definition of union. In the latter case, x must be either in E or in C (or both). In the former subcase, we can conclude that x E AU B and thus x E (AUE) UC, by the definition of union; in the latter subcase, we can conclude that x E (AU B) UC, again using the definition of union. The argument in the other direction is practically identical, with the roles of A, E, and C switched around. 23. There are many ways to prove identities such as the one given here. One way is to reduce them to logical identities (some of the associative and distributive laws for V and /\ ). Alternately, we could argue in each case that the left-hand side is a subset of the right-hand side and vice versa. Another method would be to construct membership tables (they will have eight rows in order to cover all the possibilities). Here we choose Chapter 2 56 Basic Structures: Sets, Functions, Sequences, Sums, and l\fatrices the third method. We construct the following membership table and note that the fifth and eighth columns are identical. A B BnC Au (B n C) AuB Aue (Au B) n (AU C) c 1 1 1 1 0 0 0 0 1 1 0 0 1 0 1 0 1 0 0 0 1 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 25. These are straightforward applications of the definitions. a) The set of elements common to all three sets is {4, 6}. b) The set of elements in at least one of the three sets is {O, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. c) The set of elements in C and at the same time in at least one of A and B is {4, 5, 6, 8, 10}. d) The set of elements either in C or in both A and B (or in both of these) is {O, 2, 4, 5, 6, 7, 8, 9, 10}. 27. a) In the figure we have shaded the A set with horizontal bars (including the double-shaded portion, which includes both horizontal and vertical bars), and we have shaded the set B- C with vertical bars (that portion inside B but outside C. The intersection is where these overlap-the double-shaded portion (shaped like an arrowhead). b) In the figure we have shaded the set A nB with horizontal bars (including the double-shaded portion, which includes both horizontal and vertical bars), and we have shaded the set A n C with vertical bars. The union is the entire region that has any shading at all (shaped like a tilted mustache). c) In the figure we have shaded the set An B with horizontal bars (including the double-shaded portion, which includes both horizontal and vertical bars), and we have shaded the set An C with vertical bars. The union is the entire region that has any shading at all (everything inside A except the triangular middle portion where all three sets overlap) portion (shaped like an arrowhead). (a) (c) (b) 29. a) If B adds nothing new to A, then we can conclude that all the elements of B were already in A. In other words, B <:;; A. b) In this case, all the elements of A are forced to be in B as well, so we conclude that A <:;; B. c) This equality holds precisely when none of the elements of A are in B (if there were any such elements, then A - B would not contain all the elements of A). Thus we conclude that A and B are disjoint (A n B = 0). d) We can conclude nothing about A and B in this case, since this equality always holds. e) Every element in A- B must be in A, and every element in B - A must not be in A. Since no item can be in A and not be in A at the same time, there are no elements in both A - B and B - A. Thus the only way for these two sets to be equal is if both of them are the empty set. This means that every element of A must be in B, and every element of B must be in A. Thus we conclude that A = B. 31. This is the set-theoretic version of the contrapositive law for logic, which says that p to --.q -+ --.p. We argue as follows. A<:;; B =Vx(x E A-+ x E B) =Vx(x tf. B-+ x tf. A) =Vx(x E B -+ x EA) -+ =B <:;;A q is logically equivalent Section 2.2 Set Operations 57 33. Clearly this will be the set of students majoring in computer science or mathematics but not both. 35. This is just a restatement of the definition. An element is in (AU B) - (An B) if it is in the union (i.e., in either A or B), but not in the intersection (i.e., not in both A and B). 37. We will use the result of Exercise 36 as well as some obvious identities (some of which are in Exercises a) A EB A= (A - A) U (A - A)= 0 u 0 = 0 c) A EB U =(A - U) u (U - A) = 0 u A= A 6~10). b) A EB 0 =(A - 0) u (0 - A)= Au 0 =A d) A EB A= (A - A) u (A - A)= Au A= U 39. We can conclude that B = 0. To see this, suppose that B contains some element b. If b E A, then b is excluded from A EB B, so A EB B cannot equal A. On the other hand, if b tf: A, then b must be in A EB B, so again A EB B cannot equal A. Thus in either case, A EB B -/=- A. We conclude that B cannot have any elements. 41. Yes. To show that A= B, we need to show that x E A implies x E B and conversely. By symmetry, it will be enough to show one direction of this. So assume that A EB C = B EB C, and let x E A be given. There are two cases to consider, depending on whether x E C. If x E C, then by definition we can conclude that x t/: A EB C. Therefore x tf: B EB C. Now if x were not in B, then x would be in B EB C (since x E C by assumption). Since this is not true, we conclude that x E B, as desired. For the other case, assume that x t/: C. Then x E A EB C. Therefore x E B EB C as well. Again, if x were not in B, then it could not be in B EB C (since x t/: C by assumption). Once again we conclude that x E B, and the proof is complete. 43. Yes. Both sides equal the set of elements that occur in an odd number of the sets A, B, C, and D. 45. We give a proof by contradiction. If A U B is finite, then it has n elements for some natural number n. But A already has more than n elements, because it is infinite, and A U B has all the elements that A has, so A U B has more than n elements. This contradiction shows that A U B must be infinite. 47. a) The union of these sets is the set of elements that appear in at least one of them. In this case the sets are "increasing": Ai ~ A2 ~ • · · ~ An. Therefore every element in any of the sets is in An, so the union is An= {1,2, ... ,n}. b) The intersection of these sets is the set of elements that appear in all of them. Since Ai = {1} , only the number 1 has a chance to be in the intersection. In fact 1 is in the intersection, since it is in all of the sets. Therefore the intersection is Ai = {1}. 49. a) Here the sets are increasing. A bit string of length not exceeding 1 is also a bit string of length not exceeding 2, so Ai ~ Az. Similarly, Az ~ A3 ~ A4 ~ · · · ~ An. Therefore the union of the sets Ai, Az, ... , An is just An itself. b) Since Ai is a subset of all the Ai 's, the intersection is Ai , the set of all nonempty bit strings of length not exceeding 1, namely {O, 1}. 51. a) As i increases, the sets get larger: Ai C A2 C A 3 · · ·. All the sets are subsets of the set of integers, and every integer is included eventually, so LJ:i Ai = Z. Because Ai is a subset of each of the others, n:i Ai= Ai= {-1, 0, 1}. b) All the sets are subsets of the set of integers, and every nonzero integer is in exactly one of the sets, so LJ:i Ai = Z - {O}. Each pair of these sets are disjoint, so no element is common to all of the sets. Therefore n:iAi = 0. 58 Chapter 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices c) This is similar to part (a), the only difference being that here we are working with real numbers. Therefore 1 Ai = R (the set of all real numbers), and 1 Ai = A1 = [-1, 1] (the interval of all real numbers between -1 and 1, inclusive). LJ: n: d) This time the sets are getting smaller as i increases: · · · C A 3 C A2 C A 1 . Because A 1 includes all LJ: the others, 1 Ai = A1 = [1, oo) (all real numbers greater than or equal to 1). Every number eventually gets excluded as i increases, so 1 A, = 0. Notice that oo is not a real number, so we cannot write 1 Ai = { oo}. n: n: 53. The ith digit in the string indicates whether the ith number in the universal set (in this case the number i) is in the set in question. a) {1,2,3,4,7,8,9,10} b) {2,4,5,6,7} c) {1, 10} 55. We are given two bit strings, representing two sets. We want to represent the set of elements that are in the first set but not the second. Thus the bit in the ith position of the bit string for the difference is 1 if the ith bit of the first string is 1 and the ith bit of the second string is 0, and is 0 otherwise. 57. We represent the sets by bit strings of length 26, using alphabetical order. Thus A is represented by 11 1110 0000 0000 0000 0000 0000, B is represented by 01 1100 1000 0000 0100 0101 0000, To a) b) c) d) C is represented by 00 1010 0010 0000 1000 0010 0111, and D is represented by 00 0110 0110 0001 1000 0110 0110. find the desired sets, we apply the indicated bitwise operations to these strings. 11 1110 0000 0000 0000 0000 0000 V 01 1100 1000 0000 0100 0101 0000 = 111110 1000 0000 0100 0101 0000, which represents the set {a,b,c,d,e,g,p,t,v} 11 1110 0000 0000 0000 0000 0000 /\ 011100 1000 0000 0100 0101 0000 = 01 1100 0000 0000 0000 0000 0000, which represents the set {b, c, d} (11 1110 0000 0000 0000 0000 0000 V 00 0110 0110 0001 1000 0110 0110) /\ (01 1100 1000 0000 0100 0101 0000 v 00 1010 0010 0000 1000 0010 0111) = 11 1110 0110 0001 1000 0110 0110 /\ 01 1110 1010 0000 1100 0111 0111 = 011110 0010 0000 1000 0110 0110, which represents the set {b,c,d,e,i,o,t,u,x,y} 11 1110 0000 0000 0000 0000 0000 v 01 1100 1000 0000 0100 0101 0000 v 00 1010 0010 0000 1000 0010 0111 v 00 0110 0110 0001 1000 0110 0110 = 11 1110 1110 0001 1100 0111 0111, which represents the set {a,b,c,d,e,g,h,i,n,o,p,t,u,v,x,y,z} 59. We simply adjoin the set itself to the list of its elements. a) {1,2,3,{l,2,3}} b) {0} c) {0,{0}} d) {0,{0},{0,{0}}} 61. a) The multiplicity of a in the union is the maximum of 3 and 2, the multiplicities of a in A and B. Since the maximum is 3, we find that a occurs with multiplicity 3 in the union. Working similarly with b, c (which appears with multiplicity 0 in B), and d (which appears with multiplicity 0 in A), we find that AU B = {3 ·a, 3 · b, 1 · c, 4 · d}. b) This is similar to part (a), with "maximum" replaced by "minimum." Thus An B = {2 ·a, 2 · b}. (In particular, c and d appear with multiplicity 0-i.e., do not appear-in the intersection.) c) In this case we subtract multiplicities, but never go below 0. Thus the answer is { 1 · a, 1 · c}. d) Similar to part (c) (subtraction in the opposite order); the answer is {1 · b,4 · d}. e) We add multiplicities here, to get {5 · a, 5 · b, 1 · c, 4 · d}. Section 2.3 Functions 59 63. Assume that the universal set contains just Alice, Brian, Fred, Oscar, and Rita. We subtract the degrees of membership from 1 to obtain the complement. Thus F is {0.4 Alice, 0.1 Brian, 0.6 Fred, 0.9 Oscar, 0.5 Rita}, and R is {0.6 Alice, 0.2 Brian, 0.8 Fred, 0.1 Oscar, 0.3 Rita}. 65. Taking the minimums, we obtain {0.4 Alice, 0.8 Brian, 0.2 Fred, 0.1 Oscar, 0.5 Rita} for F n R. SECTION 2.3 Functions The importance of understanding what a function is cannot be overemphasized-functions permeate all of mathematics and computer science. This exercise set enables you to make sure you understand functions and their properties. Exercise 33 is a particularly good benchmark to test your full comprehension of the abstractions involved. The definitions play a crucial role in doing proofs about functions. To prove that a function f : A ---> B is one-to-one, you need to show that x 1 -j. x 2 ---> f(xi) -j. f(x2) for all x 1 , x2 E A. To prove that such a function is onto, you need to show that \::/y EB 3x EA (f(x) = y). 1. a) The expression I/x is meaningless for x is no rule at all. In other words, f = 0, which is one of the elements in the domain; thus the "rule" (0) is not defined. b) Things like Hare undefined (or, at best, are complex numbers). c) The "rule" for f is ambiguous. We must have f(x) defined uniquely, but here there are two values associated with every x, the positive square root and the negative square root of x 2 + 1 . 3. a) This is not a function, because there may be no zero bit in S, or there may be more than one zero bit in S. Thus there may be no value for f (S) or more than one. In either case this violates the definition of a function, since f(S) must have a unique value. b) This is a function from the set of bit strings to the set of integers, since the number of 1 bits is always a clearly defined nonnegative integer. c) This definition does not tell what to do with a nonempty string consisting of all O's. Thus, for example, f(OOO) is undefined. Therefore this is not a function. 5. In each case we want to find the domain (the set on which the function operates, which is implicitly stated in the problem) and the range (the set of possible output values). a) Clearly the domain is the set of all bit strings. The range is Z; the function evaluated at a string with n l's and no O's is n, and the function evaluated at a string with n O's and no l's is -n. b) Again the domain is clearly the set of all bit strings. Since there can be any natural number of O's in a bit string, the value of the function can be 0, 2, 4, .... Therefore the range is the set of even natural numbers. c) Again the domain is the set of all bit strings. Since the number of leftover bits can be any whole number from 0 to 7 (if it were more, then we could form another byte), the range is {O, 1, 2, 3, 4, 5, 6, 7}. d) As the problem states, the domain is the set of positive integers. Only perfect squares can be function values, and clearly every positive perfect square is possible. Therefore the range is {l, 4, 9, 16, ... }. 7. In each case, the domain is the set of possible inputs for which the function is defined, and the range is the set of all possible outputs on these inputs. a) The domain is z+ x z+, since we are told that the function operates on pairs of positive integers (the word "pair" in mathematics is usually understood to mean ordered pair). Since the maximum is again a positive integer, and all positive integers are possible maximums (by letting the two elements of the pair be the same), the range is z+ . Chapter 2 60 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices z+ . Since the decimal representation of an integer has to have at least one digit, at most nine digits do not appear, and of course the number of missing digits could be any number less than 9. Thus the range is {O, 1, 2, 3, 4, 5, 6, 7, 8, 9}. b) We are told that the domain is c) We are told that the domain is the set of bit strings. The block 11 could appear no times, or it could appear any positive number of times, so the range is N. d) We are told that the domain is the set of bit strings. Since the first 1 can be anywhere in the string, its position can be 1, 2, 3, .... If the bit string contains no l's, the value is 0 by definition. Therefore the range is N. 9. The floor function rounds down and the ceiling function rounds up. a)l b)O c)O d)-1 e)3 f)-1 g)l~+l~lJ=l~+2J=l2~J=2 h) lH~JJ = l~. 2J = llJ = 1 11. We need to determine whether the range is all of {a, b, c, d}. It is for the function in part (a), but not for the other two functions. 13. a) This function is onto, since every integer is 1 less than some integer. In particular, f(x + 1) = x. b) This function is not onto. Since n 2 + 1 is always positive, the range cannot include any negative integers. c) This function is not onto, since the integer 2, for example, is not in the range. In other words, 2 is not the cube of any integer. d) This function is onto. If we want to obtain the value x, then we simply need to start with 2x, since f(2x) = l2x/2l = lxl = x for all x E Z. 15. An onto function is one whose range is the entire codomain. Thus we must determine whether we can write every integer in the form given by the rule for f in each case. a) Given any integer n, we have f(O, n) = n, so the function is onto. b) Clearly the range contains no negative integers, so the function is not onto. c) Given any integer m, we have f(m, 25) = m, so the function is onto. (We could have used any constant in place of 25 in this argument.) d) Clearly the range contains no negative integers, so the function is not onto. e) Given any integer m, we have f(m, 0) = m, so the function is onto. 17. a) This may be one-to-one (if there are no shared offices) or not (if there are shared offices). b) Again, this depends on the policy of the school. Assuming that no bus gets more than one teacher chaperone, this function will be one-to-one. c) This is most likely not one-to-one, because two teachers might have the same salary. On the other hand, it may happen that everyone's salary is different, in which case it is one-to-one. d) This is clearly a one-to-one function, because social security numbers are unique--no two people can have the same social security number. 19. a) The codomain could be the set of all offices in the school. This is probably not onto; for example, the secretaries probably have offices, and those offices are not in the range of this function (because the secretaries are not in the domain). b) The codomain could be the set of busses going on the field trip. This is probably an onto function, as long as school policy is that every bus has to have a teacher chaperone. c) The codomain could be all positive real numbers (with the understanding that the number represents the salary in dollars). The function is clearly not onto; no teacher has a salary of y'2 dollars or 10 10 dollars. Section 2.3 Functions 61 d) The codomain could be all strings of nine digits. This function is not onto, because the social security number of everyone who is not a teacher at the school is not in the range of the function. 21. Obviously there are an infinite number of correct answers to each part. The problem asked for a "formula." Parts (a) and ( c) seem harder here, since we somehow have to fold the negative integers into the positive ones without overlap. Therefore we probably want to treat the negative integers differently from the positive integers. One way to do this with a formula is to make it a two-part formula. If one objects that this is not "a formula,'' we can counter as follows. Consider the function g( x) = L2x J/2x. Clearly if x 2: 0, then 2x is a positive integer, so g( x) = 2x /2x = 1. If x < 0, then 2x is a number between 0 and 1, so g( x) = 0/2x = 0. Ifwe want to define a function that has the value fi(x) when x 2: 0 and h(x) when x < 0, then we can use the formula g(x) · fi(x) + (1- g(x)) · h(x). a) We could map the positive integers (and 0) into the positive multiples of 3, say, and the negative integers into numbers that are 1 greater than a multiple of 3, in a one-to-one manner. This will give us a function that leaves some elements out of the range. So let us define our function as follows: f(x) = { 3x+3 3lxl + 1 if x 2: 0 if x < 0 The values of f on the inputs 0 through 4 are then 3, 6, 9, 12, 15; and the values on the inputs -1 to -4 are 4, 7, 10, 13. Clearly this function is one-to-one, but it is not onto since, for example, 2 is not in the range. b) This is easier. We can just take f(x) = lxl + 1. It is clearly onto, but f(n) and f(-n) have the same value for every positive integer n, so f is not one-to-one. c) This is similar to part (a), except that we have to be careful to hit all values. Mapping the nonnegative integers to the odds and the negative integers to the evens will do the trick: f(x) = { ~~11 if x 2: 0 if x < 0 d) Here we can use a trivial example like f(x) = 17 or a simple nontrivial one like f(x) = x 2 + 1. Clearly these are neither one-to-one nor onto. 23. a) One way to determine whether a function is a bijection is to try to construct its inverse. This function is a bijection, since its inverse (obtained by solving y = 2x + 1 for x) is the function g(y) = (y - 1) /2. Alternatively, we can argue directly. To show that the function is one-to-one, note that if 2x + 1 = 2x' + 1, then x = x'. To show that the function is onto, note that 2( (y - 1) /2) + 1 = y, so every number is in the range. b) This function is not a bijection, since its range is the set ofreal numbers greater than or equal to 1 (which is sometimes written [1, oo)), not all of R. (It is not injective either.) c) This function is a bijection, since it has an inverse function, namely the function f(y) = y 1 13 (obtained by solving y = x 3 for x). d) This function is not a bijection. It is easy to see that it is not injective, since x and -x have the same image, for all real numbers x. A little work shows that the range is only { y I 0.5 :S: y < 1} = [0.5, 1). 25. The key here is that larger denominators make smaller fractions, and smaller denominators make larger fractions. We have two things to prove, since this is an "if and only if" statement. First, suppose that f is strictly decreasing. This means that f(x) > f(y) whenever x < y. To show that g is strictly increasing, suppose that x < y. Then g(x) = 1/ f(x) < 1/ f(y) = g(y). Conversely, suppose that g is strictly increasing. This means that g( x) < g(y) whenever x < y. To show that f is strictly decreasing, suppose that x < y. Then f(x) = l/g(x) > l/g(y) = f(y). 62 Chapter 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 27. a) Let f be the given strictly decreasing function from R to itself. We need to show that f(a) = f(b) implies a= b for all a, b E R. We give an indirect proof by proving the contrapositive: if a i- b, then f(a) i- f(b). There are two cases. Suppose a < b; then because f is strictly decreasing, it follows that f(a) > f(b). Similarly, if a> b, then f(a) < f(b). Thus in either case, f(a) i- f(b). b) We need to make the function decreasing, but not strictly decreasing, so, for example, we could take the trivial function f (x) = 17. If we want the range to be all of R, we could define f(x) = -x- l for x < -1; f(x) = 0 for -1:::; x:::; 1; and f(x) = -x+ 1forx>1. f in parts this way: 29. The function is not one-to-one (for example, f(2) = 2 = f(-2) ), so it is not invertible. On the restricted domain, the function is the identity function from the set of nonnegative real numbers to itself, f (x) = x, so it is one-to-one and onto and therefore invertible; in fact, it is its own inverse. 31. In each case, we need to compute the values of f(x) for each x ES. a) Note that f(±2) = l(±2) 2 /3J = l4/3J = 1, J(±l) = l(±1) 2 /3J = ll/3J = 0, f(O) = l0 2 /3J = lOJ = 0, and f (3) = l 32 /3 J = l 3J = 3. Therefore f (S) = {O, 1, 3}. b) In addition to the values we computed above, we note that f(4) = 5 and f(5) = 8. Therefore f(S) = {0,1,3,5,8}. c) Note this time also that f(7) = 16 and f(ll) = 40, so f(S) = {0,8, 16,40}. d) {f(2),f(6),f(10),f(l4)} = {1,12,33,65} 33. In both cases, we can argue directly from the definitions. a) Assume that both f and g are one-to-one. We need to show that fog is one-to-one. This means that we need to show that if x and y are two distinct elements of A, then f(g(x)) i- f(g(y)). First, since g is one-to-one, the definition tells us that g(x) i- g(y). Second, since now g(x) and g(y) are distinct elements of B, and since f is one-to-one, we conclude that f(g(x)) i-f(g(y)), as desired. b) Assume that both f and g are onto. We need to show that f o g is onto. This means that we need to show that if z is any element of C, then there is some element x E A such that f(g(x)) = z. First, since f is onto, we can conclude that there is an element y E B such that f (y) = z. Second, since g is onto and y E B, we can conclude that there is an element x EA such that g(x) = y. Putting these together, we have z = f(y) = f(g(x)), as desired. 35. To establish the setting here, let us suppose that g : A ___, B and f : B ___, C. Then f o g: A ___, C. We are told that f and fog are onto. Thus all of C gets "hit" by the images of elements of B; in fact, each element in C gets hit by an element from A under the composition f o g. But this does not seem to tell us anything about the elements of B getting hit by the images of elements of A. Indeed, there is no reason that they must. For a simple counterexample, suppose that A= {a}, B = {b 1 ,b2 }, and C = {c}. Let g(a) = b1 , and let f(b 1 ) = c and f(b 2 ) = c. Then clearly f and fog are onto, but g is not, since b2 is not in its range. 37. We just perform the indicated operations on the defining expressions. Thus f + g is the function whose value at x is (x 2 +1) + (x + 2), or, more simply, (f + g)(x) = x 2 + x + 3. Similarly Jg is the function whose value at x is (x 2 + l)(x + 2); in other words, (f g)(x) = x 3 + 2x 2 + x + 2. 39. We simply solve the equation y = ax + b for x. This gives x = (y - b) /a, which is well-defined since a i- 0. Thus the inverse is 1- 1 (y) = (y-b)/a. To check that our work is correct, we must show that f of- 1 (y) = y for all y E R and that 1- 1 o f(x) = x for all x E R. Both of these are straightforward algebraic manipulations. For the first, we have f o 1- 1 (y) = J(f- 1 (y)) = J((y- b)/a) = a((y- b)/a) + b = y. The second is similar. Functions Section 2.3 63 41. a) Let us arrange for 8 and T to be nonempty sets that have empty intersection. Then the left-hand side will be f(0), which is the empty set. If we can make the right-hand side nonempty, then we will be done. We can make the right-hand side nonempty by making the codomain consist of just one element, so that J(8) and f(T) will both be the set consisting of that one element. The simplest example is as follows. Let A = {1, 2} and B = {3}. Let f be the unique function from A to B (namely /(1) = /(2) = 3 ). Let S = {1} and T = {2}. Then !(8 n T) = /(0) = 0, which is a proper subset of /(8) n f (T) = {3} n {3} = {3}. b) Assume that f is one-to-one. We must show that every element of l (8) n l (T) is an element of l (8 n T). Let y E B be an element of 1(8) n l(T). Then y E 1(8), so y = f(xi) for some x 1 E 8. Similarly, y E l (T), so y = l (x2) for some X2 ET. Because l is one-to-one, it follows that x 1 = x 2 . This element is therefore in 8 n T' so y E l (8 n T). 43. a) We want to find the set of all numbers whose floor is 0. Since all numbers from 0 to 1 (including 0 but not 1) round down to 0, we conclude that g- 1 ( {O}) = { x I 0 ~ x < 1} = [O, 1). b) This is similar to part (a). All numbers from -1 to 2 (including -1 but not 2) round down to -1, 0, or l; we conclude that g- 1 ({-1,0, 1}) = {x I -1~x<2} = [-1,2). c) Since g(x) is always an integer, there are no values of x such that g(x) is strictly between 0 and 1. Thus the inverse image in this case is the empty set. 45. Note that the complementation here is with respect to the relevant universal set. Thus S = B - 8 and l- 1 (8) =A- 1- 1 (8). There are two things to prove in order to show that these two sets are equal: that the left-hand side of the equation is a subset of the right-hand side, and that the right-hand side is a subset of the left-hand side. First let x E 1- 1 (S). This means that l (x) ES, or equivalently that l (x) 8. Therefore by definition of inverse image, x 1- 1 (8), so x E 1- 1 (8). For the other direction, assume that x E 1- 1 (8). Then x l- 1 (8). By definition this means that l(x) 8, which means that l(x) ES. Therefore by definition, x E l- 1 (S). tt tt tt tt 47. There are three cases. Define the "fractional part" of x to be l(x) = x- lxJ. Clearly l(x) is always between 0 and 1 (inclusive at 0, exclusive at 1), and x = lxJ + l(x). If l(x) is less than~, then x - ~will have a value slightly less than lx J ' so when we round up, we get lx J. In other words, in this case x - ~ l = lx J ' and indeed that is the integer closest to x. If l(x) is greater than~' then x - ~will have a value slightly greater than lx J , so when we round up, we get lx J + 1. In other words, in this case Ix - ~ l = lx J + 1, and indeed that is the integer closest to x in this case. Finally, if the fractional part is exactly ~ , then x is midway between two integers, and x - ~ l = lx J' which is the smaller of these two integers. r r 49. We can write the real number x as l x J + t, where t is a real number satisfying 0 ~ t < 1. Since t = x - l x J , we have 0 ~ x - lx J < 1. The first two inequalities, x - 1 < lx J and lx J ~ x, follow algebraically. For the other two inequalities, we can write x = x l - E, where again 0 ~ E < 1. Then 0 ~ x l - x < 1, and again the desired inequalities follow by easy algebra. r r 51. a) One direction (the "only if" part) is obvious: If x < n, then since lxJ ~ x it follows that lxJ < n. We will prove the other direction (the "if" part) indirectly (we will prove its contrapositive). Suppose that x 2: n. Then "the greatest integer not exceeding x" must be at least n, since n is an integer not exceeding x. That is, lx J 2: n. b) One direction (the "only if" part) is obvious: If n < x, then since x ~ Ixl it follows that n < fx l . We will prove the other direction (the "if" part) indirectly (we will prove its contrapositive). Suppose that n 2: x. Then "the smallest integer not less than x" must be no greater than n, since n is an integer not less than x. That is, lxl ~ n. Chapter 2 64 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 53. If n is even, then n = 2k for some integer k. Thus l n/2 J = l k J = k = n/2. If n is odd, then n = 2k + 1 for some integer k. Thus Ln/2J = Lk + ~J = k = (n -1)/2. 55. Without loss of generality we can assume that x 2 0, since the equation to be proved is equivalent to the same equation with -x substituted for x. Then the left-hand side is f-x l by definition, and the right-hand side is - l x J. Thus this problem reduces to Exercise 54. Its proof is straightforward. Write x as n + E, where n is a natural number and E is a real number satisfying 0 s E < 1. Then clearly -xl = -n - El = -n and -LxJ =-Ln+Ej =-n as well. r r 57. In some sense this question is its own answer-the number of integers strictly between a and b is the number of integers strictly between a and b. Presumably we seek an expression involving a, b, and the floor and/or ceiling function to answer this question. If we round a down and round b up to integers, then we will be looking at the smallest and largest integers just outside the range of integers we want to count, respectively. These values are of course la J and fb l , respectively. Then the answer is fbl - la J - 1 (just think of counting all the integers between these two values, excluding both ends-if a row of fenceposts one foot apart extends for k feet, then there are k - 1 fenceposts not counting the end posts). Note that this even works when, for example, a= 0.3 and b = 0.7. 59. Since a byte is eight bits, all we are asking for in each case is fn/81 , where n is the number of bits. a) f7/8l = 1 b) f17/8l = 3 d) f28800/8l = 3600 c) f1001/8l = 126 61. In each case we need to divide the number of bytes (octets) by 1500 and round up. In other words, the answer r is n/15001, where n is the number of bytes. a) f150,000/1500l = 100 d) 45,300,000;15001 = 30,200 r b) f384,000/1500l = 256 c) fl,544,000/15001 = 1030 63. The graph will look exactly like the graph of the function f (x) = lx J, shown in Figure lOa, except that the picture will be compressed by a factor of 2 in the horizontal direction, since x has been replaced by 2x. -2 -1 -1 _, _, -2 -3 65. This is a step function, with values changing only at the integers. We note the pattern that f(x) jumps by 1 when x passes through an odd integer (because of the lxJ term), and by 2 when x passes through an even integer (an additional jump caused by the l x /2 J term). The result is as shown. -3 -2 -1 -1 -2 _, -3 -4 _, -5 1 2 3 4 Section 2.3 65 Functions 67. a) The graph will look exactly like the graph of the function f(x) = lxJ, shown in Figure lOa, except that the picture will be shifted to the left by ~ unit, since x has been replaced by x + ~ = x - (- ~). 3 _, 2 _, 1 _, -4 - 2 _ , -1 _, 4 -2 _, -3 b) The graph will look exactly like the graph of the function f(x) = l2xj, shown in the solution to Exercise 63, except that the picture will be shifted to the left by ~ unit, since x has been replaced by x + ~. Alternatively, we can note that f(x) can be rewritten as l2xj + 1, so the graph is the graph shown in the solution to Exercise 63 shifted up one unit. -2 -1 _, _, -1 -2 _, -3 c) The graph will look exactly like the graph of the function f(x) = j x l, shown in Figure lOb, except that the x-axis is stretched by a factor of 3. Thus we can use the same picture and just relabel the x-axis. -12 -9 -6 -3 ~ -1 ~ 3 6 9 12 -2 ~ -3 d) The graph is a step version of the usual hyperbola y = 1/x. Note that x = 0 is not in the domain. The graph can be drawn by first plotting the points at which 1/x is an integer (x = 1, ±~, ±~, ... ) and then filling in the horizontal segments, making sure to note that they go to the right (for example, if x is a little bigger than ~, then 1/x is a little less than 2, so f(x) = 2, since we are rounding up here). Note that f(x) = 1 for x 2 1, and f(x) = 0 for x < -1. eo 4 3 _, - ~ -1 ~ -1 _, eo -2 -3 e) The key thing to note is that since we can pull integers outside the floor and ceiling function (identity (4) in Table 1), we can write f (x) more simply as l x J + j x l · When x is an integer, this is just 2x. When x is between two integers, however, this has the value of the integer between the two integers 2 l x J and 2 j x l . The graph is therefore as shown here. 66 Chapter 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 4 • ~ • -2 -1 -1 • -2 -3 ~ • -4 f} The basic shape is the parabola, y = x 2 . In particular, for x an even integer, l(x) = x 2 , since the terms inside the floor and ceiling function symbols are integers. However, because of these step functions, the curve is broken into steps. At even integers other than x = 0 there are isolated points in the graph. Also, the graph takes jumps at all the integer and half-integer values outside the range -2 < x < ~ (where in fact l(x) = 0). The portion of the graph near the origin is shown here. _, • -2 4 -1 -1 -2 -3 -4 g) Despite the complicated-looking formula, this is really quite similar to part (a}; in fact, we'll see that it's identical! First note that the expression inside the outer ceiling function symbols is always going to be a half-integer; therefore we can tell exactly what its rounded-up value will be, namely l x - ~ J+ 1. Furthermore, since identity (4) of Table 1 allows us to move the 1 inside the floor function symbols, we have l(x) = lx+ ~J. Therefore this is the same function as in part (a). 69. We simply need to solve the equation y = x 3 +1 for x. This is easily done by algebra: x = (y-1) 113 . Therefore the inverse function is given by the rule 1- 1 (y) = (y-1) 113 (or, equivalently, by the rule 1- 1 (x) = (x -1) 113 , since the variable in the definition is just a dummy variable). 71. We can prove all of these identities by showing that the left-hand side is equal to the right-hand side for all possible values of x. In each instance (except part ( c), in which there are only two cases), there are four cases to consider, depending on whether x is in A and/or B. a) If x is in both A and B, then fAnB(x) = 1; and the right-hand side is 1 · 1 = 1 as well. Otherwise x tJ_ A n B , so the left-hand side is 0, and the right-hand side is either 0 · 1 or 1 · 0 or 0 · 0, all of which are also 0. b} If xis in both A and B, then lAuB(x) = 1; and the right-hand side is 1+1-1·1=1 as well. If xis in A but not B, then x E AU B, so the left-hand side is still 1, and the right-hand side is 1 + 0 - 1 · 0 = 1, as desired. The case in which x is in B but not A is similar. Finally, if x is in neither A nor B, then the left-hand side is 0, and the right-hand side is 0 + 0 - 0 · 0 = 0 as well. c) If x E A, then x tJ_ A, so f-x( x) = 0. The right-hand side equals 1 - 1 = 0 in this case, as well. On the other hand, if x tJ_ A, then x E A, so the left-hand side is 1, and the right-hand side is 1 - 0 = 1 as well. d} If x is in both A and B, then x tJ_ A EBB, so 1AEFJB(x) = 0. The right-hand side is 1+1 - 2 · 1·1 = 0 as well. Next, if x E A but x tJ_ B, then x E A EBB, so the left-hand side is 1. The right-hand side is 1 + 0 - 2 · 1 · 0 = 1 as well. The case x E B /\ x tJ_ A is similar. Finally, if x is in neither A nor B, then x tJ_ A EBB, so the left-hand side is 0; and the right-hand side is also 0 + 0 - 2 · 0 · 0 = 0. Section 2.3 Functions 67 73. a) This is true. Since lxJ is already an integer, flxJl = lxJ. b) A little experimentation shows that this is not always true. To disprove it we need only produce a counterexample, such as x = ~. In that case the left-hand side is l 1J = 1, while the right-hand side is 2. 0 = o. c) This is true. We prove it by cases. If x is an integer, then by identity (4b) in Table 1, we know that fx + y l = x + fy l , and it follows that the difference is 0. Similarly, if y is an integer. The remaining case is that x = n + E and y = m + 8, where n and m are integers and E and 8 are positive real numbers less than 1 . Then x + y will be greater than m + n but less than m + n + 2, so fx + y l will be either m + n + 1 or m + n + 2. Therefore the given expression will be either (n + 1) + (m + 1) - (m + n + 1) = 1 or (n + 1) + (m + 1) - (m + n + 2) = 0, as desired. d) This is clearly false, as we can find with a little experimentation. Take, for example, x Then the left-hand side is f3/10l = 1, but the right-hand side is 1 · 3 = 3. = 1/10 and y = 3. e) Again a little trial and error will produce a counterexample. Take x = 1/2. Then the left-hand side is 1 while the right-hand side is 0. 75. a) If x is a positive integer, then the two sides are identical. So suppose that x = n 2 + m + E, where n is the largest perfect square integer less than x, m is a nonnegative integer, and 0 < E < 1. For example, if x = 13.2, then n = 3, m = 4, and E = 0.2. Then both fa and = Jn 2 + m are between n and n + 1. Therefore both sides of the equation equal n. VIXJ b) If x is a positive integer, then the two sides are identical. So suppose that x = n 2 - m - E, where n is the smallest perfect square integer greater than x, m is a nonnegative integer, and E is a real number with 0 < E < 1. For example, if x = 13.2, then n = 4, m = 2, and E = 0.8. Then both fa and = Jn 2 -- m are between n - 1 and n. Therefore both sides of the equation equal n. v1JXT 77. In each case we easily read the domain and codomain from the notation. The domain of definition is obtained by determining for which values the definition makes sense. The function is total if the domain of definition is the entire domain (so that there are no values for which the partial function is undefined). a) The domain is Z and the codomain is R. Since division is possible by every nonzero number, the domain of definition is all the nonzero integers; {0} is the set of values for which f is undefined. (It is not total.) b) The domain and codomain are both given to be Z. Since the definition makes sense for all integers, this is a total function, whose domain of definition is also Z; the set of values for which f is undefined is 0. c) By inspection, the domain is the Cartesian product Z x Z , and the co domain is Q . Since fractions cannot have a 0 in the denominator, we must exclude the "slice" of Z x Z in which the second coordinate is 0. Thus the domain of definition is Z x (Z - {O}), and the function is undefined for all values in Z x {O}. It is not a total function. d) The domain is given to be Z x Z and the codomain is given to be Z. Since the definition makes sense for all pairs of integers, this is a total function, whose domain of definition is also Z x Z; the set of values for which f is undefined is 0. e) Again the domain and codomain are Z x Z and Z, respectively. Since the definition is only stated for those pairs in which the first coordinate exceeds the second, the domain of definition is { (m, n) I m > n}, and therefore the set of values for which the function is undefined is { (m, n) I m ::; n}. It is not a total function. 79. a) By definition, to say that S has cardinality m is to say that S has exactly m distinct elements. Therefore we can imagine enumerating them, as a child counts objects: assign the first object to 1, the second to 2, and so on. This provides the one-to-one correspondence. b) By part (a), there is a bijection f from S to {1,2, ... ,m} and a bijection This tells us that g- 1 from T to {1,2, ... ,m}. is a bijection from {1, 2, ... , m} to T. Then the composition g- 1 of is the desired g 68 Chapter 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices bijection from S to T. SECTION 2.4 Sequences and Summations This exercise set contains a lot of routine practice with the concept of and notation for sequences. It also discusses telescoping sums; the product notation, corresponding to the summation notation discussed in the section; and the factorial function, which occurs repeatedly in subsequent chapters. There are also a few challenging exercises on more complicated sequences and sums. 1. a) a0 =2·(-3) 0 +5°=2·1+1=3 b) c) a4 = 2 · (-3) 4 + 54 = 2 · 81+625 = 787 a1 =2·(-3) 1 +5 1 =2·(-3)+5=-1 d) a 5 = 2 · (-3) 5 + 55 = 2 · (-243) + 3125 = 2639 3. In each case we simply evaluate the given function at n = 0, 1, 2, 3. a) ao = 2° + 1 = 2, b) ao = 11 = 1, a1 a1 = 21 + 1 = 3, = 22 = 4, a2 a2 = 22 + 1 = 5, a3 = 23 + 1 = 9 = 33 = 27, a3 = 44 = 256 c) ao = L0/2J = 0, a1 = Ll/2J = 0, a2 = L2/2J = 1, a3 = L3/2j = 1 d) ao = L0/2j + I0/21 = 0 + 0 = 0, ai = Ll/2j + ll/21 = 0 + 1 = 1, az = L2/2j + 12/21 a3 = L3/2J + 13/21=1+2 = 3. Note that Ln/2J + ln/21 always equals n. 1+1 = 2, 5. In each case we just follow the instructions. a) 2,5,8,11,14,17,20,23,26,29 b) 1,1,1,2,2,2,3,3,3,4 c) 1,1,3,3,5,5,7,7,9,9 d) This requires a bit of routine calculation. For example, the fifth term is 5! - 25 = 120 - 32 = 88. The first ten terms are -1, -2, -2, 8, 88, 656, 4912, 40064, 362368, 3627776. e) 3,6,12,24,48,96,192,384,768,1536 f) 2,4,6,10,16,26,42,68,110,178 g) For n = 1, the binary expansion is 1, which has one bit, so the first term of the sequence is 1. For n = 2, the binary expansion is 10, which has two bits, so the second term of the sequence is 2. Continuing in this way we see that the first ten terms are 1,2,2,3,3,3,3,4,4,4. Note that the sequence has one 1, two 2's, four 3's, eight 4's, as so on, with 2k-l copies of k. h) The English word for 1 is "one" which has three letters, so the first term is 3. This makes a good brain-teaser; give someone the sequence and ask her or him to find the pattern. The first ten terms are 3,3,5,4,4,3,5,5,4,3. 7. One pattern is that each term is twice the preceding term. A formula for this would be that the nth term is 2n-l. Another pattern is that we obtain the next term by adding increasing values to the previous term. Thus to move from the first term to the second we add 1; to move from the second to the third we add 2 ; then add 3, and so on. So the sequence would start out 1, 2, 4, 7, 11, 16, 22, .... We could also have trivial answers such as the rule that the first three terms are 1, 2, 4 and all the rest are 17 (so the sequence is 1, 2, 4, 17, 17, 17, ... ), or that the terms simply repeat 1, 2, 4, 1, 2, 4, 1, 2, 4, .... Here is another pattern: Take n points on the unit circle, and connect each of them to all the others by line segments. The inside of the circle will be divided into a number of regions. What is the largest this number can be? Call that value an. If there is one point, then there are no lines and therefore just the one original region inside the circle; thus a 1 = 1. If n = 2, then the one chord divides the interior into two parts, so a 2 = 2. Three points give us a triangle, and that makes four regions (the inside of the triangle and the three pieces outside the triangle), so a 3 = 4. Careful drawing shows that the sequence starts out 1, 2, 4, 8, 16, 31. That's right: 31, not 32. Section 2.4 Sequences and Summations 69 Creative students may well find other rules or patterns with various degrees of appeal. 9. We need to compute the terms of the sequence one at a time, since each term is dependent upon one or more of the previous terms. a) We are given ao = 2. Then by the recurrence relation an = 6an-1 we see (by letting n = 1) that a 1 = 6ao = 6·2 = 12. Similarly a 2 = 6a 1 = 6·12 = 72, then a3 = 6a 2 = 6·72 = 432, and a 4 = 6a 3 = 6·432 = 2592. b) a1 = 2 (given), a2 = ai = 22 = 4, a3 =a~= 42 = 16, a 4 =a~= 16 2 = 256, a5 =a~= 256 2 = 65536 c) This time each term depends on the two previous terms. We are given a 0 = 1 and a 1 = 2. To compute = 2 in the recurrence relation, obtaining a 2 = a 1 + 3a0 = 2 + 3 · 1 = 5. Then we have a3 = a2 + 3a1 = 5 + 3 · 2 = 11 and a4 = a3 + 3a2 = 11 + 3 · 5 = 26. a2 we let n d) ao = 1 (given), a1 = 1 (given), a 2 = 2a1+2 2ao = 2 · 1+4 · 1 = 6, a 3 = 3a2 + 32a 1 =3·6+9 · 1 = 27, a4 = 4a3 + 4 2a2 = 4 · 27 + 16 · 6 = 204 e) We are given ao = 1, ai = 2, and a 2 = 0. Then a 3 = a 2 + a 0 = 0 + 1 = 1 and a 4 = a 3 + a 1 = 1 + 2 = 3. 11. a) We simply plug in n = 0, n = 1, n = 2, n = 3, and n = 4. Thus we have a 0 = 2° + 5 · 3° = 1 + 5 · 1 = 6, a1 = 21 + 5 · 3I = 2 + 5 · 3 = 17, a 2 = 22 + 5 · 32 = 4 + 5 · 9 = 49, a 3 = 23 + 5 · 33 = S + 5 · 27 = 143, and a4 = 24 + 5 · 34 = 16 + 5 · Sl = 421. b) Using our data from part (a), we see that 49 = 5 · 17 - 6 · 6, 143 = 5 · 49 - 6 · 17, and 421 = 5 · 143 - 6 · 49. c) This is algebra. The messiest part is factoring out a large power of 2 and a large power of 3. If we substitute n - 1 for n in the definition we have an-1 = 2n-l + 5 · 3n-I; similarly an_ 2 = 2n- 2 + 5 · 3n- 2 . We start with the right-hand side of our desired identity: 5an-I - 6an-2 = 5(2n-l + 5 · 3n-l) - 6(2n- 2 + 5 · 3n- 2) = 2n- 2(10 - 6) + 3n- 2(75 - 30) = 2n- 2 · 4 + 3n- 2 · 9 · 5 = 2n + 3n . 5 = an 13. In each case we have to substitute the given equation for an into the recurrence relation an =San-I -16an_ 2 and see if we get a true statement. Remember to make the appropriate substitutions for n (either n - 1 or n - 2) on the right-hand side. What we are really doing here is performing the inductive step in a proof by mathematical induction: if the formula is correct for an-I (and also for an- 2 , etc., in some cases), then the formula is also correct for an . a) Plugging an Therefore an = 0 into the equation an = 8an-1 - 16an_ 2 , we obtain the true statement that 0 = 0. = 0 is a solution of the recurrence relation. b) Plugging an = 1 into the equation an =San-I -16an-2, we obtain the false statement 1 = S· 1-16· 1 = -S. Therefore an = 1 is not a solution. c) Plugging an= 2n into the equation an= 8an-l -16an_ 2 , we obtain the statement 2n = s.2n- 1 -15.2n- 2 . By algebra, the right-hand side equals 2n- 2 (8 · 2 - 16) = 0. Since this is not equal to the left-hand side, we conclude that an = 2n is not a solution. d) Plugging an= 4n into the equation an= San-I -16an-2, we obtain the statement 4n = s.4n-l _ 15.4n- 2 . By algebra, the right-hand side equals 4n- 2 (S · 4-16) = 4n- 2 • 16 = 4n- 2 · 42 = 4n. Since this is the left-hand side, we conclude that an = 4n is a solution. e) Plugging an = n4n into the equation an= 8an-l -16an_ 2 , we obtain the statement n4n = 8(n-1)4n-l l6(n-2)4n- 2 . By algebra, the right-hand side equals 4n- 2 (S(n-1)·4-16(n-2)) = 4n- 2 (32n-32-16n+32) = 4n- 2(l6n) = 4n- 2 · 42 n = n4n. Since this is the left-hand side, we conclude that an= n4n is a solution. Chapter 2 70 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices f) Plugging a,, = 2 · 4n + 3n4" into the equation an = 8an-l - 16a,,_ 2 , we obtain the statement 2 · 4n + 3n4" = 8(2 · 4n-l + 3(n - 1)4n-l) - 16(2 · 4n- 2 + 3(n - 2)4n- 2). By algebra, the right-hand side equals 4"- 2 (8 · 2 ·4+8 ·3(n-1) · 4-16 · 2-16 · 3(n-2)) = 4n- 2(64+96n-96-32-48n+96) = 4n- 2(48n+32) = 4n- 2 ·4 2(3n+2) = (2+3n)4n. Since this is the same as the left-hand side, we conclude that an= 2.4n +3n4n is a solution. g) Plugging an= (-4)n into the equation a,, = 8an_ 1 -l6a 11 _2, we obtain the statement (-4)" = 8·(-4)"- 1 16· (-4)n-2. Byalgebratheright-handsideequals (-4)"- 2(8·(-4)-16) = (-4)n- 2(-48) = -3(-4)n. Since this is not equal to the left-hand side, we conclude that an= (-4)n is not a solution. h) Plugging a,, = n 2 4n into the equation an = 8a11 _1 2 - l6a 11 _ 2 , we obtain the statement n 4n = 8(n 1 2 2 2 2 2 2 1) 4n- -16(n-2) 4n- . By algebra, the right-hand side equals 4n- (8(n-1) ·4-16(n-2) ) = 4n- 2 (32(n 2 2n + 1) -16(n 2 - 4n+ 4)) = 4n- 2(32n 2 - 64n + 32 -16n 2 + 64n- 64) = 4"- 2 (16n 2 - 32) = 4n- 2 · 42 (n 2 - 2) = 4"(n 2 - 2). Since this is not equal to the left-hand side, we conclude that an= n 24n is not a solution. 15. In each case we have to plug the purported solution into the right-hand side of the recurrence relation and see if it simplifies to the left-hand side. The algebra can get tedious, and it is easy to make a mistake. a) We have an-l + 2an-2 + 2n - 9 = -(n - 1) + 2 + 2(-(n - 2) + 2) + 2n - 9 = -n+2 =an. b) We have an-l + 2an-2 + 2n - 9 = 5(-1)"- 1 - (n - 1) + 2 + 2(5(-1) 11 - 2 - (n - 2) + 2) + 2n - 9 = 5(-1)"- 2(-1+2) - n + 2 =a,,. Note that we had to factor out ( -1) 11 - 2 and that this is the same as ( -1 )" since ( -1 ) 2 = 1. c) We have an-l + 2a,,_2 + 2n - 9 = 3(-l)n-l + 2n-l - (n - 1) + 2 + 2(3(-1)"- 2 + 2n- 2 - (n - 2) + 2) + 2n - 9 = 3(-1)"- 2(-1+2) + 2n- 2(2 + 2) - n + 2 =a,,. Note that we had to factor out 211 - 2 and that 2n- 2 · 4 = 2". d) We have an-l + 2an-2 + 2n - 9 = 7 · 2n-l - (n - 1) + 2 + 2(7 · 2"- 2 - (n - 2) + 2) + 2n - 9 = 2n- 2(7 · 2 + 2 · 7) - n + 2 =an. 17. In the iterative approach, we write a,, in terms of a,,_ 1 , then write an-l in terms of an-2 (using the recurrence relation with n - 1 plugged in for n), and so on. When we reach the end of this procedure, we use the given initial value of a 0 . This will give us an explicit formula for the answer or it will give us a finite series, which we then sum to obtain an explicit formula for the answer. a) We write an = 3an-l 2 = 3(3a 11 -2) = 3 an-2 2 3 = 3 (3an-3) = 3 an-3 Note that we figured out the last line by following the pattern that had developed in the first few lines. Therefore the answer is an = 2 · 3" . Section 2.4 Sequences and Summations 71 b) We write an= 2 +an-I = 2+ (2 + an-2) = (2 + 2) + an-2 = (2 · 2) + an-2 = (2 · 2) + (2 + an-3) = (3 · 2) + an-3 = (n · 2) + an-n = (n · 2) + ao = (n · 2) + 3 = 2n + 3. Again we figured out the last line by following the pattern that had developed in the first few lines. Therefore the answer is an = 2n + 3. c) We write (note that it is more convenient to put the an-I at the end) an= n +an-I = n + ((n - 1) + an-2) = (n + (n - 1)) + an-2 = (n + (n - 1)) + ((n - 2) + an-3) = (n + (n - 1) + (n - 2)) + an-3 = (n + (n - 1) + (n - 2) + · · · + (n - (n -1))) + an-n = (n + (n - 1) + (n - 2) + · · · + 1) + ao n(n + 1) 2 _n 2 +n+2 1 + 2 Therefore the answer is an= (n 2 + n + 2)/2. The formula used to obtain the last line-for the sum of the first n positive integers~is given in Table 2. d) We write an = 3 + 2n +an-I = 3 + 2n + (3 + 2(n - 1) + an-2) = (2 · 3 + 2n + 2(n - 1)) + an-2 = (2 · 3 + 2n + 2(n - 1)) + (3 + 2(n - 2) + an-3) = (3 · 3 + 2n + 2(n - 1) + 2(n - 2)) + an-3 = (n · 3 + 2n + 2(n - 1) + 2(n - 2) + · · · + 2(n - (n - 1))) + an-n = (n · 3 + 2n + 2(n - 1) + 2(n - 2) + · · · + 2 · 1) + a0 = 3n + 2 · n(n + l) + 4 = n 2 + 4n + 4. 2 Therefore the answer is an integers from Table 2. e) We write = n 2 + 4n + 4. Again we used the formula for the sum of the first n positive an= -1+2an-I = -1+2(-1+2an-2) = -3 + 4an-2 = -3 + 4(-1+2an-3) = -7 + 8an-3 = -7 + 8(-1+2an-4) = -15 + l6an-4 = -15 + 16(-1+2an-5) = -31+32an-5 = -(2n - 1) + 2nan-n = -2n + 1 + 2n · 1 = 1. This time it was somewhat harder to figure out the pattern developing in the coefficients, but it became clear after we carried out the computation far enough. The answer, namely that an = 1 for all n, it is clear in retrospect, after we found it, since 2 · 1 - 1 = 1. Chapter 2 72 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices f) We write an= 1+3an-l 2 = 1+3(1+3an-2) = (1 + 3) + 3 an-2 2 2 3 = (1 + 3) + 3 (1 + 3an-3) = (1 + 3 + 3 ) + 3 an-3 = (l+3+3 2 +···+3n-l)+3nan-n = 1 + 3 + 32 + · · · + 3n-l + 3n 3n+l - 1 (a geometric series) 3-1 3n+l -1 2 Thus the answer is an = (3n+l - 1) /2. g) We write an= nan-l = n(n - l)an-2 = n(n - l)(n - 2)an-3 = n(n - l)(n - 2)(n - 3)an-4 = n(n - l)(n - 2)(n - 3) · · · (n - (n - 1)) an-n = n(n - l)(n - 2)(n - 3) · · · 1 · ao = n! · 5 = 5n!. h) We write 2 = 2n(2(n - l)an-2) = 2 (n(n - l))an-2 = 22(n(n -1)) (2(n - 2)an-3) = 23 (n(n - l)(n - 2))an-3 = 2nn(n - l)(n - 2)(n - 3) · · · (n - (n - l))an-n = 2nn(n - l)(n - 2)(n - 3) · · · 1 · ao 19. a) Since the number of bacteria triples every hour, the recurrence relation should say that the number of bacteria after n hours is 3 times the number of bacteria after n - 1 hours. Letting bn denote the number of bacteria after n hours, this statement translates into the recurrence relation bn = 3bn-l. b) The given statement is the initial condition b0 = 100 (the number of bacteria at the beginning is the number of bacteria after no hours have elapsed). We solve the recurrence relation by iteration: bn = 3bn-l = 32bn_ 2 = · · · = 3nbn-n = 3nbo. Letting n = 10 and knowing that b0 = 100, we see that b10 = 310 · 100 = 5,904,900. 21. a) Let Cn be the number of cars produced in the first n months. The initial condition could be taken to be c0 = 0 (no cars are made in the first 0 months). Since n cars are made in the nth month, and since Cn- l cars are made in the first n - 1 months, we see that Cn = Cn-l + n. b) The number of cars produced in the first year is c 12 . To compute this we will solve the recurrence relation and initial condition, then plug in n = 12 (alternately, we could just compute the terms c1 , c2 , ... , c 12 Section 2.4 Sequences and Summations 73 directly from the definition). We proceed by iteration exactly as we did in Exercise 17c: + Cn-1 = n + ((n -1) + Cn-2) = (n + (n - 1)) + Cn-2 = (n + (n -1)) + ((n - 2) + Cn-3) = (n + (n -1) + (n - 2)) + Cn-3 Cn = = n (n + (n - 1) + (n - 2) + · · · + (n - (n - 1))) + c,,_n = (n + (n - 1) + (n - 2) + · · · + 1) +co n(n+l) n 2 +n 2 +O= - 2 Therefore the number of cars produced in the first year is (12 2 + 12) /2 = 78. c) We found the formula in our solution to part (b). 23. Each month our account accrues some interest that must be paid. Since the balance the previous month is B(k - 1), the amount of interest we owe is (0.07 /12)B(k - 1). After paying this interest, the rest of the $100 payment we make each month goes toward reducing the principal. Therefore we have B(k) = B(k- l) - (100- (0.07/12)B(k-1)). This can be simplified to B(k) = (1 + (0.07/12))B(k-1) -100. The initial condition is B(O) = 5000. If one calculates this as k goes from 0 to 60, we see the balance gradually decrease and finally become negative when k = 60 (i.e., after five years). 25. In some sense there are no right answers here. The solutions stated are the most appealing patterns that the author has found. a) It looks as if we have one 1 and one 0, then two of each, then three of each, and so on, increasing the number of repetitions by one each time. Thus we need three more 1's (and then four O's) to continue the sequence. b) A pattern here is that the positive integers are listed in increasing order, with each even number repeated. Thus the next three terms are 9, 10, 10. c) The terms in the odd locations (first, third, fifth, etc.) are just the successive terms in the geometric sequence that starts with 1 and has ratio 2, and the terms in the even locations are all 0. The nth term is 0 if n is even and is 2m + ~ for some positive integer m-this would imply that n :::; m 2 + m + ~ and n > m 2 + m, an impossibility. Therefore {yin}= {Jn+~}, and we are done. An alternative solution is provided in the answer section of the text. 29. a) 2+3+4+5+6=20 b) 1-2+4-8+16=11 c) 3+3+···+3=10·3=30 d) This series "telescopes": each term cancels part of the term before it (see also Exercise 35). The sum is (2 - 1) + (4 - 2) + (8 - 4) + ... + (512 - 256) = -1+512 = 511. 31. We use the formula for the sum of a geometric progression: L~=O arJ = a(rn+I - l)/(r - 1). a) Here a= 3, r = 2, and n = 8, so the sum is 3(2 9 - 1)/(2 - 1) = 1533. b) Here a = 1, r = 2, and n = 8. The sum taken over all the values of j from 0 to n is, by the formula, (2 9 - 1)/(2 - 1) = 511. However, our sum starts at j = 1, so we must subtract out the term that isn't there, namely 2°. Hence the answer is 511 - 1 = 510. c) Again we have to subtract the missing terms, so the sum is ((-3) 9 4921 - 1 - (-3) = 4923. d) 2((-3) 9 - - 1)/((-3) - 1) - (-3) 0 - (-3)I = 1)/((-3) - 1) = 9842 33. The easiest way to do these sums, since the number of terms is reasonably small, is just to write out the summands explicitly. Note that the inside index (j) runs through all of its values for each value of the outside index ( i ). a) (1+1) + (1+2) + (1+3) + (2 + 1) + (2 + 2) + (2 + 3) = 21 b) (0 + 3 + 6 + 9) + (2 + 5 + 8 + 11) + (4 + 7 + 10 + 13) = 78 c) (1+1+1) + (2 + 2 + 2) + (3 + 3 + 3) = 18 d) (0 + 0 + 0) + (1 + 2 + 3) + (2 + 4 + 6) = 18 35. If we just write out what the sum means, we see that parts of successive terms cancel, leaving only two terms: n L(a1 - a1 -I) = aI - ao + a2 - aI + a3 - J=I 37. a) We use the hint, where ak = k2 : n n k=I k=I a2 +···+an-I - an-2 +an - an-I =an - ao Section 2.5 Cardinality of Sets 75 b) We can use the distributive law to rewrite terms of the sum we want, S = L~=l k: n Now we solve for S, obtaining S 2::~= 1 (2k -1) (which we know from part (a) equals n 2 ) in n n = (n 2 + n)/2, which is usually expressed as n(n + 1)/2. 39. This exercise is like Example 23. From Table 2 we know that 2::~~1 k 99 · 100/2 = 4950. Therefore the desired sum is 20100 - 4950 = = 200 · 201/2 = 20100, and 2::~~ 1 k = 15150. 41. If we write down the first few terms of this sum we notice a pattern. It starts (1 + 1+1) + (2 + 2 + 2 + 2 + 2) + (3 + 3 + 3 + 3 + 3 + 3 + 3) + · · ·. There are three l's, then five 2'ss, then seven 3'ss, and so on; in general there are (i + 1) 2 - i 2 = 2i + 1 copies of i. So we need to sum i(2i + 1) for an appropriate range of values for i. We must find this range. It gets a little messy at the end if m is such that the sequence stops before a complete range of the last value is present. Let n = LvmJ - 1. Then there are n + 1 blocks, and (n + 1) 2 - 1 is where the next-to-last block ends. The sum of those complete blocks is I:~=l i(2i + 1) = I:~= 1 2i 2 + i = n(n + 1)(2n + 1)/3 + n(n + 1)/2. The remaining terms in our summation all have the value n + 1 and the number of them present is m - ((n + 1) 2 - 1). Our final answer is therefore n(n + 1)(2n + 1)/3 + n(n + 1)/2 + (n + l)(m - (n + 1) 2 + 1). 43. a) 0 (anything times 0 is 0) b) 5 . 6 . 7 . 8 = 1680 c) Each factor is either 1 or -1, so the product is either 1 or -1. To see which it is, we need to determine how many of the factors are -1. Clearly there are 50 such factors, namely when i ( -1 ) 50 = 1, the product is 1. = 1, 3, 5, ... , 99. Since d) 2 . 2 ... 2 = 210 = 1024 45. O! + 1! + 2! + 3! + 4! SECTION 2.5 = 1+ 1+ 1·2 + 1·2 ·3 + 1·2 ·3·4 = 1 + 1 + 2 + 6 + 24 = 34 Cardinality of Sets Don't feel bad if you find this section confusing. When Cantor started talking about sizes of infinity in the nineteenth century, many mathematicians thought he made no sense. The basic rule to keep in mind is that if an infinite set can be given in a list, then it is countable. It is not always easy to find the right list. Various indirect means are also available for showing that an infinite set is countable, such as showing that the set is a subset of a countable set, or showing that it is the union of a countable collection of countable sets. Proving sets uncountable usually requires some sort of diagonal argument, although in fact Cantor's first proof of the uncountability of the real numbers used a different approach (a nice summary can be found in an article in the American Mathematical Monthly, 117:7 (2010), 633~637). 76 Chapter 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 1. a) The negative integers are countably infinite. Each negative integer can be paired with its absolute value to give the desired one-to-one correspondence: 1 +--> -1, 2 +--> -2, 3 +--> -3, and so on. b) The even integers are countably infinite. We can list the set of even integers in the order 0, 2, -2, 4, -4, 6, -6, .... and pair them with the positive integers listed in their natural order. Thus 1 +--> 0, 2 +--> 2, 3 +--> -2, 4 +--> 4, and so on. There is no need to give a formula for this correspondence-the discussion given is quite sufficient; but it is not hard to see that we are pairing the positive integer n with the even integer f(n), where f(n) = n if n is even and f(n) = 1 - n if n is odd. c) This set is again countably infinite. We can list its elements in the order 99, 98, 97, .... A formula for a correspondence with the set of positive integers is given by f (n) = 100 - n. For example, the positive integer 117 is paired with -17. d) The proof that the set of real numbers between 0 and 1 is not countable (Example 5) can easily be modified to show that the set of real numbers between 0 and 1/2 is not countable. We need to let the digit d, be something like 2 if d,, "I 2 and 3 otherwise. The number thus constructed will be a real number between 0 and 1/2 that is not in the list. e) This set is finite; it has cardinality 999,999.999. f) This set is countably infinite, exactly as in part (b); the only difference is that there we are looking at the multiples of 2 and here we are looking at the multiples of 7. The correspondence is given by pairing the positive integer n with 7n/2 if n is even and -7(n - 1)/2 if n is odd: 0, 7, -7, 14, -14, 21, -21, .... 3. a) The bit strings not containing 0 are just the bit strings consisting of all l's, so this set is {.\ 1, 11, 111, 1111, ... } , where ,\ denotes the empty string (the string of length 0). Thus this set is countably infinite, where the correspondence matches the positive integer n with the string of n - 1 l's. b) This is a subset of the set of rational numbers, so it is countable (see Exercise 16). To find a correspondence, we can just follow the path in Example 4, but omit fractions in the top three rows (as well as continuing to omit those fractions that are duplicates of rational numbers already encountered). c) This set is uncountable, as can be shown by applying the diagonal argument of Example 5. d) This set is uncountable, as can be shown by applying the diagonal argument of Example 5. 5. Suppose m new guests arrive at the fully occupied hotel. If we move the guest in Room 1 to Room m + 1, the guest in Room 2 to Room m + 2, and so on, then rooms with numbers from 1 to m become vacant. The new guests can then occupy these rooms. 7. We can use the guests in the even-numbered rooms to occupy the original rooms, and the guests in the oddnumbered rooms to occupy the rooms in the second building. Specifically, for each positive integer n, put the guest currently in Room 2n into Room n, and the guest currently in Room 2n - 1 into Room n of the new building. 9. There is more than one way to do this. Here is one method. First spread out the original guests so that the gaps between occupied rooms get larger and larger. Specifically, keep the first guest (i.e., the one currently in Room 1) in Room 1; leave Room 2 vacant; put the second guest (the one currently in Room 2) into Room 3; leave Rooms 4 and 5 vacant; put the third guest into Room 6; leave Rooms 7, 8, and 9 vacant, and so on. Have the guests from the first bus fill the first free room in each gap (Rooms 2, 4, 7, 11, and so on). After this is done, once again the gaps between occupied rooms get larger and larger. (The unoccupied rooms are now 5. 8, 9, 12. 13. 14, and so on.) So we can repeat the process with the second busload. We continue in this manner for the countable infinity of busloads. An alternative approach is given in the answer key. 11. In each case, we can make the intersection what we want it to be, and then put additional elements into A and into B (with no overlap) to make them uncountable. Section 2.5 Cardinality of Sets 77 a) The simplest solution would be to make An B = 0. So, for example, take A to be the interval (1, 2) of real numbers, and take B to be the interval (3, 4). b) Take the example from part (a) and adjoin the positive integers. Thus, let A = (1, 2) U z+ and let B = (3, 4) U z+. c) Let A= (1,3) and B = (2,4). 13. Suppose that A is countable. This means either that A is finite or that there exists a one-to-one correspondence f from A to z+. In the former case, there is a one-to-one function g from A to a subset of z+ (the range of g is the first n positive integers, where IAI = n ). In either case, we have met the requirements of Definition 2, so IAI : : ; jz+j. Conversely, suppose that IAI : : ; jz+j. By definition, this means that there is a one-to-one function g from A to z+, so A has the same cardinality as a subset of z+ (namely, the range of g ). Now by Exercise 16 we conclude that A is countable. 15. This is just the contrapositive of Exercise 16 and so follows directly from it. In more detail, suppose that B were countable, say with elements b1 , b2 , .... Then since As:;; B, we can list the elements of A using the order in which they appear in this listing of B . Therefore A is countable, contradicting the hypothesis. Thus B is not countable. 17. Yes. We need to look at this from the other direction, by noting that A= (An B) U (A - B). We are given that B is countable, so its subset An B is also countable (Exercise 16). If A - B were also countable, then, since the union of two countable sets is countable (Theorem 1), we would conclude that A is countable. But we are given that A is not countable. Therefore our assumption that A - B is countable is wrong, and we conclude that A - B is uncountable. (This is an example of a proof by contradiction.) 19. By what we are given, we know that there are bijections f from A to B and g from C to D. Then we can define a bijection from Ax C to Bx D by sending (a,c) to (f(a),g(c)). This is clearly one-to-one and onto, so we have shown that A x C and B x D have the same cardinality. IAI : : ; IBI is that there is a one-to-one function f : A _, B. Similarly, we are given a one-to-one function g : B _, C. By Exercise 33 in Section 2.3, the composition go f : A_, C is one-to-one. Therefore by definition IAI : : ; ICI. 21. The definition of 23. This proof implicitly uses an assumption called the Axiom of Choice. Define a sequence a 1 , a 2 , a 3 , . . . of elements of A as follows. First, a 1 is any element of A. Once we have selected a 1 , a 2 , a 3 , ... , ak, let ak+l be any element of A - {a 1, a2, ... , ak}. Such an element must exist because A is infinite. The resulting set {a 1, a2, a 3 , ... } is the desired countably infinite subset of A. 25. The set of finite strings of characters over a finite alphabet is countably infinite, because we can list these strings in alphabetical order by length. For example, if the alphabet is {a, b, c}, then our list is ,\, a, b, c, aa , ab, ac, ba, bb, be, ca, cb, cc, aaa, aab, . . . . (See also Exercise 29.) Therefore the infinite set S can be identified with an infinite subset of this countable set, which by Exercise 16 is also countably infinite. 27. Since empty sets do not contribute any elements to unions, we can assume that none of the sets in our given countable collection of countable sets is the empty set. If there are no sets in the collection, then the union is empty and therefore countable. Otherwise let the countable sets be A 1 , A 2 , . . . . (If there are only a finite number k of them, then we can still assume that they form an infinite sequence by taking Ak+l = Ak+ 2 = · · · = A 1 . ) Since each set A, is countable and nonempty, we can list its elements in a sequence as a, 1 , ai 2 , ... ; again, if the set is finite we can list its elements and then list a,1 repeatedly to assure an Chapter 2 78 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices infinite sequence. Now we just need a systematic way to put all the elements a 21 into a sequence. We do this by listing first all the elements a21 in which i + j = 2 (there is only one such pair, (1, 1) ), then all the elements in which i + j = 3 (there are only two such pairs, (1, 2) and (2, 1) ), and so on; except that we do not list any element that we have already listed. So, assuming that these elements are distinct, our list starts a 11 , a12 , a 21 , a 13, a 22 , a 31 , a14, . . . . (If any of these terms duplicates a previous term, then it is simply omitted.) The result of this process will be either an infinite sequence or a finite sequence containing all the elements of the union of the sets A 2 • Thus that union is countable. 29. There are only a finite number of bit strings of each finite length, so we can list all the bit strings by listing first those of length 0, then those of length 1, etc. The listing might be >., 0, 1, 00, 01, 10, 11, 000, 001, .... (Recall that >. denotes the empty string.) Actually this is a special case of Exercise 27: the set of all bit strings is the union of a countable number of countable (actually finite) sets, namely the sets of bit strings of length n for n = 0, 1, 2, .... 31. A little experimentation with this function shows the pattern: f(l, 1) f(l, 2) j(l, 3) f(l, 4) f (l, 5) f(l, 6) =1 =2 =4 = f(2, 1) f(2, 2) f(2, 3) f(2, 4) f (2, 5) f (2, 6) 7 = 11 = f (l, 7) = 16 22 =3 = 5 =8 = 12 = 17 = 23 =6 =9 = 13 f(3, 4) = 18 f (3, 5) = 24 = 10 = 14 = 19 f(4, 4) = 25 f(3, 1) f(3, 2) f(3, 3) f(4, 1) f(4, 2) f(4, 3) f(5, 1) = 15 f(5, 2) = 20 f(5, 3) = 26 f(6, 1) = 21 f(6, 2) = 27 We see by looking at the diagonals of this table that the function takes on successive values as m+n increases. When m + n = 2, f(m, n) = 1. When m + n = 3, f(m, n) takes on the values 2 and 3. When m + n = 4, f (m, n) takes on the values 4, 5, and 6. And so on. It is clear from the formula that the range of values the function takes on for a fixed value of m + n, say m + n = x, is (x- 2 ~(x-l) + 1 through (x- 2 ~(x-l) + (x - 1), since m can assume the values 1, 2, 3, ... , (x - 1) under these conditions, and the first term in the formula is a fixed positive integer when m + n is fixed. To show that this function is one-to-one and onto, we merely need to show that the range of values for x + 1 picks up precisely where the range of values for x left off, i.e., that f(x - 1, 1) + 1 = j(l, x). We compute: f(x - 1, 1) + 1 = (x - 2)2(x - 1) + (x - 1) +1= x2 - ; + 2 = (x ~ l)x + 1 = f(l, x) 33. It suffices to find one-to-one functions f : (0, 1) --+ [O, 1] and g : [O, 1] --+ (0, 1). We can obviously use the function f(x) = x in the first case. For the second, we can just compress [O, 1] into, say, [~,~];the increasing linear function g(x) = (x + 1)/3 will do that. It then follows from the Schroder-Bernstein theorem that l(O, 1)1 = l[O, l]I. 35. We can follow the hint or argue as follows, which really amounts to the same thing. (See the answer key for a proof using bit strings.) Suppose there were such a one-to-one correspondence f from z+ to the power set of z+ (the set of all subsets of z+ ). Thus, for each x E z+, f(x) is a subset of z+. We will derive a contradiction by showing that f is not onto; we do this by finding an element not in its range. To this end, let A = { x I x tJ_ f(x)}. We claim that A is not in the range of f. If it were, then A = f(x 0 ) for some x 0 E z+ . Let us look at whether x 0 E A or not. On the one hand, if x 0 E A, then by the definition of A, it must be true that x 0 tJ_ f (x 0 ), which means that x 0 tJ_ A; that is a contradiction. On the other hand, if if x 0 tJ_ A, then by the definition of A, it must be true that x 0 E f(x 0 ), which means that x 0 EA, again a contradiction. Therefore no such one-to-one correspondence exists. Section 2.6 79 Matrices 37. We argued in the solution to Exercise 29 that the set of all strings of symbols from the alphabet {O, 1} is countable, since there are only a finite number of bit strings of each length. There was nothing special about the alphabet {O, 1} in that argument. For any finite alphabet (for example, the alphabet consisting of all upper and lower case letters, numerals, and punctuation and other mathematical marks typically used in a programming language), there are only a finite number of strings of length 1 (namely the number of symbols in the alphabet), only a finite number of strings of length 2 (namely, the square of this number), and so on. Therefore, using the result of Exercise 27, we conclude that there are only countably many strings from any given finite alphabet. Now the set of all computer programs in a particular language is just a subset of the set of all strings over that alphabet (some strings are meaningless jumbles of symbols that are not valid programs), so by Exercise 16, this set, too, is countable. 39. In Exercise 37 we saw that there are only a countable number of computer programs, so there are only a countable number of computable functions. In Exercise 38 we saw that there are an uncountable number of functions. Hence not all functions are computable. Indeed, in some sense, since uncountable sets are so much bigger than countable sets, almost all functions are not computable! This is not really so surprising; in real life we deal with only a small handful of useful functions, and these are computable. Note that this is a nonconstructive proof-we have not exhibited even one noncomputable function, merely argued that they have to exist. Actually finding one is much harder, but it can be done. For example, the following function is not computable. Let T be the function from the set of positive integers to {O, 1} defined by letting T(n) be 0 if the number 0 is in the range of the function computed by the nth computer program (where we list them in alphabetical order by length) and letting T(n) = 1 otherwise. SECTION 2.6 Matrices In addition to routine exercises with matrix calculations, there are several exercises here asking for proofs of various properties of matrix operations. In most cases the proofs follow immediately from the definitions of the matrix operations and properties of operations on the set from which the entries in the matrices are drawn. Also, the important notion of the (multiplicative) inverse of a matrix is examined in Exercises 18~21. Keep in mind that some matrix operations are performed "entrywise," whereas others operate on whole rows or columns at a time. Exercise 29 foreshadows material in Section 9.4. 1. a) Since A has 3 rows and 4 columns, its size is 3 x 4. b) The thfrd column of A is the 3 x 1 matdx [ i] · c) The second row of A is the 1 x 4 matrix [2 0 4 6] . d) This is the element in the third row, second column, namely 1. e) The transpose of A is the 4 x 3 matrix [ : ~ !]· 3 6 7 3. a) We use the definition of matrix multiplication to obtain the four entries in the product AB. The (1, l)th entry is the sum anb 11 + ai2b 21 = 2 · 0 + 1·1 = 1. Similarly, the (1, 2)th entry is the sum anb12 + a12b22 = 2·4+1·3 = 11; (2, l)th entry is the sum a 21 b11 +a 22 b21 =3·0 + 2 · 1 = 2; and (2,2)th entry is the sum a 21 bi2 + a 22 b22 = 3 · 4 + 2 · 3 = 18. Therefore the answer is [; i~] . b) The calculation is similar. Again, to get the (i,j)th entry of the product, we need to add up all the products a,kbk1 . You can visualize "lifting" the ith row from the first factor (A) and placing it on top of the Chapter 2 80 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices lh column from the second factor ( B), multiplying the pairs of numbers that lie on top of each other, and taking the sum. Here we have rn -2 -1] Yi [; 2 0 = [1·3+(-1)·1 0·3+1·1 2·3+3·1 1·(-2)+(-1)·0 1·(-1)+(-1)·2] 0. (-2) + 1. 0 0·(-1)+1·2 2. (-2) + 3. 0 2·(-1)+3·2 U~: Tl c) The calculation is similar to the previous parts: [ 34 -3] -1 [-1 3 2 -2] 0 -1 -2 5 0 -1 4 -3 [4·(-l)+(-3)·0 3·(-1)+(-1)·0 0·(-1)+(-2)·0 (-1)·(-1)+5·0 15 -4 -3 -3 10 2 l 2 -8 0 1 -8 18 [-4 -~3 4·3+(-3)·(-1) 3·3+(-1)·(-1) 0·3+(-2)·(-1) (-1)·3+5·(-1) l 4. 2 + (-3). 4 4. (-2) + (-3) . (-3) 3·2+(-1)·4 3. (-2) + (-1). (-3) 0. 2 + (-2). 4 0. (-2) + (-2) . (-3) (-1)·2+5·4 (-1). (-2) + 5. (-3) l 5. First we need to observe that A = [ai1 ] must be a 2 x 2 matrix; it must have two rows since the matrix it is being multiplied by on the left has two columns, and it must have two columns since the answer obtained has two columns. If we write out what the matrix multiplication means, then we obtain the following system of linear equations: 2a11 + 3a21 = 3 2a12 + 3a22 = 0 la11 + 4a21 = 1 la12 + 4a22 = 2 Solving these equations by elimination of variables (or other means-it's really two systems of two equations each in two unknowns), we obtain a 11 = 9/5, a12 = -6/5, a21 = -1/5, a22 = 4/5. As a check we compute that, indeed, 2 3] [ 9/5 [1 4 -1/5 -6/5] = [3 OJ 4/5 1 2 . 7. Since the (i,j)th entry of 0 +A is the sum of the (i,j)th entry of 0 (namely 0) and the (i,j)th entry of A, this entry is the same as the (i,j)th entry of A. Therefore by the definition of matrix equality, 0 +A= A. A similar argument shows that A + 0 = A. 9. We simply look at the (i,j)th entries of each side. The (i,j)th entry of the left-hand side is ai1 + (bi 1 + ci1 ). The (i, j)th entry of the right-hand side is (aij + bi1 ) + c,1 . By the associativity law for real number addition, these are equal. The conclusion follows. 11. In order for AB to be defined, the number of columns of A BA to be defined, the number of columns of B must equal integers m and n, it must be the case that A is an m x n to say this is to say that A must have the same size as Bt must equal the number of rows of B. In order for the number of rows of A. Thus for some positive matrix and B is an n x m matrix. Another way (and/or vice versa). Section 2.6 81 Matrices 13. Let us begin with the left-hand side and find its (i, j)th entry. First we need to find the entries of BC. By k definition, the (q, j)th entry of BC is E bqrCr1 . (See Section 2.4 for the meaning of summation notation. r=l This symbolism is a shorthand way of writing bq1C1j + bq2c21 + · · · + bqkCkJ .) Therefore the (i,j)th entry of k p A(BC) is E a,q ( q=l E bqrCrj). r=l By distributing multiplication over addition (for real numbers), we can move p the term inside the inner summation, to obtain k E E aiqbqrcr1 . (We are also implicitly using associativity q=l r=l of multiplication of real numbers here, to avoid putting parentheses in the product aiqbqrCrj . ) a,q k A similar analysis with the right-hand side shows that the (i, j)th entry there is equal to k p I: (I: r=l q=l a,qbqr )cr1 p E E a,qbqrCrj. Now by the commutativity of addition, the order of summation (whether we sum over r=l q=l r first and then q, or over q first and then r) does not matter, so these two expressions are equal, and the proof is complete. 15. Let us begin by computing An for the first few values of n. A1 = [~ 3] A4 [10 4]1 ' A5 [10 5]1 . 2] 1] , A 2 3 1 =[1o 1 ' A =[1 o1' It seems clear from this pattern, then, that An -- [01 nl] = = . (A proof of this fact could be given using mathematical induction, discussed in Section 5.1.) 17. a) The (i,j)th entry of (A+ B)t is the (j, i)th entry of A+ B, namely a1 , + b1 ,. On the other hand, the (i,j)th entry of At+ Bt is the sum of the (i,j)th entries of At and Bt, which are the (j, i)th entries of A and B, again aji + b1 i. Hence (A+ B)t =At+ Bt. n b) The (i,j)th entry of (AB)t is the (j,i)th entry of AB, namely E a 1 kbki. k=l of summation notation. This symbolism is a shorthand way of writing (SeeSection2.4forthemeaning baj 1 bii + n a 12 b 2 , + ··· + a 1 nbni .) On E bk,aJk (since the (i,k)th entry of Bt is bki and the (k,j)th k=l entry of At is ajk). By the commutativity of multiplication of real numbers, these two values are the same, so the matrices are equal. the other hand, the (i,j)th entry of BtAt is 19. All we have to do is form the products AA- 1 and A- 1A, using the purported A- 1 , and see that both of them are the 2 x 2 identity matrix. It is easy to see that the upper left and lower right entries in each case are (ad - be)/ (ad - be) = 1, and the upper right and lower left entries are all 0. r = I, where I is the n x n identity matrix. Since matrix multiplication is associative, we can write this product as 21. We must show that An (A - 1 An ((A- 1r) = A(A ... (A(AA- 1)A- 1) ... A- 1)A-l. By dropping each AA- 1 = I from the center as it is obtained, this product reduces to I. Similarly ((A- 1)n)An =I. Therefore by definition (An)- 1 = (A- 1 (A more formal proof requires mathematical induction; see Section 5.1.) r. 23. By definition, the (i,j)th entry of A+ At is ai1 + a 1 ,. Similarly, the (j, i)th entry of A+ At is a 1 i + a, 1 . By the commutativity of addition, these are equal, so A+ At is symmetric by the definition of symmetric matrices. Chapter 2 82 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 25. Using the idea in Exercise 24, we see that the given system can be expressed as AX = B, where A is the coefficient matrix, X is an n x 1 matrix with Xi the entry in its ith row, and B is the n x 1 matrix of right-hand sides. Specifically we have ~~~ :nd[ t r infrs~t]-. ~:::f:: can find x 1 :::e -1 -1 But Exercise 18 tells us simply by computing A -1 B. 3 We should plug in x 1 = 1, x 2 = -1, and x 3 = -2 to see that these do indeed form the solution. 27. These routine exercises simply require application of the appropriate definitions. Parts (a) and (b) are entrywise operations, whereas the operation 8 in part (c) is similar to matrix multiplication (the (i,j)th entry of A 8 B depends on the ith row of A and the lh column of B ). a) AV B l ~ ~ ~ i [ 29. Note that Al 2l means A 8 A, and Al 3l means A 8 A 8 A. We just apply the definition. c) A v A l2l V A l3l = [ 1~ o~ o~l 31. These are immediate from the commutativity of the corresponding logical operations on variables. a) AV B = [a, 1 V bi1 ] = [bi 1 V a,1 ] = B VA b) B /\A= [b, 1 /\ a, 1 ] = [ai 1 /\ b, 1 ] =A/\ B 33. These are immediate from the distributivity of the corresponding logical operations on variables. a) AV (B /\ C) = [ai 1 V (b, 1 b) A/\ (B V C) = [ai 1 /\ /\ ci1 )] (bi 1 V ci1 )] = [(a, 1 V bi1 ) /\ (a, 1 V ci1 )] =(AV B) /\(AV C) = [(ai1 /\ bi1 ) V (ai 1 /\ ci1 )] =(A/\ B) V (A/\ C) 35. The proof is identical to the proof in Exercise 13, except that real number multiplication is replaced by /\, and real number addition is replaced by V. Briefly, in symbols, A 8 (B 8 C) p k [V V aiqAbqrAcr1 ] q=l r=l k = p k k q=l r=l p [V V aiq/\bqr/\cr1 ] = [V (V r=l q=l p = [ V aiq /\ ( V bqr /\ Crj)] = r=l q=l a,q/\bqr) /\cr1] = (A8B)8C. 83 Review Questions GUIDE TO REVIEW QUESTIONS FOR CHAPTER 2 1. Seep. 119. To prove that A is a subset of B we need to show that an arbitrarily chosen element x of A must also be an element of B . 2. The empty set is the set with no elements. It satisfies the definition of being a subset of every set vacuously. 3. a) See p. 121. b) See p. 128. 4. a) See p. 121. b) always 5. a) See pp. 127 and 128 and the preamble to Exercise 32 in Section 2.2. b) union: integers that are odd or positive; intersection: odd positive integers; difference: even positive integers; symmetric difference: even positive integers together with odd negative integers 6. a) A= B =(A<:;;; B /\ B <:;;;A)= Vx(x EA+-+ x EB) b) See pp. 129-132. c) An B n C =An (Bu C) =(An B) u (An C) =(A- B) u (A - C); use Venn diagrams 7. Underlying each set identity is a logical equivalence. See, for instance, Example 11 in Section 2.2. 8. a) See p. 139. b) Z, Z, 9. a) See p. 141. f) f(n) = 42548 10. a) Seep. 145: z+ = N - {O} b) See p. 143. 1- 1 (b) =a= f(a) = c) f(n) = n d) f(n) = 2n e) f(n) = fn/21 b b) when it is one-to-one and onto c) yes-itself 11. a) See p. 149. b) integers 12. Hint: subtract 5 from each term and look at the resulting sequence. 13. The formula depends on the initial condition, namely the value of a0 . After that, each term is 5 less than the preceding term, so an = ao - 5n. 14. See p. 164. 15. Set up a one-to-one correspondence between the set of positive integers and the set of all odd integers, such as 1 +-+ 1, 2 +-+ -1, 3 +-+ 3, 4 +-+ -3, 5 +-+ 5, 6 +-+ -5, and so on. 16. See Example 5 in Section 2.5. 17. See page 179. For AB to be defined, the number of columns of A must equal the number of rows of B. 18. See Example 4 in Section 2.6. 84 Chapter 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices SUPPLEMENTARY EXERCISES FOR CHAPTER 2 1. a) A= the set of words that are not in A b) A n B = the set of words that are in both A and B c) A - B = the set of words that are in A but not B d) An B =(AU B) = the set of words that are in neither A nor B e) A EBB= the set of words that are in A or B but not both (can also be written as (A - B) U (B - A) or as (AUB)-(AnB)) 3. Yes. We must show that every element of A is also an element of B. So suppose a is an arbitrary element of A. Then {a} is a subset of A, so it is an element of the power set of A. Since the power set of A is a subset of the power set of B, it follows that {a} is an element of the power set of B, which means that {a} is a subset of B. But this means that the element of {a}, namely a, is an element of B, as desired. 5. We will show that each side is a subset of the other. First suppose x E A - (A - B). Then x E A and x tf- A - B. Now the only way for x not to be in A - B, given that it is in A, is for it to be in B. Thus we have that x is in both A and B , so x E A n B. For the other direction, let x E A n B . Then x E A and x E B. It follows that x tf- A - B, and so x is in A - (A - B). 7. We need only provide a counterexample to show that (A - B) - C is not necessarily equal to A - (B - C). Let A = C = {l}, and let B = 0. Then (A - B) - C = ({1} - 0) - {l} = {l} - {l} = 0, whereas A- (B-C) = {1}- (0- {1}) = {1}-0 = {1}. 9. This is not necessarily true. For a counterexample, let A = B = {1, 2}, let C = 0, and let D = {1}. Then (A- B) - (C - D) = 0 - 0 = 0, but (A - C) - (B - D) = {1, 2} - {2} = {1}. 11. a) Since 0 ~ An B ~ A~ AU B ~ U, we have the order 101 ::; IA n Bl ::; IAI ::; IA U Bl ::; IUI. ~ AEBB ~ AUB. Also recall that IAUBI = IAI + IBl-IAnBI, so that IAUBI is always less than or equal to IAI + IBI. Putting this all together, we have 101 ::; IA- Bl ::; IA EB Bl ::; IA U Bl ::; IAI + IBI. b) Note that A-B 13. a) Yes, f is one-to-one, since each element of the domain {1, 2, 3, 4} is sent by f to a different element of the codomain. No, g is not one-to-one, since g sends the two different elements a and d of the domain to the same element, 2. b) Yes, f is onto, since every element in the codomain {a, b, c, d} is the image under f of some element in the domain {1,2,3,4}. In other words, the range off is the entire codomain. No, g is not onto, since the element 4 in the codomain is not in the range of g (is not the image under g of any element of the domain {a, b, c, d} ). c) Certainly f has an inverse, since it is one-to-one and onto. Its inverse is the function from {a, b, c, d} to {1,2,3,4} that sends a to 3, sends b to 4, sends c to 2, and sends d to 1. (Each element in {a,b,c,d} gets sent by 1- 1 to the element in {l,2,3,4} that gets sent to it by f .) Since g is not one-to-one and onto, it has no inverse. 15. If f is one-to-one, then f provides a bijection between S and f (S), so they have the same cardinality by definition. If f is not one-to-one, then there exist elements x and y in S such that f(x) = f(y). Let S = {x,y}. Then ISi = 2 but lf(S)I = 1. Note that we do not need the hypothesis that A and B are finite. Supplementary Exercises 85 17. The key is to look at sets with just one element. On these sets, the induced functions act just like the original functions. So let x be an arbitrary element of A. Then {x} E P(A), and S1({x}) = {l(y) I y E {x}} = {f(x)}. By the same reasoning, S9 ({x}) = {g(x)}. Since S1 = S9 , we can conclude that {f(x)} = {g(x)}, and so necessarily l(x) = g(x). 19. This is certainly true if either x or y is an integer, since then this equation is equivalent to the identity (4a) in Table 1 of Section 2.3. Otherwise, write x and y in terms of their integer and fractional parts: x = n + E and y = m + 8, where n = Lx J , 0 < E < 1, m = LY J , and 0 < 6 < l. If 8 + E < 1, then the equation is true, since both sides equal m + n; if 8 + E 2: 1, then the equation is false, since the left-hand side equals m + n, but the right-hand side equals m + n + 1. In summary, the equation is true if and only if either at least one of x and y is an integer or the sum of the fractional parts of x and y is less than 1. (Note that the second condition in the disjunction subsumes the first.) + f and y = m + fj, where n = lx J , 0 ::; E < 1, m = lY J , and 0 ::; 8 < 1. If 8 = E = 0, then both sides equal n + m. If E = 0 but 8 > 0, then the left-hand side equals n + m + 1, but the right-hand side equals n + m. If E > 0, then the right-hand side equals n + m + 1, so the two sides will be equal if and only if E + fj::; 1 (otherwise the left-hand side would be n + m + 2 ). In summary, the equation is true if and only if either both x and y are integers, or x is not an integer but the sum of the fractional parts of x and y is less than or equal to 1 . 21. Write x and y in terms of their integer and fractional parts: x = n 23. If xis an integer, then clearly LxJ + Lm-xJ = x+m-x = m. Otherwise, write x in terms of its integer and fractional parts: x = n+E, where n = LxJ and 0 < E < l. In this case LxJ + Lm-xJ = Ln+cJ + Lm-n-Ej = n + m - n - 1 = m - 1 , because we had to round m - n - E down to the next smaller integer. i. 25. Write n = 2k + 1 for some integer k. Then n 2 = 4k 2 + 4k + 1, so n 2 /4 = k 2 + k + Therefore In 2 /41 2 2 2 2 2 k + k + 1 . But we also have (n + 3) / 4 = (4k + 4k + 1 + 3) / 4 = (4k + 4k + 4) / 4 = k + k + 1 . 27. Let us write x = n + (r / m) + E, where n is an integer, r is an nonnegative integer less than m, and E is a real number with 0::; E < 1/m. In other words, we are peeling off the integer part of x (i.e., n = lxJ) and the whole multiples of 1/m beyond that. Then the left-hand side is lnm + r + mEj =nm+ r. On the right-hand side, the terms LxJ through Lx + (m - r - 1)/mJ are all just n, and the remaining terms, if any, from Lx + (m - r)/mJ through Lx + (m - 1)/mJ, are all n + l. Therefore the right-hand side is (m - r)n + r(n + 1) =nm+ r as well. 29. This product telescopes. The numerator in the fraction for k cancels the denominator in the fraction for k + 1. So all that remains of the product is the numerator for k = 100 and the denominator for k = 1, namely 101/1=101. 31. There is no good way to determine a nice rule for this kind of problem. One just has to look at the sequence and see what seems to be happening. In this sequence, we notice that 10 = 2 · 5, 39 = 3 · 13, 172 = 4 · 43, and 885 = 5 · 177. We then also notice that 3 = 1 · 3 for the second and third terms. So each odd-indexed term (assuming that we call the first term a 1 ) comes from the term before it, by multiplying by successively larger integers. In symbols, this says that a 2 n+l = n·a 2 n for all n > 0. Then we notice that the even-indexed terms are obtained in a similar way by adding: a 2 n = n + a 2 n- 1 for all n > 0. So the next four terms are a13 = 6 · 891 = 5346, a14 = 7 + 5346 = 5353, a 15 = 7 · 5353 = 37471. and a 14 = 8 + 37471=37479. 33. If such a function 1 exists, then S equals the union of a countable number of countable sets, namely 1- 1 (2) U · · ·. It follows from Exercise 27 in Section 2.5 that S is countable. 1- 1 ( 1) U Chapter 2 86 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices 35. Because there is a one-to-one correspondence between R and the open interval (0, 1) (given by f(x) = 2 arctan(x)/7r, it suffices to shows that l(O, 1) x (O. l)I = l(O, l)j. We use the Schroder-Bernstein theorem; it suffices to find injective functions f from (0,1) to (0,1) x (0,1) and g from (0,1) x (0,1) to (0,1). For f we can just use f(x) = (x, ~);it is clearly injective. For g we follow the hint. Suppose (x, y) E (0, 1) x (0, 1), and represent x and y with their decimal expansions, never choosing the expansion of any number that ends in an infinite string of 9s (we can avoid that by having all finite decimals end in an infinite string of Os). Let x = O.x 1x2x3 ... and y = O.y1Y2Y3 ... be these expansions. Let g(x, y) be the decimal expansion obtained by interweaving these two strings, namely O.X1Y1X2Y2X3y3 .... Because we can recover x and y from g(x, y) (namely by taking every other digit starting with the first or second decimal digit, respectively), it follows that g is one-to-one, and our proof is complete. 37. Let us begin by computing An for the first few values of n. A1 = [ 0 -1 l] 0 ' A2= [-1 0 0] -1 Since A 4 = I, the pattern will repeat from here: A 5 Thus for all n 2 0 we have ' = A3= [O 1 -1] [l OJ 0 .A=o1· 4 A 4 A = IA = A, A 6 -1 ] 0 , = = A 3, and A2 , A7 A 4n +4 = [ 1 0] 0 1 so on. . 39. (The notation cl means the identity matrix I with each entry multiplied by the real number c; thus this matrix consists of e's along the main diagonal and O's elsewhere.) Let A = [: ~]. We will determine what these entries have to be by using the fact that AB = BA for a few judiciously chosen matrices B. First let B 0 =w = [~ ~] . Then and u = x. AB = [ ~ : ] , and BA = [ ~ Next choose B matrix A must be in the form [ ~ = [~ ~] . Since these two must be equal, we know that ~] . Then we get [ ~ ~] ~] , which is just u [ ~ ~] , whence v = 0. Therefore the times the identity matrix, as desired. 41. a) The (i,j)th entry of A 8 0 is by definition the Boolean sum (V) of some Boolean products (A) of the form a,k A 0. Since the latter always equals 0, every entry is 0, so A 8 0 = 0. Similarly 0 8 A consists of entries that are all 0, so it, too, equals 0. b) Since V operates entrywise, the statements that A V 0 = A and 0 V A = A follow from the facts that a,J V 0 = a,1 and 0 V a,j = a,J . c) Since A operates entrywise, the statements that A A 0 = 0 and 0 A A = 0 follow from the facts that ai1 A 0 = 0 and 0 A a,1 = 0. Writing Projects 87 WRITING PROJECTS FOR CHAPTER 2 Books and articles indicated by bracketed symbols below are listed near the end of this manual. You should also read the general comments and advice you will find there about researching and writing these essays. 1. A classic source here is [Wil]. It gives a very readable account of many philosophical issues in the foundations of mathematics, including the topic for this essay. 2. Our list of references mentions several history of mathematics books, such as [Bo4] and [Ev3]. You should also browse the shelves in your library, around QA 21. 3. Go to the Encyclopedia's website, oeis. org. 4. A Web search should turn up some useful references here, including an article in Science News Online. It gets its name from the fact that a graph describing it looks like the output of an electrocardiogram. 5. A Web search for this phrase will turn up much information. 6. A classic source here is [Wil]. It gives a very readable account of many mathematical and philosophical issues in the foundations of mathematics, including the topic for this essay. Of course a Web search will turn up lots of useful material, as well. Your essay should delve into the generalized continuum hypothesis for the higher orders of infinity: 2Nn = ~n+l . 88 Chapter 3 Algorithms CHAPTER3 Algorithms SECTION 3.1 Algorithms J\fany of the exercises here are actually miniature programming assignments. Since this is not a book on programming. we have glossed over some of the finer points. For example, there are (at least) two ways to pass variables to procedures-by value and by reference. In the former case the original values of the arguments are not changed. In the latter case they are. In most cases we will assume that arguments are passed by reference. None of these exercises are tricky; they just give the reader a chance to become familiar with algorithms written in pseudocode. The reader should refer to Appendix 3 for more details of the pseudocode being used here. 1. Initially max is set equal to the first element of the list, namely 1. The for loop then begins, with i set equal to 2. Immediately i (namely 2) is compared to n, which equals 10 for this sequence (the entire input is known to the computer, including the value of n ). Since 2 < 10. the statement in the loop is executed. This is an if. .. then statement, so first the comparison in the if part is made: max (which equals 1) is compared to a, = a 2 = 8. Since the condition is true, namely 1 < 8, the then part of the statement is executed, so max is assigned the value 8. The only statement in the for loop has now been executed, so the loop variable i is incremented (from 2 to 3 ), and we repeat the process. First we check again to verify that i is still less than n (namely 3 < 10 ), and then we execute the if. .. then statement in the body of the loop. This time, too, the condition is satisfied, since max = 8 is less than a 3 = 12. Therefore the assignment statement max := a, is executed, and max receives the value 12. Next the loop variable is incremented again, so that now i = 4. After a comparison to determine that 4 < 10, the if. .. then statement is executed. This time the condition fails, since max = 12 is not less than a4 = 9. Therefore the then part of the statement is not executed. Having finished with this pass through the loop, we increment i again, to 5. This pass through the loop, as well as the next pass through, behave exactly as the previous pass, since the condition max < a, continues to fail. On the sixth pass through the loop, however, with i = 7, we find again that max < a,, namely 12 < 14. Therefore max is assigned the value 14. After three more uneventful passes through the loop (with i = 8, 9, and 10), we finally increment i to 11. At this point, when the comparison of i with n is made, we find that i is no longer less than or equal to n, so no further passes through the loop are made. Instead, control passes beyond the loop. In this case there are no statements beyond the loop, so execution halts. Note that when execution halts, max has the value 14 (which is the correct maximum of the list), and i has the value 11. (Actually in many programming languages, the value of i after the loop has terminated in this way is undefined.) 3. We will call the procedure AddEmUp. Its input is a list of integers, just as was the case for Algorithm l. Indeed, we can just mimic the structure of Algorithm l. We assume that the list is not empty (an assumption made in Algorithm 1 as well). Section 3.1 89 Algorithms procedure AddEmUp(a 1 , a 2 , ... , an: integers) sum:= a1 for i := 2 to n sum:= sum+ a, return sum { sum is the sum of all the elements in the list} 5. We need to go through the list and find cases when one element is equal to the following element. However, in order to avoid listing the values that occur more than once more than once, we need to skip over repeated duplicates after we have found one duplicate. The following algorithm will do it. (If we wanted to "return" the answer, we would form c 1 , c2 , ... , ck into a list and return that list.) procedure duplicates(a 1 , a 2 , ... , an: integers in nondecreasing order) k := 0 {this counts the duplicates} j := 2 while j Sn if a1 = a1 _ 1 then k := k+ 1 Ck := a1 while j S n and a1 = j := j Ck +1 j := j + 1 { c1, c2, ... , Ck is the desired list} 7. We need to go through the list and record the index of the last even integer seen. procedure last even location(a 1 , a2, ... , an: integers) k := 0 for i := 1 ton if a, is even then k := i return k { k is the desired location (or 0 if there are no evens)} 9. We just need to look at the list forward and backward simultaneously, going about half-way through it. procedure palindrome check(a 1 a2 ... an : string) answer:= true fori:=lto ln/2J if a,# an+I-i then answer:= false return answer { answer is true if and only if string is a palindrome} 11. We cannot simply write x := y followed by y := x, because then the two variables will have the same value, and the original value of x will be lost. Thus there is no way to accomplish this task with just two assignment statements. Three are necessary, and sufficient, as the following code shows. The idea is that we need to save temporarily the original value of x. temp:= x x := y y :=temp 13. We will not give these answers in quite the detail we used in Exercise 1. a) Note that n = 8 and x = 9. Initially i is set equal to 1 . The while loop is executed as long as i S 8 and the ith element of the list is not equal to 9. Thus on the first pass we check that 1 S 8 and that 9 # 1 (since a 1 = 1 ), and therefore perform the statement i := i + 1. At this point i = 2. We check that 2 S 8 and 9 # 3, and therefore again increment i, this time to 3. This process continues until i = 7. At that point the condition "i S 8 and 9 # a," is false, since a1 = 9. Therefore the body of the loop is not executed (so i is still equal to 7), and control passes beyond the loop. Chapter 3 90 Algorithms The next statement is the if... then statement. The condition is satisfied, since 7 ::::; 8, so the statement location := i is executed, and location receives the value 7. The else clause is not executed. This completes the procedure, so location has the correct value, namely 7, which indicates the location of the element x (namely 9) in the list: 9 is the seventh element. b) Initially i is set equal to 1 and j is set equal to 8. Since i < j at this point, the steps of the while loop are executed. First m is set equal to l(l + 8)/2J = 4. Then since x (which equals 9) is greater than a 4 (which equals 5), the statement i := m + 1 is executed, so i now has the value 5. At this point the first iteration through the loop is finished, and the search has been narrowed to the sequence a 5 , ... , a 8 . In the next pass through the loop (there is another pass since i < j is still true), m becomes l(5 + 8)/2J 6. Since again x > am , we reset i to be m + 1 , which is 7. The loop is now repeated with i = 7 and j This time m becomes 7, so the test x > am (i.e., 9 > 9) fails; thus j := m is executed, so now j = 7. = = 8. At this point i f:. j, so there are no more iterations of the loop. Instead control passes to the statement beyond the loop. Since the condition x = a, is true, location is set to 7, as it should be, and the algorithm is finished. 15. We need to find where x goes, then slide the rest of the list down to make room for x, then put x into the space created. In the procedure that follows, we employ the trick of temporarily tacking x + 1 onto the end of the list, so that the while loop will always terminate. Also note that the indexing in the for loop is slightly tricky since we need to work from the end of the list toward the front. procedure insert(x, ai, a2, ... , an : integers) {the list is in order: a 1 ::::; a2 ::::; · · · ::::; an } an+l := X + 1 i := 1 while x >a, i := i + 1 {the loop ends when i is the index for x} for j := 0 to n - i {shove the rest of the list to the right} an- 1 +1 := an-J a,:= x { x has been inserted into the correct spot in the list, now of length n + 1} 17. This algorithm is similar to max, except that we need to keep track of the location of the maximum value, as well as the maximum value itself. Note that we need a strict inequality in the test max a2 then interchange a 1 and a 2 if a2 > a3 then interchange a2 and a3 if a 1 > a2 then interchange a 1 and a 2 {the first three elements are now in nondecreasing order} 23. For notation, assume that f : A ___, B, where A is the set consisting of the distinct integers a 1 , a 2 , ... , an, and B is the set consisting of the distinct integers b1 , b2 , ... , bm . All n + m + 1 of these entities (the elements of A, the elements of B, and the function f) are the input to the algorithm. We set up an array called hit (indexed by the integers) to keep track of which elements of B are the images of elements of A; thus hit(b,) equals 0 until we find an aJ such that f (a1 ) = b,, at which time we set hit(b,) equal to 1. Simultaneously we keep track of how many hits we have made (i.e., how many times we changed some hit(b,) from 0 to 1 ). If at the end we have made m hits, then f is onto; otherwise it is not. Note that we record the output as a logical value assigned to the variable that has the name of the procedure. This is a common practice in some programming languages. Chapter 3 92 Algorithms procedure onto(!: function, a1, a2, ... , an, b1, b2, ... , bm : integers) for i := 1 tom hzt(b,) := 0 {no one has been hit yet} count := 0 {there have been no hits yet} for j := 1 ton if hit(f(a1 )) = 0 then {a new hit!} hit(f(a1 )) := 1 count := count + 1 if count = m then return true else return false { f is onto if and only if there have been m hits} 25. This algorithm is straightforward. procedure count ones(a1a 2 ... an : bit string) count:= 0 {no l's yet} for i := 1 to n if a, = 1 then count := count + 1 return count { count contains the number of l's} 27. We start with the pseudocode for binary search given in the text and modify it. In particular, we need to compute two middle subscripts (one third of the way through the list and two thirds of the way through) and compare x with two elements in the list. Furthermore, we need special handling of the case when there are two elements left to be considered. The following pseudocode is reasonably straightforward. procedure ternary search(x: integer, a 1 , a 2 , ... , an : increasing integers) i := 1 j := n while i < j - 1 l := l(i + j)/3J u := l2(i + j)/3J if x > au then i := u + 1 else if x > az then i := l + 1 j := u else j := l if x =a, then location:= i else if x = a1 then location := j else location := 0 return location { location is the subscript of the term equal to x ( 0 if not found)} 29. The following algorithm will find the first mode in the sequence. At each point in the execution of this algorithm, modecount is the number of occurrences of the element found to occur most often so far (which is called mode). Whenever a more frequently occurring element is found (the main inner loop), modecount and mode are updated. Section 3.1 Algorithms 93 procedure find a mode(a 1 , a 2 , •.. , an: nondecreasing integers) modecount := 0 i := 1 while i::; n value:= a, count:= 1 while i ::; n and a, = value count := count+ 1 i := i if count +1 > modecount then modecount := count mode := value return mode { mode is the first value occurring most often, namely modecount times} 31. The following algorithm goes through the terms of the sequence one by one, and, for each term, compares it to all previous terms. If it finds a match, then it stores the subscript of that term in location and terminates the search. If no match is ever found, then location is set to 0. procedure find duplicate(a 1 , a 2 , ... , an : integers) location := 0 {no match found yet} i := 2 while i ::; n and location = 0 j := 1 while j < i and location= 0 if a, = a1 then location := i else j := j + 1 i := i + 1 return location { location is the subscript of the first value that repeats a previous value in the sequence and is 0 if there is no such value} 33. The following algorithm goes through the terms of the sequence one by one, and, for each term, checks whether it is less than the immediately preceding term. If it finds such a term, then it stores the subscript of that term in location and terminates the search. If no term satisfies this condition, then location is set to 0. procedure find decrease(a 1 , a 2 , ... , an : positive integers) location := 0 {no match found yet} i := 2 while i ::; n and location = 0 if a, < a,_ 1 then location := i else i := i + 1 return location { location is the subscript of the first value that is less than the immediately preceding one and is 0 if there is no such value} 35. There are four passes through the list. On the first pass, the 3 and the 1 are interchanged first, then the next two comparisons produce no interchanges, and finally the last comparison results in the interchange of the 7 and the 4. Thus after one pass the list reads 1, 3, 5, 4, 7. During the next pass, the 5 and the 4 are interchanged, yielding 1, 3, 4, 5, 7. There are two more passes, but no further interchanges are made, since the list is now in order. 37. We need to add a Boolean variable to indicate whether any interchanges were made during a pass. Initially this variable, which we will call stilLinterchanging, is set to true. If no interchanges were made, then we can 94 Chapter 3 Algorithms quit. To do this neatly, we turn the outermost loop into a while loop that is executed as long as i stilLinterchanging is true. Thus our pseudocode is as follows. < n and procedure betterbubblesort( ai, . .. , an) i := 1 stilLinterchanging :=true while i < n and stilLinterchanging stilLinterchanging := false for j := 1 to n - i if a1 > a1 + 1 then stilLinterchanging := true interchange a1 and a1 + 1 i := i + 1 { a 1 •... , an is in nondecreasing order} 39. We start with 3, 1, 5, 7, 4. The first step inserts 1 correctly into the sorted list 3, producing 1, 3, 5, 7, 4. Next 5 is inserted into 1, 3, and the list still reads 1, 3, 5, 7, 4, as it does after the 7 is inserted into 1, 3, 5. Finally, the 4 is inserted, and we obtain the sorted list 1, 3, 4, 5, 7. At each insertion, the element to be inserted is compared with the elements already sorted, starting from the beginning, until its correct spot is found, and then the previously sorted elements beyond that spot are each moved one position toward the back of the list. 41. We assume that when the least element is found at each stage, it is interchanged with the element in the position it wants to occupy. a) The smallest element is 1, so it is interchanged with the 3 at the beginning of the list, yielding 1, 5, 4, 3, 2. Next, the smallest element among the remaining elements in the list (the second through fifth positions) is 2, so it is interchanged with the 5 in position 2, yielding 1, 2, 4, 3, 5. One more pass gives us 1, 2, 3, 4, 5. At this point we find the fourth smallest element among the fourth and fifth positions, namely 4, and interchange it with itself, again yielding 1, 2, 3, 4, 5. This completes the sort. b) The process is similar to part (a). We just show the status at the end of each of the four passes: 1, 4, 3, 2,5; 1,2,3,4.5; 1.2,3,4,5; 1,2,3,4,5. c) Again there are four passes. but all interchanges result in the list remaining as it is. 43. We carry out the linear search algorithm given as Algorithm 2 in this section, except that we replace x =I- a, by x < a,. and we replace the else clause with else location := n + 1. The cursor skips past all elements in the list less than x, the new element we are trying to insert, and ends up in the correct position for the new element. 45. We are counting just the comparisons of the numbers in the list, not any comparisons needed for the bookkeeping in the for loop. The second element in the list must be compared with the first and compared with itself (in other words, when j = 2 in Algorithm 5, i takes the values 1 and 2 before we drop out of the while loop). The third element must be compared with the first two and itself, since it exceeds them both. We continue in this way, until finally the nth element must be compared with all the elements. So the total number of comparisons is 2 + 3 + 4 + · · · + n, which can be written as (n 2 + n - 2)/2. This is the worst case for insertion sort in terms of number of comparisons; see Example 6 in Section 3.3. On the other hand, no movements of elements are required, since each new element is already in its correct position. 47. There are two kinds of steps-the searching and the inserting. We assume the answer to Exercise 44, which is to use Algorithm 3 but replace the final check with if x < a, then location := i else location := i + 1. So the first step is to find the location for 2 in the list 3, and we insert it in front of the 3, so the list now reads 2. 3, 4, 5. 1, 6. This took one comparison. Next we use binary search to find the location for the 4, and Section 3.1 Algorithms 95 we see, after comparing it to the 2 and then the 3, that it comes after the 3, so we insert it there, leaving still 2, 3, 4, 5, 1, 6. Next we use binary search to find the location for the 5, and we see, after comparing it to the 3 and then the 4, that it comes after the 4, so we insert it there, leaving still 2, 3, 4, 5, 1, 6. Next we use binary search to find the location for the 1, and we see, after comparing it to the 3 and then the 2 and then the 2 again, that it comes before the 2, so we insert it there, leaving 1, 2, 3, 4, 5, 6. Finally we use binary search to find the location for the 6, and we see, after comparing it to the 3 and then the 4 and then the 5, that it comes after the 5, so we insert it there, giving the final answer 1, 2, 3, 4, 5, 6. Note that this took 11 comparisons in all. 49. We combine the search technique of Algorithm 3, as modified in Exercises 44 and 47, with the insertion part of Algorithm 5. procedure binary insertion sort(a1, a2, ... , an : real numbers with n 2: 2) for j := 2 ton {binary search for insertion location i } left:= 1 right:= j - 1 while left < right middle:= L(left + right)/2J if a 1 > amiddle then left := middle + 1 else right := middle if aj < azeft then i := left else i := left + 1 {insert a1 in location i by moving ai through a1 _ 1 toward back of list} m :=a1 for k := 0 to j - i - 1 aj-k ai := a 1 -k-1 :=m { ai, a2, ... , an are sorted} 51. If the elements are in close to the correct order, then we would usually find the correct spot for the next item to be inserted near the upper end of the list of already-sorted elements. Hence the variation from Exercise 50, which starts comparing at that end, would be best. 53. In each case we use as many quarters as we can, then as many dimes to achieve the remaining amount, then as many nickels, then as many pennies. a) The algorithm uses the maximum number of quarters, two, leaving 1 cent. It then uses the maximum number of dimes (none) and nickels (none), before using one penny. b) two quarters, leaving 19 cents, then one dime, leaving 9 cents, then one nickel, leaving 4 cents, then four pennies c) three quarters, leaving 1 cent, then one penny d) two quarters, leaving 10 cents, then one dime 55. In each case we uses as many quarters as we can, then as many dimes to achieve the remaining amount, then as many pennies. a) The algorithm uses the maximum number of quarters, two, leaving 1 cent. It then uses the maximum number of dimes (none), before using one penny. Since the answer to Exercise 53a used no nickels anyway, the greedy algorithm here certainly used the fewest coins possible. b) The algorithm uses two quarters, leaving 19 cents, then one dime, leaving 9 cents, then nine pennies. The greedy algorithm thus uses 12 coins. Since there are no nickels available, we must either use nine pennies or else use only one quarter and four pennies, along with four dimes to reach the needed total of 69 cents. This uses only nine coins, so the greedy algorithm here did not achieve the optimum. 96 Chapter 3 Algorithms c) The algorithm uses three quarters, leaving 1 cent, then one penny. Since the answer to Exercise 53c used no nickels anyway, the greedy algorithm here certainly used the fewest coins possible. d) The algorithm uses two quarters, leaving 10 cents, then one dime. Since the answer to Exercise 53c used no nickels anyway, the greedy algorithm here certainly used the fewest coins possible. 57. We first sort the talks by finishing times and get the following list: 9:00-9:45, 9:30-10:00, 9:50-10:15, 10:1010:25, 10:00-10:30, 10:15-10:45, 10:30-10:55, 10:30-11:00, 11:00-11:15, 10:55-11:25, 10:45-11:30. We then go through the list in order and schedule every talk that is compatible with the talks already scheduled. So first we schedule the 9:00-9:45 talk, then the first one on our list that starts after that talk is finished, namely the 9:50-10:15 talk. Next comes the 10:15-10:45 talk, and then the 11:00-11:15 talk. There are no more talks that start after this one ends, so we are done, having scheduled four talks. 59. a) We propose the following greedy algorithm. Order the talks by starting time. Number the lecture halls 1, 2, 3, and so on. For each talk, assign it to lowest numbered lecture hall that is currently available. So, for example, using the talks from Exercise 57, we would assign the 9:00-9:45 talk to lecture hall 1, the 9:30-10:00 talk to lecture hall 2, the 9:50-10:15 talk to lecture hall 1, the 10:00-10:30 talk to lecture hall 2, the 10:1010:25 talk to lecture hall 3, the 10: 15-10:45 talk to lecture hall 1, the 10:30-10:55 talk to lecture hall 2, the 10:30-11:00 talk to lecture hall 3, the 10:45-11:30 talk to lecture hall 1, the 10:55-11:25 talk to lecture hall 2, and the 11:00-11:15 talk to lecture hall 3. Therefore three halls were sufficient. b) This algorithm is optimal, because if it uses n lecture halls, then at the point the nth hall was first assigned, it had to be used (otherwise a lower-numbered hall would have been assigned), which means that n talks were going on simultaneously (this talk just assigned and the n - 1 talks currently in halls 1 through n - 1 ). 61. In the algorithm presented here, the input consists, for each man, of a list of all women in his preference order, and for each woman, of a list of all men in her preference order. At the risk of being sexist, we will let the men be the suitors and the women the suitees (although obviously we could reverse these roles). The procedure needs to have data structures (lists) to keep track, for each man, of his status (rejected or not) and the list of women who have rejected him, and, for each woman, of the men currently on her proposal list. procedure stable(A11, M2, ... , lvf8 , W1, W2, ... , W 8 ,: preference lists) for i := 1 to s mark man i as rejected for i := 1 to s set man i's rejection list to be empty for j := 1 to s set woman j's proposal list to be empty while rejected men remain for i := 1 to s if man i is marked rejected then add i to the proposal list for the woman j who ranks highest on his preference list but does not appear on his rejection list, and mark i as not rejected for j := 1 to s if woman j's proposal list is nonempty then remove from j's proposal list all men i except the man io who ranks highest on her preference list, and for each such man i mark him as rejected and add j to his rejection list for j := 1 to s match j with the one man on j's proposal list {This matching is stable.} 63. Suppose the assignment is not stable. Then there is a man m and a woman w such that m prefers w to the woman (call her w') with whom he is matched, and w prefers m to the man with whom she is matched. But Section 3.2 The Growth of Functions 97 m must have proposed to w before he proposed to w' , since he prefers the former. And since m did not end up matched with w, she must have rejected him. Since women reject a suitor only when they get a better proposal, and they eventually get matched with a pending suitor, the woman with whom w is matched must be better in her eyes than m, contradicting our original assumption. Therefore the matching is stable. 65. The algorithm is simply to run the two programs on their inputs concurrently and wait for one to halt. This algorithm will terminate by the conditions of the problem, and we'll have the desired answer. SECTION 3.2 The Growth of Functions The big-0 notation is used extensively in computer science and other areas. Think of it as a crude ruler for measuring functions in terms of how fast they grow. The idea is to treat all functions that are more or less the same as one function-one mark on this ruler. Thus, for example, all linear functions are simply thought of as O(n). Although technically the big-0 notation gives an upper bound on the growth of a function, in practice we choose the smallest big-0 estimate that applies. (This is made more rigorous with the big-8 notation, also discussed in this section.) In essence, one finds best big-0 estimates by discarding lower order terms and multiplicative constants. Furthermore, one usually chooses the simplest possible representative of the big-0 (or big-8) class (for example, writing 0( n 2 ) rather than 0(3n 2 + 5) ). A related concept, used in combinatorics and applied mathematics, is the little-o notation, dealt with in Exercises 61-69. 1. Note that the choices of witnesses C and k are not unique. a) Yes, since 1101::::; lxl for all x > 10. The witnesses are C = 1 and k = 10. b) Yes, since l3x + 71 ::::; l4xl = 4lxl for all x > 7. The witnesses are C = 4 and k = 7. c) No. There is no constant C such that lx 2 + x + 1 I :::; Clxl for all sufficiently large x. To see this, suppose this inequality held for all sufficiently large positive values of x. Then we would have x 2 :::; Cx, which would imply that x ::::; C for all sufficiently large x, an obvious impossibility. d) Yes. This follows from the fact that log x < x for all x > 1 (which in turn follows from the fact that x < 2x, which can be formally proved by mathematical induction-see Section 5.1). Therefore l5logxl::::; 5lxl for all x > 1. The witnesses are C = 5 and k = 1. lx J : : ; e) Yes. This follows from the fact that and k = 0. x. Thus f) Yes. This follows from the fact that lx/21::::; (x/2) The witnesses are C = 1 and k = 2. Ilx JI : : ; + 1. lxl for all x > 0. The witnesses are C Thus llx/211:::; l(x/2) + ll:::; 3. We need to put some bounds on the lower order terms. If x > 9 then we have x 4 x4 + x 4 + x 4 + x 4 = 4x4 • Therefore x 4 + 9x3 + 4x + 7 is O(x 4 ), taking witnesses C = 1 lxl for all x > 2. + 9x 3 + 4x + 7 < = 4 and k = 9. 5. We use long division to rewrite this function: x2 +1 x+l x 2 2 1+2 = x - 1 x+l x+l - + _2_ x+l = x _ 1 + _2_ x+l Now this is certainly less than x as long as x > 1, so our function is O(x). The witnesses are C = 1 and k = 1. 98 Chapter 3 Algorithms 7. a) Since log x grows more slowly than x, x 2 log x grows more slowly than x 3 , so the first term dominates. Therefore this function is O(x 3 ) but not O(xn) for any n < 3. More precisely, 2x3 +x 2 log x :::; 2x 3 +x 3 = 3x 3 for all x, so we have witnesses C =3 and k = 0. b) We know that log x grows so much more slowly than x that every power of log x grows more slowly than x (see Exercise 58). Thus the first term dominates, and the best estimate is O(x 3 ). More precisely, (log x ) 4 < x 3 for all x > 1, so 3x 3 + (log x ) 4 :::; 3x3 + x 3 = 4x 3 for all x, so we have witnesses C = 4 and k = 1. c) By long division, we see that f(x) = x +lower order terms. Therefore this function is O(x), so n fact, f(x) =x + x~l :::; = 1. In > 1, so the witnesses can be taken to be C = 2 and k = 1. this quotient has the form f(x) = 1 +lower order terms. Therefore this function = 0. Since 5 log x < x 4 for x > 1, we have f (x) :::; 2x 4 / x 4 = 2, so we can take as 2x for all x d) Again by long division, is 0(1). In other words, n witnesses C = 2 and k = 1. 9. On the one hand we have x 2 + 4x + 17:::; x 2 + x 2 + x 2 = 3x 2 :::; 3x3 for all x > 17, so x 2 + 4x + 17 is O(x 3 ), with witnesses C = 3 and k = 17. On the other hand, if x 3 were O(x 2 + 4x + 17), then we would have x 3 :::; C(x 2 + 4x + 17) :::; 3Cx 2 for all sufficiently large x. But this says that x :::; 3C, clearly impossible for the constant C to satisfy for all large x. Therefore x 3 is not O(x 2 + 4x + 17). 11. For the first part we have 3x 4 + 1 :::; 4x 4 = 8lx 4 /21 for all x > 1; we have witnesses C second part we have x 4 /2:::; 3x4 :::; 1 · J3x 4 + lJ for all x; witnesses are C = 1, k = 0. = 8, k = 1. For the > 0. In terms of witnesses we have C = 1 and k = 0. On the other hand, if 3n were 0(2n), then we would have 3n :::; C · 2n for all sufficiently large n. This is equivalent to C ::::: ( ~) n, which is clearly impossible, since ( ~) n grows without bound as n increases. 13. To show that 2n is 0(3n) it is enough to note that 2n :::; 3n for all n 15. A function f is 0(1) if lf(x)J :::; C for all sufficiently large x. In other words, is bounded for all x > k (where k is some constant). f is 0(1) if its absolute value 17. Let C1, C2, ki, and k2 be numbers such that lf(x)I :::; C1lg(x)I for all x > ki and lg(x)I :::; C2lh(x)I for all x > k 2 . Let C = C1 C2 and let k be the larger of k1 and k2. Then for all x > k we have lf(x)J:::; C1lg(x)I:::; C1C2lh(x)I = Clh(x)I, which is precisely what we needed to show. 19. Because 2n+i = 2 · 2n, clearly it is 0(2n) (take C = 2). To see that 22n is not 0(2n), look at the ratio: 22 n /2n = 2n. Because this is unbounded, there is no constant C such that 22 n :::; C · 2n for all sufficiently large n. 21. The order is lOOOlogn, yin, nlogn, n 2/1000000, 2n, 3n, 2n!. Thateachisbig-0 ofthenextisclear. 23. Because n log n is 0( n 3 12) but n 3 12 is not 0( n log n), the first algorithm uses fewer operations for large n. In fact, if we solve n log n < n 3 12 , we get n > 4. In other words, the first algorithm uses fewer operations for all n > 4. 25. a) The significant terms here are the n 2 being multiplied by the n; thus this function is O(n 3 ). b) Since log n is smaller than n, the significant term in the first factor is n 2 . Therefore the entire function is O(n 5 ). c) For the first factor we note that 2n < n! for n 2: 4, so the significant term is n!. For the second factor, the significant term is n 3 . Therefore this function is O(n3 n!). Section 3.2 The Growth of Functions 99 27. a) First we note that log(n 2 +1) and logn are in the same big-0 class, since logn 2 = 2logn. Therefore the second term here dominates the first, and the simplest good answer would be just 0( n 2 log n). b) The first term is in the same big-0 class as O(n 2(logn) 2), while the second is in a slightly smaller class, 0( n 2 log n). (In each case, we can throw away the smaller order terms, since they are dominated by the terms we are keeping-this is the essence of doing big-0 estimates.) Therefore the answer is O(n 2(1ogn) 2). c) The only issue here is whether 2n or n 2 is the faster-growing, and clearly it is the former. Therefore the best big-0 estimate we can give is O(n 2"). 29. We can use the following rule of thumb to determine what simple big- 8 function to use: throw away all the lower order terms (those that don't grow as fast as other terms) and all constant coefficients. a) This function is 8(x), so it is not 8(x 2), since x 2 grows faster than x. To be precise, x 2 is not 0(17x+ll). For the same reason, this function is not O(x 2). b) This function is 8(x 2); we can ignore the "+ 1000'' since it is a lower order term. Of course, since J(x) is 8(x 2), it is also O(x 2). c) This function grows more slowly than x 2 , since logx grows more slowly than x. Therefore f(x) is not 8(x 2) or O(x 2). d) This function grows faster than x 2 . Therefore f(x) is not 8(x 2), but it is D(x 2 ). e) Exponential functions (with base larger than 1) grow faster than all polynomials, so this function is not O(x 2) and therefore not 8(x 2). But it is O(x 2). f) For large values of x, this is quite close to x 2 , since both factors are quite close to x. Certainly l x J · fxl is always between x 2/2 and 2x 2 , for x > 2. Therefore this function is 8(x 2) and hence also O(x 2). 31. If J(x) is 8(g(x)), then lf(x)I::; C2lg(x)I and lg(x)I::; c1 1lf(x)I for all x > k. Thus f(x) is O(g(x)) and g(x) is O(f(x)). Conversely, suppose that f(x) is O(g(x)) and g(x) is O(f(x)). Then (with appropriate choice of variable names) we may assume that IJ(x)I ::; C 2lg(x)I and lg(x)I ::; Clf(x)I for all x > k. (The k here will be the larger of the two k's involved in the hypotheses.) If C > 0 then we can take C 1 = c~ 1 to obtain the desired inequalities in "f(x) is G(g(x)) ." If C ::; 0, then g(x) = 0 for all x > k, and hence by the first inequality f(x) = 0 for all x > k; thus we have f(x) = g(x) for all x > k, and we can take C1=C2=1. 33. The definition of "f(x) is 8(g(x))" is that f(x) is both O(g(x)) and O(g(x)). That means that there are positive constants C1, k1, C2, and k2 such that IJ(x)I ::; C2lg(x)I for all x > k2 and lf(x)I ?: C1lg(x)I for all x > k1 . That is practically the same as the statement in this exercise. We need only note that we can take k to be the larger of k1 and k2 if we want to prove the "only if" direction, and we can take k1 = k2 = k if we want to prove the "if" direction. 35. In the following picture, the wavy line is the graph of the function f. For simplicity we assume that the graph of g is a straight line through the origin. Then the graphs of C1 g and C2 g are also straight lines through the origin, as drawn here. The fact that f(x) is G(g(x)) is shown by the fact that for x > k the graph off is confined to the shaded wedge-shaped space between these latter two lines (see Exercise 33). (We assume that g(x) is positive for positive x, so that lg(x)I is the same as g(x).) Chapter 3 100 Algorithms y 37. Looking at the definition tells us that if f(x) is 8(1) then lf(x)I has to be bounded between two positive constants. In other words, f(x) can't get too large (either positive or negative), and it can't get too close to 0. 39. We are given that lf(x)I ::::; Cl9(x)I for all x > k. Hence lr(x)I = lf(x)ln ::::; cn19n(x)I for all x x) is 0(9n (x)) (take the constants in the definition to be en and k). r( > k, so 41. Since the functions are given to be increasing and unbounded, we may assume that they both take on values greater than 1 for all sufficiently large x. The hypothesis can then be written as f(x)::::; C9(x) for all x > k. If we take the logarithm of both sides, then we obtain log J(x) ::::; log C +log 9(x). Finally, this latter expression is less than 2log9(x) for large enough x, since log9(x) is growing without bound. Note that the "converse" implication does not hold; even though log(3n) is O(log(2n)) (both functions are linear), it is not true that 3" is 0(2n). 43. By definition there are positive constants C 1 , C{, C2, C~, k1, k{, k2, and k~ such that fi(x) 2 C1l9(x)I for all x > ki, fi(x)::::; Cil9(x)I for all x > ki, h(x) ~ C2l9(x)I for all x > k2, and h(x)::::; C~l9(x)I for all x > k~. We are able to omit the absolute value signs on the f(x) 's since we are told that they are positive; we are also told here that the 9(x) 's are positive, but we do not need that. Adding the first and third inequalities we obtain fi(x) + h(x) 2 (C1 + C2)l9(x)I for all x > max(k1, k2); and similarly with the second and fourth inequalities we know Ji (x) + h(x) ::::; definition of being 8(g(x)). (Ci + q)l9(x)I for all x > max(ki, k~). Thus Ji (x) + h(x) meets the If the f's can take on negative values, then this is no longer true. For example, let fi (x) = x 2 + x, let h(x) = -x 2 + x, and let g(x) = x 2 . Then each fi(x) is 8(9(x)), but the sum is 2x, which is not 8(g(x)). 45. This is not true. It is similar to Exercise 43, and essentially the same counterexample suffices. Let Ji (x) = x 2 +2x, h(x) = x 2 +x, and 9(x) = x 2 . Then clearly Ji (x) and h(x) are both 8(9(x)), but (11 - h)(x) = x is not. 47. The key here is that if a function is to be big-0 of another, then the appropriate inequality has to hold for all large inputs. Suppose we let f (x) = x 2 for even x and x for odd x. Similarly, we let 9( x) = x 2 for odd x and x for even x. Then clearly neither inequality lf(x)I::::; Clg(x)I nor J9(x)I::::; Clf(x)I holds for all x, since for even x the first function is much bigger than the second, while for odd x the second is much bigger than the first. 49. We are given that there are positive constants C1, Ci, C2, q, k1, ki, k2, and k~ such that lf1(x)I 2 C1lg1(x)I for all x > k1, lfi(x)I::::; Cil91(x)I for all x > ki, lh(x)I ~ C2l92(x)I for all x > k2, and Ih (x) I ::::; q Jg 2(x) I for all x > k~. Since h and 9 2 never take on the value 0, we can rewrite the last two of these inequalities as ll/ h(x)I ::::; (1/C2)ll/g2(x)I and 11/ h(x)I ~ (1/crn1/g2(x)J. Now we multiply the first inequality and the rewritten fourth inequality to obtain lfi(x)/ h(x)I ~ (Ci/q)lg1(x)/g2(x)I for all x > max(k 1 ,k~). Working with the other two inequalities gives us lfi(x)/h(x)I::::; (Ci/C2)lg1(x)/92(x)I for all x > max( ki, k2) . Together these tell us that Ji/ h is big- 8 of gi/ 9 2 . Section 3.2 The Growth of Functions 101 51. We just make the analogous change in the definition of big-8 that was made in the definition of big-0: there exist positive constants C1, C2, ki, k2, ki, k~ such that lf(x,y)I :S C1lg(x,y)I for all x > ki and y > k2, and lf(x, y)I 2: C2lg(x, y)I for all x > ki and y > k~. 53. For all values of x and y greater than 1, each term of the expression inside parentheses is less than x 2 y, so the entire expression inside parentheses is less than 3x 2 y. Therefore our function is less than 27x 6 y 3 for all x > 1 and y > 1. By definition this shows that it is big-0 of x 6 y 3 . Specifically, we take C = 27 and ki = k2 = 1 in the definition. 55. For all positive values of x and y, we know that lxy J :::; xy by definition (since the floor function value cannot exceed the argument). Thus lxyj is O(xy) from the definition, taking C = 1 and k1 = k 2 = 0. In fact, lxyj is also O(xy) (and therefore 8(xy) ); this is easy to see since Lxyj 2: (x - 1)(y - 1) 2: ( ~x) ( ~y) = i-xy for all x and y greater than 2. 57. Because d < c, clearly nd < nc for all n 2: 2; therefore nd is O(nc). To see that nd is not O(nc), look at the ratio: nd /nc = nd-c. Because this is unbounded (the exponent is positive), there is no constant C such that nd :::; enc for all sufficiently large n. 59. If f and g are positive-valued functions for which we can compute the limit of the ratio f(x)/g(x) as x __, oo, then the value of that limit will tell us about the asymptotic behavior of those functions relative to each other. Indeed, if the limit is a finite number C, then for large enough x, we have f (x) < (C + 1)g( x) , so f (n) is O(g(n)). If the limit is oo, then clearly f(n) is not O(g(n)). In the case at hand, limx_, 00 xd /bx =0 (apply L'H6pital's rule Idl times), and similarly limx_, 00 bx jxd = oo. The desired conclusions follow. 61. All that we need to do is determine whether the ratio of the two functions approaches 0 as x approaches infinity. . x2 a ) 1im X---+(X) X3 = l' 1 1m X--+cx::> X =0 1 · l' s ru1e £or t h e second equa1.ity ) b) ll·m x log x -_ 11·m log x -- 11·m - -- -- 0 (using L'H'op1ta X--->00 x2 X--->00 x X--->00 x ln 2 2 c) lim x X--->00 2X d) lim X---+00 x2 = lim X--->00 ~lx = 2x n 2 +x +1 = X2 lim X--->00 lim (1 X---+(X) 2 (1 ) 2X n 2 2 + -X1 + 2X1 ) = 63. The picture shows the graph of y = x2 = 0 (with two applications of L'H6pital's rule) 1 =/= 0 increasing quite rapidly and y ratio is hard to see on the picture; it rises to about y = 0.53 = x log x at about x = increasing less rapidly. The 2.7 and then slowly decreases toward 0. The limit as x __, oo of (x log x) / x 2 is in fact 0. x2 y 30 20 x log x 10 /x log x)/x 2 2 3 4 5 6 Chapter 3 102 65. No. As one example, take f(x) = x- 2 and g(x) Algorithms = x- 1 . Then f(x) is o(g(x)), since lim x- 2 /x- 1 2 1 = lim 2.r- -x- = 2°=1 f' O. x~oo 2 lim 1/x = 0. On the other hand lim (2.r- ;2xX---->OC• :r~,'.X) 1 ) X---1'CX"; 67. a) Since the limit of f(x)/g(x) is 0 (as x----+ oo ), so too is the limit of lf(x)l/lg(x)I. In particular, for x large enough, this ratio is certainly less than 1. In other words lf(x)I:::; lg(x)I for sufficiently large x, which meets the definition of "f(x) is O(g(.r,))." b) We can simply let f (:r) = g( x) be any function with positive values. Then the limit of their ratio is 1, not 0, so f(x) is not o(g(x)), but certainly f(x) is O(g(x)). 69. This follows immediately from Exercise 67a (whereby we can conclude that h(x) is O(g(x))) and Corollary 1 to Theorem 2. 71. What we want to show is equivalent to the statement that log(nn) is at most a constant times log(n!), which in turn is equivalent to the statement that nn is at most a constant power of n! (because of the fact that ClogA = log(Ac)~see Appendix 2). We will show that in fact nn:::; (n!) 2 for all n > 1. To do this, let us write (n!) 2 as (n · l) · ( (n - l) · 2)- ( (n - 2) · 3) · · · (2 · (n -1)) · (1 · n). Now clearly each product pair (i + 1) · (n- i) is at least as big as n (indeed, the ones near the middle are significantly bigger than n ). Therefore the entire product is at least as big as nn, as desired. 73. For n = 5 we compute that log5! ::::o 6.9 and (5log5)/4 ::::o 2.9, so the inequality holds (it actually holds for all n > 1). Therefore we can assume that n ;:::: 6. Since n! is the product of all the integers from n down to 1, we certainly have n! > n(n - l)(n - 2) · · · In/21 (since at least the term 2 is missing). Note that there are more than n/2 terms in this product, and each term is at least as big as n/2. Therefore the product is greater than (n/2)(n/ 2 J. Taking the log of both sides of the inequality, we have n)n/2 n n n logn! >log ( = 2 1og 2 = 2 (logn-1) > (nlogn)/4, 2 since n > 4 implies log n - 1 > (log n) /2. 75. In each case we need to evaluate the limit of f (x) / g( x) as x ----+ oo. If it equals 1, then f and g are asymptotic; otherwise (including the case in which the limit does not exist) they are not. Most of these are straightforward applications of algebra, elementary notions about limits, or L'H6pital's rule. a) f (x) = log(x 2 + 1) ;:::: log(x 2 ) = 2 log .r. Therefore f (.r) / g(:r) ;:::: 2 for all x. Thus the limit is not 1 (in fact, of course, it's 2), so f and g are not asymptotic. b) By the algebraic rules for exponents, f(x)/g(x) = 2- 4 = 1/16. Therefore the limit of the ratio is 1/16, not 1, so f and g are not asymptotic. 22' " 2 c) lim - 2 = lim 22 -x . As :r gets large, the exponent grows without bound, so this limit is oo. Thus f x---+oo 2x :r------roo and g are not asymptotic. 2x 2 +x+l d) lim = lim 2 1 -:r. As :r gets large, the exponent grows in the negative direction without bound, 2 .r---+CX) 2.r + 2 x .T---+00 so this limit is 0. Thus f and g are not asymptotic. Section 3.3 Complexity of Algorithms SECTION 3.3 103 Complexity of Algorithms Some of these exercises involve analysis of algorithms, as was done in the examples in this section. These are a matter of carefully counting the operations of interest, usually in the worst case. Some of the others are algebra exercises that display the results of the analysis in real terms-the number of years of computer time, for example, required to solve a large problem. Horner's method for evaluating a polynomial, given in Exercise 14, is a nice trick to know. It is extremely handy for polynomial evaluation on a pocket calculator (especially if the calculator is so cheap that it does not use the usual precedence rules). 1. The statement t := t + ij is executed just 12 times, so the number of operations is 0(1). (Specifically, there are just 24 additions or multiplications.) 3. The nesting of the loops implies that the assignment statement is executed roughly n 2 /2 times. Therefore the number of operations is 0( n 2 ) . 5. Assuming that the algorithm given to find the smallest element of a list is identical to Algorithm 1 in Section 3.1, except that the inequality is reversed (and the name max replaced by the name min), the analysis will be identical to the analysis given in Example 1 in the current section. In particular, there will be 2n - 1 comparisons needed, counting the bookkeeping for the loop. 7. The linear search would find this element after at most 9 comparisons ( 4 to determine that we have not yet finished with the while loop, 4 more to determine if we have located the desired element yet, and 1 to set the value of location). Binary search, according to Example 3, will take 2 log 32 + 2 = 2 · 5 + 2 = 12 comparisons. Since 9 < 12, the linear search will be faster, in terms of comparisons. 9. The algorithm simply scans the bits one at a time. Thus clearly O(n) comparisons are required (perhaps one for bookkeeping and one for looking at the ith bit, for each i from 1 to n ). 11. a) We can express the suggested algorithm in pseudocode as follows. Notice that the Boolean variable disjoint is set to true at the beginning of the comparison of sets S, and S1 , and becomes false if and when we find an element common to those two sets. If disjoint is never set to false, then we have found a disjoint pair, and answer is set to true. This process is repeated for each pair of sets (controlled by the outer two loops). procedure disjointpair(S1 , S 2 , ... , Sn : subsets of {1, 2, ... , n}) answer:= false for i := 1 ton for j := i + 1 ton disjoint := true fork:= 1 ton if k E Si and k E S1 then disjoint:= false if disjoint then answer := true return answer b) The three nested loops imply that the elementhood test needs to be applied O(n 3 ) times. 13. a) Here we have n = 2, a0 = 1, a 1 = 1, a 2 = 3, and c = 2. Initially, we set power equal to 1 and y equal to 1. The first time through the for loop (with i = 1 ) , power becomes 2 and so y becomes 1 + 1 · 2 = 3. The second and final time through the loop, power becomes 2 · 2 = 4 and y becomes 3 + 3 · 4 = 15. Thus the value of the polynomial at x = 2 is 15. b) Each pass through the loop requires two multiplications and one addition. Therefore there are a total of 2n multiplications and n additions in all. 104 Chapter 3 Algorithms 15. This is an exercise in algebra, numerical analysis (for some of the parts), and using a calculator. Since each bit operation requires 10- 9 seconds, we want to know for what value of n there will be at most 10 9 bit operations required. Thus we need to set the expression equal to 109 , solve for n, and round down if necessary. a) Solving logn = 109 , we get (recalling that "log'' means logarithm base 2) n = 2109 . By taking log 10 of both sides, we find that this number is approximately equal to 103oo,ooo,ooo. Obviously we do not want to write out the answer explicitly! b) Clearly n = 109 . c) Solving n log n = 109 is not trivial. There is no good formula for solving such transcendental equations. An algorithm that works well with a calculator is to rewrite the equation as n = 109 /log n, enter a random starting value, say n = 2, and repeatedly calculate a new value of n. Thus we would obtain, in succession, n = 109 /log2 = 109 , n = 109 /log(10 9 ):::::; 33,447,777.3, n = 109 /log(33,447,777.3):::::; 40,007,350.14, n = 109 /log( 40,007,350.14) :::::; 39,598,061.08, and so on. After a few more iterations, the numbers stabilize at approximately 39,620,077. 73, so the answer is 39,620,077. d) Solving n 2 = 109 gives n = 104 ·5 , which is 31,622 when rounded down. e) Solving 2n = 109 gives n = log(10 9 ):::::; 29.9. Rounding down gives the answer, 29. f) The quickest way to find the largest value of n such that n! :::; 109 is simply to try a few values of n. We find that 12! :::::; 4.8 x 108 while 13! :::::; 6.2 x 109 , so the answer is 12. 17. If each bit operation takes 10- 12 second, then we can carry out 10 12 bit operations per second, and therefore 60 · 10 12 bit operations per minute. Therefore in each case we want to solve the equation f(n) = 60 · 10 12 for n and round down to an integer. Obviously a calculator will come in handy here. a) If loglogn = 60 · 10 12 , then n = 22 12 60 60 10 12 , which is an unfathomably huge number. 1012 b) If log n = 60 · 10 , then n = 2 , which is still an unfathomably huge number. 5 2 12 c) If (log n ) = 60 · 10 , then log n = V6Q · 106 , so n = L2v'60·l0 J , which is still an extremely large number (it has over 2 million digits). d) If l,000,000n = 60 · 10 12 , then n = 60 · 106 = 60,000,000. e) If n 2 = 60 · 10 12 , then n f) If 2n = 60 · 10 12 , then n the base 2.) 2 = lV66 · 106 J = 7,745,966. = Llog(60 · 10 12 )J = Llog 60 + 12log10J = 45. (Remember, we are taking log to g) If 2n = 60 · 10 12 , then n to the base 2.) = h/log(60 · 10 12 )J = l yflog 60 + 12log10J = 6. (Remember, we are taking log 19. In each case, we just multiply the number of seconds per operation by the number of operations (namely 250 ). To convert seconds to minutes, we divide by 60; to convert minutes to hours, we divide by 60 again. To convert hours to days, we divide by 24; to convert days to years, we divide by 365 ~ . a) 250 x 10- 6 b) 250 c) 250 10- 9 = 1,125,899,907 seconds:::::; 36 years = 1,125,899.907 seconds:::::; 13 days x x 10- 12 = 1,125.899907 seconds:::::; 19 minutes 21. In each case we want to compare the function evaluated at n +1 to the function evaluated at n. The most desirable form of the comparison (subtraction or division) will vary. a) Notice that log( n + 1) - log n = log "~ 1 . If n is at all large, the fraction in this expression is approximately equal to 1, and therefore the expression is approximately equal to 0. In other words, hardly any extra time is required. For example, in going from n = 10 to n = 11, the number of extra milliseconds is log 11/10:::::; 0.14. b) lOO(n + 1) - lOOn = 100. One hundred extra milliseconds are required, independent of n. c) Because (n + 1) 2 - n 2 = 2n + 1, we conclude that 2n + 1 additional milliseconds are needed for the larger problem. Section 3.3 Complexity of Algorithms d) Because (n + 1) 3 105 n 3 = 3n 2 + 3n + 1, we conclude that 3n 2 + 3n + 1 additional milliseconds are needed - for the larger problem. e) This time it makes more sense to use a ratio comparison, rather than a difference comparison. Because 2n+i /2n = 2, we see that twice as much time is required for the larger problem. 2 f) Because 2 107. c) n 3 is not less than a constant times n 2 + 18n n > 107. + 107, since their ratio exceeds n 3 / (3n 2 ) = n/3 for all 4. (log n ) 3 , fo,, lOOn + 101, n 3 /1000000, 2nn 2 , 3n, n! 5. a) For the sum, take the largest term; for the product multiply the factors together. b) g(n) = nn- 2 2n = (2n)n /n 2 6. a) the largest, average, and smallest number of comparisons used by the algorithm before it stops, among all lists of n integers b) all are n - 1 7. a) See pp. 194-196. b) See p. 220. c) No-it depends on the lists involved. (However, the worst case complexity for binary search is always better than that for linear search for lists of any given size except for very short lists.) 8. a) See pp. 196-197. b) On the first pass, the 5 bubbles down to the end, producing 2 4 1 3 5. On the next pass, the 4 bubbles down to the end, producing 213 4 5. On the next pass, the 1 and the 2 are swapped. No further changes are made on the fourth pass. c) O(n 2 ); see Example 5 in Section 3.3 9. a) See pp. 197-198. b) On the first pass, the 5 is inserted into its correct position relative to the 2, producing 2 5 14 3. On the next pass, the 1 is inserted into its correct position relative to 2 5, producing 1 2 5 4 3. On the next pass, the 4 is inserted into its correct position relative to 1 2 5, producing 1 2 4 5 3. On the final pass, the 3 is inserted, producing the sorted list. c) O(n 2 ); see Example 6 in Section 3. 10. a) See p. 198. b) See Example 6 and Theorem 1 in Section 3.1. c) See Exercise 55b in Section 3.1. 11. Seep. 226 for "tractable.'' A solvable problem is simply one that can be solved by an algorithm. The halting problem is proved on pp. 201-202 to be unsolvable. Chapter 3 108 Algorithms SUPPLEMENTARY EXERCISES FOR CHAPTER 3 1. a) This algorithm will be identical to the algorithm first largest for Exercise 17 of Section 3.1, except that we want to change the value of location each time we find another element in the list that is equal to the current value of max. Therefore we simply change the strict less than ( <) in the comparison max < a, to a less than or equal to (:::; ), rendering the fifth line of that procedure ''if max :::; a, then." b) The number of comparisons used by this algorithm can be computed as follows. There are n - 1 passes through the for loop, each one requiring a comparison of max with ai. In addition, n comparisons are needed for bookkeeping for the loop (comparison of i with n, as i assumes the values 2, 3, ... , n + 1). Therefore 2n - 1 comparisons are needed altogether, which is O(n). 3. a) We will try to write an algorithm sophisticated enough to avoid unnecessary checking. The answer-true or false-will be placed in a variable called answer. procedure zeros(a 1 a2 ... an : bit string) i := 1 answer :=false {no pair of zeros found yet} while i < n and -ianswer if a, = 1 then i := i + 1 else if a,+1 = 1 then i := i + 2 else answer:= true return answer { answer was set to true if and only if there were a pair of consecutive zeros} b) The number of comparisons depends on whether a pair of O's is found and also depends on the pattern of increments of the looping variable i. Without getting into the intricate details of exactly which is the worst case, we note that at worst there are approximately n passes through the loop, each requiring one comparison of a, with 1 (there may be two comparisons on some passes, but then there will be fewer passes). In addition, n bookkeeping comparisons of i with n are needed (we are ignoring the testing of the logical variable answer). Thus a total of approximately 2n comparisons are used, which is 0( n). 5. a) and b). We have a variable min to keep track of the minimum as well as a variable max to keep track of the maximum. procedure smallest and largest(a 1 , a 2 , ... , an: integers) min:= ai max:= ai for i := 2 ton if a, < min then min := a, if a,> max then max:= a, { min is the smallest integer among the input, and max is the largest} c) There are two comparisons for each iteration of the loop, and there are n - 1 iterations, so there are 2n - 2 comparisons in all. 7. We think of ourselves as observers as some algorithm for solving this problem is executed. We do not care what the algorithm's strategy is, but we view it along the following lines, in effect taking notes as to what is happening and what we know as it proceeds. Before any comparisons are done, there is a possibility that each element could be the maximum and a possibility that it could be the minimum. This means that there are 2n different possibilities, and 2n - 2 of them have to be eliminated through comparisons of elements, since we need to find the unique maximum and the unique minimum. We classify comparisons of two elements as "nonvirgin" or "virgin," depending on whether or not both elements being compared have been in any previous comparison. A virgin comparison, between two elements that have not yet been involved in any comparison, eliminates the possibility that the larger one is the minimum and that the smaller one is the maximum; thus Supplementary Exercises 109 each virgin comparison eliminates two possibilities, but it clearly cannot do more. A nonvirgin comparison, one involving at least one element that has been compared before, must be between two elements that are still in the running to be the maximum or two elements that are still in the running to be the minimum, and at least one of these elements must not be in the running for the other category. For example, we might be comparing x and y, where all we know is that x has been eliminated as the minimum. If we find that x > y in this case, then only one possibility has been ruled out-we now know that y is not the maximum. Thus in the worst case, a nonvirgin comparison eliminates only one possibility. (The cases of other nonvirgin comparisons are similar.) Now there are at most l n/2 J comparisons of elements that have never been compared before, each removing two possibilities; they remove 2ln/2J possibilities altogether. Therefore we need 2n - 2 - 2ln/2J more comparisons that, as we have argued, can remove only one possibility each, in order to find the answers in the worst case, since 2n -2 possibilities have to be eliminated. This gives us a total of 2n - 2- 2 ln/2 J + l n/2 J comparisons in all. But 2n-2-2ln/2J+ln/2j = 2n-2-ln/2j = 2n-2+f-n/2l = f2n-n/2l-2 = f3n/2l-2, as desired. Note that this gives us a lower bound on the number of comparisons used in an algorithm to find the minimum and the maximum. On the other hand, Exercise 6 gave us an upper bound of the same size. Thus the algorithm in Exercise 6 is the most efficient algorithm possible for solving this problem. 9. The following uses the brute-force method. The sum of two terms of the sequence ai, a 2 , ... , an is given by ai + a1 , where i < j. If we loop through all pairs of such sums and check for equality, we can output two pairs whenever we find equal sums. A pseudocode implementation for this process follows. Because of the nested loops, the complexity is O(n 4 ). procedure equal sums(a1, a2, ... , an) for i := 1 ton for j := i + 1 to n {since we want i < j} fork:= 1 ton for l : = k + 1 to n {since we want k < l } if ai + a1 = ak + a1 and (i,j)-/:- (k, l) then output these pairs 11. After the comparison and possible exchange of adjacent elements on the first pass, from front to back, the list is 3, 1, 4, 5, 2, 6, where the 6 is known to be in its correct position. After the comparison and possible exchange of adjacent elements on the second pass, from back to front, the list is 1, 3, 2, 4, 5, 6, where the 6 and the 1 are known to be in their correct positions. After the next pass, the result is 1, 2, 3, 4, 5, 6. One more pass finds nothing to exchange, and the algorithm terminates. 13. There are possibly as many as n - 1 passes through the list (or parts of it-it depends on the particular way it is implemented), and each pass uses O(n) comparisons. Thus there are O(n 2 ) comparisons in all. 15. Since log n < n, we have (n log n + n 2 ) 3 :::; ( n 2 + n 2 ) 3 :::; (2n 2 ) 3 = 8n6 for all n (nlogn+n 2 ) 3 is O(n6 ),withwitnesses C=8 and k=O. > 0. This proves that 17. In the first factor the x 2 term dominates the other term, since (Iogx) 3 is O(x). Therefore by Theorem 2 in Section 3.2, this term is O(x 2 ). Similarly, in the second factor, the 2x term dominates. Thus by Theorem 3 of Section 3.2, the product is O(x 2 2x). 19. Let us look at the ratio n! n·(n-l)·(n-2)···3·2·1 n n-l n-2 3 2 1 = 2. -2-. -2- ... 2. 2. 2 2n 2 · 2 · 2· · ·2 · 2 · 2 Each of the fractions in the final expression is greater than 1 except the last one, so the entire expression is at least (n/2)/2 = n/4. Since n!/2n increases without bound as n increases, n! cannot be bounded by a constant times 2n, which tells us that n! is not 0(2n). Chapter 3 110 Algorithms 21. Each of these functions is of the same order as n 2 , so all pairs are of the same order. One way to see this is to think about ''throwing away lower order terms.'' Notice in particular that log 2n = n, and that the n 3 terms cancel in the fourth function. 23. We know that exponential functions grow faster than polynomial functions, so such a value of n must exist. If we take logs of both sides, then we obtain the equivalent inequality 2 100 log( n) < n, or n/ log n > 2 100 . This tells us that n has to be very large. In fact, n = 2 100 is not large enough, because for that value, the left-hand side is smaller by a factor of 100. If we go a little bigger, however, then the inequality will be satisfied. For example, if n = 2 107 , then we have ___!:!:_ logn = 2107 = 128 . 2100 > 2100 . 107 107 25. Clearly nn is growing the fastest, so it belongs at the end of our list. Next, l.OOOln is an exponential function, so it is bigger (in big-0 terms) than any of the others not yet considered. Next, note that J1og 2 n < log 2 n for large n, so taking 2 to the power of these two expressions shows that 2vflog 2 n is O(n). Therefore, the competition for third and fourth places from the right in our list comes down to n i.oool and n(log n) 1001 , and since all positive powers of n grow faster than any power of logn (see Exercise 58 in Section 3.2), the former wins third place. Finally, to see that (log n )2 is the slowest-growing of these functions, compare it to 2vflog 2 n by taking the base-2 log of both and noting that 2 log log n grows more slowly than yflog n. So the required list is (logn) 2 , 2V10g2 n, n(logn) 1001 , nl.OOOl, l.OOOln, nn. 27. We want the functions to play leap-frog, with first one much bigger, then the other. Something like this will do the trick: Let J(n) = n 2ln/ 2J+i. Thus, f(l) = 11 , J(2) = 23 , f(3) = 3 3 , f(4) = 4 5 , J(5) = 55 , f(6) = 6 7 , and so on. Similarly, let g(n) = n 2 rn/ 2l. Thus, g(l) = 12 , g(2) = 22 , g(3) = 34 , g(4) = 44 , g(5) = 56 , g(6) = 66 , and so on. Then for even n we have J(n)/g(n) = n, and for odd n we have g(n)/J(n) = n. Because both ratios are unbounded, neither function is big- 0 of the other. 29. a) We loop through all pairs (i, j) with i < j and check whether a,+ a1 all values of k). = ak for some k (by looping through procedure brute(a 1 , a2, ... , an : integers) for i := 1 to n - 1 for j := i + 1 to n fork:= 1 ton if a,+ a1 = ak then return true else return false b) Because of the loop within a loop within a loop, clearly the time complexity is O(n 3). 31. There are six possible matchings. We need to determine which ones are stable. The matching [(m 1, wi), ( m 2, w 2), (m 3, w3)] is not stable, because m 3 and w 2 prefer each other over their current mate. The matching [(m 1, w 1), (m 2, w3), (m 3, w 2)] is stable; although m 1 would prefer W3, she ranks him lowest, and men m2 and m 3 got their first picks. The matching [(m 1, w 2), (m 2, w1), (m 3, w3)] is stable; although m 1 would prefer w 1 or w3 , they both rank him lowest, and m 2 and m 3 will not break their respective matches because their potential girlfriends got their first choices. The matching [(m 1,w 2),(m 2,w 3),(m3,w 1)] is not stable, because m 3 and w 3 prefer each other over their current mate. The matching [(m 1, w3), (m 2, w 1), (m 3, w2)] is not stable, because m 2 and w3 will run off together. Finally, [(m 1,w 3),(m2,w 2),(m3,w 1)] is not stable, again because m 3 and w3 will run off together. To summarize, the stable matchings are [(m 1, w1). (m2, w3), (m 3, w 2 )] and [(m 1, w 2), (m 2, w1), (m 3, w3)]. Reading off this list, we see that the valid partners are as follows: for m 1 : w1 and w 2 ; for m 2 : w1 and w3 ; for m3: w2 and W3; for w1 : m1 and m2; for w2: m1 and m3; and for w3 : m2 and m3 . Supplementary Exercises 111 33. We just take the definition of male optimal and female pessimal and interchange the sexes. Thus, a matching in which each woman is assigned her valid partner ranking highest on her preference list is called female optimal, and a matching in which each man is assigned his valid partner ranking lowest on his preference list is called male pessimal. 35. a) We just rewrite the preamble to Exercise 60 in Section 3.1 with the appropriate modifications: Suppose we have s men m 1 , m 2 , ... , ms and t women w 1 , w 2 , ... , Wt. We wish to match each person with a person of the opposite gender, to the extent possible (namely, min(s, t) marriages). Furthermore suppose that each person ranks, in order of preference, with no ties, the people of the opposite gender. We say that a matching of people of opposite genders to form couples is stable if we cannot find a man m and a woman w who are not assigned to each other such that m prefers w over his assigned partner (or lack of a partner) and w prefers m to her assigned partner (or lack of a partner). (We assume that each person prefers any mate to being unmatched.) b) The simplest way to do this is to create Js - tJ fictitious people (men or women, whichever is in shorter supply) so that the number of men and the number of women become the same, and to put these fictitious people at the bottom of the preference lists of the people of opposite gender. The preference lists for the fictitious people can be specified arbitrarily. We then just run the algorithm as before. c) Because being unmatched is least desirable, it follows immediately from the proof that the original algorithm produces a stable matching (Exercise 63 in Section 3.1) that the modified algorithm produces a stable matching. 37. If we schedule the jobs in the order shown, then Job 3 will finish at time 20, Job 1 will finish at time 45, Job 4 will finish at time 50, Job 2 will finish at time 65, and Job 5 will finish at time 75. Comparing these to the deadlines, we see that only Job 2 is late, and it is late by 5 minutes (we'll call the time units minutes for convenience). A similar calculation for the other order shows that Job 1 is 10 minutes late, and Job 2 is 15 minutes late, so the maximum lateness is 15. 39. Consider the first situation in Exercise 37. We saw there that it is possible to achieve a maximum lateness of 5. If we schedule the jobs in order of increasing time required, then Job 1 will be scheduled last and finish at time 75. This will give it a lateness of 25, which gives a maximum lateness worse than the previous schedule. (Using the algorithm from Exercise 40 gives a maximum lateness of only 5.) 41. a) We want to maximize the mass of the contents of the knapsack. So we can try each possible subset of the available items to see which ones can fit into the knapsack (i.e., have total mass not exceeding W) and thereby find a subset having the maximum mass. In detail, then, examine each of the 2n subsets S of { 1, 2, ... , n}, and for each subset compute the total mass of the corresponding items (the sum of w 1 for all j E S). Keep track of the subset giving the largest such sum that is less than or equal to W, and return that subset as the output of the algorithm. Note that this is quite inefficient, because the number of subsets to examine is exponential. In fact, there is no known efficient algorithm for solving this problem. b) Essentially we find the solution here by inspection. Among the 32 subsets of items we try (from the empty set to the set of all five items), we stumble upon the subset consisting of the food pack and the portable stove, which has total mass equal to the capacity, 18. 43. a) The makespan is always at least as large as the load on the processor assigned to do the lengthiest job, which must obviously be at least max1 = 1 , 2 ,... ,n t1 . Therefore the minimum makespan L* satisfies this inequality. b) The total amount of time the processors need to spend working on the jobs (the total load) is 2:7= 1 t 1 . Therefore the average load per processor is ~ :L;=l t1 . The maximum load cannot be any smaller than the average, so the makespan is always at least this large. It follows that the minimum makespan L * is at least this large, as we were asked to prove. 112 Chapter 3 Algorithms 45. The algorithm will assign job 1 to processor 1 (one of the processors with smallest load at that point, namely 0), assign job 2 to processor 2 (for the same reason), and assign job 3 to processor 3. The loads are 3, 5, and 4 at this point. Then job 4 gets assigned to processor 1 because it has the lightest load; the loads are now 10, 5, 4. Finally, job 5 gets assigned to processor 3, giving it load 12, so the makespan is 12. Notice that we can do better by assigning job 1 and job 4 to processor 1 (load 10), job 2 and job 3 to processor 2 (load 9), and job 5 to processor 3 (load 8), for a makespan of 10. Notice, too, that this latter solution is best possible, because to achieve a makespan of 9, all three processors would have to have a load of 9, and this clearly cannot be achieved. WRITING PROJECTS FOR CHAPTER 3 Books and articles indicated by bracketed symbols below are listed near the end of this manual. You should also read the general comments and advice you will find there about researching and writing these essays. 1. Algorithms are as much a subject of computer science as they are a subject of mathematics. Thus sources on the history of computer science (or perhaps even verbose introductory programming or comprehensive computer science textbooks) might be a good place to look. See also [Ha2]. 2. The original is [Ba2]. Good history of mathematics books would be a place to follow up. 3. See [Mel], or do a Web search. 4. Knuth's volume 3 [Kn] is the bible for sorting algorithms. 5. Look up Moore's law. 6. A modern book on algorithm design, such as [CoLe] is the obvious best source. 7. The Association for Computing Machinery (ACM) is the organization that bestows this prestigious award. 8. This is a vast and extremely important subject in computer science today. One basic book on the subject is [Gi]; see also an essay in [De2]. 9. See the comments for Writing Project 8, above. One basic algorithm to think about doing in parallel is sorting. Imagine a group of school-children asked to arrange themselves in a row by height, and any child can determine whether another child is shorter or taller than him/herself. 10. Many websites discuss NP-complete problems, including www.claymath.org/millennium/P _vs_NP, which discusses the $1,000,000 prize the Clay Institute has offered for finding an efficient algorithm for such problems or showing that none exists. The classic book reference is [GaJo]. 11. See [GaJo] or a website about NP-complete problems. Section 4.1 Divisibility and Modular Arithmetic 113 CHAPTER4 Number Theory and Cryptography SECTION 4.1 Divisibility and Modular Arithmetic Number theory is playing an increasingly important role in computer science. This section and these exercises just scratch the surface of what is relevant. Many of these exercises are simply a matter of applying definitions. It is sometimes hard for a beginning student to remember that in order to prove something about a concept (such as modular arithmetic), it is usually necessary to invoke the definition! Exercises 34-44 hint at the rich structure that modular arithmetic has (sometimes resembling real number arithmetic more than integer arithmetic). In many contexts in mathematics and computer science, modular arithmetic is more relevant and convenient than ordinary integer arithmetic. 1. a) yes, since 68 = 17 · 4 c) yes, since 357 = 17 · 21 b) no, remainder= 16 d) no, remainder= 15 3. If a I b, then we know that b = at for some integer t. Therefore be = a( tc), so by definition a I be. 5. The given conditions imply that there are integers s and t such that a = bs and b = at. Combining these, we obtain a = ats; since a =/=- 0, we conclude that st = 1. Now the only way for this to happen is for s = t = 1 or s = t = -1. Therefore either a= b or a= -b. 7. The given condition means that be= (ac)t for some integer t. Since c =/=- 0, we can divide both sides by c to obtain b = at. This is the definition of a Ib, as desired. 9. In each case we need to find (the unique integers) q and r such that a= dq + r and 0:::; r d are the given integers. In each case q = La/ dJ. < d, where a and b) -111 = 11 · ( -11) + 10, so q = -11 and r = 10 c) 789=23·34+7,so q=34 and r=7 d) 1001=13·77+0,so q=77 and r=O e) 0 = 19 · 0 + 0 , so q = 0 and r = 0 f) 3 = 5 · 0 + 3, so q = 0 and r = 3 g) -1 = 3 · (-1) + 2, so q = -1 and r = 2 h) 4 = 1 · 4 + 0, so q = 4 and r = 0 a) 19 = 7 · 2 + 5, so q = 2 and r = 5 11. We are doing arithmetic modulo 12 for this exercise. a) Because 11+80 mod 12 = 7, the clock reads 7:00. b) Because 12 - 40 mod 12 = -28 mod 12 = -28 + 36 mod 12 = 8, the clock reads 8:00. c) Because 6 + 100 mod 12 = 10, the clock reads 10:00. 13. In each case we merely have to compute the expression on the right mod 13. This means dividing it by 13 and taking the (nonnegative) remainder. a) 9 · 4 mod 13 = 36 mod 13 = 10 b) 11·9 mod 13 = 99 mod 13 = 8 c) 4 + 9 mod 13 = 13 mod 13 = 0 d) 2 · 4 + 3 · 9 mod 13 = 35 mod 13 2 2 e) 4 + 9 mod 13 = 97 mod 13 = 6 f) 4 3 - 93 mod 13 = -665 mod 13 = 11 (because -665 = -52 · 13 + 11) =9 Chapter 4 114 Number Theory and Cryptography 15. The given condition, that a mod m = b mod m, means that a and b have the same remainder when divided by m. In symbols, a = qi m + r and b = q2m + r for some integers qi , q2, and r. Subtracting these two equations gives us a - b = (qi - q2)m, which says that m divides (is a factor of) a - b. This is precisely the definition of a= b (mod m). 17. The quotient n/k lies between two consecutive integers, say b-1 and b, possibly equal to b. In symbols, there exists a positive integer b such that b - 1 < n/k::; b. In particular, fn/kl = b. Also, since n/k > b- 1, we have n > k(b-1), and so (since everything is an integer) n-1 2: k(b-1). This means that (n -1)/k 2: b-1, so L(n-1)/kj 2'.b-1. Ontheotherhand, L(n-1)/kj :S(n-1)/k fm/2l Note that if m is even, then we can, alternatively, take f(m/2) = -m/2. 21. For these problems, we need to perform the division (as in Exercise 9) and report the remainder. a) 13 = 3 · 4 + 1, so 13 mod 3 = 1 b) -97 = 11 · ( -9) + 2, so -97 mod 11 = 2 c) 155=19·8+3,so 155mod19=3 d) -221=23·(-10)+9,so -221mod23=9 23. Recall that a div m and a mod m are the integer quotient and remainder when a is divided by m. a) Because 228 = 1 · 119 + 109, we have 228 div 119 = 1 and 228 mod 119 = 109. b) Because 9009 = 40 · 223 + 89, we have 9009 div 223 = 40 and 9009 mod 223 = 89. c) Because -10101 = -31 · 333 + 222, we have -10101 div 333 = -31 and -10101 mod 333 = 222. (Note that 10101 -;- 333 is 30 ~~~, so without the negative dividend we would get a different absolute quotient and different remainder. But we have to round the negative quotient here, -30 ~~~ , down to -31 in order for the remainder to be nonnegative.) d) Because - 765432 = - 21 · 38271 + 38259, we have - 765432 div 38271 = - 21 and - 765432 mod 38271 = 38259. 25. a) Because -15 already satisfies the inequality, the answer is -15. b) Because 24 is too large to satisfy the inequality, we subtract 31 and obtain the answer is - 7. c) Because 99 is too smaU to satisfy the inequality, we add 41 and obtain the answer is 140. 27. We just need to start at -1 and repeatedly subtract or add 25 until we exceed the desired range. Thus the negative values we seek are -1, -26, -51, and -76, and the positive values are 24, 49, 74, and 99. 29. For these problems, we need to divide by 17 and see whether the remainder equals 5. Remember that the quotient can be negative, but the remainder r must satisfy 0 ::; r < 17. a) 80 = 17 · 4 + 12 , so 80 "I- 5 (mod 17) c) -29 = 17 · (-2) + 5, so -29 b) 103 = 17 · 6 + 1, so 103 = 5 (mod 17) "I- 5 (mod 17) d) -122 = 17·(-8)+14, so -122-=/=- 5 (mod 17) Section 4.1 Divisibility and Modular Arithmetic 115 31. = 13, so the answer is 13. 457 · 182 = 20 · 21 = 420 = 6. a) Working modulo 23, we have -133 b) Working modulo 23, we have + 261 = 128 = (3 2 mod 32) 3 mod 15 = 93 mod 15 = 729 mod 15 = 9 b) (34 mod 17) 2 mod 11 = (81 mod 17) 2 mod 11 = 13 2 mod 11 = 22 mod 11 = 4 c) (19 3 mod 23) 2 mod 31 = ((-4) 3 mod 23) 2 mod 31 = (-64 mod 23) 2 mod 31 = 52 mod 31 = 25 d) (89 3 mod 79) 4 mod 26 = (10 3 mod 79) 4 mod 26 = (1000 mod 79) 4 mod 26 = 52 4 mod 26 04 mod 26 = 0 33. a) (99 2 mod 32) 3 mod 15 35. The hypothesis a= b (mod m) means that m l(a - b). Since we are given that n Im, Theorem l(iii) implies that n l(a - b). Therefore a= b (mod n), as desired. 37. a) To show that this conditional statement does not necessarily hold, we need to find an example in which ac =be (mod m), but a¢. b (mod m). Let m = 4 and c = 2 (what is important in constructing this example is that m and c have a nontrivial common factor). Let a = 0 and b = 2 . Then ac = 0 and be = 4, so ac =be (mod 4), but 0 ¢. 2 (mod 4). b) To show that this conditional statement does not necessarily hold, we need to find an example in which a= b (mod m) and c d (mod m), but ac ¢. bd (mod m). If we try a few randomly chosen positive integers, we will soon find one. Let m = 5, a= 3, b = 3, c = 1, and d = 6. Then ac = 3 and bd = 729 4 (mod 5), so 3 1 ¢. 36 (mod 5), even though 3 3 (mod 5) and 1 6 (mod 5). = = = = 39. By Exercise 38 the sum of two squares must be either 0 + 0, 0 + 1, or 1 + 1, modulo 4. Therefore the sum cannot be 3 modulo 4, which means that it cannot be of the form 4k + 3. 41. There are at least two ways to prove this. One way is to invoke Theorem 5 repeatedly. Since a= b (mod m), Theorem 5 implies that a· a = b · b (mod m), i.e., a 2 = b2 (mod m). Invoking Theorem 5 again, since a= b (mod m) and a 2 = b2 (mod m), we obtain a 3 = b3 (mod m). After k - 1 applications of this process, we obtain ak bk (mod m), as desired. (This is really a proof by mathematical induction, a topic to be considered formally in Chapter 5.) = Alternately, we can argue directly, using the algebraic identity ak-bk = (a-b)(ak-l +ak- 2 b+· · ·+abk- 2 + bk-l). Specifically, the hypothesis that a= b (mod m) means that m l(a - b). Therefore by Theorem l(ii), m divides the right-hand side of this identity, so m l(ak - bk). This means precisely that ak =bk (mod m). 43. The closure property states that a ·m b E Zm whenever a, b E Zm. Recall that Zm = {O, 1, 2, ... , m - 1} and that a ·m b is defined to be (a · b) mod m. But this last expression will by definition be an integer in the desired range. To see that multiplication is associative, we must show that (a ·m b) ·m c =a ·m (b ·m c). This is equivalent to ((a· b mod m) · c) mod m =(a· (b · c mod m)) mod m. This is true, because both sides equal (a· b · c) mod m (multiplication of integers is associative). Similarly, multiplication in Zm is commutative because multiplication in Z is commutative, and 1 is the multiplicative identity for Zm because 1 is the multiplicative identity for Z. 45. We will use + and · for these operations to save space and improve the appearance of the table. Notice that we really can get by with a little more than half of this table if we observe that these operations are commutative; then we would need to list a + b and a · b only for a ::;: b. Chapter 4 116 Number Theory and Cryptography 0+0=0 0+1=1 0+2=2 0+3=3 0+4=4 1+0=1 1+1=2 1+2=3 1+3=4 1+4=0 2+0=2 2+1=3 2+2=4 2+3=0 2+4=1 3+0=3 3+1=4 3+2=0 3+3=1 3+4=2 4+0=4 4+1=0 4+2=1 4+3=2 4+4=3 0 ·O = 0 0·1=0 0. 2 = 0 O· 3 = 0 0. 4 = 0 1·0 = 0 1·1=1 1·2 = 2 1·3 = 3 1·4 = 4 2. 0 = 0 2 · 1=2 2. 2 = 4 2. 3 = 1 2. 4 = 3 3 ·O = 0 3·1=3 3. 2 = 1 3. 3 = 4 3. 4 = 2 4. 0 = 0 4·1=4 4. 2 = 3 4. 3 = 2 4. 4 = 1 47. If d = 1, then f(a) =a and g(a) = 0. Therefore f is clearly one-to-one and onto, and g is neither. If d > 1, then f is still onto, because f (db) = b for any desired b E Z, but it is clearly not one-to-one, because f (0) = f (1) = 0. Furthermore, g is clearly not onto, because its range is just {O, 1, 2, ... , d - 1}, and it is not one-to-one because g(O) = g( d) = 0. SECTION 4.2 Integer Representations and Algorithms In addition to having some routine calculation exercises, this exercise set introduces other forms of representing integers. These are balanced ternary expansion, Cantor expansion, binary coded decimal (or BCD) representation, and one's and two's complement representations. Each has practical and/or theoretical importance in mathematics or computer science. If all else fails, one can carry out an algorithm by "playing computer" and mechanically fallowing the pseudocode step by step. 1. We divide repeatedly by 2, noting the remainders. The remainders are then arranged from right to left to obtain the binary representation of the given number. a) We begin by dividing 231 by 2, obtaining a quotient of 115 and a remainder of 1. Therefore a 0 = 1. Next 115/2 = 57, remainder 1. Therefore a 1 = 1. Similarly 57 /2 = 28, remainder 1. Therefore a 2 = 1. Then 28/2 = 14, remainder 0, so a 3 = 0. Similarly a 4 = 0, after we divide 14 by 2, obtaining 7 with remainder 0. Three more divisions yield quotients of 3, 1, and 0, with remainders of 1, 1, and 1, respectively, so a 5 = a 6 = a 7 = 1. Putting all this together, we see that the binary representation is (a 7a 6a 5a4a 3a 2a 1a 0 )2 = (1110 0111)2. As a check we can compute that 2° + 2 1 + 22 + 25 + 26 + 27 = 231. b) Following the same procedure as in part (a), we obtain successive remainders 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1. Therefore 4532 = (1 0001 1011 0100)2. c) By the same method we obtain 97644 = (1 0111 1101 0110 1100)2. 3. a) (1 1111)2 = 24 + 23 + 22 + 2 1 + 2° = 16 + 8 + 4 + 2 + 1 that (1 1111) 2 = (10 0000)2 - 1 = 25 - 1 = 31. b) (10 0000 0001)2 = 29 + 2° = 31. An easier way to get the answer is to note = 513 c) (1 0101 0101)2 = 2 + 2 + 24 + 22 + 2° = 256 + 64 + 16 + 4 + 1 = 341 8 6 d) (110 1001 0001 0000)2 = 2 14 + 2 13 + 2 11 + 28 + 24 = 16384 + 8192 + 2048 + 256 + 16 = 26896 Section 4.2 Integer Representations and Algorithms 117 5. In each case we follow the idea given in Example 7, converting each octal digit to its binary equivalent (including leading O's where necessary). Note that by convention we then group the binary digits into groups of fours, starting at the right. a) Since (5) 8 = (101)2, (7) 8 = (lll)z, and (2) 8 = (010)2, we have (572) 8 = (1 0111 1010)2. b) We concatenate 1, 110, 000, and 100 to obtain (11 1000 0100)2. c) (1 0001 0011)2 d) (101 0000 1111)2 7. Following Example 7, we simply write the binary equivalents of each digit: (A)16 (C)16 = (1100)2, (D)16 = (1101)2, (E)16 = (1110)2, and (F) 16 of four binary digits is just for readability by humans. = (1010)2, (B) 16 = (1011)2, = (1111)2. Note that the blocking by groups a) (80E)16 = (1000 0000 1110)2 b) (135AB)16 = (0001 0011 0101 1010 1011)2 c) (ABBA) 16 = (1010 1011 1011 1010)2 d) (DEFACED) 16 = (1101 1110 1111 1010 1100 1110 1101) 2 9. Following Example 7, we simply write the binary equivalents of each digit. Since (A) 16 = (1010)2, (B) 16 = (1011)2, (C)16 = (1100)2, (D)16 = (1101)2, (E)16 = (1110)2, and (F)15 = (1111)2, we see that (ABCDEF) 16 = (101010111100110111101111)2. Following the convention shown in Exercise 3 of grouping binary digits by fours, we can write this in a more readable form as 1010 1011 1100 1101 1110 1111. 11. Following Example 7, we simply write the hexadecimal equivalents of each group of four binary digits. Thus we have (1011 0111 1011)2 = (B7B)16. 13. We adopt a notation that will help with the explanation. Adding up to three leading O's if necessary, write the binary expansion as ( ... b23b22b21b20b13b12bnb10bo3bo2bo1booh. The value of this numeral is boo+ 2bo1 + 4b02 + 8b03 + 24 b10 + 25 bn + 26 b12 + 27 b13 + 28 b20 + 29 b21 + 210 b22 + 2nb23 + · · ·, which we can rewrite as boo+ 2bo1+4bo2 + 8bo3 + (b10 + 2b11+4b12 + 8b13) · 24 + (b20 + 2b21+4b22 + 8b23) · 28 + · · ·. Now (b,3b,2b,1b,oh translates into the hexadecimal digit h, . So our number is ho+ h 1 · 24 + h 2 · 28 + · · · = ho + h 1 · 16 + h2 · 16 2 + · · · , which is the hexadecimal expansion ( ... h1h 1 ho)l6. 15. We adopt a notation that will help with the explanation. Adding up to two leading O's if necessary, write the binary expansion as ( ... b22b21b20b12b11b10bo2bo1booh. The value of this numeral is b00 + 2bo1 + 4bo2 + 23b10 + 24 bn + 25 b12 + 26 b20 + 27 b21 + 28 b22 + · · ·, which we can rewrite as boo+ 2bo 1 + 4bo2 + (b10 + 2bn + 4b12) · 23 + (b20 + 2b21 + 4b22) · 26 + · · ·. Now (b, 2biib,o)z translates into the octal digit h,. So our number is ho+ h1 · 23 + h2 · 26 + · · · = ho+ h 1 · 8 + h2 · 82 + · · ·, which is the octal expansion (... h 1h 1 h 0 ) 8 . 17. In each case we follow the method of Example 7, blocking by threes instead of fours. We replace each octal digit of the given numeral by its 3-digit binary equivalent and string the digits together. The first digit is (7)s = (111)2, the next is (3)s = (011)2, and so on, so we obtain (1 1101 1100 1010 1101 0001)2. For the other direction, we split the given binary numeral into blocks of three digits, adding initial O's to fill it out: 001 010 111 011. Then we replace each block by its octal equivalent, obtaining the answer (1273) 8 . 19. Since we have procedures for converting both octal and hexadecimal to and from binary (Example 7), to convert from octal to hexadecimal, we first convert from octal to binary and then convert from binary to hexadecimal. 21. We can just add and multiply using the grade-school algorithms, working with these very simple addition and multiplication tables: 0 + 0 = 0, 0 + 1 = 1 + 0 = 1, 1 + 1 = 10, which means that we "carry" the 1 into the Chapter 4 118 Number Theory and Cryptography next column; 0 · 0 = 0 · 1 = 1 · 0 = 0, 1 · 1 = 1. See Examples 8 and 10. Note that we can check our work by converting everything to decimal numerals (the check is shown in parentheses below). For convenience, we leave off the ''2" subscripts throughout. a) 100 0111+1110111=1011 1110 (decimal: 71+119 = 190) 100 0111·1110111=10 0001 0000 0001 (decimal: 71·119 = 8449) b) 11101111+10111101=110101100 (decimal: 239+189=428) 1110llll·10111101=101100000111 0011 (decimal: 239·189 = 45,171) c) 10 10101010+111110000=100 1001 1010 (decimal: 682 + 496 = 1178) 10 1010 1010 · 1 11110000=10100101001 0110 0000 (decimal: 682 · 496 = 338,272) d) 10 0000 0001+11 1111 1111=110 0000 0000 (decimal: 513 + 1023 = 1536) 10 0000 0001·1111111111=1000 0000 000111111111 (decimal: 513 · 1023 = 524,799) 23. We can just add and multiply using the grade-school algorithms (working column by column starting at the right), using the addition and multiplication tables in base eight (for example, 5 + 6 = 13 and 5 · 6 = 36). When a digit-by-digit answer is too large to fit (i.e., greater than 7). we '"carry" into the next column. Note that we can check our work by converting everything to decimal numerals (the check is shown in parentheses below). For convenience. we leave off the "8'' subscripts throughout. a) 763 + 147 = 1132 (decimal: 499 + 103 = 602) 763 · 147 = 144,305 (decimal: 499 · 103 = 51,397) b) 6001 + 272 = 6273 (decimal: 3073 + 186 = 3259) 6001 · 272 = 2,134,272 (decimal: 3073 · 186 = 571,578) c) 1111+777 = 2110 (decimal: 585 + 511=1096) 1111·777 = 1,107,667 (decimal: 585 · 511=298,935) d) 54321+3456 = 57,777 (decimal: 22,737 + 1838 = 24,575) 54321 · 3456 = 237,326.216 (decimal: 22,737 · 1838 = 41,790,606) 25. In effect, this algorithm computes 7 mod 645, 72 mod 645, 74 mod 645, 78 mod 645, 7 16 mod 645, ... , and then multiplies (modulo 645) the required values. Since 644 = (1010000100)2, we need to multiply together 74 mod 645, 7128 mod 645, and 7512 mod 645, reducing modulo 645 at each step. We compute by repeatedly squaring: 72 mod 645 = 49, 74 mod 645 = 49 2 mod 645 = 2401 mod 645 = 466, 78 mod 645 = 466 2 mod 645 = 217156 mod 645 = 436, 716 mod 645 = 436 2 mod 645 = 190096 mod 645 = 466. At this point we see a pattern with period 2, so we have 7 32 mod 645 = 436, 764 mod 645 = 466, 7128 mod 645 = 436, 7256 mod 645 = 466, and 7512 mod 645 = 436. Thus our final answer will be the product of 466, 436, and 436, reduced modulo 645. We compute these one at a time: 466 · 436 mod 645 = 203176 mod 645 = 1, and 1 · 436 mod 645 = 436. So 7644 mod 645 = 436. A computer algebra system will verify this; use the command "7 &- 644 mod 645;" in Maple, for example. The ampersand here tells Maple to use modular exponentiation, rather than first computing the integer 7644 , which has over 500 digits, although it could certainly handle this if asked. The point is that modular exponentiation is much faster and avoids having to deal with such large numbers. 27. In effect, this algorithm computes 3 mod 99, 32 mod 99, 34 mod 99, 38 mod 99, 3 16 mod 99, ... , and then multiplies (modulo 99) the required values. Since 2003 = (11111010011)2, we need to multiply together 3 mod 99, 32 mod 99, 316 mod 99, 364 mod 99, 3128 mod 99, 3256 mod 99, 3512 mod 99, and 3 1024 mod 99, reducing modulo 99 at each step. We compute by repeatedly squaring: 32 mod 99 = 9, 34 mod 99 = 81, 38 mod 99 = 81 2 mod 99 = 6561 mod 99 = 27, 316 mod 99 = 27 2 mod 99 = 729 mod 99 = 36, 332 mod 99 = 36 2 mod 99 = 1296 mod 99 = 9, and then the pattern repeats, so 364 mod 99 = 81, 3128 mod 99 = 27, 3256 mod 99 = 36, 3512 mod 99 = 9, and 31024 mod 99 = 81. Thus Section 4.2 Integer Representations and Algorithms 119 our final answer will be the product of 3, 9, 36, 81, 27, 36, 9, and 81. We compute these one at a time modulo 99: 3 · 9 is 27, 27 · 36 is 81, 81 · 81 is 27, 27 · 27 is 36, 36 · 36 is 9, 9 · 9 is 81, and finally 81 · 81 is 27. So 32003 mod 99 = 27. 29. The binary expansion of an integer represents the integer as a sum of distinct powers of 2. For example, since 21 = (1 0101)2, we have 21 = 24 + 22 + 2°. Since binary expansions are unique, each integer can be so represented uniquely. 31. Let the decimal expansion of the integer a be given by a = (an-lan- 2 ... a 1 a 0 )i 0 . Thus a = 10n- 1an-l + 10n- 2an-2 + · · · + l0a1 + ao. Since 10 1 (mod 3), we have a an-I + an-2 + · · · + ai + ao (mod 3). Therefore a= 0 (mod 3) if and only if the sum of the digits is congruent to 0 (mod 3). Since being divisible by 3 is the same as being congruent to 0 (mod 3), we have proved that a positive integer is divisible by 3 if and only if the sum of its decimal digits is divisible by 3. = = 33. Let the binary expansion of the positive integer a be given by a = (an_ 1an_ 2 ... a 1 a 0 )2. Thus a = a 0 + 2a1 + 22 a2 + · · · + 2n- 1an-l. Since 22 1 (mod 3), we see that 2k 1 (mod 3) when k is even, and 2k = 2 = -1 (mod 3) when k is odd. Therefore we have a= a0 - a 1 + a 2 - a 3 +···±an-I (mod 3). Thus a = 0 (mod 3) if and only if the sum of the binary digits in the even-numbered positions minus the sum of the binary digits in the odd-numbered positions is congruent to 0 modulo 3. Since being divisible by 3 is the same as being congruent to 0 (mod 3), our proof is complete. = = 35. a) Since the leading bit is a 1, this represents a negative number. The binary expansion of the absolute value of this number is the complement of the rest of the expansion, namely the complement of 1001, or 0110. Since (0110)2 = 6, the answer is -6. b) Since the leading bit is a 0, this represents a positive number, namely the number whose binary expansion is the rest of this string, 1101. Since (1101)2=13, the answer is 13. c) The answer is the negative of the complement of 0001, namely -(1110) 2 = -14. d) -(0000)2 = O; note that 0 has two different representations, 0000 and 1111 37. We must assume that the sum actually represents a number in the appropriate range. Assume that n bits are being used, so that numbers strictly between -2n-l and 2n-l can be represented. The answer is almost, but not quite, that to obtain the one's complement representation of the sum of two numbers, we simply add the two strings representing these numbers using Algorithm 3. Instead, after performing this operation, there may be a carry out of the left-most column; in such a case, we then add 1 more to the answer. For example, suppose that n = 4; then numbers from -7 to 7 can be represented. To add -5 and 3, we add 1010 and 0011, obtaining 1101; there was no carry out of the left-most column. Since 1101 is the one's complement representation of -2, we have the correct answer. On the other hand, to add -4 and -3, we add 1011 and 1100, obtaining 1 0111. The 1 that was carried out of the left-most column is instead added to 0111, yielding 1000, which is the one's complement representation of - 7. A proof that this method works entails considering the various cases determined by the signs and magnitudes of the addends. 2 39. If m is positive (or 0), then the leading bit (an-I) is 0, so the formula reads simply m = 2=~:0 a,2', which is clearly correct, since this is the binary expansion of m. (See Section 2.4 for the meaning of summation notation. This symbolism is a shorthand way of writing a0 + 2a 1 + 4a 2 + · · · + 2n- 2 an_ 2 .) Now suppose that m is negative. The one's complement expansion for m has its leading bit equal to 1. By the definition of one's complement, we can think of obtaining the remaining n - 1 bits by subtracting -m, written in binary, from 111 ... 1 (with n - 1 1 's), since subtracting a bit from 1 is the same thing as complementing it. Equivalently, if we view the bit string (an-2an-l ... a0 ) as a binary number, then it represents (2n-l - 1) - (-m). In Chapter 4 120 symbols, this says that (2n-l - Number Theory and Cryptography 1) - (-m) = '2:~:02 ai2'. Solving for m gives us the equation we are trying to prove (since an-1 = 1 ) . 41. Following the definition, if the first bit is a 0, then we just evaluate the binary expansion. If the first bit is a 1, then we find what number x is represented by the remaining four bits in binary; the answer is then -(2 4 -x). a) Since the first bit is a 1. and the remaining bits represent the number 9, this string represents the number -(2 4 - 9) = -7. b) Since the first bit is a 0 and this is just the binary expansion of 13, the answer is 13. c) Since the first bit is a 1. and the remaining bits represent the number 1, this string represents the number -(2 4 -1) = -15. d) Since the first bit is a 1, and the remaining bits represent the number 15, this string represents the number -(2 4 -15) = -1. Note that 10000 would represent -(2 4 - 0) = -16, so in fact we can represent one extra negative number than positive number with this notation. 43. The nice thing about two's complement arithmetic is that we can just work as if it were all in base 2, since -x (where x is positive) is represented by 2" - x; in other words, modulo 2", negative numbers represent themselves. However, if overflow occurs, then we must recognize an error. Let us look at some examples, where n = 5 (i.e., we use five bits to represent numbers between -15 and 15 ). To add 5 + 7, we write 00101 + 00111 = 01100 in base 2, which gives us the correct answer, 12. However, if we try to add 13 + 7 we obtain 01101+00111 = 10100, which represents -12, rather than 20, so we report an overflow error. (Of course these two numbers are congruent modulo 32.) Similarly, for 5 + (-7), we write 00101+11001=11110 in base 2, and 11110 is the two's complement representation of -2, the right answer. For (-5) + (-7), we write 11011+11001=110100 in base 2; if we ignore the extra 1 in the left-most column (which doesn't exist), then this is the two's complement representation of -12, again the right answer. To summarize, to obtain the two's complement representation of the sum of two integers given in two's complement representation, add them as if they were binary integers, and ignore any carry out of the left-most column. However, if the left-most digits of the two addends agree and the left-most digit of the answer is different from their common value, then an overflow has occurred, and the answer is not valid. 45. If m is positive (or 0), then the leading bit ( an-l) is 0, so the formula reads simply m = 2=~:0 ai2i, which is clearly correct, since this is the binary expansion of m. (See Section 2.4 for the meaning of summation notation. This symbolism is a shorthand way of writing a 0 + 2a 1 + 4a 2 + · · · + 2n- 2 an_ 2 .) Now suppose that m is negative. The two's complement expansion for m has its leading bit equal to 1. By the definition of two's complement, the remaining n - 1 bits are the binary expansion of 2n-l - (-m). In symbols, this says 2 that 2n-l - ( -m) = 2=~:0 a, 2' . Solving for m gives us the equation we are trying to prove (since an-l = 1). 2 47. Clearly we need 4n digits, four for each digit of the decimal representation. 49. To find the Cantor expansion, we will work from left to right. Thus the first step will be to find the largest number n whose factorial is still less than or equal to the given positive integer x. Then we determine the digits in the expansion, starting with an and ending with a 1 . Section 4.2 Integer Representations and Algorithms 121 procedure Cantor(x: positive integer) n := 1; factorial := 1 while (n + 1) ·factorial ::::; x n := n + 1 factorial := factorial · n {at this point we know that there are n digits in the expansion} y := x {this is just so we do not destroy the original input} while n > 0 an:= LY/factorialJ y := y - an . factorial factorial := factorial/n n := n -1 {we are done: x = ann! + an-i(n -1)! + · · · + a22! +ail!} 51. Note that n = 5. Initially the carry is c = 0, and we start the for loop with j = 0. Since a0 = 1 and b0 = 0, we set d to be L(l + 0 + 0)/2J = O; then so= 1+0 + 0- 2 · 0, which equals 1, and finally c = 0. At the end of the first pass, then, the right-most digit of the answer has been determined (it's a 1), and there is a carry of 0 into the next column. Now j = 1, and we compute d to be L(ai +bi+ c)/2J = L(l + 1+0)/2J = l; whereupon si becomes 1 + 1 + 0 - 2 · 1 = 0, and c is set to 1. Thus far we have determined that the last two bits of the answer are 01 (from left to right), and there is a carry of 1 into the next column. The next three passes through the loop are similar. As a result of the pass when j = 2 we set d = 1, s2 = 0, and then c = 1. When j = 3, we obtain d = 1, s 3 = 0, and then c = 1. Finally, when j = 4, we obtain d = 1, S4 = 1, and then c = 1. At this point the loop is terminated, and when we execute the final step, s 5 = 1. Thus the answer is 11 0001. 53. We will assume that the answer is not negative, since otherwise we would need something like the one's complement representation. The algorithm is similar to the algorithm for addition, except that we need to borrow instead of carry. Rather than trying to incorporate the two cases (borrow or no borrow) into one, as was done in the algorithm for addition, we will use an if. .. then statement to treat the cases separately. The notation is the usual one: a= (an-i ... aiao)z and b = (bn-i ... bibo)z procedure subtract( a, b: nonnegative integers) borrow:= 0 for j := 0 to n - 1 if a1 - borrow 2:: b1 then Sj := a1 - borrow - bj borrow:= 0 else Sj := a1 + 2 - borrow - b1 borrow:= 1 {assuming a 2:: b, we have a - b = (sn-iSn-2 ... siso)z} 55. To determine which of two integers (we assume they are nonnegative), given in binary as a = (an-i ... aiao)z and b = (bn-i ... bibo)z, is larger, we need to compare digits from the most significant end ( i = n - 1) to the least ( i = 0), stopping if and when we find a difference. For variety here we record the answer as a character string; in most applications it would probably be better to set compare to one of three code values (such as -1, 1, and 0) to indicate which of the three possibilities held. 122 Chapter 4 Number Theory and Cryptography procedure compare( a, b: nonnegative integers) i := n -1 while i > 0 and a, =bi i := i - 1 if a; > b, then answer:= "a> b" else if ai < b, then answer:= "a< b" else answer:= "a= b" return answer 57. There is one division for each pass through the while loop. Also, each pass generates one digit in the base b expansion. Thus the number of divisions equals the number of digits in the base b expansion of n. This is just l logb n J + 1 (for example, numbers from 10 to 99, inclusive, have common logarithms in the interval [1,2)). Therefore exactly llogbnJ + 1 divisions are required, and this is O(logn). (We are counting only the actual division operation in the statement q := lq/bJ. If we also count the implied division in the statement ak := q mod b, then there are twice as many as we computed here. The big- 0 estimate is the same, of course.) 59. The only time-consuming part of the algorithm is the while loop, which is iterated q times. The work done inside is a subtraction of integers no bigger than a, which has log a bits. The results now follows from Example 9. SECTION 4.3 Primes and Greatest Common Divisors The prime numbers are the building blocks for the natural numbers in terms of multiplication, just as the elements (like carbon, oxygen, or uranium) are the building blocks of all matter. Just as we can put two hydrogen atoms and one oxygen atom together to form water, every composite natural number is uniquely constructed by multiplying together prime numbers. Analyzing numbers in terms of their prime factorizations allows us to solve many problems, such as finding greatest common divisors. Prime numbers have fascinated people for millennia, and many easy-to-state questions about them remain unanswered. Students interested in pursuing these topics more should definitely consider taking a course in number theory. 1. In each case we can just use trial division up to the square root of the number being tested. a) Since 21 = 3 · 7, we know that 21 is not prime. b) Since 2 ,(29, 3 ,(29, and 5 ,(29, we know that 29 is prime. We needed to check for prime divisors only up to J2§, which is less than 6. c) Since 2 ,( 71, 3 ,( 71 , 5 ,( 71, and 7 ,( 71, we know that 71 is prime. d} Since 2 ,(97, 3 ,(97, 5 ,(97, and 7 ,(97, we know that 97 is prime. = 3 · 37, we know that 111 is not prime. 143 = 11 · 13, we know that 143 is not prime. e) Since 111 f) Since 3. In each case we can use trial division, starting with the smallest prime and increasing to the next prime once we find that a given prime no longer is a divisor of what is left. A calculator comes in handy. Alternatively, one could use a factor tree. a) We note that 2 is a factor of 88, and the quotient upon division by 2 is 44. We divide by 2 again, and then again, leaving a quotient of 11. Since 11 is prime, we are done, and we have found the prime factorization: 88 = 23 · 11. b) 126 = 2 . 63 = 2 . 3 . 21 = 2 . 3 . 3 . 7 = 2 . 32 . 7 = 3 . 243 = 3 . 3 . 81 = 3 . 3 . 3 . 27 = 3 . 3 . 3 . 3 . 9 = 3 . 3 . 3 . 3 . 3 . 3 = 36 1001 = 7. 143 = 7. 11 . 13 c) 729 d} Section 4.3 Primes and Greatest Common Divisors e) 1111=ll·101 (we know that 101 is prime because we have already tried all prime factors less than 123 v'IOI) f) 909090 = 2·454545 = 2·3·151515 = 2·3·3·50505 = 2·3·3·3·16835 = 2·3·3·3·5·3367= 2·3·3·3·5·7·481 = 2 . 3 . 3 . 3 . 5 . 7 . 13 . 37 = 2 . 3 3 . 5 . 7 . 13 . 37 5. 10! = 2 · 3 · 4 · 5 · 6 · 7 · 8 · 9 · 10 = 2 · 3 · 2 2 · 5 · (2 · 3) · 7 · 23 . 32 · (2. 5) = 28 . 34 . 52 . 7 7. The input is an integer n greater than 1. We try dividing it by all integers from 2 to yn, and if we find one that leaves no remainder then we know that n is not prime. The pseudocode below accomplishes this. procedure primetester(n: integer greater than 1) isprime :=true d := 2 while isprime and d :::; yn if n mod d = 0 then isprime :=false else d := d + 1 return isprime 9. We use what we know about factoring from algebra. In particular, we know that am+ 1 = (a+ l)(am-l am- 2 + am- 3 + · · · - 1). (Notice that this works if and only if m is odd, because the final sign has to be a plus sign.) Because a and m are both greater than 1, we know that 1 < a+ 1 < am+ 1. This provides a factoring of am+ 1 into two proper factors, so am+ 1 is composite. 11. We give a proof by contradiction. Suppose that in fact log 2 3 is the rational number p / q, where p and q are integers. Since log 2 3 > 0, we can assume that p and q are positive. Translating the equation log 2 3 = p / q into its exponential equivalent, we obtain 3 = 2p/q. Raising both sides to the qth power yields 3q = 2P. Now this is a violation of the Fundamental Theorem of Arithmetic, since it gives two different prime factorizations of the same number. Hence our assumption (that log 2 3 is rational) must be wrong, and we conclude that log 2 3 is irrational. 13. This is simply an existence statement. To prove that it is true, we need only exhibit the primes. Indeed, 3, 5, and 7 satisfy the conditions. (Actually, this is the only example, and a harder problem is to prove that there are no others.) 15. The prime factors of 30 are 2, 3, and 5. Thus we are looking for positive integers less than 30 that have none of these as prime factors. Since the smallest prime number other than these is 7, and 72 is already greater than 30, in fact only primes (and the number 1) will satisfy this condition. Therefore the answer is 1, 7, 11, 13, 17, 19, 23, and 29. 17. a) Since gcd(ll, 15) = 1, gcd(ll, 19) = 1, and gcd(15, 19) = 1, these three numbers are pairwise relatively prime. b) Since gcd(15,21) = 3 > 1, these three numbers are not pairwise relatively prime. c) Since gcd(l2, 17) = 1, gcd(12, 31) = 1, gcd(12, 37) = 1, gcd(l 7, 31) = 1, gcd(l 7, 37) = 1, and gcd(31, 37) = 1, these four numbers are pairwise relatively prime. (Indeed, the last three are primes, and the prime factors of the first are 2 and 3.) d) Again, since no two of 7, 8, 9, and 11 have a common factor greater than 1, this set is pairwise relatively prime. 19. The identity shown in the hint is valid, as can be readily seen by multiplying out the right-hand side (all the terms cancel-telescope-except for 2ab and -1). We will prove the assertion by proving its contrapositive. Suppose that n is not prime. Then by definition n = ab for some integers a and b each greater than 1 . Since a > 1, 2a - 1, the first factor in the suggested identity, is greater than 1. Clearly the second factor is greater than 1. Thus 2n - 1 = 2ab - 1 is the product of two integers each greater than 1, so it is not prime. 124 Chapter 4 Number Theory and Cryptography 21. We compute (n) here by enumerating the set of positive integers less than n that are relatively prime to n. a) ¢(4) = l{l,3}1=2 b) ¢(10) = l{l,3, 7,9}1=4 c) ¢(13) = l{l, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}1 = 12 23. All the positive integers less than or equal to pk (and there are clearly pk of them) are less than pk and relatively prime to pk unless they are a multiple of p. Since the fraction l/p of them are multiples of p, we have (pk)= pk (l - 1/p) =pk - pk-1. 25. To find the greatest common divisor of two numbers whose prime factorizations are given, we just need to take the smaller exponent for each prime. a) The first number has no prime factors of 2, so the gcd has no 2's. Since the first number has seven factors of 3, but the second number has only five, the gcd has five factors of 3. Similarly the gcd has a factor of 53 . So the gcd is 35 . 53 . b) These numbers have no common prime factors, so the gcd is 1 . e) These numbers have no common prime factors, so the gcd is 1 . c) 23 17 d) 41. 43. 53 f) The gcd of any positive integer and 0 is that integer, so the answer is 1111. 27. To find the least common multiple of two numbers whose prime factorizations are given, we just need to take the larger exponent for each prime. a) The first number has no prime factors of 2 but the second number has 11 of them, so the lcm has 11 factors of 2. Since the first number has seven factors of 3 and the second number has five, the lcm has seven factors of 3. Similarly the lcm has a factor of 59 and a factor of 73 . So the lcm is 211 · 37 · 59 · 73 . b) These numbers have no common prime factors, so the lcm is their product, 29 · 37 · 55 · 73 · 11 · 13 · 17. c) 23 31 d) 41·43 · 53 e) 212 · 3 13 · 5 17 · 721 , as in part (b) f) It makes no sense to ask for a positive multiple of 0, so this question has no answer. Least common multiples are defined only for positive integers. 29. First we find the prime factorizations: 92928 = 28 · 3 · 11 2 and 123552 = 25 · 33 · 11 · 13. Therefore gcd(92928, 123552) = 25 · 3 · 11 = 1056 and lcm(92928, 123552) = 28 · 33 · 11 2 · 13 = 10872576. The requested products are (2 5 · 3 · 11) · (2 8 · 33 · 11 2 · 13) and (2 8 · 3 · 11 2 ) · (2 5 · 33 · 11 · 13), both of which are 213 . 34 . 11 3 . 13 = 11,481,440,256. 31. The important observation to make here is that the smaller of any two numbers plus the larger of the two numbers is always equal to the sum of the two numbers. Since the exponent of the prime p in gcd( a, b) is the smaller of the exponents of p in a and in b, and since the exponent of the prime p in lcm(a, b) is the larger of the exponents of p in a and in b, the exponent of p in gcd(a, b)lcm(a, b) is the sum of the smaller and the larger of these two values. Therefore by the observation, it equals the sum of the two values themselves, which is clearly equal to the exponent of p in ab. Since this is true for every prime p, we conclude that gcd(a, b)lcm(a, b) and ab have the same prime factorizations and are therefore equal. 33. a) By Lemma 1, gcd(12, 18) is the same as the gcd of the smaller of these two numbers ( 12) and the remainder when the larger ( 18) is divided by the smaller. In this case the remainder is 6, so gcd(12, 18) = gcd(12, 6). Now gcd(12, 6) is the same as the gcd of the smaller of these two numbers ( 6) and the remainder when the larger (12) is divided by the smaller, namely 0. This gives gcd(12,6) = gcd(6,0). But gcd(x,O) = x for all positive integers, so gcd(6,0) = 6. Thus the answer is 6. In brief (the form we will use for the remaining parts), gcd(12, 18) = gcd(l2,6) = gcd(6,0) = 6. b) gcd(lll,201) = gcd(lll,90) = gcd(90,21) = gcd(21,6) = gcd(6,3) = gcd(3,0) = 3 Section 4.3 125 Primes and Greatest Common Divisors c) gcd(lOOl, 1331) = gcd(lOOl, 330) = gcd(330, 11) = gcd(ll, 0) = 11 d) gcd(12345, 54321) = gcd(12345, 4941) = gcd(4941, 2463) = gcd(2463, 15) = gcd(15, 3) = gcd(3, 0) = 3 e) gcd(lOOO, 5040) = gcd(lOOO, 40) = gcd( 40, 0) = 40 f) gcd(9888, 6060) = gcd(6060, 3828) = gcd(3828, 2232) = gcd(2232, 1596) = gcd(1596, 636) = gcd(636, 324) = gcd(324, 312) = gcd(312, 12) = gcd(12, 0) = 12 35. In carrying out the Euclidean algorithm on this data, we divide successively by 55, 34, 21, 13, 8, 5, 3, 2, and 1, so nine divisions are required. 37. One can compute gcd(2a - 1, 2b - 1) using the Euclidean algorithm. Let us look at what happens when we do so. If b = 1, then the answer is just 1, which is the same as 2gcd(a,b) - 1 in this case. Otherwise, we reduce the problem to computing gcd(2b - 1, (2a - 1) mod (2b - 1)). Now from Exercise 36 we know that this second argument equals 2a mod b - 1 . Therefore the exponents involved in the continuing calculation are b and a mod b-exactly the same quantities that are involved in computing gcd( a, b) ! It follows that when the process terminates, the answer must be 2gcd(a,b) - 1, as desired. 39. a) This first one is easy to do by inspection. Clearly 10 and 11 are relatively prime, so their greatest common divisor is 1, and 1 = 11 - 10 = ( -1) · 10 + 1 · 11. b) In order to find the coefficients s and t such that 21s + 44t = gcd(21, 44), we carry out the steps of the Euclidean algorithm. 44 = 2. 21+2 21=10. 2+1 Then we work up from the bottom, expressing the greatest common divisor (which we have just seen to be 1) in terms of the numbers involved in the algorithm, namely 44, 21, and 2. In particular, the last equation tells us that 1 = 21 - 10 · 2, so that we have expressed the gcd as a linear combination of 21 and 2. But now the first equation tells us that 2 = 44 - 2 · 21; we plug this into our previous equation and obtain 1 = 21 - 10 . (44 - 2 . 21) = 21 . 21 - 10 . 44. Thus we have expressed 1 as a linear combination (with integer coefficients) of 21 and 44, namely gcd( 21, 44) = 21·21+(-10)·44. c) Again, we carry out the Euclidean algorithm. Since 48 = 1·36+ 12, and 12 I 36, we know that gcd(36, 48) = 12. From the equation shown here, we can immediately write 12 = ( -1) · 36 + 48. d) The calculation of the greatest common divisor takes several steps: 55 = 1·34 + 21 34 = 1. 21+13 21=1. 13 + 8 13 = 1·8 + 5 8=1·5+3 5=1·3+2 3=1·2+1 Then we need to work our way back up, successively plugging in for the remainders determined in this Chapter 4 126 Number Theory and Cryptography calculation: 1=3-2 = 3 - (5 - 3) = 2. 3 - 5 = 2. (8 - 5) - 5 = 2. 8 - 3. 5 = 2 . 8 - 3 . (13 - 8) = 5 . 8 - 3 . 13 = 5 . (21 - 13) - 3 . 13 = 5 . 21 - 8 . 13 = 5. 21 - 8. (34 - 21) = 13. 21 - 8. 34 = 13. (55 - 34) - 8. 34 = 13. 55 - 21 . 34 e) Here are the two calculations-down to the gcd using the Euclidean algorithm, and then back up by substitution until we have expressed the gcd as the desired linear combination of the original numbers. 213 = 1. 117 + 96 117 = 1 . 96 + 21 96 = 4. 21+12 21=1. 12 + 9 12 = 1·9 + 3 Since 3 I9, we have gcd(ll 7, 213) = 3. 3 = 12 - 9 = 12 - (21 - 12) = 2 . 12 - 21 = 2. (96 - 4. 21) - 21 = 2. 96 - 9. 21 = 2 . 96 - 9 . ( 117 - 96) = 11 . 96 - 9 . 117 = 11. (213 - 117) - 9. 117 = 11. 213 - 20. 117 f) Clearly gcd(O, 223) = 223, so we can write 223 = s · 0 + 1 · 223 for any integer s. g) Here are the two calculations-down to the gcd using the Euclidean algorithm, and then back up by substitution until we have expressed the gcd as the desired linear combination of the original numbers. 2347 = 19. 123 + 10 123 = 12 . 10 + 3 10=3·3+1 Thus the greatest common divisor is 1. 1=10-3·3 = 10 - 3. (123 - 12. 10) = 37. 10 - 3. 123 = 37. (2347 - 19. 123) - 3. 123 = 37. 2347 - 706. 123 h) Here are the two calculations-down to the gcd using the Euclidean algorithm, and then back up by substitution until we have expressed the gcd as the desired linear combination of the original numbers. 4666 = 3454 + 1212 3454 = 2 . 1212 + 1030 1212 = 1030 + 182 1030 = 5 . 182 + 120 182 = 120 + 62 120 = 62 + 58 62 = 58 + 4 58 = 14. 4 + 2 Section 4.3 Primes and Greatest Common Divisors 127 Since 2 I4, the greatest common divisor is 2. 2 = 58 -14. 4 = 58 - 14. (62 - 58) = 15. 58 - 14. 62 = 15 . (120 - 62) - 14. 62 = 15 . 120 - 29 . 62 = 15 . 120 - 29. (182 - 120) = 44. 120 - 29 . 182 = 44 . (1030 - 5 . 182) - 29 . 182 = 44. 1030 - 249 . 182 = 44 . 1030 - 249 . (1212 - 1030) = 293 . 1030 - 249 . 1212 = 293. (3454 - 2 . 1212) - 249 . 1212 = 293. 3454 - 835 . 1212 = 293. 3454 - 835. (4666 - 3454) = 1128. 3454 - 835 . 4666 i) Here are the two calculations-down to the gcd using the Euclidean algorithm, and then back up by substitution until we have expressed the gcd as the desired linear combination of the original numbers. 11111=9999+1112 9999 = 8 . 1112 + 1103 1112 = 1103 + 9 1103 = 122 . 9 + 5 9=5+4 5=4+1 Thus 1 is the greatest common divisor. 1=5-4 = 5 - (9 - 5) = 2 . 5 - 9 = 2 . (1103 - 122 . 9) - 9 = 2 . 1103 - 245 . 9 = 2. 1103 - 245. (1112 - 1103) = 247. 1103 - 245. 1112 = 247. (9999 - 8. 1112) - 245. 1112 = 247. 9999 - 2221 . 1112 = 247. 9999 - 2221. (11111 - 9999) = 2468. 9999 - 2221. 11111 41. When we apply the Euclidean algorithm we obtain the following quotients and remainders: Qi = 0, r 2 = 26, Q2 = 3, r 3 = 13, q3 = 2. Note that n = 3. Thus we compute the successive s's and t's as follows, using the given recurrences: s2 = so - Qi si = 1 - 0 · 0 = 1 , t2 = to - Qi ti = 0 - 0 · 1 = 0 t3 = ti - Q2t2 = 1 - 3 . 0 = 1 S3 = Si - Q2S2 = 0 - 3 · 1 = -3, Thus we have s3a + t3b = (-3) · 26 + 1 · 91 = 13, which is gcd(26, 91). 43. When we apply the Euclidean algorithm we obtain the following quotients and remainders: Qi = 1, r 2 = 55, Q2=l, r3=34, q3=l, r4=21, q4=l, rs=l3, Qs=l, r5=8, q5=l, r1=5, q7=l, rs=3, Qs=l, rg = 2, q9 = 1, r 10 = 1, q 10 = 2. Note that n = 10. Thus we compute the successive s's and t's as follows, using the given recurrences: S2 =So - QiSi = 1 - 1·0 = 1, t2 =to - Qiti = 0 - 1·1 = -1 t3 =ti - q2t2 = 1 - 1. (-1) = 2 S3 =Si - Q2S2 = 0 - 1·1 = -1, t4 = t2 - q3t3 = -1 - 1 . 2 = -3 S4 = S2 - Q3S3 = 1 - 1 · ( -1) = 2, Ss = S3 - Q4S4 = -1 - 1 · 2 = -3, ts = t3 - q4t4 = 2 - 1 · ( -3) = 5 t5 = t4 - qsts = -3 - 1 . 5 = -8 S5 = S4 - QsSs = 2 - 1 · ( -3) = 5, s7 = ss - q5s5 = -3 - 1 · 5 = -8, t1 = ts - q5t5 = 5 - 1 · ( -8) = 13 128 Chapter 4 83 = 85 - q187 = 5 - 1 · ( -8) = 13, 89 = 87 - q 8 8 8 = -8 - 1 · 13 = -21, 810 = 83 - qg8g = 13 - 1 · ( -21) = 34, Thus we have 810a + tiob = Number Theory and Cryptography q7 t1 = -8 - 1·13 = -21 tg = t1 - q8t 8 = 13 - 1 · (-21) = 34 tio =ts - q9 t 9 = -21 - 1 · 34 = -55 ts = t5 - 34 · 144 + (-55) · 89 = 1, which is gcd(144, 89). 45. We start with the pseudocode for the Euclidean algorithm (Algorithm 1) and add variables to keep track of the 8 and t values. We need three of them, since the new 8 depends on the previous two s's, and similarly for t. We also need to keep track of q. procedure extended Euclidean( a, b: positive integers) x :=a y := b oldolds := 1 olds:= 0 oldoldt := 0 oldt := 1 while y "I 0 q := x div y r := x mod y x := y y := r 8 := oldolds - q · olds t := oldoldt - q · oldt oldolds := olds oldoldt := oldt olds := 8 oldt := t { gcd( a, b) is x, and the Bezout coefficients are given by ( oldold8 )a + (oldoldt )b = x } 47. Obviously there are no definitive answers to these problems, but we present below a reasonable and satisfying rule for forming the sequence in each case. a) There are l's in the prime locations and O's elsewhere. In other words, the nth term of the sequence is 1 if n is a prime number and 0 otherwise. b) The suspicious 2's occurring every other term and the appearance of the 11 and 13 lead us to discover that the nth term is the smallest prime factor of n (and is 1 when n = 1 ) . c) The nth term is the number of positive divisors of n. For example, the twelfth term is 6, since 12 has the positive divisors 1, 2, 3, 4, 6, and 12. A tip-off to get us going in the right direction is that there are 2's in the prime locations. d) Perhaps the composer of the problem had something else in mind, but one rule here is that the nth term is 0 if and only if n has a repeated prime factor; the l's occur at locations for which n is "square-free" (has no factor, other than 1, that is a perfect square). For example, 12 has the square 22 , so the twelfth term is 0. e) We note that all the terms (after the first one) are primes. This leads us to guess that the nth term is the largest prime less than or equal to n (and is 1 when n = 1). f) Each term comes from the one before it by multiplying by a certain number. The multipliers are 2, 3, 5, 7, 11, 13, 17, 19, and 23~the primes. So the rule seems to be that we obtain the next term from the nth term by multiplying by the nth prime number (and we start at 1). In other words, the nth term is the product of the smallest n - 1 prime numbers. 49. Consider the product n(n + l)(n + 2) for some integer n. Since every second integer is even (divisible by 2), this product is divisible by 2. Since every third integer is divisible by 3, this product is divisible by 3. Therefore this product has both 2 and 3 in its prime factorization and is therefore divisible by 2 · 3 = 6. Section 4.3 Primes and Greatest Common Divisors 129 51. It is hard to know how to get started on this problem. To some extent, mathematics is an experimental science, so it would probably be a good idea to compute n 2 - 79n + 1601 for several positive integer values of n to get a feel for what is happening. Using a computer, or at least a calculator, would be helpful. If we plug in n = 1, 2, 3, 4, and 5, then we get the values 1523, 1447, 1373, 1301, and 1231, all of which are prime. This may lead us to believe that the proposition is true, but it gives us no clue as to how to prove it. Indeed, it seems as if it would be very hard to prove that this expression always produces a prime number, since being prime means the absence of nontrivial factors, and nothing in the expression seems to be very helpful in proving such a negative assertion. (The fact that we cannot factor it algebraically is irrelevant-in fact, if it factored algebraically, then it would essentially never be prime.) Perhaps we should try some more integers. If we do so, we find a lot more prime numbers, but we are still skeptical. Well, perhaps there is some way to arrange that this expression will have a factor. How about 1601? Well, yes! If we let n = 1601, then all three terms will have 1601 as a common factor, so that 1601 is a factor of the entire expression. In fact, 1601 2 - 79 · 1601 + 1601 = 1601 · 1523. So we have found a counterexample after all, and the proposition is false. Note that this was not a problem in which we could proceed in a calm, calculated way from problem to solution. Mathematics is often like that-lots of false leads and approaches that get us nowhere, and then suddenly a burst of insight that solves the problem. (The smallest n for which this expression is not prime is n = 80; this gives the value 1681 = 41 · 41.) 53. Here is one way to find a composite term in the sequence. If we set k = 1, then we get a + b. That number is greater than 1, but it may not be composite. So let's increase k by a+ b, which will have the effect of adding a multiple of a+ b to our previous answer, and we will therefore get a composite number, because a+ b will be a nontrivial factor of it. So setting k =a+ b + 1 should work. Indeed, with that choice we have ak + b = a(a + b + 1) + b = a 2 +ab+ a+ b, which factors nicely as (a+ l)(a + b). Since a and b are both positive integers, both factors are greater than 1, and we have our composite number. 55. Recall that the proof that there are infinitely many primes starts by assuming that there are only finitely many primes P1 , P2 , ... , Pn , and forming the number P1P2 · · · Pn + 1 . This number is either prime or has a prime factor different from each of the primes p 1 , p 2 , ... , Pn; this shows that there are infinitely many primes. So, let us suppose that there are only finitely many primes of the form 4k + 3, namely q1 , q2, ... , qn, where q1 = 3, q2 = 7, and so on. What number can we form that is not divisible by any of these primes, but that must be divisible by a prime of the form 4k + 3? We might consider the number 4q1 q2 · · · qn + 3. Unfortunately, this number is not prime, as it is is divisible by 3 (because q1 = 3). Instead we consider the number Q = 4q 1 q2 · · ·qn -1. Note that Q is of the form 4k + 3 (where k = q1 q2 · · · qn - 1). If Q is prime, then we have found a prime of the desired form different from all those listed. If Q is not prime, then Q has at least one prime factor not in the list q1 , q2 , ... , qn , because the remainder when Q is divided by q1 is q1 - 1 , and q1 - 1 =I- 0. Therefore q1 AQ for j = 1, 2, ... , n. Because all odd primes are either of the form 4k + 1 or of the form 4k + 3, and the product of primes of the form 4k + 1 is also of this form (because (4k + 1) (4m + 1) = 4( 4km + k + m) + 1), there must be a factor of Q of the form 4k + 3 different from the primes we listed. This complete the proof. 57. We need to show that this function is one-to-one and onto. In other words, if we are given a positive integer x, we must show that there is exactly one positive rational number m/n (written in lowest terms) such that K(m/n) = x. To do this, we factor x into its prime factorization and then read off them and n such that K (m / n) = x. The primes that occur to even powers are the primes that occur in the prime factorization of m, with the exponents being half the corresponding exponents in x; and the primes that occur to odd powers are the primes that occur in the prime factorization of n, with the exponents being half of one more than the exponents in x. Since this uniquely determines m and n, there is one and only one fraction, in Chapter 4 130 Number Theory and Cryptography lowest terms, that maps to x under K. SECTION 4.4 Solving Congruences Many of these exercises are reasonably straightforward calculations, but the amount of arithmetic involved in some of them can be formidable. Look at the worked out examples in the text if you need help getting the hang of it. The theoretical exercises, such as #18 and #19 give you a good taste of the kinds of proofs in an elementary number theory course. 1. We simply need to show that 15 · 7 =1 (mod 26), or in other words, that 15 · 7 - 1 is divisible by 26. But this quantity is 104, which is 26 · 4. 3. We want to find an integer k such that 4k is 1 greater than a multiple of 9. We compute 4 · 1 = 4 = 0 · 9 + 4, 4. 2 = 8 = 0. 9 + 8, 4. 3 = 12 = 1·9 + 3, 4. 4 = 16 = 1·9 + 7, 4. 5 = 20 = 2. 9 + 2, 4. 6 = 24 = 2. 9 + 6, 4 · 7 = 28 = 3 · 9 + 1. Therefore an inverse of 4 modulo 9 is 7. 5. a) Following the procedure of Example 2, we carry out the Euclidean algorithm to find gcd( 4, 9): 9=2·4+1 4= 4·1 Then we work backwards to rewrite the gcd (the last nonzero remainder, which is 1 here) in terms of 4 and 9: 1=9-2·4 Therefore the Bezout coefficients of 9 and 4 are 1 and -2, respectively. The coefficient of 4 is our desired answer, namely -2, which is the same as 7 modulo 9. Note that this agrees with our answer in Exercise 3. b) We proceed as above: 141=7.19 + 8 19 = 2. 8 + 3 8=2·3+2 3=1·2+1 2=2·1 Then we work backwards to rewrite the gcd (the last nonzero remainder, which is 1 here) in terms of 141 and 19: 1=3-1·2 = 3 - 1 . (8 - 2 . 3) = 3 . 3 - 1 . 8 = 3 . (19 - 2 . 8) - 1 . 8 = 3 . 19 - 7. 8 = 3. 19 - 7. (141 - 7. 19) = (-7). 141+52. 19 Therefore the Bezout coefficient of 19 is 52, and that is an inverse of 19 modulo 141. c) We proceed as above: 89 = 1·55 + 34 55 = 1·34 + 21 34=1·21+13 21=1·13 + 8 13 = 1·8 + 5 8=1·5+3 5=1·3+2 3=1·2+1 2 = 1·2 Section 4.4 Solving Congruences 131 Then we work backwards to rewrite the gcd (the last nonzero remainder, which is 1 here) in terms of 89 and 55: 1=3-1·2 = 3 - 1 . (5 - 1 . 3) = 2 . 3 - 1 . 5 = 2 . (8 - 1 . 5) - 1 . 5 = 2 . 8 - 3 . 5 = 2. 8 - 3. (13 - 1 . 8) = 5. 8 - 3. 13 = 5 . (21 - 1 . 13) - 3 . 13 = 5 . 21 - 8 . 13 = 5. 21 - 8. (34 - 1. 21) = 13. 21 - 8. 34 = 13. (55 - 1 . 34) - 8. 34 = 13. 55 - 21 . 34 = 13. 55 - 21 . (89 - 1 . 55) = 34. 55 - 21 . 89 Therefore the Bezout coefficient of 55 is 34, and that is an inverse of 55 modulo 89. d) We proceed as above: 232 = 2 . 89 + 54 89 = 1·54 + 35 54 = 1. 35 + 19 35 = 1. 19 + 16 19 = 1·16 + 3 16=5.3+1 3= 3·1 Then we work backwards to rewrite the gcd (the last nonzero remainder, which is 1 here) in terms of 232 and 89: 1=16 - 5. 3 = 16 - 5. (19 - 1 . 16) = 6. 16 - 5. 19 = 6 . (35 - 1 . 19) - 5 . 19 = 6 . 35 - 11 . 19 = 6. 35 - 11. (54 - 1. 35) = 17. 35 - 11. 54 = 17. (89 - 1. 54) - 11. 54 = 17. 89 - 28. 54 = 17. 89 - 28 . (232 - 2 . 89) = 73 . 89 - 28 . 232 Therefore the Bezout coefficient of 89 is 73, and that is an inverse of 89 modulo 232. 7. We follow the hint. Suppose that we had two inverses of a modulo m, say b and c. In symbols, we would have ba 1 (mod m) and ca 1 (mod m) . The first congruence says that m divides ba - 1 , and the second says that m divides ca - 1. Therefore m divides the difference (ba -1) - (ca -1) = ba - ca. (The difference of two multiples of m is a multiple of m.) Thus ba =ca (mod m). It follows immediately from Theorem 7 in Section 4.3 (the roles of a, b, and c need to be permuted) that b = c (mod m), which is what we wanted to prove. = = 9. In Exercise 5a we found that an inverse of 4 modulo 9 is 7. Therefore we multiply both sides of this equation by 7, obtaining x 35 8 (mod 9). As a check, we compute 4 · 8 = 32 5 (mod 9). = = = 11. Our answers are not unique, of course-anything in the same congruence class works just as well. a) In Exercise 5b we found that an inverse of 19 modulo 141 is 52. Therefore we multiply both sides of this equation by 52, obtaining x 208 67 (mod 141). As a check, we compute 19 · 67 = 1273 4 (mod 141). b) In Exercise 5c we found that an inverse of 55 modulo 89 is 34. Therefore we multiply both sides of this equation by 34, obtaining x 1156 88 (mod 89). As a check, we compute 55 · 88 55 · ( -1) = -55 34 (mod 89). = = = = = = = Chapter 4 132 Number Theory and Cryptography c) In Exercise 5d we found that an inverse of 89 modulo 232 is 73. Therefore we multiply both sides of this equation by 73, obtaining x 146 (mod 232). As a check, we compute 89 · 146 = 12994 2 (mod 232). = = 13. We follow the hint. Adding 6 to both sides gives the equivalent congruence 15x 2 + 19x + 6 =0 (mod 11), because 5 + 6 = 11 = 0 (mod 11). This factors as (5x + 3)(3x + 2) = 0 (mod 11). Because there are no non-zero divisors of 0 working modulo 11, we conclude that the solutions are precisely the solutions of 5x + 3 0 (mod 11) and 3x + 2 0 (mod 11). We solve these by the method of Example 3. By inspection (trial-and-error) or working it out through the Euclidean algorithm and back-substituting, we find that an = = inverse of 5 modulo 11is9, and multiplying both sides of 5x+3 = = = 0 (mod 11) by 9 yields x+27 = 0 (mod 11), = = so x -27 6 (mod 11). Similarly, an inverse of 3 modulo 11 is 4, and we get x -8 3 (mod 11). So the solution set is {3, 6} (and anything congruent to these modulo 11 ). Plugging these values into the original equation to check, we have 15·32 +19 · 3 + 6 = 198 0 (mod 11) and 15·62 +19 · 6 + 6 = 660 0 (mod 11). = = 15. The hypothesis tells us that m divides ac- be, which is the product (a- b)c. Let m' be m/ gcd(c, m). Then m' is a factor of m, so certainly m' J(a - b)c. Now since all the common factors of m and c were divided out of m to get m', we know that m' is relatively prime to c. It follows from Lemma 2 in Section 4.3 that m' I a - b. But this means that a= b (mod m'), exactly what we were trying to prove. 17. We want to find numbers x such that x 2 = 1 (mod p), in other words, such that p divides x 2 - 1. Factoring this expression, we see that we are seeking numbers x such that p I( x + 1) (x - 1) . By Lemma 3 in Section 4.3, this can only happen if p I x + 1 or p I x - 1. But these two congruences are equivalent to the statements x -1 (mod p) and x 1 (mod p) . = = 19. a) If two of these integers were congruent modulo p, say ia and ja, where 1 ::::; i < j < p, then we would have p Ija - ia, or p I(j - i)a. By Lemma 2 (or Lemma 3) in Section 4.3, since a is not divisible by p, p must divide j - i. But this is impossible, since j - i is a positive integer less than p. Therefore no two of these integers are congruent modulo p. b) By part (a), since no two of a, 2a, ... , (p - l)a are congruent modulo p, each must be congruent to a different number from 1 to p- 1. Therefore if we multiply them all together, we will obtain the same product, modulo p, as if we had multiplied all the numbers from 1 to p - 1. In symbols, =1 · 2 · 3 · · · (p - 1) (mod p). 1 The left-hand side of this congruence is clearly (p - 1)! · aP- , and the right-hand side is just (p - l)!, as desired. a· 2a · 3a · · · (p - l)a c) Wilson's theorem says that (p - 1)! is congruent to -1 modulo p. Therefore the congruence in part (b) says that (-1) · ap-l -1 (mod p). Multiplying both sides by -1, we see that ap-l = 1 (mod p), as desired. Note that we already assumed the hypothesis that p ,./'a in part (a). = p I a, then both sides of aP =a (mod p) are 0 modulo p, so the congruence holds. If not, then we just multiply the result obtained in part ( c) by a. d) If 21. Since 2, 3, 5, and 11 are pairwise relatively prime, we can use the Chinese remainder theorem. The answer will be unique modulo 2 · 3 · 5 · 11 = 330. Using the notation in the text, we have a 1 = 1, m 1 = 2, a2 = 2, m2 = 3, a3 = 3, m3 = 5, a4 = 4, m4 = 11, m = 330, Ali= 330/2 = 165, M2 = 330/3 = 110, 1\13 = 330/5 = 66, l'vl4 = 330/11=30. Then we need to find inverses y, of M, modulo m, for i = 1,2,3,4. This can be done by inspection (trial and error), since the moduli here are so small, or systematically using the Euclidean algorithm, as in Exercise 5; we find that y 1 = 1, y 2 = 2, y 3 = 1, and y4 = 7 (for this last one, 30 8 (mod 11), so we want to solve 8y4 = 1 (mod 11), and we observe that 8 · 7 = 56 = 1 (mod 11) ). Thus our solution is x = 1 · 165 · 1 + 2 · 110 · 2 + 3 · 66 · 1 + 4 · 30 · 7 = 1643 = 323 (mod 330). So the solutions are all integers of the form 323 + 330k, where k is an integer. = Section 4.4 Solving Congruences 133 23. By definition, the first congruence can be written as x = 3t + 2 where t is an integer. Substituting this expression for x into the second congruence tells us that 3t + 2 = 1 (mod 4), which can easily be solved to show that t 1 (mod 4). From this we can write t = 4u + 1 for some integer u. Thus x = 3t + 2 = 3(4u + 1) + 2 = 12u + 5. We plug this into the third congruence to obtain 12u + 5 = 3 (mod 5), which we easily solve to give u 4 (mod 5). Hence u = 5v + 4, and so x = 12u + 5 = 12(5v + 4) + 5 = 60v + 53. We check our answer by confirming that 53 = 2 (mod 3), 53 = 1 (mod 4), and 53 = 3 (mod 5). = = 25. We simply translate the steps of the calculation given in the proof of Theorem 2 into pseudocode. Of course, hidden in line 7 below is a multi-step process of finding inverses in modular arithmetic, which can be accomplished by using the Euclidean algorithm and back-substituting, as in Example 2. The last loop reduces the answer x to its simplest form modulo m. All solutions are then of the form x + mk, where m is the product of the moduli and k is an integer. procedure chinese( m 1 , m2, ... , mn : relatively prime positive integers; a 1 , a 2 , ... , an : integers) m:= 1 fork:= 1 ton m :=m·mk fork:= 1 ton Mk:= m/mk Yk := Mi; 1 mod mk x := 0 fork:= 1 ton x := x + akMkYk while x 2: m x := x-m return x {the smallest solution to the system { x ak (mod mk), k = 1, 2, ... , n } } = 27. We cannot apply the Chinese remainder theorem directly, since the moduli are not pairwise relatively prime. However, we can, using the Chinese remainder theorem, translate these congruences into a set of congruences that together are equivalent to the given congruence. Since we want x = 4 (mod 12), we must have x = 4 = 1 (mod 3) and x = 4 = 0 (mod 4). Similarly, from the third congruence we must have x = 1 (mod 3) and x = 2 (mod 7). Since the first congruence is consistent with the requirement that x = 1 (mod 3), we see that our system is equivalent to the system x 7 (mod 9), x 0 (mod 4), x 2 (mod 7). These can be solved using the Chinese remainder theorem (see Exercise 21 or Example 5) to yield x 16 (mod 252). Therefore the solutions are all integers of the form 16 + 252k, where k is an integer. = = = = 29. We will argue for the truth of this statement using the Fundamental Theorem of Arithmetic. What we must show is that m1 m 2 · · · mn Ia - b. Look at the prime factorization of both sides of this proposition. Suppose that p is a prime appearing in the prime factorization of the left-hand side. Then p ImJ for some j. Since the m, 's are relatively prime, p does not appear as a factor in any of the other m, 's. Now we know from the hypothesis that mJ Ia - b. Therefore a - b contains the factor p in its prime factorization, and p must appear to a power at least as large as the power to which it appears in m 1 . But what we have just shown is that each prime power pr in the prime factorization of the left-hand side also appears in the prime factorization of the right-hand side. Therefore the left-hand side does, indeed, divide the right-hand side. 31. We are asked to solve the simultaneous congruences x = 1 (mod 2) and x = 1 (mod 3). The solution will be unique modulo 2 · 3 = 6. By inspection we see that the answer is simply that x 1 (mod 6). The solution set is {... ,-ll,-5,1,7,13, ... }. = 33. Fermat's little theorem tells us that 712 = 1 (mod 13). Note that 121 712-10 . 7 = (712)10. 7 = 110 . 7 = 7 (mod 13). 10 · 12 + 1. Therefore 7121 Chapter 4 134 35. Fermat's little theorem tells us that under the given conditions 2 a· aP- = aP-l = 1 (mod p). This is precisely the definition that ap-l aP- 2 Number Theory and Cryptography = 1 (mod p). Therefore aP- 2 is an inverse of a modulo p. . a = 37. a) We calculate 2340 = (2 10 ) 34 = 134 = 1 (mod 11), since Fermat's little theorem says that 210 = 1 (mod 11). b) We calculate 2340 = (2·5 ) 68 =32 68 =1 68 =1(mod31), since 32=1(mod31). c) Since 11 and 31 are relatively prime, and 11·31 = 341, it follows from the first two parts and Exercise 29 that 2340 = 1 (mod 341). 39. a) By Fermat's little theorem we know that 56 = 1 (mod 7); therefore 5 1998 = (5 6) 333 = 1333 = 1 (mod 7), and so 52003 = 55 · 5 1998 = 3125 · 1 = 3 (mod 7). So 52003 mod 7 = 3. Similarly, 5 10 = 1 (mod 11); therefore 52000 = (5 10 ) 200 = 1200 = 1 (mod 11), and so 52003 = 53 · 52000 = 125 · 1 = 4 (mod 11). So 1 166 1 (mod 13), and so 52003 mod 11 = 4. Finally, 5 12 = 1 (mod 13); therefore 5 1992 = (5 12 ) 166 2003 1992 11 2003 5 = 5 ·5 48,828, 125 · 1 8 (mod 13). So 5 mod 13 = 8. = = = = b) We now apply the Chinese remainder theorem to the results of part (a), as in Example 5. Let m = 7 · 11 · 13 = 1001, llfi = m/7 = 143, 1112 = m/11 = 91, and M 3 = m/13 = 77. We see that 5 is an inverse of 143 modulo 7. since 143 3 (mod 7), and 3 · 5 = 15 1 (mod 7). Similarly, 4 is an inverse of 91 modulo 11, and 12 is an inverse of 77 modulo 13. (An algorithm to compute inverses-if we don't want to find them by inspection as we've done here-is illustrated in Example 2.) Therefore the answer is (3 · 143 · 5 + 4 · 91·4 + 8 · 77 · 12) mod 1001=10993 mod 1001 = 983. = = 41. Let q be a (necessarily odd) prime dividing 2P - 1. By Fermat's little theorem, we know that q I 2q-l - 1. Then from Exercise 37 in Section 4.3 we know that gcd(2P- l, 2q-l -1) = 2gcd(p.q-l) -1. Since q is a common divisor of 2P - 1 and 2q-l - 1, we know that gcd(2P - 1, 2q-l - 1) > 1. Hence gcd(p, q - 1) = p, since the only other possibility, namely gcd(p, q - 1) = 1, would give us gcd(2P - 1, 2q-l - 1) = 1. Hence p I q - 1, and therefore there is a positive integer m such that q - 1 = mp. Since q is odd, m must be even, say m = 2k, and so every prime divisor of 2P - 1 is of the form 2kp + 1. F\lfthermore, products of numbers of this form are also of this form, since (2k 1p + 1)(2k2p + 1) = 4k 1k2p 2 + 2k 1p + 2k 2p + 1 = 2(2k1k2p + k 1 + k3)p + 1. Therefore all divisors of 2P - 1 are of this form. 43. To decide whether 2 11 - 1 = 204 7 is prime, we need only look for a prime factor not exceeding J2647 ~ 45. By Exercise 41 every such prime divisor must be of the form 22k + 1. The only candidate is therefore 23. In fact 2047 = 23 · 89, so we conclude that 2047 is not prime. We can take the same approach for 217 - 1 = 131,071, but we need either computer algebra software or patience with a calculator. By Exercise 41 every prime divisor of 217 - 1 must be of the form 34k + 1, so we need to try all such divisors (or at least those that are not obviously nonprime) up to .Jl31,071 means up to k = 10. No number of this form divides 131,071, so we conclude that it is prime. ~ 362, which 45. First note that 2047 = 23·89, so 2047 is composite. To apply Miller's test, we write 2047-1 = 2046 = 2·1023, so s = 1 and t = 1023. We must show that either 21023 = 1 (mod 204 7) or 21023 = -1 (mod 204 7) . To compute, we write 21023 = (2 11 ) 93 = 2048 93 193 = 1 (mod 2047), as desired. (We could also compute this using the modular exponentiation algorithm given in Section 4.2-see Example 12 in that section.) = 47. We factor 2821 = 7·13·31. We must show that this number meets the definition of Carmichael number, namely that b2820 1 (mod 2821) for all b relatively prime to 2821. Note that if gcd(b, 2821) = 1, then gcd(b, 7) = gcd(b, 13) = gcd(b, 31) = 1. Using Fermat's little theorem we find that b6 = 1 (mod 7), b12 = 1 (mod 13), and b30 1 (mod 31). It follows that b2820 = (b6) 470 = 1 (mod 7), b2820 = (b 12 ) 235 = 1 (mod 13), 2820 and b = (b30 )94 1 (mod 31). By Exercise 29 (or the Chinese remainder theorem) it follows that 2820 b 1 (mod 2821), as desired. = = = = Section 4.4 Solving Congruences 135 49. a) If we multiply out this expression, we get n = 1296m3 + 396m2 + 36m + 1. Clearly 6m In - 1, 12m In - 1, and 18m In - 1. Therefore, the conditions of Exercise 48 are met, and we conclude that n is a Carmichael number. b) Letting m = 51 gives n = 172,947,529. We note that 6m + 1 = 307, 12m + 1 = 613, and 18m + 1 = 919 are all prime. 51. It is straightforward to calculate the remainders when the integers from 0 to 14 are divided by 3 and by 5. For example, the remainders when 10 is divided by 3 and 5 are 1 and 0, respectively, so we represent 10 by the pair (1, 0). The exercise is simply asking us to tabulate these remainders, as in Example 7. 0 = (0, 0) 1 = (1,1) 3 = (0, 3) 2 = (2, 2) 5 4=(1,4) = (2, 0) 6=(0,1) 7 = (1,2) 8 = (2, 3) 9 = (0,4) 10 = (1,0) 11 = (2, 1) 12 = (0, 2) 13=(1,3) 14 = (2,4) 53. The method of solving a system of congruences such as this is given in the proof of Theorem 2. Here we have m1 = 99, m2 = 98, m3 = 97, and m4 = 95, so that m = 99 · 98 · 97 · 95 = 89403930. We compute the values Mk = m/mk and obtain Mi = 903070, M2 = 912285, M 3 = 921690, and M 4 = 941094. Next we need to find the inverses Yk of Mk modulo mk. To do this we first replace each Mk by its remainder modulo mk (to make the arithmetic easier), and then apply the technique shown in Example 2. For k = 1 we want to find the inverse of 903070 modulo 99, which is the same as the inverse of 903070 mod 99, namely 91. To do this we apply the Euclidean algorithm to express 1 as a linear combination of 91 and 99. 99 = 91+8 91=11·8 + 3 8=2·3+2 3=2+1 :.1=3-2 = 3 - (8 - 2 . 3) = 3 . 3 - 8 = 3 . (91 - 11 . 8) - 8 = 3 . 91 - 34. 8 = 3. 91 - 34. (99 - 91) = 37. 91 - 34. 99 We therefore conclude that the inverse of 91 modulo 99 is 37, so we have y 1 = 37. Similar calculations show that Y2 = 33, y3 = 24, and y4 = 4. Continuing with the procedure outlined in the proof of Theorem 2, we now form the sum of the products akMkYk, and this will be our solution. We have 65. 903070. 37 + 2. 912285. 33 + 51. 921690. 24 + 10. 941094. 4 = 3397886480. We want our answer reduced modulo m, so we divide by 89403930 and take the remainder, obtaining 537140. (All of these calculations are not difficult using a scientific calculator.) Finally, let us check our answer: 537140 mod 99 = 65, 537140 mod 98 = 2, 537140 mod 97 = 51, 537140 mod 95 = 10. 55. For the first question we seek an exponent n such that 2n = 5 (mod 19). For the second we want 2n = 6 (mod 19). There is no known efficient algorithm for finding these exponents, so we might as well just start computing powers of 2 modulo 19. In each case, we just need to multiply the previous result by 2, working modulo 19. We have 22 = 4 (mod 19), 23 = 2 · 4 = 8 (mod 19), 24 = 2 · 8 = 16 (mod 19), 25 = 2·16 = 32 = 13 (mod 19), 26 = 2 · 25 = 2 · 13 = 26 = 7 (mod 19), 27 = 2 · 7 = 14 (mod 19), 28 = 2·14 = 28 = 9 (mod 19), 29 = 2·9 = 18 (mod 19), 210 =2·18 = 36 = 17 (mod 19), 211 =2·17 = 34 = 15 (mod 19), 212 = 2 · 15 = 30 = 11(mod19), 213 = 2 · 11 = 22 = 3 (mod 19), 214 = 2 · 3 = 6 (mod 19). Finally! So we conclude that the discrete logarithm of 6 to the base 2 modulo 19 is 14. Continuing the calculation, we have 215 = 2 · 6 = 12 (mod 19), 216 = 2 · 12 = 24 = 5 (mod 19). So the discrete logarithm of 5 to the base 2 modulo 19 is 16. 136 Chapter 4 Number Theory and Cryptography 57. A computer algebra system such as Maple facilitates the modular arithmetic calculations. We repeatedly multiply by 3 and reduce modulo 17. We get 3° = 1 (mod 17), 31 = 3 (mod 17), 32 = 9 (mod 17), 33 = 27 = 10 (mod 17) , and so on. Thus log 3 1 = 0, log 3 3 = 1, log 3 9 = 2, log 3 10 = 3, and so on. If we collect the data and present them in order of increasing argument, we get the required table. (Of course log 3 0 does not exist.) log 3 1 = 0 log 3 9 log 3 2 = 14 log 3 3 = 1 log3 4 = 12 log3 5 = 5 log3 6 = 15 log3 7 = 11 log3 8 = 10 = 2 log3 10 = 3 log3 11 = 7 log3 12 = 13 log 3 13 = 4 log 3 14 = 9 log 3 15 = 6 log 3 16 = 8 = 59. We need to prove that if the congruence x 2 a (mod p) has any solutions at all, then it has exactly two solutions. So let us assume that s is a solution. Clearly -s is a solution as well, since (-s) 2 = s 2 . Furthermore, -s =fas (mod p), since if it were, we would have 2s = 0 (mod p), which means that p I 2s. Since p is an odd prime, that means that p Is, so that s 0 (mod p). Therefore a= 0 (mod p), contradicting the conditions of the problem. = It remains to prove that there cannot be more than two incongruent solutions. Suppose that s is one solution and that t is a second solution. We have s 2 = t 2 (mod p). This means that p I s 2 - t 2 , that is, p I(s + t) ( s - t) . Since p is prime, Lemma 3 in Section 4. 3 guarantees that p I s - t or p I s + t. This means that t = s (mod p) or t = -s (mod p). Therefore any solution t must be either the first solution or its negative. In other words, there are at most two solutions. 61. There is really almost nothing to prove here. The value (~) depends only on whether or not a is a quadratic residue modulo p, i.e., whether or not the equivalence x 2 =a (mod p) has a solution. Obviously, this depends only on the equivalence class of a modulo p. = =(;) 63. By Exercise 62 we know that (~) (~) a(p-lJ/ 2 b(p-lJ/ 2 = (ab)(p-l)/ 2 (mod p). Since the only values either side of this equivalence can take on are ±1, being congruent modulo p is the same as being equal. 65. We follow the hint. Working modulo 5, we want to solve x 2 = 4. It is easy to see that there are exactly two solutions modulo 5, namely x = 2 and x = 3. Similarly there are only the solutions x = 1 and x = 6 2 or 3 (mod 5) and x 1 modulo 7. Therefore we want to find values of x modulo 5 · 7 = 35 such that x or 6 (mod 7). We can do this by applying the Chinese remainder theorem (as in Example 5) four times, for the four combinations of these values. For example, to solve x = 2 (mod 5) and x = 1 (mod 7), we find that m = 35, Mi = 7, M2 = 5, y 1 = 3, Y2 = 3, so x 2 · 7 · 3 + 1 · 5 · 3 = 57 22 (mod 35). Doing the similar calculation with the other three possibilities yields the other three solutions modulo 35: x = 8, x = 13, and x = 27. = = = = 67. To compute logra (modp), we need to solve re= a (modp) fore. The brute force approach is just to compute re mod p for e = 0, 1, 2, ... , p - 2 until we get the answer a. This requires about p iterations, each of which can be done with O(logp) bit operations, since we need only multiply the previous value by r and find the remainder upon division by p. At worst, we require all p iterations; on average, only half that many. In either case, the time complexity is O(plogp), which is prohibitively large if pis, say, a 200-digit number. Section 4.5 Applications of Congruences SECTION 4.5 137 Applications of Congruences The great British number theorist G. H. Hardy (1877-1947) once said, "I have never done anything 'useful.' No discovery of mine has made, or is likely to make, directly or indirectly, for good or ill, the least difference to the amenity of the world." He was wrong. Number theory has many applications, especially in cryptography (see Section 4.6). In the present section we saw applications to hashing functions (important for storing large amounts of information and being able to retrieve it efficiently), pseudorandom numbers (important for computer simulations), and check digits (important in our technological world). Hardy would be appalled! The exercises in this section are mostly routine. 1. We are simply asked to compute k mod 97 for each value of k. We do this by dividing the given number by 97 and taking the remainder, which can be found either by multiplying the decimal remainder by 97, or by subtracting 97 times the quotient from k. (See the solution to Exercise 3 below for details.) a) 034567981 mod 97 = 91 b) 183211232 mod 97 = 57 c) 220195744 mod 97 = 21 d) 987255335 mod 97 = 5 3. a) We need to compute k mod 31 in each case. A good way to do this on a calculator is as follows. Enter k and divide by 31. The result will be a number with an integer part and a decimal fractional part. Subtract off the integer part, leaving a decimal fraction between 0 and 1. This is the remainder expressed as a decimal. To find out what whole number remainder that really represents, multiply by 31. The answer will be a whole number (or nearly so-it may require rounding, say from 4.9999 or 5.0001 to 5), and that number is k mod 31. (ii) 918 mod 31 = 19 (iii) 007 mod 31 = 7 (i) 317 mod 31 = 7 (iv) 100 mod 31 = 7 (v) 111 mod 31 = 18 (vi) 310 mod 31 = 0 b) Take the next available space, where the next space is computed by adding 1 to the space number and pretending that 30 + 1 = 0. 5. We apply the formula with n = 0 to obtain x 1 = (3 · x 0 + 2) mod 13 = (3 · 1 + 2) mod 13 = 5. Then X2 = (3 · x1 + 2) mod 13 = (3 · 5 + 2) mod 13 = 17 mod 13 = 4. Continuing in this way we have X3 = (3 · 4 + 2) mod 13 = 1. Because this is the same as x 0 , the sequence repeats from here on out. So the sequence is 1, 5, 4, 1, 5, 4, 1, 5, 4, .... 7. We compute until the sequence begins to repeat: x 1 = 3 · 2 mod 11 = 6 x2 = 3 · 6 mod 11 = 7 X3 = 3 · 7 mod 11 = 10 x 4 = 3 · 10 mod 11 = 8 x5 Since X5 = 3 · 8 mod 11 = 2 = xo, the sequence repeats forever: 2, 6, 7, 10, 8, 2, 6, 7, 10, 8, .... 9. We follow the instructions. Because 2357 2 = 5555449 = 05555449, the middle four digits are 5554, so 5554 is our second pseudorandom number. Next 5554 2 = 30846916, so our third pseudorandom number is 8469. Repeating the same procedure leads to the following five terms: 7239, 4031, 2489, 1951, 8064. 11. We are told to apply the formula Xn+l = x~ mod 7, starting with x 0 = 2. Thus x 1 = 23 mod 7 = 1, x 2 = 13 mod 7 = 1, and our sequence never gets off the ground! The sequence generated here is 2, 1, 1, 1, .... 13. A correctly transmitted bit string must have an even number of 1's. Therefore we can be sure that there is an error in (d), but because the other three strings have an even number of 1 's, we cannot detect an error in any of them. (Of course that doesn't mean that there is no error, because it is possible that two bits were transmitted incorrectly, in which case the sum modulo 2 does not change.) Chapter 4 138 Number Theory and Cryptography 15. Let d be the check digit. Then we know that 1·0+2·0+3·7+4·1+5·1+6·9+7·8+8·8+9·1+10·d = 0 (mod 11). = This simplifies to 213+10·d 0 (mod 11). But 213 to 4 - d = 0 (mod 11) , or d = 4. =4 (mod 11), and 10 =-1(mod11), so this is equivalent 17. The ISBN is 0073383090. To check its validity we compute, as in Example 6, 1·0+2·0 + 3 · 7 + 4 · 3 + 5 · 3 + 6 · 8 + 7 · 3 + 8 · 0 + 9 · 9 + 10 · 0 = 198. Because this is congruent to 0 modulo 11, the check digit was computed correctly. 19. To determine whether an 11-digit number is a valid USPS money order identification number, we need to verify that the sum of the first ten digits reduced modulo 9 gives the last digit. a) 7 + 4 + 0 + 5 + 1 + 4 + 8 + 9 + 6 + 2 mod 9 = 46 mod 9 = 1 -1- 3, so this is not a valid number. b) 8 + 8 + 3 + 8 + 2 + 0 + 1 + 3 + 4 + 4 mod 9 number. = 41 mod 9 = 5, which is the last digit, so this is a valid c) 5 + 6 + 1+5+2+2 + 4 + 0 + 7 + 8 mod 9 = 40 mod 9 = 4, which is the last digit, so this is a valid number. d) 6 + 6 + 6 + 0 + 6 + 6 + 3 + 1 + 1 + 7 mod 9 = 42 mod 9 = 6 -1- 8, so this is not a valid number. 21. In each case, we know that xn = x1 + x2 + X3 + X4 + xs + X5 + x1 + xs + Xg + X10 mod 9. (See the preamble to Exercise 18.) This is equivalent to x 11 = x 1 + x 2 + X3 + x 4 + x 5 + x 6 + x 7 + x 8 + x 9 + x 10 (mod 9), with 0 ::; x 11 :S 8. Therefore we will get an equation modulo 9 involving the unknown Q for each of these valid postal money order identification numbers. a) 8 = 4 + 9 + 3 + 2 + 1 + 2 + Q + 0 + 6 + 8 (mod 9), which is equivalent to 8 = Q + 35 = Q + 8 (mod 9). Therefore Q = 0 (mod 9). There are two single-digit numbers Q that makes this true: Q = 0 and Q = 9, so it is impossible to know for sure what the smudged digit was. = = b) 8 8 + 5 + 0 + Q + 9 + 1+0 + 3 + 8 + 5 (mod 9), which is equivalent to 8 Q + 39 = Q + 3 (mod 9). The only single-digit number Q that makes this true is Q = 5, so the smudged digit must have been a 5. c) 4 = 2 + Q + 9 + 4 + 1+0 + 0 + 7 + 7 + 3 (mod 9), which is equivalent to 4 = Q + 33 = Q + 6 (mod 9). The only single-digit number Q that makes this true is Q = 7, so the smudged digit must have been a 7. d) 1=6+6 + 6 + 8 + 7 + Q + 0 + 3 + 2 + 0 (mod 9), which is equivalent to 1=Q+38 = Q + 2 (mod 9). The only single-digit number Q that makes this true is Q = 8, so the smudged digit must have been an 8. 23. Because the first ten digits are added, any transposition error involving them will go undetected-the sum of the first ten digits will be the same for the transposed number as it is for the correct number. Suppose the last digit is transposed with another digit; without loss of generality, we can assume it's the tenth digit and that x 10 -1- x 11 . Then the correct equation will be X11 =X1 + X2 + X3 + X4 + X5 + X5 + X7 + Xs + Xg + X10 (mod 9) but the equation resulting from the error will read X10 =X1 + X2 + X3 + X4 + X5 + X5 + X7 + Xs + Xg + X11 (mod 9) . = Subtracting these two equations, we see that the erroneous equation will be true if and only if x 11 - x10 x 10 - x 11 (mod 9). This is equivalent to 2x 11 2x 10 (mod 9), which, because 2 is relatively prime to 9, is equivalent to x 11 = x 10 (mod 9), which is false. This tells us that the check equation will fail. Therefore we conclude that transposition errors involving the eleventh digits are detected. = 25. From Example 5. we know that a valid UPC code must satisfy the equation Section 4.5 Applications of Congruences 139 Therefore in each case we simply need to compute the left-hand side of this equation modulo 10 and see whether or not we get 0 as the answer. a) 3 · 0 + 3 + 3 · 6 + 0 + 3 · 0 + 0 + 3 · 2 + 9 + 3 · 1+4 + 3 · 5 + 2 = 60 = 0 (mod 10), so this is a valid code. b) 3 · 0 + 1 + 3 · 2 + 3 + 3 · 4 + 5 + 3 · 6 + 7 + 3 · 8 + 9 + 3 · 0 + 3 = 88 "!- 0 (mod 10) , so this is not a valid code. c) 3 · 7 + 8 + 3 · 2 + 4 + 3 · 2 + 1+3 · 8 + 4 + 3 · 3 + 0 + 3 · 1+4 = 90 d) 3 · 7 + 2 + 3 · 6 + 4 + 3 · 1+2+3·1+7 + 3 · 5 + 4 + 3 · 2 + 5 = 90 =0 (mod 10), so this is a valid code. =0 (mod 10), so this is a valid code. 27. The digits with even subscripts appear in the formula with coefficient 1, whereas those with odd subscripts appear with coefficient 3. Therefore if two digits whose positions have the same parity (both odd or both even) are switched, then th~ sum will be unchanged and such an error cannot be detected. If two digits whose parities are different are transposed, say an x in an odd position and a y in an even position, then the new sum will differ from the old sum by (x + 3y) - (3x + y), which equals 2(y- x). As long as the two transposed digits do not differ by 5, the sum will therefore be different modulo 10; if they do differ by 5, then the sum will be the same modulo 10. We conclude that transposition errors will be detected if and only if the transposed digits are an odd number of positions apart (in particular transposing neighboring digits) and do not differ by 5 . 29. In each case we need to compute a 1 a 2 ... al4 mod 7 and see if we get a 15 . This may be inconvenient on a calculator with only 12 digits of precision, but one can always divide it out by hand (or, better, use computer algebra software). a) 10133334178901 = 7 · 1447619168414 + 3. Therefore 10133334178901 mod 7 = 3 = a 15 , so this is a valid airline ticket number. (In Maple we could just type 10133334178901 mod 7 and get the response 3.) b) 00786234277044 mod 7· = 6 -/=- 5 = a 15 , so this is not a valid number. c) 11327343888253 mod 7 = 1 = a 15 , so this is a valid number. d) 00012234732287 mod 7 = 1 = a 15 , so this is a valid number. 31. Let's solve a more general problem by ignoring the word "consecutive." First we look at the case in which the transposition does not involve the check digit itself. Suppose the erroneous number formed by the first 14 digits occurs when a, is interchanged with aJ , where 1 ~ i < j ~ 14. Because of our decimal place-value numeration system, before the switch, a, was contributing a, -10 14 -z to the value of the number, and aJ was contributing aJ · 10 14 -J. Therefore this change has increased the 14-digit number by (aJ -a,)10 14 - ' +(a, -aJ)10 14 -J, which equals (aJ - a,)(10 14 -z - 10 14 -J). In order for this to still check, this last expression must be equivalent to 0 modulo 7. Obviously this will happen if ai and aJ differ by 7, but it will also happen if (10 14 - 1 -10 14 -J) is a multiple of 7. A bit of calculation shows that this will happen if and only if j - i = 6 or 12. Thus we cannot detect the error if the columns in which the transposition occurs are 6 or 12 apart or the transposed digits differ by 7. Finally, if the digit a 15 is transposed with the digit a,, where 1 ~ i ~ 14, then a 1 a 2 ••• a 14 mod 7 has gone up by (a 15 -a,)10 14 -z and the check digit has gone up by a, - a 15 , so we will not be able to detect this error ifand only if (a 15 -a,)10 14 - i =a, -a 15 (mod 7), which is equivalent to (a 15 -a,)(10 14 -'+ 1) = 0 (mod 7). Because 10 14 -'' + 1 = 0 (mod 7) if and only if i = 5 or 11, we conclude that we cannot detect the transposition error if it interchanges the check digit with a 5 or a 11 or interchanges it with a digit differing from it by 7. (Of course, the check digit must be 0 through 6, so an error that puts a 7, 8, or 9 in the last position can also be detected.) Because transposing consecutive digits is not transposing digits whose positions differ by the quantities mentioned above, we can detect all transposition errors of consecutive digits unless the digits differ by 7. 33. In each case we will compute 3d1 +4d 2 + 5d3 + 6d4 + 7d5 + 8d 6 + 9d7 mod 11. If this matches the digit given for ds, then the ISSN is valid, and conversely. Chapter 4 140 Number Theory and Cryptography a) 3 · 1 + 4 · 0 + 5 · 5 + 6 · 9 + 7 · 1 + 8 · 0 + 9 · 2 mod 11 = 107 mod 11 = 8. Because ds = 7 =/= 8, this number is not valid. b) 3 · 0 + 4 · 0 + 5 · 0 + 6 · 2 + 7 · 9 + 8 · 8 + 9 · 9 mod 11 = 220 mod 11 = 0. Because d8 = 0, this number is valid. c) 3 · 1+4 · 5 + 5 · 3 + 6 · 0 + 7 · 8 + 8 · 6 + 9 · 6 mod 11=196 mod 11 = 9. Because d8 = 9, this number is valid. d) 3 · 1+4 · 0 + 5 · 0 + 6 · 7 + 7 · 1 + 8 · 2 + 9 · 0 mod 11 = 68 mod 11 = 2. Because d 8 is "X" (representing 10 modulo 11 ), this number is not valid. 35. By subtracting d8 from both sides and noting that -1 =10 (mod 11) , we see that the checking congruence is equivalent to 3d 1 +4d 2 + 5d3 + 6d4 + 7d 5 + 8d5 + 9d1 + lOds = 0 (mod 11) . It is now easy to see that transposing adjacent digits x and y (where x is on the left) causes the left-hand side to increase by x and decrease by y, for a net change of x - y. Because x =/'. y (mod 11) , the congruence will no longer hold. Therefore errors of this type are always detected. SECTION 4.6 Cryptography In addition to exercises about the topics covered in this section, this exercise set introduces the Vigenere cipher (Exercises 18-22) and a protocol for key exchange (Exercise 33). There is a nice website for encoding and decoding with the affine cipher (far any function of the farm f(p) = ap + b ), which you can use to check your answers: www.shodor.org/interactivate/activities/CaesarCipher/. A website for the Vigenere cipher can be found here: isl ab. oregonstate. edu/koc/ ece575/02Proj ect/Mun+Lee/VigenereCipher. html 1. a) We need to replace each letter by the letter three places later in the alphabet. Thus D becomes G, 0 becomes R, and so on. The resulting message is GR QRW SDVV JR. b) We need to replace each letter by the letter 13 places later in the alphabet. Thus D becomes Q, 0 becomes B (we cycle, with A following Z), and so on. The resulting message is QB ABG CNFF TB. c) This one is a little harder, so it is probably easiest to work with the numbers. For D we have p = 3 because D is the fourth letter of the alphabet. Then 3 · 3 + 7 mod 26 = 16, so the encrypted letter is the 17th letter, or Q (remember that we start the sequence at 0). Our original message has the following numerical values: 3-14 13-14-19 15-0-18-18 6-14. Multiplying each of these numbers by 3, adding 7, and reducing modulo 26 gives us 16-23 20-23-12 0- 7-9-9 25-23. Translating back into letters we have QX UXM AHJJ ZX. 3. In each case, we translate the letters to numbers from 0 to 25, then apply the function, then translate back. (See the solution for Exercise le above for details.) In each case, the numerical message is 22-0-19-2-7 24-14-20-17 18-19-4-15. a) Adding 14 to each number modulo 26 yields 10-14-7-16-21 12-2-8-5 6-7-18-3. Translating back into letters yields KOHQV MCIF GHSD. b) Multiplying each number by 14, adding 21, and reducing modulo 26 yields 17-21-1-23-15 19-9-15-25 13-1-25-23. Translating back into letters yields RVBXP TJPZ NBZX. c) Multiplying each number by - 7, adding 1, and reducing modulo 26 yields 3-1-24-13-4 15-7-17-12 5-24-25-0. Translating back into letters yields DBYNE PHRM FYZA. 5. a) We need to undo the encryption operation, which was to choose the letter that occurred ten places later in the alphabet. Therefore we need to go backwards 10 places (or, what amounts to the same thing, forward 16 places). For example, the C decodes as S. Doing this for each letter, as in Exercise 1, gives us SURRENDER NOW. b) BE MY FRIEND c) TIME FOR FUN Section 4.6 Cryptography 141 7. We need to play detective. First note that the two-letter word DY occurs twice. Because this was a shift cipher, we know that the first letter of this word occurs five places beyond the second letter in the alphabet. One of those letters has to be a vowel. This makes it very likely that the word is either UP or TO, corresponding to k = 9 or k = 10, respectively. Since TO is a more common word, let us assume k = 10. To decrypt, we shift each letter in the encrypted message backward 10 places (or forward 16 places) in the alphabet, obtaining TO SLEEP PERCHANCE TO DREAM (from Hamlet). 9. Following the same strategy as in Exercise 7, we try to figure out k from the fact that MW is a two-letter word in the encrypted text. What fits best is IS, with k = 4. If we apply that to the three-letter word, we get ANY, which seems quite promising. We now decode the entire message: ANY SUFFICIENTLY ADVANCED TECHNOLOGY IS INDISTINGUISHABLE FROM MAGIC. 11. We want to solve the congruence c = 15p + 13 (mod 26) for p. To do that we will need an inverse of 15 modulo 26, which we can obtain using the Euclidean algorithm or by trial and error. It is 7, because 7 · 15 = 105 = 4 · 26 + 1. Therefore we have p = 7(c - 13) mod 26 = 7c - 91 mod 26 = 7c + 13 mod 26. 13. Because the most common letters are E and T, in that order, and the numerical values of E, T, Z, and J are = = = 4, 19, 25, and 9, respectively, we will assume that f( 4) 25 and f(19) 9. This means that 4a + b 25 and 19a + b 9, where we work modulo 26, of course. Subtracting the two equations gives 15a 10, which simplifies to 3a 2 (because 5 is not a factor of 26, we can divide both sides by 5). We can find an inverse of 3 modulo 26 using the Euclidean algorithm or by trial and error. It is 9, because 3 · 9 = 27 = 26 + 1. Therefore a 9 · 2 = 18. Plugging this into 4a + b 25 yields b 25 - 4a = 25 - 72 5. We therefore guess that the encryption function is f(p) = 18p + 5 mod 26. As a check, we see that f(4) = 25 and f(19) = 9. = = = = = = = Because 0'(1) = 3, we put the third letter first; because 0'(2) = 1, we put the first letter second; and so on. This gives us BEWA REOF MART IANS, presumably meant to be BEWARE OF MARTIANS. 15. We permute each block of four by undoing the permutation O". 17. Presumably the message was translated letter by letter, such as by a shift cipher or affine cipher. (Other, nonlinear, bijections on Z 26 are also possible.) 19. The numerical version of the encrypted text is 14-8-10-24-22-21-7-1-23. If we subtract the values for the key HOTHOTHOT, namely 7-14-19-7-14-19-7-14-19 and reduce modulo 26, we obtain 7-20-17-17-8-2-0-13-4, which translates to HURRICANE. 21. If l is the distance between the beginnings of the string that occurs several times, then it may be likely that the length of the key string is a factor of l. Thus if we have several such values of l, we can find their greatest common divisor and assume that the length of the key string is a factor of this gcd. 23. Suppose that we know n = pq and (p - 1) (q - 1), and we wish to find p and q. Here is how we do so. Expanding (p - 1)( q - 1) algebraically we obtain pq - p - q + 1 = n - p - q + 1. Thus we know the value of n - p - q + 1, and so we can easily calculate the value of p + q (since we know n). But we also know the value of pq, namely n. This gives us two simultaneous equations in two unknowns, and we can solve them using the quadratic formula. Here is an example. Suppose that we want to factor n = 341, and we are told that (p - 1) (q - 1) = 300. We want to find p and q. Following the argument just outlined, we know that p + q = 341 + 1 - 300 = 42. Plugging q = 42 - p into pq = 341 we obtain p( 42 - p) = 341, or p 2 - 42p + 341 = 0. The quadratic formula then tells us that p = (42 + .J42 2 - 4 · 341) /2 = 31, and so the factors are 31 and 42 - 31 = 11. Note that absolutely no trial divisions were involved here-it was just straight calculation. Chapter 4 142 Number Theory and Cryptography 25. First we translate UPLOAD into numbers: 2015 1114 0003. For each of these numbers, which we might call M, we need to compute C =Me mod n = M 17 mod 3233. Note that n = 53 · 61 = 3233 and that gcd(e, (p 1) (q - 1)) = gcd(l 7, 52 · 60) = 1, as it should be. A computational aid tells us that 2015 17 mod 3233 = 2545, 1114 17 mod 3233 = 2757, and 0003 17 mod 3233 = 1211. Therefore the encrypted message is 2545 2757 1211. 27. This problem requires a great amount of calculation. Ideally, one should do it using a computer algebra package, such as Mathematica or Maple. Let us follow the procedure outlined in Example 9. It was computed there that the inverse of e = 13 modulo n = 43·59 is d = 937. We need to compute 0667937 mod 2537 = 1808, 1947937 mod 2537 = 1121, and 0671 937 mod 2537 = 0417. (These calculations can in principle be done with a calculator, using the fast modular exponentiation algorithm, but it would probably take the better part of an hour and be prone to transcription errors.) Thus the original message is 1808 1121 0417, which is easily translated into letters as SILVER. 29. We follow the steps given in the text, with p = 23, a= 5, k 1 = 8, and k 2 = 5. Using Maple, we verify that 5 is a primitive root modulo 23, by noticing that 5k as k runs from 0 to 21 produce distinct values (and of course 522 mod 23 = 1 ). We find that 58 mod 23 = 16. So in Step (2), Alice sends 16 to Bob. Similarly, in Step (3), Bob sends 55 mod 23 = 20 to Alice. In Step (4) Alice computes 20 8 mod 23 = 6, and in Step (5) Bob computes 165 mod 23 = 6. These are the same, of course, and thus 6 is the shared key. 31. See Example 10 for the procedure. First Alice translates her message into numbers: 1804 1111 0421 0417 2419 0708 1306. She then applies her decryption transformation sending each block x to x 1183 mod 2867. (We should verify with Maple that 7 · 1183 mod (60 · 46) = 1.) Using Maple, we see that the blocks become 1804 1183 mod 2867 = 2186, 1111 1183 mod 2867 = 2087, 0421 1183 mod 2867 = 1279, 0417 1183 mod 2867 = 1251, 2419 1183 mod 2867 = 0326, 0708 1183 mod 2867 = 0816, and 1306 1183 mod 2867 = 1948. If her friends apply Alice's encryption transformation to 2186 2087 1279 1251 0326 0816 1948, they will obtain the numbers of her original message. 33. Cathy knows the shared key kAlice,Bob, but because she transmitted it to Alice encrypted, no one else knows it at the time Alice receives it. Alice can decrypt the first part of Cathy's message to find out what the key is. When Alice sends the second part of Cathy's message, which consists of kAlice.Bob encrypted with Bob's key, on to Bob, Bob can decrypt it to find the shared key, but it remains hidden from everyone else. GUIDE TO REVIEW QUESTIONS FOR CHAPTER 4 1. Dividing 210 by 17 gives a quotient of 12 and a remainder of 6, which are the respective requested values. 2. a) 7 a - b J c) (10a + 13) - b) 0 =-7; -1 =-8; 3 =17 =-11 (-4b + 20) = 3(a - b) + 7(a + b - 1); note that 7 divides both terms 3. See Theorem 5 in Section 4.1. 4. See Example 5 in Section 4.2. 5. Octal: 154533; hexadecimal: D95B 6. 1110 1000 0110 and 1010 0000 1110 1011 7. See p. 258. 8. a) See Example 4 in Section 4.3 and the preceding paragraph on p. 258. b) 11 2 . 23 . 29 Supplementary Exercises 143 9. a) See p. 265. b) find all the common factors (not a good algorithm unless the numbers are really small); find the prime factorization of each integer (works well if the numbers aren't too big and therefore can be easily factored); use the Euclidean algorithm (really the best method) c) 1 (use the Euclidean algorithm) d) 23 35 55 73 10. a) Use the Euclidean algorithm; see Example 17 in Section 4.3. b) 7 = 5 . 119 - 7. 84 11. a) aa = 1 (mod m) b) Express 1 as sa + tm (see Review Question 10). Then s is the inverse of a modulo m. c) 11 12. a) Multiply each side by the inverse of a modulo m. 13. a) See p. 278. b) { 17 + l40k I k E b) { 10 + 19k I k E z} z} 14. No; n could be a pseudoprime such as 341. 15. 9200 = 918 . 92 . 9180 = 918 . 92 . (918)20 =1 . 81 . 120 = 81 = 5 (mod 19) 16. See Example 6 in Section 4.5. 17. NCCYRF NAQ BENATRF 18. a) See p. 298. b) The amount of shift, k, is kept secret. It is needed both to encode and to decode messages. c) Although the key for decoding, d, is kept secret, the keys for encoding, n and e, are published. 19. See pp. 299-301. 20. See p. 302. SUPPLEMENTARY EXERCISES FOR CHAPTER 4 = 46518, we can conclude that the number of miles is congruent to 46,518 modulo 100,000. So it is 46518+ lOOOOOk for some natural number k (the number of miles driven cannot be negative). Thus the actual number of miles driven is 46,518 or 146,518, or 246,518, or .... 1. Because 89697 - 43179 3. Obviously there are an infinite number of possible answers. The numbers congruent to 5 modulo 17 include 5, 22, 39, 56, ... , as well as -12, -29, -46, .... = 5. From the hypothesis ac be (mod m) we know that ac - be = km for some integer k. Divide both sides by c to obtain the equation a - b = (km)/c. Now the left-hand side is an integer, and so the right-hand side must be an integer as well. In other words, cJkm. Letting d = gcd(m,c), we write c =de. Then the way that c divides km is that d Im and e I k (since no factor of e divides m/d). Thus our equation reduces to a - b = (k/e)(m/d), where both factors on the right are integers. By definition, this means that a= b (mod m/d). 7. We give an indirect proof. If n is odd, then n = 2k + 1 for some integer k. Therefore n 2 +1 = (2k + 1) 2 +1 = 4k 2 + 4k + 2 = 2 (mod 4). But perfect squares of even numbers are congruent to 0 modulo 4 (because (2m) 2 = 4m 2 ), and perfect squares of odd numbers are odd, so n 2 + 1 is not a perfect square. Chapter 4 144 Number Theory and Cryptography 9. The contribution of the digit in the kth column from the right in the binary expansion of a positive integer is 2k, where we consider the units digit to be 0 columns from the right. Therefore for k 2: 3, the contribution is divisible by 23 = 8. Any sequence of three digits other than 000 in the three right-most columns will contribute between 1 and 7, causing the number not to be divisible by 8. Thus a positive integer written in binary is divisible by 8 if and only if its last three digits are 000. 11. We assume that someone has chosen a positive integer less than 2n, which we are to guess. We ask the person to write the number in binary, using leading O's if necessary to make it n bits long. We then ask "Is the first bit a 1 ?", ·'Is the second bit a 1 ?", "Is the third bit a 1 ?", and so on. After we know the answers to these n questions, we will know the number, because we will know its binary expansion. 13. Without loss of generality, we may assume that the given integer is positive (since n I a if and only if n 1(-a), and the case a= 0 is trivial). Let the decimal expansion of the integer a be given by a= (an-ian_ 2 ... a 1a 0 )i 0 . Thus a= 10n-lan-l + 10n- 2an-2 + · · · + lOa1 + ao. Since a 1 + a 0 (mod 9). Therefore a 0 (mod 9) if and only if Since being divisible by 9 is the same as being congruent divisible by 9 if and only if the sum of its decimal digits is = 15. Note that Qn a factor of n! of Qn. Thus factors of Qn 10 = 1 (mod 9), we have a= an-1 + an-2 + · · · + the sum of the digits is congruent to 0 (mod 9). to 0 (mod 9), we have proved that an integer is divisible by 9. 2: 2. By the Fundamental Theorem of Arithmetic, Qn has a prime factorization. Because k is for all k ::;: n, when Qn is divided by k the remainder will be 1; therefore k is not a factor Qn must have a prime factor greater than n. (We have shown that in fact all of the prime will be greater than rz.) 17. The numbers whose decimal expansion ends in 1 are precisely those integers in the arithmetic progression lOk + 1. Dirichlet's theorem guarantees that this sequence includes infinitely many primes. The first few are 11, 31, 41, 61, 71, 101, 131, .... 19. Note that even numbers greater than 2 are composite and that 9 is composite. Therefore every odd number greater than 11 is the sum of two composite numbers (13 = 4 + 9, 15 = 6 + 9, 17 = 8 + 9, and so on). Similarly, because 8 is composite, so are all even numbers greater than 11: 12 = 4 + 8, 14 = 6 + 8, 16 = 8 + 8, and so on. 21. Assume that every even integer greater than 2 is the sum of two primes, and let n be an integer greater than 5. If n is odd, then we can write n = 3 + (n - 3), decompose n - 3 = p + q into the sum of two primes (since rz - 3 is an even integer greater than 2), and therefore have written n = 3 + p + q as the sum of three primes. If n is even, then we can write n = 2 + (n - 2), decompose n - 2 = p + q into the sum of two primes (since n - 2 is an even integer greater than 2), and therefore have written n = 2 + p + q as the sum of three primes. For the converse, assume that every integer greater than 5 is the sum of three primes, and let n be an even integer greater than 2. By our assumption we can write n + 2 as the sum of three primes. Since n + 2 is even, these three primes cannot all be odd, so we have n + 2 = 2 + p + q, where p and q are primes, whence n = p + q, as desired. 23. We give a proof by contradiction. For this proof we need a fact about polynomials, namely that a nonconstant polynomial can take on the same value only a finite number of times. (Think about its graph~a polynomial of degree rz has at most n "wiggles'' and so a horizontal line can intersect it at most n times. Alternatively, this statement follows from the Fundamental Theorem of Algebra, which guarantees that a polynomial of degree n has at most n O's; if f (x) = a, then x is a zero of the polynomial f (x) - a.) Our given polynomial f can take on the values 0 and ±1 only finitely many times, so if there is not some y such that f(y) is composite, Supplementary Exercises 145 then there must be some x 0 such that ±f(xo) is prime, say p. Now look at f(xo + kp). When we plug x 0 + kp in for x in the polynomial and multiply it out, every term will contain a factor of p except for the terms that form f (x 0 ) . Therefore f (x 0 + kp) = f ( Xo) + mp = (m ± 1 )p for some integer m. As k varies, this value can be 0 or p or -p only finitely many times; therefore it must be a different multiple of p and therefore a composite number for some values of k, and our proof is complete. 25. gcd(10223, 33341) = gcd(10223, 2672) = gcd(2672, 2207) = gcd(2207, 465) = gcd( 465, 347) = gcd(347, 118) = gcd(118,111) = gcd(lll, 7) =gcd(7,6) = gcd(6,1) =gcd(l,O) = 1 27. By Lemma 1 in Section 4.3, gcd(2n + 1, 3n + 2) = gcd(2n + 1, n + 1), since 2n + 1 goes once into 3n + 2 with a remainder of n + 1. Now if we divide n + 1 into 2n + 1, we get a remainder of n, so the answer must equal gcd(n + 1, n). At this point, the remainder when dividing n into n + 1 is 1, so the answer must equal gcd( n, 1), which is clearly 1. Thus the answer is 1. 29. It might be helpful to read the solution to Exercise 55 in Section 4.3 to see the philosophy behind this approach. Suppose by way of contradiction that q1 , q2 , ... , qn are all the primes of the form 6k + 5. Thus q1 = 5, q2 = 11, and so on. Let Q = 6q1q2 · · · qn - l. We note that Q is of the form 6k + 5, where k = q1q2 · · · qn - l. Now Q has a prime factorization Q = P1P2 · ··Pt. Clearly no Pi is 2, 3, or any q1 , because the remainder when Q is divided by 2 is 1, by 3 is 2, and by q1 is q1 - 1. All odd primes other than 3 are of the form 6k + 1 or 6k + 5, and the product of primes of the form 6k + 1 is also of this form. Therefore at least one of the Pi 's must be of the form 6k + 5, a contradiction. 31. Let's try the strategy used in the proof of Theorem 3 in Section 4.3. Suppose that P1, P2, ... , Pn are the only primes of the form 4k + 1. Notice that the product of primes of this form is again of this form, because (4k1+1) (4k2 + 1) = l6k1k2 + 4k1+4k2+1 = 4( 4k1k2 + k1+k2)+1. We could try looking at 4p1p2 · · · Pn + 1, which is again of this form. By the Fundamental Theorem of Arithmetic, it has prime factors, and clearly no Pi is a factor. Unfortunately, we cannot be guaranteed that any of its prime factors are of the form 4k + 1, because the product of two odd primes not of this form, namely of the form 4k + 3, is of the form 4k + 1; indeed, (4k1 +3)(4k2 + 3) = l6k 1k2 + 12k1 + 12k2 + 9 = 4( 4k1k2 + 3k1 + 3k2 + 2) + 1. Thus the proof breaks down at this point. 33. a) Since 2 is a factor of all three of these integers, this set is not mutually relatively prime. b) Since 12 and 25 share no common factors, this set has greatest common divisor 1, so it is mutually relatively prime. (It is possible for every pair of integers in a set of mutually relatively prime integers to have a nontrivial common factor (see Exercise 34), but certainly if two of the integers in a set are relatively prime, then the set is automatically mutually relatively prime.) c) Since 15 and 28 share no common factors, this set has greatest common divisor 1, so it is mutually relatively prime. d) Since 21 and 32 share no common factors, this set has greatest common divisor 1, so it is mutually relatively prime. 35. If n is even, then n 4 +4n is an even composite number, so we can restrict ourselves to n odd. The appearance of 4 suggests that we might work modulo 5, so let's try that. If n is not divisible by 5, then n 4 = 1 (mod 5) by Fermat's little theorem, and since n is odd, 4n (-l)n = -1 (mod 5). Therefore n 4 +4n is divisible by 5. So except for n = 1, in which case n 4 +4n = 5 is prime, the only possible values of n that can result in a prime value for n 4 + 4n are 5, 15, 25, and so on. Maple tells us that 54 + 4 5 = 17 · 97, 15 4 + 4 15 = 36833 · 29153, and 25 4 + 4 25 = 29 · 373 · 3121·33350257. So let us try to factor n 4 + 4n algebraically. It is not at all obvious how to discover these factors, but if we multiply out = 146 Chapter 4 Number Theory and Cryptography we get n 4 + 4n. (Because n is odd, the exponent nt 1 is an integer.) It only remains to show that each of these factors is greater than 1. The first is clearly so. The second factor takes on the values 5, 17, 65, and n+l 305 for n = 3, 5, 7, and 9, respectively. Clearly for large n the 2n term far exceeds the -2-2-n term, and our proof is complete. 37. The least common multiple of 6 and 15 is 30, so the set of solutions will be given modulo 30 (see Exercise 38). Since the numbers involved here are so small, it is probably best simply to write down the solutions of x = 4 (mod 6) and then see which, if any, of them are also solutions of x = 13 (mod 15). The solutions of the first congruence, up to 30, are 4, 10, 16, 22, and 28. Only 28 is congruent to 13 modulo 15. Therefore the general solution is all numbers congruent to 28 modulo 30, i.e., ... , -32, -2, 28, 58, .... 39. Maple tells us that this is true, namely that n 9 - n mod 30 = 0 for all n (we need only check n from 0 to 29). For a more human-oriented proof (conceptual rather than computational), notice that it suffices to show that n 9 - n 0 (mod 2), n 9 - n 0 (mod 3), and n 9 - n 0 (mod 5). The first is obvious (odd minus odd, and even minus even, are both even). The second follows from Fermat's little theorem, because n 9 = (n 3) 3 n 3 n (mod 3). The third also follows from that theorem, because n 9 = n 4 · n 5 1 · n n (mod 5). = = = = = = = (mod q) and clearly qP- 1 = O (mod q). Therefore pq-l + qP- 1 1+0 = 1 (mod q). Similarly, pq-l + qP-l = 1 (mod p). It follows from the Chinese remainder theorem that pq-l + qP-l = 1 (mod pq). 41. By Fermat's little theorem, pq-l =1 43. Because 1 and 3 are both relatively prime to 10, if the congruence is satisfied by the correct ISBN-13, it cannot be satisfied if one of the digits is changed. In particular, if a, is changed from x to y, then the change in the left-hand side of the congruence is either y - x or 3(y - x), modulo 10, neither of which can be 0. Therefore the sum can no longer be 0 modulo 10. 45. Subtract d9 from both sides of the congruence and multiply through by -1 to obtain This is equivalent to 7(d1 + d4 + d7) + 3(d2 + ds + ds) + 9(d3 + d5) =dg (mod 10). Because 0:::; dg :::; 9, it follows that dg = 7(d1 + d4 + d7) + 3(d2 + d5 + ds) + 9(d3 + d5) mod 10. We calculate with the given eight digits to conclude that d 9 = 7(1+0+0)+3(1+0+2)+9(1+0) mod 10 = 25 mod 10 = 5. 4 7. We need to find the inverse function. In other words, given (ap + b) mod 26, how does one recover p? Working modulo 26, if we subtract b, then we will have ap. If we then multiply by an inverse of a (which must exist since we are assuming that gcd( a, 26) = 1), we will have p back. Therefore the decryption function is g( q) = a( q - b) mod 26, where a is an inverse of a modulo 26. In this case, a = 7 and b = 10. Computing the inverse of 7 modulo 26 by the techniques of Section 4.4 (or by using Maple), we find a= 15, so the decryption function is g(q) = 15(q-10) mod 26. Translating the letters into numbers, we see that the encrypted message is 11-9-12-10-6 12-6-12-23-5 16-4-23-12-22. Applying this function, we obtain the decrypted message 15-11-4-0-18 4-18-4-13-3 12-14-13-4-24. This translates into PLEAS ESEND MONEY, which, after correcting the spacing, is PLEASE SEND MONEY. 49. a) The seed is 23 (X); adding this to the first character of the plaintext, 19 (T), gives 16, which is Q. Therefore the first character of the ciphertext is Q. The next character of the keystream is the aforementioned T (19); add this to H (7) to get 0 (A), so the next character of the ciphertext is A. We continue in this manner, producing the encrypted message QAL HUVEM AT WVESGB. Writing Projects 147 b) Again the seed is 23 (X); adding this to the first character of the plaintext, 19 (T), gives 16, which is Q. Therefore the first character of the ciphertext is Q. The next character of the keystream is the aforementioned Q (16); add this to H (7) to get 23 (X), so the next character of the ciphertext is X. We continue in this manner, producing the encrypted message QXB EVZZL ZEVZZRFS. WRITING PROJECTS FOR CHAPTER 4 Books and articles indicated by bracketed symbols below are listed near the end of this manual. You should also read the general comments and advice you will find there about researching and writing these essays. 1. As usual, the Web is an excellent resource here. www.mersenne.org/prime.htm. Check out the GIMPS page and then follow its links: 2. These primes are sometimes jokingly referred to as "industrial strength primes." Number theory textbooks, such as [Ro3], would be a place to start. See also the article [Le3]. 3. One can often find mathematical news reported in The New York Times and other nontechnical media. Search an index to find a story about this topic. (While you're looking at back issues of the Times, read the January 31, 1995, article on the solution to Fermat's last theorem.) 4. Your essay should mention the RSA-129 project. See The New York Times, around the spring of 1994 (use its index). For an expository article, try [Po]. 5. There are dozens of books on computer hardware and circuit design that discuss the algorithms and circuits used in performing these operations. If you are a computer science or computer engineering major, you probably have taken (or will take) a course that deals with these topics. See [Ko2] and similar books. 6. A traditional history of mathematics book should be helpful here; try [Bo4] or [Ev3]. 7. This topic has taken on a lot of significance recently as randomized algorithms become more and more important. The August/September 1994 issue of SIAM News (the newsletter of the Society for Industrial and Applied Mathematics) has a provocative article on the subject. See also [Lal], or for older material in a textbook try volume 2 of [Kn]. 8. The Web has the answers. Try www. skynet. iermartin/pages/iban.html or Wikipedia. 9. The Web has the answers. 10. The author's number theory text ([Ro3]) has material on this topic. The amazing mathematician John H. Conway (inventor of the Game of Life, among other things) has devised what he calls the Doomsday Algorithm, and it works quite fast with practice. See [BeCo]. (Conway can determine any day of the week mentally in a second or two.) 11. This topic gets into the news on a regular basis. Try The New York Times index. See also Writing Project 4, above, and 12, below. 12. If I encrypt my signature with my private key, then I will produce something that will decrypt (using my public key) as my signature. Furthermore, no one else can do this, since no one else knows my private key. Good sources for cryptography include [Be], [MeOo], and [St2]. Chapter 4 148 Number Theory and Cryptography 13. Several excellent books have appeared in the past decade on cryptography, such as [MeOo]. Many of them, including that one, will treat this topic. 14. Suppose that we use a prime for n. To find a private decryption key from the corresponding public encryption key e, one would need to find a number d that is an inverse for e modulo n - 1 so that the calculation shown before Example 9 in Section 4.6 can go through. But finding such a d is easy using the Euclidean algorithm, because the person doing this would already know n - 1. (In particular, to find d, one can work backward through the steps of the Euclidean algorithm to express 1 as a linear combination of e and n - 1 ; then d is the coefficient of e in this linear combination.) The important point in the actual RSA system is that the person trying to find this inverse will not know (p - l)(q - 1) and therefore cannot simply use the Euclidean algorithm. 15. Start with Wikipedia. Section 5.1 Mathematical Induction 149 CHAPTERS Induction and Recursion SECTION 5.1 Mathematical Induction Understanding and constructing proofs by mathematical induction are extremely difficult tasks for most students. Do not be discouraged, and do not give up, because, without doubt, this proof technique is the most important one there is in mathematics and computer science. Pay careful attention to the conventions to be observed in writing down a proof by induction. As with all proofs, remember that a proof by mathematical induction is like an essay-it must have a beginning, a middle, and an end; it must consist of complete sentences, logically and aesthetically arranged; and it must convince the reader. Be sure that your basis step (also called the "base case") is correct (that you have verified the proposition in question for the smallest value or values of n ), and be sure that your inductive step is correct and complete (that you have derived the proposition for k + 1, assuming the inductive hypothesis that the proposition is true for k ). Some, but not all, proofs by mathematical induction are like Exercises 3~17. In each of these, you are asked to prove that a certain summation has a "closed form" representation given by a certain expression. Here the proofs are usually straightforward algebra. For the inductive step you start with the summation for P(k + 1), find the summation for P(k) as its first k terms, replace that much by the closed form given by the inductive hypothesis, and do the algebra to get the resulting expression into the desired form. When doing proofs like this, however, remember to include all the words surrounding your algebra-the algebra alone is not the proof. Also keep in mind that P(n) is the proposition that the sum equals the closed-form expression, not just the sum and not just the expression. Many inequalities can be proved by mathematical induction; see Exercises 18~24, for example. The method also extends to such things as set operations, divisibility, and a host of other applications; a sampling of them is given in other exercises in this set. Some are quite complicated. One final point about notation. In performing the inductive step, it really does not matter what letter we use. We see in the text the proof of P( k) ----+ P( k + 1) ; but it would be just as valid to prove P( n) ----+ P( n + 1), since the k in the first case and the n in the second case are just dummy variables. l-Ve will use both notations in this Guide; in particular, we wi1l use k for the first few exercises but often use n afterwards. A student just beginning to write proofs by mathematical induction should be even more formal than we are in this Guide and follow the template given at the end of this section. With experience, you can relax a bit and the style can become more informal, as long as all the steps are there. 1. We can prove this by mathematical induction. Let P( n) be the statement that the train stops at station n. We want to prove that P(n) is true for all positive integers n. For the basis step, we are told that P(l) is true. For the inductive step, we are told that P(k) implies P(k + 1) for each k 2 1. Therefore by the principle of mathematical induction, P( n) is true for all positive integers 11. 3. a) Plugging in n = 1 we have that P(l) is the statement 12 = 1 · 2 · 3/6. b) Both sides of P(l) shown in part (a) equal 1. c) The inductive hypothesis is the statement that 12 + 22 + ... + k2 = k(k + 1)(2k + 1). 6 Chapter 5 150 Induction and Recursion d) For the inductive step, we want to show for each k 2'. 1 that P(k) implies P(k + 1). In other words, we want to show that assuming the inductive hypothesis (see part ( c)) we can show 12+22+ .. ·+k2+(k+l)2= (k+l)(k+2)(2k+3). 6 e) The left-hand side of the equation in part (d) equals, by the inductive hypothesis, k(k + 1)(2k + 1)/6 + (k + 1) 2 . We need only do a bit of algebraic manipulation to get this expression into the desired form: factor out (k + 1)/6 and then factor the rest. In detail, k(k + 1)(2k + 1) + (k + 1) 2 (by the inductive hypothesis) (1 2 + 22 + · · · + k2) + (k + 1) 2 = 6 1 1 (2k 2 +7k + 6) = (k(2k+1) + + 1)) = k; 6(k k; = k + 1(k+2)(2k + 3) = (k + l)(k + 2)(2k + 3) . 6 6 f) We have completed both the basis step and the inductive step, so by the principle of mathematical induction, the statement is true for every positive integer n. 5. We proceed by induction. The basis step, n = 0, is true, since 12 = 1·1 · 3/3. For the inductive step assume the inductive hypothesis that 12+32+52+ .. ·+(2k+1)2= (k+1)(2k+1)(2k+3). 3 We want to show that 12 + 32 + 52+ ... +(2k+1)2 + (2k + 3)2 = (k + 2)(2k + 3)(2k + 5) 3 (the right-hand side is the same formula with k + 1 plugged in for n ). Now the left-hand side equals, by the inductive hypothesis, (k + 1)(2k + 1)(2k + 3)/3 + (2k + 3) 2 . We need only do a bit of algebraic manipulation to get this expression into the desired form: factor out (2k + 3)/3 and then factor the rest. In detail, (1 2 + 32 + 52 + ... +(2k+1) 2) + (2k + 3) 2 (k + 1)(2k + 1)(2k + 3) . . . + (2k + 3) 2 (by the mduct1ve hypothesis) 3 2 2 3 3 = k: ((k+1)(2k+1)+3(2k+3)) = k: (2k 2 +9k+10) = = 2k+3((k+2)(2k+5)) = (k+2)(2k+3)(2k+5). 3 3 7. Let P(n) be the proposition 3 + 3 · 5 + 3 · 52 + · · · + 3 · 5n = 3(5n+l - 1)/4. To prove that this is true for all nonnegative integers n, we proceed by mathematical induction. First we verify P(O), namely that 3 = 3(5 -1)/4, which is certainly true. Next we assume that P(k) is true and try to derive P(k + 1). Now P(k + 1) is the formula 3(5k+ 2 - 1) 3 + 3. 5 + 3. 52 + ... + 3. 5k + 3. 5k+l = . 4 All but the last term of the left-hand side of this equation is exactly the left-hand side of P(k), so by the inductive hypothesis, it equals 3(5k+l - 1)/4. Thus we have 3(5k+l - 1) 3 + 3 · 5 + 3 · 52 + · · · + 3 · 5k + 3 · 5k+I = + 3 · 5k+l 4 = 5k+l (~ + 4 3) - ~ 4 = 5k+l . 15 - ~ 4 4 = 5k+2. ~ - ~ = 3(5k+2 - 1) . 4 4 4 Section 5.1 Mathematical Induction 151 9. a) We can obtain a formula for the sum of the first n even positive integers from the formula for the sum of the first n positive integers, since 2 + 4 + 6 + · · · + 2n = 2(1+2 + 3 + · · · + n). Therefore, using the result of Example 1, the sum of the first n even positive integers is 2(n(n + 1)/2) = n(n + 1). b) We want to prove the proposition P( n) : 2 + 4 + 6 + · · · + 2n = n( n + 1). The basis step, n = 1, says that 2 = 1·(1+1), which is certainly true. For the inductive step, we assume that P(k) is true, namely that 2 + 4 + 6 + ... + 2k = k(k + 1)) and try to prove from this assumption that P(k + 1) is true, namely that 2 + 4 + 6 + ... + 2k + 2(k + 1) = (k + l)(k + 2). (Note that the left-hand side consists of the sum of the first k + 1 even positive integers.) We have 2 + 4 + 6 + ... + 2k + 2(k + 1) = (2 + 4 + 6 + ... + 2k) + 2(k + 1) = k(k + 1) + 2(k + 1) (by the inductive hypothesis) =(k+l)(k+2), as desired, and our proof by mathematical induction is complete. 11. a) Let us compute the values of this sum for n :S 4 to see whether we can discover a pattern. For n = 1 the sum is ~ . For n = 2 the sum is ~ + :j = ~ . For n = 3 the sum is ~ + :j + ~ = £. And for n = 4 the sum is 15/16. The pattern seems pretty clear, so we conjecture that the sum is always (2n - 1)/2n. b) We have already verified that this is true in the base case (in fact, in four base cases). So let us assume it for k and try to prove it for k + 1. More formally, we are letting P(n) be the statement that 1 1 1 1 2n - 1 -+-+-+···+- = - - . 2 4 8 2n 2n ' and trying to prove that P(n) is true for all n. We have already verified P(l) (as well as P(2), P(3), and P(4) for good measure). We now assume the inductive hypothesis P(k), which is the equation displayed above with k substituted for n, and must derive P( k + 1), which is the equation 1 1 1 2+ 4+ 8+ 1 1 2k+l - 1 ... + 2k + 2k+l = 2k+l The "obvious" thing to try is to add l/2k+l to both sides of the inductive hypothesis and see whether the algebra works out as we hope it will. We obtain 1 1 1 1) 1 2k - 1 1 2 . 2k - 2 . 1 + 1 2k+i - 1 2k+l = 2k+l ' ( 2 + 4 + S + ... + 2k + 2k+l = 2 k + 2k+l = as desired. 13. The base case of the statement P(n): 12 -2 2 +3 2 - ··· + (-1r- 1n 2 =(-1r- 1n(n+1)/2, when n = 1, is 12 = (-1) 0 · l · 2/2, which is certainly true. Assume the inductive hypothesis P(k), and try to derive P(k+ 1): 12 - 22 + 32 - ... + ( -1 )k-1 k2 + (-1 l (k + 1)2 = (-1 )d k + 1) (k + 2) 2 . Starting with the left-hand side of P(k + 1), we have (12 - 22 + 32 - ... + (-l)k-lk2) + (-l)k(k + 1)2 = (-l)k-l k(k + l) + (-l)k(k + 1) 2 (by the inductive hypothesis) 2 = (-l)k(k + 1)((-k/2) + k + 1) =(-l)k(k+1)(~+1) the right-hand side of P(k + 1). =(-lt(k+1)2(k+2)' 152 Chapter 5 Induction and Recursion 15. The base case of the statement P(n): 1·2+2 · 3 + · · · + n(n + 1) = n(n + l)(n + 2)/3, when n = 1, is 1 · 2 = 1 · 2 · 3/3, which is certainly true. We assume the inductive hypothesis P( k), and try to derive P( k + 1): 1. 2 + 2. 3 + ... + k(k + 1) + (k + l)(k + 2) = (k + l)(k + 2)(k + 3) Starting with the left-hand side of P(k 3 + 1), we have (1. 2 + 2. 3 + ... + k(k + 1)) + (k + l)(k + 2) 2 = k(k + l)(k + ) + (k + l)(k + 2) 3 (by the inductive hypothesis) =(k+l)(k+2)(~+1) = (k+l)(k;2)(k+3)' the right-hand side of P(k + 1). 17. This proof follows the basic pattern of the solution to Exercise 3, but the algebra gets more complex. The statement P( n) that we wish to prove is 4 4 4 1 + 2 + 3 + · .. +n 4 = n(n+1)(2n+l)(3n 2 +3n-l) 30 ' where n is a positive integer. The basis step, n = 1, is true, since 1 · 2 · 3 · 5/30 = 1. Assume the displayed statement as the inductive hypothesis, and proceed as follows to prove P(n + 1): 2 (14 + 24 +· .. +n4) + ( n+ l) 4 = n(n+l)(2n+1)(3n +3n-l) + (n+l )4 30 n+l = 3() (n(2n + 1)(3n 2 + 3n - 1) + 30(n + 1) 3 ) n+l 4 3 2 = ----W-(6n + 39n + 9ln + 89n + 30) n+l = ----W-(n + 2)(2n + 3)(3(n + 1) 2 + 3(n + 1) -1) The last equality is straightforward to check; it was obtained not by attempting to factor the next to last expression from scratch but rather by knowing exactly what we expected the simplified expression to be. 19. a) P(2) is the statement that 1 + ~ < 2 - ~. b) This is true because 5 / 4 is less than 6 / 4. c) The inductive hypothesis is the statement that 1 1 1 1 + 4 + ... + k2 < 2 - k . d) For the inductive step, we want to show for each k 2: 2 that P(k) implies P(k want to show that assuming the inductive hypothesis (see part ( c)) we can show + 1). 1 1 1 1 1 + 4 + ... + k 2 + (k + 1) 2 < 2 - k + 1. e) Assume the inductive hypothesis. Then we have 1 1 1 1 1 l+4+·"+ k 2 + (k+1) 2 < 2 -k+ (k+1) 2 = 2 -(~- (k~1)2) = 2 - ( k + 2k + 1 - k) 2 k(k + 1) 2 k +k 1 =2---k(k + 1)2 k(k + 1)2 1 1 1 =2---<2--k+l k(k+1) 2 k+l' 2 In other words, we Section 5.1 Mathematical Induction 153 f) We have completed both the basis step and the inductive step, so by the principle of mathematical induction, the statement is true for every positive integer n greater than 1. 21. Let P( n) be the proposition 2n > n 2 . We want to show that P( n) is true for all n > 4. The base case is therefore n = 5, and we check that 25 = 32 > 25 = 52 . Now we assume the inductive hypothesis that 2k > k 2 and want to derive the statement that 2k+l > (k + 1) 2 . Working from the right-hand side, we have (k + 1) 2 = k 2 +2k+1 3). Thus we have (k + 1) 2 < 2k 2 < 2 · 2k (by the inductive hypothesis), which in turn equals 2k+l , as desired. 23. We compute the values of 2n + 3 and 2n for the first few values of n and come to the immediate conjecture that 2n + 3 :S:: 2n for n 2: 4 but for no other nonnegative integer values of n. The negative part of this statement is just the fact that 3 > 1, 5 > 2, 7 > 4, and 9 > 8. We must prove by mathematical induction that 2n + 3::; 2n for all n;::: 4. The base case is n = 4, in which we see that, indeed, 11::; 16. Next assume the inductive hypothesis that 2n + 3::; 2n, and consider 2(n + 1) + 3. This equals 2n + 3 + 2, which by the inductive hypothesis is less than or equal to 2n + 2. But since n ;::: 1, this in turn is at most 2n + 2n = 2n+l, precisely the statement we wished to prove. 25. We can assume that h > -1 is fixed, and prove the proposition by induction on n. Let P( n) be the proposition 1 + nh ::; (1 +hr. The base case is n = 0, in which case P(O) is simply 1 ::; 1, certainly true. Now we assume the inductive hypothesis, that 1 + kh :S:: (1 + h)k; we want to show that 1 + (k + l)h :S:: (1 + h)k+l. Since h > -1, it follows that 1 + h > 0, so we can multiply both sides of the inductive hypothesis by 1 + h to obtain (l+h)(l+kh)::; (l+h)k+l. Thus to complete the proof it is enough to show that l+(k+l)h::; (l+h)(l+kh). But the right-hand side of this inequality is the same as 1 + h + kh + kh 2 = 1 + (k + l)h + kh 2 , which is greater than or equal to 1 + (k + l)h because kh 2 ;::: 0. 27. This exercise involves some messy algebra, but the logic is the usual logic for proofs using the principle of mathematical induction. The basis step ( n = 1) is true, since 1 is greater than 2( V2 - 1) ~ 0.83. We assume that 1 1 + _!_ + ... + - - > 2(v'n+l - 1) Vn y'2 and try to derive the corresponding statement for n + 1: 1 1 1 1 + - + .. · + - + V2 Since by the inductive hypothesis we know that 1 1 1+-+···+-+ V2 VnTI Vn Vn 1 VnTI >2(vn+2-1) >2(vn+1-1)+ 1 VnTI , we will be finished if we can show that the inequality 2(Vri+T-1)+ ~>2(vn+2-1) n+l holds. By canceling the -2 from both sides and rearranging, we obtain the equivalent inequality 2(vn+2-vn+i) < k· n+l which in turn is equivalent to ~ ~ ~ ~ 2(vn-r..::-vn+l)(vn+2+vn+l) VnTI Jn+2 n+l < Vn+T+ Vn+T. n+l This last inequality simplifies to Vn+2 2<1+ ~' vn+ 1 which is clearly true. Therefore the original inequality is true, and our proof is complete. 154 Chapter 5 Induction and Recursion 29. Recall that Hk = 1/1+1/2 + · · · + l/k. We want to prove that H2n:::; 1 + n for all natural numbers n. We proceed by mathematical induction, noting that the basis step n = 0 is the trivial statement H 1 = 1 :::; 1+0. Therefore we assume that H2n :::; 1 + n; we want to show that H 2 n+1 :::; 1+(n+1). We have H 2 n+1 = :::; < = 1 1 1 + - - - + - - - + · · · + - -1 (by definition; there are 2n fractions here) 2n + 1 2n + 2 2n+ 1 1 1 (1 + n) + n + + n + + · · · + n+l (by the inductive hypothesis) 2 1 2 2 2 1 1 1 (1 + n) + - - + - - - + · · · + - - - (we made the denominators smaller) 2n + 1 2n + 1 2n + 1 2n 1 + n + - - < 1+n+1=1+(n+1). 2n + 1 H2n 31. This is easy to prove without mathematical induction, because we can observe and either n or n + 1 is even. If we want to use the principle of mathematical as follows. The basis step is the observation that 12 + 1 = 2 is divisible by hypothesis, that k2 + k is divisible by 2; we must show that (k + 1) 2 + (k + that n 2 + n = n(n + 1), induction, we can proceed 2. Assume the inductive 1) is divisible by 2. But (k + 1) 2 +(k+1) = k2 +2k+1+k+1 = (k 2 + k) + 2(k + 1). But now k2 + k is divisible by 2 by the inductive hypothesis, and 2(k + 1) is divisible by 2 by definition, so this sum of two multiples of 2 must be divisible by 2. 33. To prove that P(n): 5 l(n 5 n) holds for all nonnegative integers n, we first check that P(O) is true; indeed 5 I 0. Next assume that 5 I(n - n) , so that we can write n 5 - n = 5t for some integer t. Then we want to prove P( n + 1), namely that 5 I((n + 1)5 - ( n + 1)) . We expand and then factor the right-hand side to obtain - 5 (n + 1) 5 - (n + 1) = n 5 + 5n4 + 10n3 + 10n2 +5n+1 - n - 1 = (n 5 - n) + 5(n 4 + 2n3 + 2n 2 + n) = 5t + 5(n 4 + 2n3 + 2n 2 + n) 4 3 (by the inductive hypothesis) 2 = 5(t + n + 2n + 2n + n). Thus we have shown that (n + 1) 5 - ( n + 1) is also a multiple of 5, and our proof by induction is complete. (Note that here we have used n as the dummy variable in the inductive step, rather than k. It really makes no difference.) We should point out that using mathematical induction is not the only way to prove this proposition; it can also be proved by considering the five cases determined by the value of n mod 5. The reader is encouraged to write down such a proof. 35. First let us rewrite this proposition so that it is a statement about all nonnegative integers, rather than just the odd positive integers. An odd positive integer can be written as 2n - 1, so let us prove the proposition P(n) that (2n - 1) 2 - 1 is divisible by 8 for all positive integers n. We first check that P(l) is true; indeed 8 I 0. Next assume that 8 l((2n - 1) 2 - 1). Then we want to prove P(n + 1), namely that 8 l((2n + 1) 2 - 1). Let us look at the difference of these two expressions: (2n + 1) 2 -1- ((2n -1) 2 -1). A little algebra reduces this to 8n, which is certainly a multiple of 8. But if this difference is a multiple of 8, and if, by the inductive hypothesis, (2n - 1)2 - 1 is a multiple of 8, then (2n + 1)2 - 1 must be a multiple of 8, and our proof by induction is complete. 37. It is not easy to stumble upon the trick needed in the inductive step in this exercise, so do not feel bad if you did not find it. The form is straightforward. For the basis step ( n = 1 ), we simply observe that 11 1 +1 + 12 2 l-l = 121+12 = 133, which is divisible by 133. Then we assume the inductive hypothesis, that Mathematical Induction Section 5.1 155 11n+l+122n-i is divisible by 133, and let us look at the expression when n + 1 is plugged in for n. We want somehow to manipulate it so that the expression for n appears. We have 11(n+l)+l+122(n+l)-1 = 11. 11n+l+144. 122n-1 = 11 · 11 n+l + (11 + 133) · 122n-i = 11(11 n+l + 12 2n-i) + 133 · 12 2n-i. Looking at the last line, we see that the expression in parentheses is divisible by 133 by the inductive hypothesis, and obviously the second term is divisible by 133, so the entire quantity is divisible by 133, as desired. 39. The basis step is trivial, as usual: Ai c;;; Bi implies that n~=i AJ c;;; n~=i BJ because the intersection of one set is itself. Assume the inductive hypothesis that if AJ c;;; BJ for j = L 2, ... , k, then n:=i A 1 c;;; n:=i B 1 . We want to show that if AJ c;;; B 1 for j = 1, 2, ... , k + 1, then n:~i AJ c;;; n:~i BJ. To show that one set is a subset of another we show that an arbitrary element of the first set must be an element of the second set. So let x E n~~i AJ = ( n~=i AJ) n Ak+i. Because x E n~=i AJ, we know by the inductive hypothesis that x E n:=i BJ; because x E Ak+l, we know from the given fact that Ak+i x E (n:=l BJ) n Bk+I = <;;;; Bk+l that x E Bk+l · Therefore n:~i BJ. This is really easier to do directly than by using the principle of mathematical induction. For a noninductive proof, suppose that x E n;=l AJ. Then x E AJ for each j from 1 to n. Since Aj c;;; BJ, we know that x E B 1 . Therefore by definition, x E n;=l BJ. 41. In order to prove this statement, we need to use one of the distributive laws from set theory: (XU Y) n Z = (X n Z) U (Y n Z) (see Section 2.2). Indeed, the proposition at hand is the generalization of this distributive law, from two sets in the union to n sets in the union. We will also be using implicitly the associative law for set union. The basis step, n = 1, is the statement Ai n B the inductive hypothesis that = A1 n B, which is obviously true. Therefore we assume (Ai U A2 U · · · U An) n B = (Ai n B) U (A2 n B) U · · · U (Ann B). We wish to prove the similar statement for n + 1, namely Starting with the left-hand side, we apply the distributive law for two sets: ((Ai U A2 U .. · U An) U An+i) n B = ((Ai U A2 U .. · U An) n B) U (An+i n B) = ((A1 n B) U (A 2 n B) U · · · U (Ann B)) U (An+i n B) (by the inductive hypothesis) = (A1 n B) u (A2 n B) U · · · u (Ann B) U (An+i n B) 43. In order to prove this statement, we need to use one of De Morgan's laws from set theory: (AU B) =An B (see Section 2.2). Indeed, the proposition at hand is the generalization of this law, from two sets in the union to n sets in the union. We will also be using implicitly the associative laws for set union and intersection. The basis step, n = 1, is the statement Ai = Ai (since the union or intersection of just one set is the set itself), and this proposition is obviously true. Therefore we assume the inductive hypothesis that n LJ Ak = k=i n n Ak. k=i Chapter 5 156 We wish to prove the similar statement for n Induction and Recursion + 1, namely LJ Ak = nAk. n+l n+l k=l k=l Starting with the left-hand side, we group, apply De Morgan's law for two sets, and then the inductive hypothesis: n+l n k=l k=l LJ Ak = ( LJ Ak) U An+ i -n - = LJ Ak n An+i (by DeMorgan's law) k=l n n =n Ak) n An+1 = ( (by the inductive hypothesis) k=l n+l Ak k=l 45. This proof will be similar to the proof in Example 10. The basis step is clear, since for n = 2, the set has exactly one subset containing exactly two elements, and 2(2 - 1)/2 = 1. Assume the inductive hypothesis, that a set with n elements has n(n - 1)/2 subsets with exactly two elements; we want to prove that a set S with n + 1 elements has (n + l)n/2 subsets with exactly two elements. Fix an element a in S, and let T be the set of elements of S other than a. There are two varieties of subsets of S containing exactly two elements. First there are those that do not contain a. These are precisely the two-element subsets of T, and by the inductive hypothesis, there are n( n - 1) /2 of them. Second, there are those that contain a together with one element of T. Since T has n elements, there are exactly n subsets of this type. Therefore the total number of subsets of S containing exactly two elements is (n(n - 1)/2) + n, which simplifies algebraically to (n + l)n/2, as desired. 4 7. The hint gives the greedy algorithm. We reorder the locations if necessary so that x1 :::;; x 3 :::;; · · · :::;; Xd. The first tower is placed at position t 1 = x 1 + 1. It will serve the first building and any other buildings at locations no greater than t 1 + 1 . Assume that we have placed tower k at tk. Then place tower k + 1 at position tk+l = x + 1, where x is the smallest x, greater than tk + 1. Because all the buildings up to the one at position x were already serviced by the previous towers, and the building at position x is serviced by the new tower at tk+ 1 , all the buildings will be serviced once this process is completed. x2 :::;; 49. The one and only flaw in this proof is in this statement, which is part of the inductive step: "the set of the first n horses and the set of the last n horses [in the collection of n + 1 horses being considered] overlap." The only assumption made about the number n in this argument is that n is a positive integer. When n = 1, so that n + 1 = 2, the statement quoted is obviously nonsense: the set of the first one horse and the set of the last one horse, in this set of two horses, are disjoint. 51. The mistake is in applying the inductive hypothesis to look at max(x - 1, y - 1), because even though x and y are positive integers, x - 1 and y - 1 need not be (one or both could be 0). In fact, that is what happens if we let x = 1 and y = 2 when k = 1. 53. The base case ( n = 2) is the old "I cut and you choose'' approach. The first person cuts the cake into two portions that she thinks are each 1/2 of the cake. The second person chooses the portion he thinks is at least 1/2 of the cake (at least one of the pieces must satisfy that condition). For the inductive step, 157 Mathematical Induction Section 5.1 suppose there are k + 1 people. By the inductive hypothesis, we can suppose that the first k people have divided the cake among themselves so that each person is satisfied that he got at least a fraction 1/k of the cake. Each of them now cuts his or her piece into k + 1 pieces of equal size. The last person gets to choose one piece from each of the first k people's portions. After this is done, each of the first k people is satisfied that she still has ( 1/ k) (k / ( k + 1)) = 1/ ( k + 1) of the cake. To see that the last person is satisfied, suppose that he thought that the ith person ( 1 :S i :S k) had a portion p, of the cake, where L~=l p, = 1. By choosing what he thinks is the largest piece from each person, he is satisfied that he has at least 1 p,/(k+1) = (1/(k + 1)) 1 p, = 1/(k + 1) of the cake. 2::7= 2::7= 55. We use the notation (i, j) to mean the square in row i and column j, where we number from the left and from the bottom, starting at (0, 0) in the lower left-hand corner. We use induction on i + j to show that every square can be reached by the knight. There are six base cases, for the cases when i + j :S 2. The knight is already at (0, 0) to start, so the empty sequence of moves reaches that square. To reach (1, 0), the knight moves successively from (0, 0) to (2, 1) to (0, 2) to (1, 0). Similarly, to reach (0, 1), the knight moves successively from (0, 0) to (1, 2) to (2, 0) to (0, 1). Note that the knight has reached (2, 0) and (0, 2) in the process. For the last basis step, note this path to (1, 1): (0, 0) to (1, 2) to (2, 0) to (0, 1) to (2, 2) to (0, 3) to (1, 1). We now assume the inductive hypothesis, that the knight can reach any square (i, j) for which i + j = k, where k is an integer greater than 1 , and we want to show how the knight can reach each square (i, j) when i + j = k + 1. Since k + 1 2": 3, at least one of i and j is at least 2. If i 2": 2, then by the inductive hypothesis, there is a sequence of moves ending at (i - 2, j + 1) , since i - 2 + j + 1 = i + j - 1 = k; from there it is just one step to (i, j). Similarly, if j 2: 2, then by the inductive hypothesis, there is a sequence of moves ending at (i + 1,j - 2), since i + 1 + j - 2 = i + j - 1 = k; from there it is again just one step to (i,j). 57. The base cases are n = 0 and n = 1, and it is a simple matter to evaluate, directly from the ''limit of difference quotient" definition, the derivatives of x 0 = 1 and x 1 = x: _!!__xo = lim (x dx h-+O + h)o - d 1 l' (x -dX=Im X h-+0 h xo = lim 1 - 1 = 0 = 0. h-+O h + h)l h Xl = lim !!:. = 1 = h-+O h 1. x-1 XO We are told to assume that the product rule holds: d~ (f(x) · g(x)) = f(x) · g'(x) + g(x) · f'(x) So we work as follows, invoking the inductive hypothesis and the base cases: _!!__xn+l = j_(x · xn) = x · _!!__xn + xn · j_x dx dx dx dx = x · nxn-l + xn · 1 = nxn + xn = (n + l)xn 59. We prove this by induction on k. The basis step k = 0 is the trivial statement that 1 = 1 (mod m). Suppose that the statement is true for k. We must show it for k + 1. So let a = b (mod m) . By the inductive hypothesis we know that ak = bk (mod m). Then we apply Theorem 5 from Section 4.1 to conclude that a· ak b ·bk (mod m), which by definition says that ak+ 1 bk+ 1 (mod m), as desired. = = 61. Let P(n) be the proposition [(P1-+ P2) /\ (p2-+ p3) /\ · · · /\ (Pn-1-+ Pn)]-+ [(P1 /\p2 /\ · · · APn-d-+ Pn] · We want to prove this proposition for all n 2: 2. The basis step, (p 1 -+ P2) -+ (p 1 -+ P2) , is clearly true (a tautology), since every proposition implies itself. Now we assume P(n) and want to show P(n + 1), namely [(P1 -+ P2) /\ (P2 -+ p3)/\ · · · /\ (Pn-1 -+ Pn) /\ (Pn -+ Pn+i)J -+ [(P1 /\ P2 /\ · · · /\ Pn -1 /\ Pn) -+ Pn+i] · Chapter 5 158 Induction and Recursion To show this, we will assume that the hypothesis (everything in the first square brackets) is true and show that the conclusion (the conditional statement in the second square brackets) is also true. So we assume (P1 ---> P2) I\ (P2 ---> p3) I\··· I\ (Pn-1 ---> Pn) I\ (Pn---> Pn+1). By the associativity of A, we can group this as ( (p1 ---> P2) I\ (P2 ---> p3) I\ · · · I\ (Pn-1 ---> Pn)) I\ (Pn ---> Pn+i). By the simplification rule, we can conclude that the first group, (p1 ---> P2) I\ (P2 ---> p3) I\ · · · I\ (Pn-1 ---> Pn), must be true. Now the inductive hypothesis allows us to conclude that (p 1 Ap2 A··· APn-l)---> Pn. This together with the rest of the assumption, namely Pn ---> Pn+I, yields, by the hypothetical syllogism rule, (p1 A P2 A · · · A Pn-1) ---> Pn+I. That is almost what we wanted to prove, but not quite. We wanted to prove that (p1A P2A· · ·l\Pn-11\Pn) ---> Pn+I · In order to prove this, let us assume its hypothesis, P1A p21\· · ·l\Pn-11\Pn. Again using the simplification rule we obtain P1 A P2 I\··· APn-1. Now by modus ponens with the proposition (P1 I\ P2 I\··· APn-i) ---> Pn+I i which we proved above, we obtain Pn+l · Thus we have proved (p1 A P2 A··· APn-1 Apn)---> Pn+I, as desired. 63. This exercise, as the double star indicates, is quite hard. The trick is to induct not on n itself, but rather on log 2 n. In other words, we write n = 2k and prove the statement by induction on k. This will prove the statement for every n that is a power of 2; a separate argument is needed to extend to the general case. We take the basis step to be k = 1 (the case k = 0 is trivially true, as well), so that n = 2 1 = 2. In this case the trick is to start with the true inequality ( y'a1 - yla2) 2 2 0. Expanding, we have a1 - 2fol 1, then the inductive hypothesis tells us that we can run k - l miles, so we can run (k -1) + 2=k+1 miles. 3. a) P(8) is true, because we can form 8 cents of postage with one 3-cent stamp and one 5-cent stamp. P(9) is true, because we can form 9 cents of postage with three 3-cent stamps. P(lO) is true, because we can form 10 cents of postage with two 5-cent stamps. b) The inductive hypothesis is the statement that using just 3-cent and 5-cent stamps we can form j cents postage for all j with 8 ::::; j ::::; k , where we assume that k ~ 10 . c) In the inductive step we must show, assuming the inductive hypothesis, that we can form k postage using just 3-cent and 5-cent stamps. +1 cents + 1 cents of postage. Since k ~ 10, we know that P(k - 2) is true, that is, that we can form k - 2 cents of postage. Put one more 3-cent stamp on the envelope, and we have formed k + 1 cents d) We want to form k of postage, as desired. Chapter 5 162 Induction and Recursion e) We have completed both the basis step and the inductive step, so by the principle of strong induction, the statement is true for every integer n greater than or equal to 8. 5. a) We can form the following amounts of postage as indicated: 4 = 4, 8 = 4 + 4, 11 = 11, 12 = 4 + 4 + 4, 15 = 11+4, 16 = 4 + 4 + 4 + 4, 19 = 11+4 + 4, 20 = 4 + 4 + 4 + 4 + 4, 22 = 11+11, 23 = 11+4 + 4 + 4, 24 = 4 + 4 + 4 + 4 + 4 + 4' 26 = 11 + 11 + 4' 27 = 11 + 4 + 4 + 4 + 4' 28 = 4 + 4 + 4 + 4 + 4 + 4 + 4' 30 = 11+11+4 + 4, 31=11+4 + 4 + 4 + 4 + 4, 32 = 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4, 33=11+11+11. By having considered all the combinations, we know that the gaps in this list cannot be filled. We claim that we can form all amounts of postage greater than or equal to 30 cents using just 4-cent and 11-cent stamps. b) Let P( n) be the statement that we can form n cents of postage using just 4-cent and 11-cent stamps. We want to prove that P( n) is true for all n :'.'.'. 30. The basis step, n = 30, is handled above. Assume that we can form k cents of postage (the inductive hypothesis); we will show how to form k + 1 cents of postage. If the k cents included an 11-cent stamp, then replace it by three 4-cent stamps ( 3 · 4 = 11 + 1 ). Otherwise, k cents was formed from just 4-cent stamps. Because k :'.'.: 30, there must be at least eight 4-cent stamps involved. Replace eight 4-cent stamps by three 11-cent stamps, and we have formed k + 1 cents in postage (3·11=8·4+1). c) P( n) is the same as in part (b). To prove that P( n) is true for all n :'.'.: 30, we note for the basis step that from part (a), P(n) is true for n = 30,31,32,33. Assume the inductive hypothesis, that P(j) is true for all j with 30::;; j::;; k, where k is a fixed integer greater than or equal to 33. We want to show that P(k + 1) is true. Because k - 3 :'.'.: 30, we know that P(k - 3) is true, that is, that we can form k - 3 cents of postage. Put one more 4-cent stamp on the envelope, and we have formed k + 1 cents of postage, as desired. In this proof our inductive hypothesis included all values between 30 and k inclusive, and that enabled us to jump back four steps to a value for which we knew how to form the desired postage. 7. We can form the following amounts of money as indicated: 2 = 2, 4 = 2 + 2, 5 = 5, 6 = 2 + 2 + 2. By having considered all the combinations, we know that the gaps in this list ($1 and $3) cannot be filled. We claim that we can form all amounts of money greater than or equal to 5 dollars. Let P(n) be the statement that we can form n dollars using just 2-dollar and 5-dollar bills. We want to prove that P( n) is true for all n :'.'.: 5. We already observed that the basis step is true for n = 5 and 6. Assume the inductive hypothesis, that P(j) is true for all j with 5 ::;; j ::;; k, where k is a fixed integer greater than or equal to 6. We want to show that P( k + 1) is true. Because k - 1 :'.'.: 5, we know that P( k - 1) is true, that is, that we can form k - 1 dollars. Add another 2-dollar bill, and we have formed k + 1 dollars, as desired. 9. Following the hint, we let P(n) be the statement that there is no positive integer b such that J2 = n/b. For the basis step, P(l) is true because J2 > 1 :'.'.'. l/b for all positive integers b. For the inductive step, assume that P(j) is true for all j ::;; k, where k is an arbitrary positive integer; we must prove that P(k + 1) is true. So assume the contrary, that J2 = (k + 1)/b for some positive integer b. Squaring both sides and clearing fractions, we have 2b 2 = (k + 1) 2 . This tells us that (k + 1) 2 is even, and so k + 1 is even as well (the square of an odd number is odd, by Example 1 in Section 1.7). Therefore we can write k + 1 = 2t for some positive integer t. Substituting, we have 2b 2 = 4t 2 , so b2 = 2t 2 . By the same reasoning as before, b is even, so b = 2s for some positive integer s . Then we have J2 = (k + 1) / b = (2t) / (2s) = t / s. But t ::;; k, so this contradicts the inductive hypothesis, and our proof of the inductive step is complete. 11. There are four base cases. If n = 1 = 4 · 0 + 1, then clearly the first player is doomed, so the second player wins. If there are two, three, or four matches ( n = 4 · 0 + 2, n = 4 · 0 + 3, or n = 4 · 1), then the first player can win by removing all but one match. Now assume the strong inductive hypothesis, that in games with k or fewer matches, the first player can win if k 0, 2 or, 3 (mod 4) and the second player can win if k 1 (mod 4). Suppose we have a game with k + 1 matches, with k :'.'.: 4. If k + 1 0 (mod 4), then the first = = = Section 5.2 163 Strong Induction and Well-Ordering = player can remove three matches, leaving k- 2 matches for the other player. Since k - 2 1 (mod 4), by the inductive hypothesis, this is a game that the second player at that point (who is the first player in our game) can win. Similarly, if k + 1 2 (mod 4), then the first player can remove one match, leaving k matches for the other player. Since k = 1 (mod 4), by the inductive hypothesis, this is a game that the second player at = that point (who is the first player in our game) can win. And if k + 1 = 3 (mod 4), then the first player can remove two matches, leaving k - 1 matches for the other player. Since k - 1 1 (mod 4), by the inductive hypothesis, this is again a game that the second player at that point (who is the first player in our game) can win. Finally, if k + 1 1 (mod 4) , then the first player must leave k, k - 1 , or k - 2 matches for the other player. Since k 0 (mod 4), k - 1 3 (mod 4), and k - 2 2 (mod 4), by the inductive hypothesis, this is a game that the first player at that point (who is the second player in our game) can win. Thus the first player in our game is doomed, and the proof is complete. = = = = = 13. Let P(n) be the statement that exactly n - 1 moves are required to assemble a puzzle with n pieces. Now P(l) is trivially true. Assume that P(j) is true for all j < n, and consider a puzzle with n pieces. The final move must be the joining of two blocks, of size k and n - k for some integer k, 1 :s; k :s; n - 1. By the inductive hypothesis, it required k - 1 moves to construct the one block, and n - k - 1 moves to construct the other. Therefore 1 + (k - 1) + (n - k - 1) = n - 1 moves are required in all, so P(n) is true. Notice that for variety here we proved P( n) under the assumption that P(j) was true for j < n; so n played the role that k + 1 plays in the statement of strong induction given in the text. It is worthwhile to understand how all of these forms are saying the same thing and to be comfortable moving between them. 15. Let the Chomp board have n rows and n columns. We claim that the first player can win the game by making the first move to leave just the top row and left-most column. (He does this by selecting the cookie in the second column of the second row.) Let P(n) be the statement that if a player has presented his opponent with a Chomp configuration consisting of just n cookies in the top row and n cookies in the left-most column (both of these including the poisoned cookie in the upper left corner), then he can win the game. We will prove \/nP(n) by strong induction. We know that P(l) is true, because the opponent is forced to take the poisoned cookie at his first turn. Fix k 2 1 and assume that P(j) is true for all j :=:; k. We claim that P(k + 1) is true. It is the opponent's turn to move. If she picks the poisoned cookie, then the game is over and she loses. Otherwise, assume that she picks the cookie in the top row in column j, or the cookie in the left column in row j, for some j with 2 :=:; j :=:; k + 1. The first player now picks the cookie in the left column in row j, or the cookie in the top row in column j, respectively. This leaves the position covered by P(j - 1) for his opponent, so by the inductive hypothesis, he can win. 17. Let P(n) be the statement that if a simple polygon with n sides is triangulated, then at least two of the triangles in the triangulation have two sides that border the exterior of the polygon. We will prove \In 2 4 P( n). The statement is clearly true for n = 4, because there is only one diagonal, leaving two triangles with the desired property. Fix k 2 4 and assume that P(j) is true for all j with 4 :s; j :s; k. Consider a polygon with k + 1 sides, and some triangulation of it. Pick one of the diagonals in this triangulation. First suppose that this diagonal divides the polygon into one triangle and one polygon with k sides. Then the triangle has two sides that border the exterior. Furthermore, the k-gon has, by the inductive hypothesis, two triangles that have two sides that border the exterior of that k-gon, and only one of these triangles can fail to be a triangle that has two sides that border the exterior of the original polygon. The only other case is that this diagonal divides the polygon into two polygons with j sides and k + 3 - j sides for some j with 4 :s; j :s; k - 1. By the inductive hypothesis, each of these two polygons has two triangles that have two sides that border their exterior, and in each case only one of these triangles can fail to be a triangle that has two sides that border the exterior of the original polygon. 164 Chapter 5 Induction and Recursion 19. Let P(n) be the statement that the area of a simple polygon with n sides and vertices all at lattice points is given by I+ B /2 - 1, where I and B are as defined in the exercise. We will prove 'Vn;::: 3 P( n). We begin by proving an additivity lemma. If P is a simple polygon with all vertices at the lattice points, divided into polygons P 1 and P 2 by a diagonal, then J(P) + B(P)/2-1 = (J(P1) + B(P1)/2-1) + (J(P2) + B(P2)/2-1). To see this, suppose there are k lattice points on the diagonal, not counting its endpoints. Then I(P) = J(P1) + J(P2) + k and B(P) = B(P1) + B(P2) - 2k - 2; and the result follows by simple algebra. What this says in particular is that if Pick's formula gives the correct area for P 1 and P 2 , then it must give the correct formula for P, whose area is the sum of the areas for P1 and P2 ; and similarly if Pick's formula gives the correct area for P and one of the P, 's, then it must give the correct formula for the other P, . Next we prove the theorem for rectangles whose sides are parallel to the coordinate axes. Such a rectangle necessarily has vertices at (a, b), (a, c), (d, b), and (d, c), where a, b, c, and d are integers with b < c and a< d. Its area is clearly (c- b)(d- a). By looking at the perimeter, we see that it has B = 2(c- b + d- a), and we see also that it has I= (c - b - l)(d - a - 1) = (c - b)(d - a) - (c - b) - (d - a)+ 1. Therefore I+ B /2 - 1 = (c - b)( d - a) - (c - b) - (d - a) + 1 + (c - b + d - a) - 1 = (c - b)( d - a), which is the desired area. Next consider a right triangle whose legs are parallel to the coordinate axes. This triangle is half a rectangle of the type just considered, for which Pick's formula holds, so by the additivity lemma, it holds for the triangle as well. (The values of B and I are the same for each of the two triangles, so if Pick's formula gave an answer that was either too small or too large, then it would give a correspondingly wrong answer for the rectangle.) For the next step, consider an arbitrary triangle with vertices at the lattice points that is not of the type already considered. Embed it in as small a rectangle as possible. There are several possible ways this can happen, but in any case (and adding one more edge in one case), the rectangle will have been partitioned into the given triangle and two or three right triangles with sides parallel to the coordinate axes. See the figure for a typical case. Again by the additivity lemma, we are guaranteed that Pick's formula gives the correct area for the central triangle. Note that we have now proved P(3), the basis step in our strong induction proof. For the inductive step, given an arbitrary polygon, use Lemma 1 in the text to split it into two polygons. Then by the additivity lemma above and the inductive hypothesis, we know that Pick's formula gives the correct area for this polygon. Here are some good websites for more details: planetmath.org/encyclopedia/ProofDfPicksTheorem.html mathforum.org/library/drmath/view/65670.html 21. a) Use the left figure. Angle abp is smallest for p, but the segment bp is not an interior diagonal. b) Use the right figure. The vertex other than b with smallest x-coordinate is d, but the segment bd is not an interior diagonal. Section 5.2 Strong Induction and Well-Ordering 165 c) Use the right figure. The vertex closest to b is d, but the segment bd is not an interior diagonal. 23. a) When we try to prove the inductive step and find a triangle in each subpolygon with at least two sides bordering the exterior, it may happen in each case that the triangle we are guaranteed in fact borders the diagonal (which is part of the boundary of that polygon). This leaves us with no triangles guaranteed to touch the boundary of the original polygon. b) We proved 'v'n24T(n) in Exercise 17. Since we can always find two triangles that satisfy the property, perforce, at least one triangle does. Thus we have proved 'v'n 2 4 E( n). 25. a) The inductive step here allows us to conclude that P(3), P(5), ... are all true, but we can conclude nothing about P(2), P(4), .... b) We can conclude that P( n) is true for all positive integers n, using strong induction. c) The inductive step here allows us to conclude that P(2), P(4), P(8), P(16), ... are all true, but we can conclude nothing about P( n) when n is not a power of 2. d) This is mathematical induction; we can conclude that P( n) is true for all positive integers n. 27. Suppose, for a proof by contradiction, that there is some positive integer n such that P(n) is not true. Let m be the smallest positive integer greater than n for which P( m) is true; we know that such an m exists because P( m) is true for infinitely many values of m, and therefore true for more than just 1, 2, ... , n - 1. But we are given that P( m) ----> P( m - 1), so P( m - 1) is true. Thus m - 1 cannot be greater than n, so m - 1 = n and P(n) is in fact true. This contradiction shows that P(n) is true for all n. 29. The error is in going from the basis step n = 0 to the next value, n = 1. We cannot write 1 as the sum of two smaller natural numbers, so we cannot invoke the inductive hypothesis. In the notation of the "proof," when k = 0, we cannot write 0 + 1 = i + j where 0 :::;: i :::;: 0 and 0 :::;: j :S 0. 31. To show that strong induction is valid, let us suppose that we have a proposition 'v'nP( n) which has been proved using it. We must show that in fact 'v'nP(n) is true (to say that a principle of proof is valid means that it proves only true propositions). Let S be the set of counterexamples, i.e., S = { n I •P(n) }. We want to show that S = 0. We argue by contradiction. Assume that S =I- 0. Then by the well-ordering property, S has a smallest element. Since part of the method of strong induction is to show that P(l) is true, this smallest counterexample must be greater than 1. Let us call it k + 1. Since k + 1 is the smallest element of S, it must be the case that P(l) /\ P(2) /\ · · · /\ P(k) is true. But the rest of the proof using strong induction involved showing that P(l) /\ P(2) /\ · · · /\ P(k) implied P(k + 1); therefore since the hypothesis is true, the conclusion must be true as well, i.e., P(k + 1) is true. This contradicts our assumption that k + 1 E S. Therefore we conclude that S = 0, so 'v'nP( n) is true. 33. In each case we will argue on the basis of a "smallest counterexample." a) Suppose that there is a counterexample, that is, that there are values of n and k such that P( n, k) is not true. Choose a counterexample with n + k as small as possible. We cannot have n = l and k = 1, because we are given that P(l, 1) is true. Therefore either n > 1 or k > 1. In the former case, by our choice of counterexample, we know that P(n - 1, k) is true. But the inductive step then forces P(n, k) to be true, a contradiction. The latter case is similar. So our supposition that there is a counterexample must be wrong, and P(n, k) is true in all cases. b) Suppose that there is a counterexample, that is, that there are values of n and k such that P( n, k) is not true. Choose a counterexample with n as small as possible. We cannot have n = 1, because we are given that P(l, k) is true for all k. Therefore n > 1. By our choice of counterexample, we know that P(n - 1, k) 166 Chapter 5 Induction and Recursion is true. But the inductive step then forces P(n, k) to be true, a contradiction. So our supposition that there is a counterexample must be wrong, and P( n, k) is true in all cases. c) Suppose that there is a counterexample, that is, that there are values of n and k such that P( n, k) is not true. Choose a counterexample with k as small as possible. We cannot have k = 1, because we are given that P( n, 1) is true for all n. Therefore k > 1. By our choice of counterexample, we know that P( n, k - 1) is true. But the inductive step then forces P(n, k) to be true, a contradiction. So our supposition that there is a counterexample must be wrong, and P(n, k) is true in all cases. 35. We want to calculate the product a 1 a 2 · · · an by inserting parentheses to express the calculation as a sequence of multiplications of two quantities. For example, we can insert parentheses into a 1a 2a 3a4a 5 to render it (a 1 (a2a 3 ))(a4a 5 ), and then the four multiplications are a 2 · a 3 , a4 · a 5 , a 1 · (a 2 a 3 ), and finally the product of these last two quantities. We must show that no matter how the parentheses are inserted, n -1 multiplications will be required. If n = 1, then clearly 0 multiplications are required, so the basis step is trivial. Now assume the strong inductive hypothesis, that for all k < n, no matter how parentheses are inserted into the product of k numbers, k - 1 multiplications are required to compute the answer. Consider a parenthesized product of ai through an, and look at the last multiplication. Thus we have (a 1 a 2 · · · ar) · (ar+l · · ·an), where we do not care how the parentheses are distributed within the pairs shown here. By the inductive hypothesis, it requires r - 1 multiplications to obtain the first product in parentheses and n - r - 1 to obtain the second (that second product has n - r factors). Furthermore, 1 additional multiplication is needed to multiply these two answers together. This gives a total of (r - 1) + (n - r - 1) + 1 = n - 1 multiplications for the given problem, exactly what we needed to show. 37. Suppose that we have two such pairs, say (q, r) and (q', r'), so that a= dq + r = dq' + r', with 0 :Sr, r' < d. We will show that the pairs are really the same, that is, that q = q' and r = r'. From dq + r = dq' + r' we obtain d( q - q') = r' - r. Therefore d I(r' - r). But Ir' - rl < d (since both r' and r are nonnegative integers less than d). The only multiple of d in that range is 0, so we are forced to conclude that r' = r. Then it easily follows that q = q' as well, since q = (a - r)/d = (a - r')/d = q'. 39. This problem deals with a paradox caused by self-reference. First of all, the answer to the question is clearly "no,'' because there are a finite number of English words, and so only a finite number of strings of fifteen words or fewer; therefore only a finite number of positive integers can be so described, not all of them. On the other hand, we might offer the following "proof" that every positive integer can be so expressed. Clearly 1 can be so expressed (e.g., "one" or "the cardinality of the power set of the empty set"). By the well-ordering property, if there is a positive integer that cannot be expressed in fifteen words or fewer, then there is a smallest such, say s. Then the phrase "the smallest positive integer that cannot be described using no more than fifteen English words'' is a description of s using no more than fifteen English words, a contradiction. Therefore no such s exists, and we seem to have proved that every positive integer can be so expressed, in obvious violation to common sense (and the argument presented above). Paradoxes like this are likely to arise whenever we try to use language to talk about itself; the use of language in this way, while seeming to be meaningful, is in fact nonsense. 41. We will prove this by contradiction. Suppose that the well-ordering property were false. Let S be a counterex- ample: a nonempty set of nonnegative integers that contains no smallest element. Let P(n) be the statement "i t/:. S for all i :S n." We will show that P( n) is true for all n (which will contradict the assertion that S is nonempty). Now P(O) must be true, because if 0 E S then clearly S would have a smallest element, namely 0. Suppose now that P(n) is true, so that it/:. S for i = 0, 1, ... ,n. We must show that P(n + 1) is true, which amounts to showing that n + 1 t/:. S. If n + 1 E S, then n + 1 would be the smallest element of S, and this would contradict our assumption. Therefore n + 1 tf:. S. Thus we have shown by the principle Section 5.3 Recursive Definitions and Structural Induction 167 of mathematical induction that P( n) is true for all n, which means that there can be no elements of S. This contradicts our assumption that S -1- 0, and our proof by contradiction is complete. 43. First we claim that strong induction implies the principle of mathematical induction. Suppose we have proved P(l) and proved for all k 2 1 that P(k)-> P(k + 1) is true. This certainly implies that [P(l) /\ · · · /\ P(k)] -> P( k + 1) is true (here we have a stronger hypothesis). Therefore by strong induction P( n) is true for all n. By Exercise 41, the principle of mathematical induction implies the well-ordering property. Therefore by assuming strong induction as an axiom, we can prove the well-ordering property. SECTION 5.3 Recursive Definitions and Structural Induction The best way to approach a recursive definition is first to compute several instances. For example, if you are given a recursive definition of a function f, then compute f(O) through J(8) to get a feeling for what is happening. Most of the time it is necessary to prove statements about recursively defined objects using structural induction (or mathematical induction or strong induction), and the induction practically takes care of itself, mimicking the recursive definition. = 0, together with the given fact that f(O) = 1. Then we compute f(2) by using the recursive part of the definition with n = 1, together with the given value of f(l). We continue in this way to obtain f(3) and f(4). 1. In each case, we compute f(l) by using the recursive part of the definition with n a) f(l)=f(0)+2=1+2=3; f(2)=f(1)+2=3+2=5; f(3)=f(2)+2=5+2=7; f(4)=f(3)+2= 7+2=9 b) f(l) = 3f(O) = 3 · 1 = 3; f(2) = 3f(l) = 3 · 3 = 9; f(3) = 3f(2) = 3 · 9 = 27; f(4) = 3f(3) = 3 · 27 = 81 c) f(l) = 2f(O) = 21 = 2; f(2) = 2J(l) = 22 = 4; f(3) = 2f( 2 ) = 24 = 16; f(4) = 2J( 3 ) = 216 = 65,536 d) f(l) = J(0) 2 + f(O)+l = 12 +1+1 = 3; J(2) = J(1) 2 + J(l)+l = 32 +3+1=13; f(3) = f(2) 2 + f(2)+1 = 13 2 + 13 + 1=183; !(4) = !(3) 2 + !(3) + 1=1832 + 183 + 1 = 33,673 3. In each case we compute the subsequent terms by plugging into the recursive formula, using the previously given or computed values. a) J(2) = f(l) + 3f(O) = 2 + 3(-1) = -1; f(3) = f(2) + 3f(l) = -1+3 · 2 = 5; J(4) = J(3) + 3f(2) = 5+3(-1)=2; f(5)=f(4)+3J(3)=2+3·5=17 b) f(2) = f(1) 2 f(O) = 22 · (-1) = -4; f(3) = J(2) 2 J(l) = (-4) 2 · 2 = 32; f(4) = J(3) 2 f(2) = 32 2 · (-4) = -4096; !(5) = !(4) 2 !(3) = (-4096) 2 . 32 = 536,870,912 c) f(2) = 3f(1) 2 - 4f(0) 2 = 3 · 22 - 4 · (-1) 2 = 8; f(3) = 3f(2) 2 - 4f(1) 2 = 3 · 82 - 4 · 22 = 176; !(4) = 3/(3) 2 -4/(2) 2 = 3·1762 -4·82 = 92,672; /(5) = 3/(4) 2 -4/(3) 2 = 3·92672 2 -4·176 2 = 25,764,174,848 d) f(2) = f(O)/J(l) = (-1)/2 = -1/2; J(3) = f(l)/J(2) = 2/(-~) = -4; f(4) = f(2)/J(3) = (-~)/(-4) = 1/8; !(5) = J(3)/J(4) = (-4)/i = -32 5. a) This is not valid, since letting n = 1 we would have f(l) = 2/(-1), but f(-1) is not defined. b) This is valid. The basis step tells us what f(O) is, and the recursive step tells us how each subsequent value is determined from the one before. It is not hard to look at the pattern and conjecture that f(n) = 1- n. We prove this by induction. The basis step is f(O) = 1=1- O; and if f(k) = 1- k, then J(k + 1) = J(k) - 1 = 1 - k - 1 = 1 - (k + 1). c) The basis conditions specify f (0) and f ( 1), and the recursive step gives f (n) in terms of f (n -1) for n 2: 2 , so this is a valid definition. If we compute the first several values, we conjecture that f(n) = 4 - n if n > 0, but f (0) = 2. That is our "formula." To prove it correct by induction we need two basis steps: f (0) = 2, and f(l) = 3 = 4-1. For the inductive step (with k 2: 1), J(k + 1) = f(k) -1 = (4- k) -1=4- (k + 1). Chapter 5 168 Induction and Recursion d) The basis conditions specify f(O) and f(l), and the recursive step gives f(n) in terms of f(n - 2) for n ;:::: 2, so this is a valid definition. The sequence of function values is 1, 2, 2, 4, 4, 8, 8, ... , and we can fit a formula to this if we use the floor function: f(n) = 2l(n+ll/ 2 J. For a proof, we check the base cases: f(O) = 1 = 2l(O+l)/ 2 J and f(l) = 2 = 2l(l+ll/ 2 J. For the inductive step: f(k + 1) = 2f(k - 1) = 2 · 2lk/ 2 J = 2lk/2j+1 = 2l((k+l)+l)/2J. e) The definition tells us explicitly what f(O) is. The recursive step specifies f(l), f(3), ... in terms of f(O), f(2), ... ; and it also gives f(2), f(4), ... in terms of f(O), f(2), .... So the definition is valid. We compute that f (1) = 3, f (2) = 9 , f (3) = 27, and so conjecture that f (n) = 3n . The basis step of the inductive proof is clear. For odd n greater than 0 we have f(n) = 3f(n - 1) = 3 · 3n-l = 3n, and for even n greater than 1 we have f(n) = 9f(n - 2) = 9 · 3n- 2 = 3n. Note that we used a slightly different notation here, letting n be the new value, rather than k + 1, but the logic is the same. 7. There are many correct answers for these sequences. We will give what we consider to be the simplest ones. a) Clearly each term in this sequence is 6 greater than the preceding term. Thus we can define the sequence by setting ai = 6 and declaring that an+l =an+ 6 for all n ;:::: 1. b) This is just like part (a), in that each term is 2 more than its predecessor. Thus we have a 1 = 3 and an+l = an + 2 for all n ;:::: 1 . c) Each term is 10 times its predecessor. Thus we have a 1 = 10 and an+l = lOan for all n;:::: 1. d) Just set al = 5 and declare that an+l =an for all n ;:::: 1. 9. We need to write F(n + 1) in terms of F(n). Since F(n) is the sum of the first n positive integers (namely 1 through n ), and F(n+ 1) is the sum of the first n+ 1 positive integers (namely 1 through n+ 1 ), we can obtain F (n + 1) from F (n) by adding n + 1. Therefore the recursive part of the definition is F (n + 1) = F (n) +n + 1. The initial condition is a specification of the value of F(O); the sum of no positive integers is clearly 0, so we set F(O) = 0. (Alternately, if we assume that the argument for F is intended to be strictly positive, then we set F(l) = 1, since the sum of the first one positive integer is 1.) 11. We need to see how Pm(n + 1) relates to Pm(n). Now Pm(n + 1) = m(n + 1) = mn + m = Pm(n) + m. Thus the recursive part of our definition is just Pm(n + 1) = Pm(n) + m. The basis step is Pm(O) = 0, since m · 0 = 0, no matter what value m has. 13. We prove this using the principle of mathematical induction. The base case is n = 1, and in that case the statement to be proved is just Ji = h; this is true since both values are 1. Next we assume the inductive hypothesis, that Ji+ h + · · · + hn-1 and try to prove the corresponding statement for n Ji+ h = hn' + 1 , namely, + · · · + hn-1 + hn+l = hn+2 · We have Ji+ h + · · · + hn-1 + hn+l = hn + hn+l (by the inductive hypothesis) = hn+2 (by the definition of the Fibonacci numbers). 15. We prove this using the principle of mathematical induction. The basis step is for n = 1, and in that case the statement to be proved is just fofi + fih = Ji; this is true since 0 · 1+1 · 1 = 12 . Next we assume the inductive hypothesis, that fofi + fih + · · · + hn-lhn =fin' Section 5.3 Recursive Definitions and Structural Induction and try to prove the corresponding statement for n Joli 169 + 1 , namely, + lifz + · · · + fzn-ifzn + fznfzn+i + fzn+dzn+Z = fin+Z · Note that two extra terms were added, since the final subscript has to be even. We have Joli+ lifz + · · · + fzn-dzn + fznfzn+i + fzn+dzn+Z = JJn + fznfzn+i + fzn+dzn+Z (by the inductive hypothesis) = fzn(fzn + fzn+1) + fzn+ifzn+Z (by factoring) = fznfzn+2 + fzn+dzn+Z (by the definition of the Fibonacci numbers) + fzn+1)fzn+Z = fzn+zfzn+Z = fin+z· = (Jzn 17. Let dn be the number of divisions used by Algorithm 1 in Section 4.3 (the Euclidean algorithm) to find gcd(Jn+1, f n). We write the calculation in this order, since fn+i 2: fn. We begin by finding the values of dn for the first few values of n, in order to find a pattern and make a conjecture as to what the answer is. For n = 0 we are computing gcd(Ji, Jo) = gcd(l, 0). Without performing any divisions, we know immediately that the answer is 1, so do= 0. For n = 1 we are computing gcd(fz,li) = gcd(l,1). One division is used to show that gcd(l, 1) = gcd(l, 0), so di = 1. For n = 2 we are computing gcd(h, fz) = gcd(2, 1). One division is used to show that gcd(2, 1) = gcd(l, 0), so dz = 1. For n = 3, the computation gives successively gcd(J4 ,h) = gcd(3,2) = gcd(2,l) = gcd(l,O), for a total of 2 divisions; thus d3 = 2. For n = 4, we have gcd(f5, f4) = gcd(5, 3) = gcd(3, 2) = gcd(2, 1) = gcd(l, 0), for a total of 3 divisions; thus d4 = 3. At this point we see that each increase of 1 in n seems to add one more division, in order to reduce gcd(fn+l• fn) to gcd(fn,fn-i). Perhaps, then, for n 2: 2, we have dn = n -1. Let us make that conjecture. We have already verified the basis step when we computed that dz = 1. Now assume the inductive hypothesis, that dn = n - 1. We must show that dn+l = n. Now dn+i is the number of divisions used in computing gcd(fn+z, fn+i). The first step in the algorithm is to divide fn+i into fn+z. Since fn+z = f n+i + fn (this is the key point) and fn < fn+i, we get a quotient of 1 and a remainder of fn. Thus we have, after one division, gcd(Jn+z, fn+i) = gcd(jn+l• fn). Now by the inductive hypothesis we need exactly dn = n - 1 more divisions, since the algorithm proceeds from this point exactly as it proceeded given the inputs for the case of n. Therefore 1 + (n - 1) = n divisions are used in all, and our proof is complete. The answer, then, is that d 0 = 0, di = 1, and dn = n - 1 for n : :'.'. 2. (If we interpreted the problem as insisting that we compute gcd(fn, f n+i), with that order of the arguments, then the analysis and the answer are slightly different: d0 = 1, and dn = n for n :::'.'. 1.) 19. The determinant of the matrix A= [ ~ ~] , written IAI, is by definition ad - be; and the determinant has the multiplicative property that IABI = IAllBI. Therefore the determinant of the matrix A= r. U ~] in On the other hand, the determinant of the matrix Exercise 16 is 1 . 0 - 1 . 1 = -1, and IAn I = IA In = ( -1 1 [f :: ] is by definition f n+ifn-l - f~. In Exercise 18 we showed that An is this latter matrix. The 1 1 identity in Exercise 14 follows. 'J: 21. Assume that the definitions given in Exercise 20 were as follows: the max or min of one number is itself; max( ai, az) = a 1 if ai :::'.'. az and az if ai < az, whereas min( ai, az) = az if ai :::'.'. a2 and ai if ai < a2; and for n :::'.'. 2, 170 Chapter 5 Induction and Recursion and We can then prove the three statements here by induction on n. a) For n = 1, both sides of the equation equal -a1. For n = 2, we must show that max(-a 1, -a 2) = - min( a 1, a 2) . There are two cases, depending on the relationship between a 1 and a 2 . If a 1 :::;; a 2 , then -a1 2 -a2, so by our definition, max(-a1. -a2) = -a 1 . On the other hand our definition implies that min(a1,a2) = a1 in this case. Therefore max(-a1,-a2) = -a1 = -min(a1,a2). The other case, a 1 > a 2 , is similar: max( -a 1, -a2) = -a2 = - min( a 1, a2). Now we are ready for the inductive step. Assume the inductive hypothesis, that We need to show the corresponding equality for n + 1. We have = max(max(-a1, -a2, ... , -an), -an+1) =max(- min(a1, a2, ... , an), -an+1) = -min(min(a1, a2, ... , an), an+1) = - min(a1, a2, ... , an, an+i) (by definition) (by the inductive hypothesis) (by the already proved case n = 2) (by definition). b) For n = 1, the equation is simply the identity a 1 + b1 = a 1 + b1 . For n = 2, the situation is a little messy. Let us consider first the case that a1 + b1 2 a2 + b2. Then max(a 1 + b1, a2 + b2) = a 1 + b1 . Also note that ai :::;; max(a 1, b1), and b1 :::;; max(b1, b2), so that a 1 +bi :::;; max(a1, a 2) + max(b 1, b2). Therefore we have max(a1 +bi, a2 + b2) = ai + b1 :::;; max(a1, a2) + max(b1, b2). The other case, in which ai +bi < a2 + b2, is similar. Now for the inductive step, we first need a lemma: if u :::;; v, then max( u, w) :::;; max( v, w); this is easy to prove by looking at the three cases determined by the size of w relative to the sizes of u and v. Now assuming the inductive hypothesis, we have max(a1 +bi, a2 + b2, ... , an+ bn, an+l + bn+1) = max(max(a1 + b1, a2 + b2, ... , an+ bn), an+I + bn+1) (by definition) :::;; max(max(a1, a2, ... , an)+ max(b1, b2, ... , bn), an+I + bn+1) (by the inductive hypothesis and the lemma) :::;; max(max(a1, a2, ... , an), an+1) + max(max(b1, b2, ... , bn), bn+i) (by the already proved case n = 2) = max(a1, a2, ... , an, an+1) + max(b1, b2, ... , bn, bn+1) (by definition). c) The proof here is exactly dual to the proof in part (b). We replace every occurrence of "max" by "min,'' and invert each inequality. The proof then reads as follows. For n = 1, the equation is simply the identity a1 + b1 = a1 + b1 . For n = 2, the situation is a little messy. Let us consider first the case that a 1 + b1 :::;; a 2 + b2. Then min(a1 + b1,a2 + b2) = a1 + b1. Also note that a1 2 min(a1,a 2), and b1 2 min(bi,b2), so that a1 +b1 2 min(a1, a2)+min(b1, b2). Therefore we have min(a1 +b1, a2+b2) = a1 +b1 2 min(a1, a 2)+min(b1, b2). The other case, in which a 1 + b1 > a 2 + b2 , is similar. Now for the inductive step, we first need a lemma: if u 2 v, then min( u, w) 2 min( v, w); this is easy to prove by looking at the three cases determined by the size Section 5.3 Recursive Definitions and Structural Induction 171 of w relative to the sizes of u and v. Now assuming the inductive hypothesis, we have min(a1 + b1, a2 + b2, ... , a + bn, an+l + bn+1) = min(min(a1 + b1, a2 + b2, ... , a,,+ bn), an+l + bn+d (by definition) 2 min(min(a1, a2, ... , an)+ min(b1, b2 .... , b an+l + bn+I) 11 11 ), (by the inductive hypothesis and the lemma) 2'. min(min(a1, a2, ... , an), an+d + min(min(b1, b2, ... , bn), bn+I) (by the already proved case n = 2) = min(a1, a2, ... , an, an+1) + min(b1, b2, ... , bn, bn+I) (by definition). 23. We can define the set S = { x I x is a positive integer and x is a multiple of 5} by the basis step requirement that 5 E S and the recursive requirement that if n E S, then n + 5 E S. Alternately we can mimic Example 5, making the recursive part of the definition that x + y E S whenever :r and y are in S. 25. a) Since we can generate all the even integers by starting with 0 and repeatedly adding or subtracting 2, a simple recursive way to define this set is as follows: 0 E S; and if x E S then x + 2 E S and x - 2 E S. b) The smallest positive integer congruent to 2 modulo 3 is 2, so we declare 2 obtained by adding multiples of 3, so our inductive step is that if x E S, then x E S. All the others can be +3E S. c) The positive integers not divisible by 5 are the ones congruent to 1. 2, 3, or 4 modulo 5. Therefore we can proceed just as in part (b), setting 1 E S, 2 E S, 3 E S, and 4 E S as the base cases, and then declaring that if x E S, then x + 5 E S. 27. a) If we apply each of the recursive step rules to the only element given in the basis step, we see that (0, 1), (1, 1), and (2, 1) are all in S. If we apply the recursive step to these we add (0, 2), (1, 2), (2, 2), (3, 2), and (4, 2). The next round gives us (0, 3), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3), and (6, 3). And a fourth set of applications adds (0,4), (1,4), (2,4), (3,4), (4,4), (5,4), (6,4), (7,4), and (8,4). b) Let P( n) be the statement that a ::; 2b whenever (a, b) E S is obtained by n applications of the recursive step. For the basis step, P(O) is true, since the only element of S obtained with no applications of the recursive step is (0, 0), and indeed 0 ::; 2 · 0. Assume the strong inductive hypothesis that a ::; 2b whenever (a, b) ES is obtained by k or fewer applications of the recursive step, and consider an element obtained with k + 1 applications of the recursive step. Since the final application of the recursive step to an element (a, b) must be applied to an element obtained with fewer applications of the recursive step, we know that a ::; 2b. So we just need to check that this inequality implies a ::; 2(b + 1). a+ 1 ::; 2(b + 1), and a+ 2 ::; 2(b + 1). But this is clear, since we just add 0 ::; 2. 1 ::; 2, and 2 ::; 2, respectively, to a ::; 2b to obtain these inequalities. c) This holds for the basis step, since 0 ::::'. 0. If this holds for (a, b), then it also holds for the elements obtained from (a, b) in the recursive step, since adding 0 ::; 2, 1 ::; 2, and 2 ::; 2, respectively, to a ::; 2b yields a ::; 2(b + 1), a+ 1 ::; 2(b + 1), and a+ 2 ::; 2(b + 1). 29. a) Since we are working with positive integers, the smallest pair in which the sum of the coordinates is even is (1, 1). So our basis step is (1, 1) E S. If we start with a point for which the sum of the coordinates is even and want to maintain this parity, then we can add 2 to the first coordinate, or add 2 to the second coordinate, or add 1 to each coordinate. Thus our recursive step is that if (a, b) E S, then (a + 2, b) E S, (a, b + 2) E S, and (a+ 1, b + 1) E S. To prove that our definition works, we note first that (1, 1) has an even sum of coordinates, and if (a, b) has an even sum of coordinates, then so do (a+ 2, b), (a, b + 2), and (a + 1, b + 1) , since we added 2 to the sum of the coordinates in each case. Conversely, we must show that if a + b is even, then (a, b) E S by our definition. We do this by induction on the sum of the coordinates. If the sum is 2, then (a,b) = (1,1), and the basis step put (a,b) into S. Otherwise the sum is at least 4, and 172 Chapter 5 Induction and Recursion at least one of (a - 2, b), (a, b - 2), and (a -1, b -1) must have positive integer coordinates whose sum is an even number smaller than a + b, and therefore must be in S by our definition. Then one application of the recursive step shows that (a, b) E S by our definition. b) Since we are working with positive integers, the smallest pairs in which there is an odd coordinate are (1, 1), (1, 2), and (2, 1). So our basis step is that these three points are in S. If we start with a point for which a coordinate is odd and want to maintain this parity, then we can add 2 to that coordinate. Thus our recursive step is that if (a, b) ES, then (a+ 2, b) ES and (a, b + 2) ES. To prove that our definition works, we note first that (1, 1), (1, 2), and (2, 1) all have an odd coordinate, and if (a, b) has an odd coordinate, then so do (a+ 2, b) and (a, b + 2), since adding 2 does not change the parity. Conversely (and this is the harder part), we must show that if (a, b) has at least one odd coordinate, then (a, b) E S by our definition. We do this by induction on the sum of the coordinates. If (a, b) = (1, 1) or (a, b) = (1, 2) or (a, b) = (2, 1), then the basis step put (a, b) into S. Otherwise either a or b is at least 3, so at least one of (a - 2, b) and (a, b - 2) must have positive integer coordinates whose sum is smaller than a+ b, and therefore must be in S by our definition, since we haven't changed the parities. Then one application of the recursive step shows that (a, b) E S by our definition. c) We use two basis steps here, (1,6) ES and (2,3) ES. Ifwe want to maintain the parity of a+b and the fact that b is a multiple of 3, then we can add 2 to a (leaving b alone), or we can add 6 to b (leaving a alone). So our recursive step is that if (a, b) E S, then (a + 2, b) E S and (a, b + 6) E S. To prove that our definition works, we note first that (1, 6) and (2, 3) satisfy the condition, and if (a, b) satisfies the condition, then so do (a+ 2, b) and (a, b + 6), since adding 2 or 6 does not change the parity of the sum, and adding 6 maintains divisibility by 3. Conversely (and this is the harder part), we must show that if (a, b) satisfies the condition, then (a, b) E S by our definition. We do this by induction on the sum of the coordinates. The smallest sums of coordinates satisfying the condition are 5 and 7, and the only points are (1, 6), which the basis step put into S, (2, 3), which the basis step put into S, and (4, 3) = (2 + 2, 3), which is in S by one application of our recursive definition. For a sum greater than 7, either a ~ 3, or a ~ 2 and b ~ 9 (since 2 + 6 is not odd). This implies that either (a - 2, b) or (a, b - 6) must have positive integer coordinates whose sum is smaller than a + b and satisfy the condition for being in S, and hence are in S by our definition. Then one application of the recursive step shows that (a, b) E S by our definition. 31. The answer depends on whether we require fully parenthesized expressions. Assuming that we do not, then the following definition is the most straightforward. Let F be the required collection of formulae. The basis step is that all specific sets and all variables representing sets are to be in F. The recursive part of the definition is that if a and j3 are in F, then so are a, (a) , a U (3, a n (3, and a - (3. If we insist on parentheses, then the recursive part of the definition is that if a and (3 are in F, then so are a, (a U (3), (an (3) , and (a - (3). 33. Let D = {O, 1, 2, 3, 4, 5, 6, 7, 8, 9} be the set of decimal digits. We think of a string as either being an element of D or else coming from a shorter string by appending an element of D, as in Definition 1. This problem is somewhat like Example 7. a) The basis step is for a string of length 1, i.e., an element of D. If x E D, then m(x) = x. For the recursive step, if the string s = tx, where t E D* and x E D, then m( s) = min( m( s), x). In other words, if the last digit in the string is smaller than the minimum digit in the rest of the string, then the last digit is the smallest digit in the string; otherwise the smallest digit in the rest of the string is the smallest digit in the string. b) Recall the definition of concatenation (Definition 2). The basis step does not apply, since s and t here must be nonempty. Lett= wx, where w ED* and x ED. If w =>.,then m(st) = m(sx) = min(m(s),x) = min(m(s), m(x)) by the recursive step and the basis step of the definition of min part (a). Otherwise, m(st) = m((sw)x) = min(m(sw),x) by the definition of min part (a). But m(sw) = min(m(s),m(w)) by the inductive hypothesis of our structural induction, so m(st) = min(min(m(s), m(w)), x) = min(m(s), min(m(w), x)) Section 5.3 Recursive Defi.nitions and Structural Induction 173 by the meaning of min. But min( m( w), x) = m( wx) = m( t) by the recursive step of the definition of m in part (a). Thus m(st) = min(m(s), m(t)). 35. The string of length 0, namely the empty string, is its own reversal, so we define ).. R = ).. . A string w of length n + 1 can always be written as vy, where v is a string of length n (the first n symbols of w ), and y is a symbol (the last symbol of w). To reverse w, we need to start with y, and then follow it by the first part of w (namely v ), reversed. Thus we define wR = y(vR). (Note that the parentheses are for our benefit~they are not part of the string.) 37. We set w 0 =)..(the concatenation of no copies of w should be defined to be the empty string). For i;::: 0, we define wi+l = ww", where this notation means that we first write down w and then follow it with w". 39. The recursive part of this definition tells us that the only way to modify a string in A to obtain another string in A is to tack a 0 onto the front and a 1 onto the end. Starting with the empty string, then, the only strings we get are>-., 01, 0011, 000111, .... In other words, A= {on1n In 2 0}. 41. The basis step is i = 0, where we need to show that the length of w 0 is 0 times the length of w. This is true, no matter what w is, since l(w 0 ) = l(>-.) = 0. Assume the inductive hypothesis that l(w') = i · l(w). Then l( w"+l) = l( wwi) = l( w) + l( w"), this latter equality having been shown in Example 12. Now by the inductive hypothesis we have l(w) + l(w") = l(w) + i · l(w) = (i + 1) · l(w), as desired. 43. This is similar to Theorem 2. For the full binary tree consisting of just the root r the result is true since n(T) = 1 and h(T) = 0, and 1 2 2 · 0 + 1. For the inductive hypothesis we assume that n(T1) 2 2h(T1) + 1 and n(T2) 2: 2h(T2) + 1 where T1 and T2 are full binary trees. By the recursive definitions of n(T) and h(T), we have n(T) = 1 + n(T1) + n(T2) and h(T) = 1 +max( h(T1), h(T2)). Therefore n(T) = 1 + n(T1) + n(T2) ;::: 1+2h(T1)+1+2h(T2) + 1 2 1 + 2 · max(h(T1), h(T2)) + 2 since the sum of two nonnegative numbers is at least as large as the larger of the two. But this equals 1 + 2(max(h(T1), h(T2 )) + 1) = 1 + 2h(T), and our proof is complete. 45. The basis step requires that we show that this formula holds when (m, n) = (0, 0). The inductive step requires that we show that if the formula holds for all pairs smaller than (m, n) in the lexicographic ordering of N x N, then it also holds for (m, n) . For the basis step we have a0 ,0 = 0 = 0 + 0. For the inductive step, assume that am' ,n' = m' + n' whenever (m', n') is less than (m, n) in the lexicographic ordering of N x N. By the recursive definition, if n = 0 then am,n = am-l,n + 1; since (m - 1, n) is smaller than (m, n), the inductive hypothesis tells us that am-l,n = m - 1 + n, so am,n = m - 1+n+1 = m + n, as desired. Now suppose that n > 0, so that am,n = am,n-l + 1. Again we have am,n-l = m + n - 1, so am,n = m + n - 1+1 = m + n, and the proof is complete. 47. a) It is clear that Pm,m =Pm, since a number exceeding m can never be used in a partition of m. b) We need to verify all five lines of this definition, show that the recursive references are to a smaller value of m or n, and check that they take care of all the cases and are mutually compatible. Let us do the last of these first. The first two lines take care of the case in which either m or n is equal to 1. They are consistent with each other in case m = n = 1. The last three lines are mutually exclusive and take care of all the possibilities for m and n if neither is equal to 1, since, given any two numbers, either they are equal or one is greater than the other. Note finally that the third line allows m = 1; in that case the value is defined to be P 1,1 , which is consistent with line one, since P1 ,n = 1. Chapter 5 174 Induction and Recursion Next let us make sure that the logic of the definition is sound, specifically that Pm,n is being defined in terms of P,,1 for i :::; rn and j :::; n, with at least one of the inequalities strict. There is no problem with the first two lines, since these are not recursive. The third line is okay, since rn < n, and Pm,n is being defined in terms of Pm,m. The fourth line is also okay, since here Pm,m is being defined in terms of Pm,m-l. Finally, the last line is okay, since the subscripts satisfy the desired inequalities. Finally, we need to check the content of each line. (Note that so far we have hardly even discussed what Pm,n means!) The first line says that there is only one way to write the number 1 as the sum of positive integers, none of which exceeds n, and that is patently true, namely as 1 = 1. The second line says that there is only one way to write the number rn as the sum of positive integers, none of which exceeds 1, and that, too, is obvious, namely rn = 1 + 1 + · · · + 1. The third line says that the number of ways to write rn as the sum of integers not exceeding n is the same as the number of ways to write rn as the sum of integers not exceeding rn as long as rn < n. This again is true, since we could never use a number from {rn + 1, rn + 2, ... , n} in such a sum anyway. Now we begin to get to the meat. The fourth line says that the number of ways to write rn as the sum of positive integers not exceeding rn is 1 plus the number of ways to write rn as the sum of positive integers not exceeding m - 1. Indeed, there is exactly one way to write m as the sum of positive integers not exceeding m that actually uses m, namely rn = m; all the rest use only numbers less than or equal to m - 1. This verifies line four. The real heart of the matter is line five. How can we write rn as the sum of positive integers not exceeding n? We may use an n, or we may not. There are exactly Pm,n-1 ways to form the sum without using n, since in that case each summand is less than or equal to n - 1 . If we do use at least one n, then we have m = n + (m - n) . The number of ways this can be done, then, is the same as the number of ways to complete the partition by writing (m - n) as the sum of positive integers not exceeding n. Thus there are Pm-n,n ways to write rn as the sum of numbers not exceeding n, at least one of which equals n. By the sum rule (see Chapter 6), we have Pm,n = Pm,n-1 + Pm-n,n, as desired. c) We expand each Pm,n according to the definition. For the first problem we have (deleting the commas in the subscripts for readability) Ps = Pss = l+Ps4 = l+P.s3+P14 = l+Ps2+P23+l = l+Ps1 +P32+P22+l = l+l+P31 +P12 + l+P21 +1=1+1+ 1+1+ 1+ 1+1 = 7. For the second problem we have P5 = P6 5 = l+P5 5 = l+P54+P1s = l+P53+P24+l = l+P52+P33+P22+l = l+P51 +P42+l+P32+l+P21 +1 = l+l+P41 + P 22 +1+P31 +P12 +1+1+1 = l+l+l+l+P21 +l+l+l+l+l+l=1+1+1+1+1+1+1+1+1+1+1=11. 49. We prove this by induction on m. The basis step is m = 1, so we need to compute A(l, 2). Line four of the definition tells us that A(l, 2) = A(O, A(l, 1)). Since A(l, 1) = 2, by line three, we see that A(l, 2) = A(O, 2). Now line one of the definition applies, and we see that A(l, 2) = A(O, 2) = 2 · 2 = 4, as desired. For the inductive step, assume that A(m - 1, 2) = 4, and consider A(rn, 2). Applying first line four of the definition, then line three, and then the inductive hypothesis, we have A(m, 2) = A(m - 1, A(m, 1)) = A(m -1, 2) = 4. 51. a) We use the results of Exercises 49 and 50: A(2, 3) = A(l, A(2, 2)) = A(l, 4) = 24 = 16. b) We have A(3,3) = A(2,A(3,2)) = A(2,4) by Exercise 49. Now one can show by induction (using the 2 result of Exercise 50) that A(2, n) is equal to 22 22 22 = 216 = 65,536. , with n 2's in the tower. Therefore the answer is 53. It is often the case in proofs by induction that you need to prove something stronger than the given proposition, in order to have a stronger inductive hypothesis to work with. This is called inductive loading (see the preamble to Exercise 74 in Section 5.1). That is the case with our proof here. We will prove the statement "A(rn,k) > A(rn,l) if k > l for all m, k, and l," and we will use double induction, inducting first on m, and then within the inductive step for that induction, inducting on k (using strong induction). Note that this stronger statement implies the statement we are trying to prove-just take k = l + 1 . Section 5.3 Recursive Definitions and Structural Induction 175 The basis step is m = 0, in which the statement at hand reduces (by line one of the definition) to the true conditional statement that if k > l, then 2k > 2l. Next we assume the inductive hypothesis on m, namely that A( m, x) > A( m, y) for all values of x and y with x > y. We want now to show that if k > l, then A( m + 1, k) > A( m + 1, l). This we will do by induction on k. For the basis step, k = 0, there is nothing to prove, since the condition k > l is vacuous. Similarly, if k = 1, then A(m + 1, k) = 2 and A(m + 1, l) = 0 (since necessarily l = 0 ), so the desired inequality holds. So assume the inductive hypothesis (using strong induction), that A(m + l,r) > A(m + l,s) whenever k > r > s, where k;:::: 2. We need to show that A(m + 1, k) > A(m + 1, l) if k > l. Now A(m + 1, k) = A(m, A(m + 1, k - 1)) by line four of the definition. Since k - 1 ;:::: l, we apply the inductive hypothesis on k to yield A(m + 1, k - 1) > A(m + 1, l - 1), and therefore by the inductive hypothesis on m, we have A( m, A( m + 1, k - 1)) > A( m, A( m + 1, l - 1)). But this latter value equals A(m + 1, l), as long as l;:::: 2. Thus we have shown that A(m + 1, k) > A(m + 1, l) as long as l 2: 2. On the other hand, if l = 0 or 1, then A(m + 1, l) :::; 2 (by lines two and three of the definition), whereas A(m + 1, 2) = 4 by Exercise 49. Therefore A(m + 1, k) ;:::: A(m + 1, 2) > A(m + 1, l). This completes the proof. 55. We repeatedly invoke the result of Exercise 54, which says that A( m + 1, j) > A( m, j). Indeed, we have A(i,j);:::: A(i-1,j) 2: · · ·;:::: A(O,j) = 2j 2: j. 57. Let P(n) be the statement "F is well-defined at n; i.e., F(n) is a well-defined number." We need to show that P(n) is true for all n. We do this by strong induction. First P(O) is true, since F(O) is well-defined by the specification of F(O). Next assume that P(k) is true for all k < n. We want to show that P(n) is also true, in other words that F(n) is well-defined. Since the definition gave F(n) in terms of F(O) through F(n - 1), and since we are assuming that these are all well-defined (our inductive hypothesis), we conclude that F(n) is well-defined, as desired. 59. a) This would be a proper definition if the recursive part were stated to hold for n ;:::: 2. As it stands, however, F(l) is ambiguous. b) This definition makes no sense as it stands; F(2) is not defined, since F(O) isn't. c) For n = 4, the recursive part makes no sense, since we would have to know F( 4/3). Also, F(3) is ambiguous. d) The definition is ambiguous about n = 1, since both the second clause and the third clause seem to apply. If the second clause is restricted to odd n 2: 3, then the sequence is well-defined and begins 1 , 2, 2, 3, 3, 3, 4, 4, 5, 4. e) We note that F(l) is defined explicitly, but we run into problems trying to compute F(2): F(2) = 1+F(F(l))=1 + F(2). This not only leaves us begging the question as to what F(2) is, but is a contradiction, since 0-/= 1. 61. In each case we will apply the definition to compute log(o) , then log(l) , then logC 2 l, then logC 3 l and so on. As soon as we get an answer no larger than 1 we stop; the last "exponent" is the answer. In other words log* n is the number of times we need to apply the log function until we get a value less than or equal to 1. Note that log(l) n = log n for n > 0. Similarly, log( 2 ) n = log(log n) as long as it is defined ( n > 1), logC 3 l n = log(log(log n)) as long as it is defined ( n > 2), and so on. Normally the parentheses are understood and omitted. a) log(O) 2 = 2, log(l) 2 =log 2 = 1; therefore log* 2 = 1, the last "exponent." b) log(o) 4 = 4, log(l) 4 = log 4 = 2, logC 2 l 4 = log 2 = 1; therefore log* 4 = 2, the last "exponent." We had to take the log twice to get from 4 down to 1. Chapter 5 176 Induction and Recursion c) log(Ol 8 = 8, log( 1 ) 8 = log 8 = 3, log( 2 ) 8 = log 3 ~ 1.585, log( 3 ) 8 ~ log 1.585 ~ 0.664; therefore log* 8 = 3, the last "exponent." We had to take the log three times to get from 8 down to something no bigger than 1. d) log(o) 16 = 16, log(l) 16 = log 16 = 4, log( 2 ) 16 = log 4 = 2, log< 3 l 16 = log 2 = 1; therefore log* 16 = 3, the last "exponent." We had to take the log three times to get from 16 down to 1. e) log< 0 l 256 = 256, log< 1 l 256 = log 256 = 8; by part ( c), we need to take the log three more times in order to get from 8 down to something no bigger than 1, so we have to take the log four times in all to get from 256 down to something no bigger than 1. Thus log* 256 = 4. f) log 65536 = 16; by part ( d), we need to take the log three more times in order to get from 16 down to 1, so we have to take the log four times in all to get from 65536 down to 1. Thus log* 65536 = 4. g) log 22048 = 2048; taking log four more times gives us, successively, 11, approximately 3.46, approximately 1. 79, approximately 0.84. So log* 22048 = 5. 63. Each application of the function f subtracts another a from the argument. Therefore iterating this function k times (which is what J(k) does) has the effect of subtracting ka. Therefore J(k)(n) = n - ka. Now f 0(n) is the smallest k such that Jlkl(n) :::::; 0, i.e., n - ka:::::; 0. Solving this for k easily yields k?:: n/a. Thus f 0(n) = In/ al (we need to take the ceiling function because k must be an integer). 65. Each application of the function f takes the square root of its argument. Therefore iterating this function k times (which is what J(k) does) has the effect of taking the (2k)th root. Therefore J(kl(n) = n 1 12 k. Now f2(n) is the smallest k such that J(k)(n):::::; 2, that is, n 112 •:::::; 2. Solving this for n easily yields n :S 22 k, so k ?:: log log n, where logarithm is taken to the base 2. Thus f2 (n) = f1og log nl for n ?:: 2 (we need to take the ceiling function because k must be an integer) and f2(1) = 0. SECTION 5.4 Recursive Algorithms Recursive algorithms are important theoretical entities, but they often cause a lot of grief on first encounter. Sometimes it is helpful to "play computer" very carefully to see how a recursive algorithm works. Ironically, however. it is good to avoid doing that after you get the idea. Instead, convince yourself that if the recursive algorithm handles the base case correctly, and handles the recursive step correctly (gives the correct answer assuming that the correct answer was obtained on the recursive call), then the algorithm works. Let the computer worry about actually "recursing all the way down to the base case"! 1. First, we use the recursive step to write 5! = 5 · 4!. We then use the recursive step repeatedly to write 4! = 4 · 3!, 3! = 3 · 2!, 2! = 2 · l!, and 1! = 1 · O!. Inserting the value of O! = 1, and working back through the steps, we see that 1! = 1·1=1, 2! = 2·1! = 2·1=2, 3! = 3 · 2! = 3 · 2 = 6, 4! = 4 · 3! = 4 · 6 = 24, and 5! = 5 . 4! = 5 . 24 = 120. 3. With this input, the algorithm uses the else clause to find that gcd(8, 13) = gcd(l3 mod 8, 8) = gcd(5, 8). It uses this clause again to find that gcd(5, 8) = gcd(8 mod 5, 5) = gcd(3, 5), then to get gcd(3, 5) = gcd(5 mod 3, 3) = gcd(2, 3), then gcd(2, 3) = gcd(3 mod 2, 2) = gcd(l, 2), and once more to get gcd(l, 2) = gcd(2 mod 1, 1) = gcd(O, 1). Finally, to find gcd(O, 1) it uses the first step with a= 0 to find that gcd(O, 1) = 1. Consequently, the algorithm finds that gcd(8, 13) = 1. Section 5.4 177 Recursive Algorithms 5. First, because n = 11 is odd, we use the else clause to see that mpower(3, 11, 5) = (mpower(3, 5, 5) 2 mod 5 · 3 mod 5) mod 5. We next use the else clause again to see that mpower(3, 5, 5) = (mpower(3, 2, 5) 2 mod 5 · 3 mod 5) mod 5. Then we use the else if clause to see that mpower(3, 2, 5) = mpower(3, 1, 5) 2 mod 5. Using the else clause again, we have mpower(3, 1, 5) = (mpower(3, 0, 5) 2 mod 5 · 3 mod 5) mod 5. Finally, using the if clause, we see that mpower(3, 0, 5) = 1. Now we work backward: mpower(3, 1, 5) = (1 2 mod 5 · 3 mod 5) mod 5 = 3, mpower(3, 2, 5) = 32 mod 5 = 4, mpower(3, 5, 5) = (4 2 mod 5 · 3 mod 5) mod 5 = 3, and finally that mpower(3, 11, 5) = (3 2 mod 5 · 3 mod 5) mod 5 = 2. We conclude that 3 11 mod 5 = 2. 7. The key idea for this recursive procedure is that nx = ( n - 1 )x + x. Thus we compute nx by calling the procedure recursively, with n replaced by n - 1 , and adding x. The base case is 1 · x = x. procedure product(n: positive integer, x: integer) if n = 1 then return x else return product(n - 1, x) + x 9. If we have already found the sum of the first n - 1 odd positive integers, then we can find the sum of the first n positive integers simply by adding on the value of the nth odd positive integer. We need to realize that the nth odd positive integer is 2n - 1, and we need to note that the base case (in which n = 1) gives us a sum of 1 . The algorithm is then straightforward. procedure sum of odds(n: positive integer) if n = 1 then return 1 else return sum of odds(n - 1) + 2n - 1 11. We recurse on the size of the list. If there is only one element, then it is the smallest. Otherwise, we find the smallest element in the list consisting of all but the last element of our original list, and compare it with the last element of the original list. Whichever is smaller is the answer. (We assume that there is already a function min, defined for two arguments, which returns the smaller.) procedure smallest(a 1 , a 2 , ... , an : integers) if n = 1 then return 1 else return min(smallest(a1, a2, ... , an-1), an) 13. We basically just take the recursive algorithm for finding n! and apply the mod operation at each step. Note that this enables us to calculate n! mod m without using excessively large numbers, even if n! is very large. procedure modfactorial(n, m: positive integers) if n = 1 then return 1 else return (n · (modfactorial(n -1,m)) mod m 15. We need to worry about which of our arguments is the larger. Since we are to make sure always to call the algorithm with the first argument less than two stopping conditions: when a = 0 (in which case the answer is b), and become equal (in which case the answer is their common value). Otherwise that gcd(a, b) given a < b as input, we need the second. There need to be when the two arguments have we use the recursive condition = gcd(a, b - a), taking care to reverse the arguments if necessary. 178 Chapter 5 Induction and Recursion procedure gcd(a, b: nonnegative integers with a< b) if a = 0 then return b else if a = b - a then return a else if a< b - a then return gcd(a, b - a) else return gcd(b - a, a) 17. We build the recursive steps into the algorithm. procedure multiply(x, y: nonnegative integers) if y = 0 then return 0 else if y is even then return 2 · multiply(x, y/2) else return 2 · multiply(x, (y - 1)/2) + x 19. We use strong induction on a, starting at a = 0. If a = 0, we know that gcd(O, b) = b for all b > 0, so the if clause handles this basis case correctly. Now fix k > 0 and assume the inductive hypothesis-that the algorithm works correctly for all values of its first argument less than k. Consider what happens with input (k, b), where k < b. Since k > 0, the else clause is executed, and the answer is whatever the algorithm gives as output for inputs (b mod k, k). Note that b mod k < k, so the input pair is valid. By our inductive hypothesis, this output is in fact gcd(b mod k, k). By Lemma 1 in Section 4.3 (when the Euclidean algorithm was introduced), we know that gcd(k, b) = gcd(b mod k, k), and our proof is complete. 21. For the basis step, if n = 1, then nx = x, and the algorithm correctly returns x. For the inductive step, assume that the algorithm correctly computes kx, and consider what it does to compute (k + 1)x. The recursive clause applies, and it recursively computes the product of k + 1 - 1 = k and x, and then adds x. By the inductive hypothesis, it computes that product correctly, so the answer returned is kx + x = ( k + 1)x, which is the correct answer. 23. As usual with recursive algorithms, the algorithm practically writes itself. procedure square(n: nonnegative integer) if n = 0 then return 0 else return square(n - 1) + 2(n - 1) + 1 The proof of correctness, by mathematical induction, practically writes itself as well. Let P( n) be the statement that this algorithm correctly computes n 2 . Since 02 = 0, the algorithm works correctly (using the if clause) if the input is 0. Assume that the algorithm works correctly for input k. Then for input k + 1 it gives as output (because of the else clause) its output when the input is k, plus 2(k + 1 - 1) + 1. By the inductive hypothesis, its output at k is k 2 , so its output at k+ 1 is k 2 +2(k+1-1) + 1 = k 2 +2k+1 = (k+ 1) 2 , exactly what it should be. 25. Algorithm 2 uses 2n multiplications by a, one for each factor of a in the product a 2 n The algorithm in Exercise 24, based on squaring, uses only n multiplications (each of which is a multiplication of a number 24 by itself). For instance, to compute a = a 16 , this algorithm will compute a· a= a 2 (one multiplication), 4 2 2 then a · a = a (a second multiplication), then a 4 · a4 = as (a third), and finally as· as = a 16 (a fourth multiplication). 27. Algorithm 2 uses n multiplications by a, one for each factor of a in the product an. The algorithm in Exercise 26 will use O(log n) multiplications as it computes squares. Furthermore, in addition to squaring, sometimes a multiplication by a is needed; this will add at most another O(log n) multiplications. Thus a total of O(log n) multiplications are used altogether. 29. This is very similar to the recursive procedure for computing the Fibonacci numbers. Note that we can combine the two base cases (stopping rules) into one. Section 5.4 Recursive Algorithms 179 procedure sequence (n : nonnegative integer) if n < 2 then return n + 1 else return sequence(n - 1) · sequence(n - 2) 31. The iterative version is much more efficient. The analysis is exactly the same as that for the Fibonacci sequence given in this section. Indeed, the nth term in this sequence is actually just 2fn, as is easily shown by induction. 33. This is essentially just Algorithm 8, with a different operation and with different (and more) initial conditions. procedure iterative(n: nonnegative integer) if n = 0 then return 1 else if n = 1 then return 2 else x := 1 y := 2 := 3 for i := 1 to n - 2 w :=x+y+z x := y y := z z z :=w return z 35. These algorithms are very similar to the procedures for computing the Fibonacci numbers. Note that for the recursive version, we can combine the three base cases (stopping rules) into one. procedure recursive(n: nonnegative integer) < 3 then return 2n + 1 else return recursive(n -1) · (recursive(n - 2)) 2 • (recursive(n - 3)) 3 if n procedure iterative(n: nonnegative integer) = 0 then return 1 else if n = 1 then return 3 else x := 1 y := 3 if n z := 5 for i := 1 to n - 2 w := z · y 2 · x 3 x := y y := z z :=w return z The recursive version is much easier to write, but the iterative version is much more efficient. In doing the computation for the iterative version, we just need to go through the loop n - 2 times in order to compute an, so it requires 0( n) steps. In doing the computation for the recursive version, we are constantly recalculating previous values that we've already calculated, just as was the case with the recursive version of the algorithm to calculate the Fibonacci numbers. 37. We use the recursive definition of the reversal of a string given in Exercise 35 of Section 5.3, namely that (vy )R = y( vR) , where y is the last symbol in the string and v is the substring consisting of all but the last symbol. The right-hand side of the last statement in this procedure means that we concatenate bn with the output of the recursive call. 180 Chapter 5 Induction and Recursion procedure reverse(b 1b2 ... bn : bit string) if n = 0 then return .A else return bnreverse(b1b2 ... bn-1) 39. The procedure correctly gives the reversal of .A as .A (the basis step of our proof by mathematical induction on n ), and because the reversal of a string consists of its last character followed by the reversal of its first n -1 characters (see Exercise 35 in Section 5.3), the algorithm behaves correctly when n > 0 by the inductive hypothesis. 41. The algorithm merely implements the idea of Example 14 in Section 5.1. If n = 1 (the basis step here), we simply place the one right triomino so that its armpit corresponds to the hole in the 2 x 2 board. If n > 1, then we divide the board into four boards, each of size 2n-l x 2n-l, notice which quarter the hole occurs in, position one right triomino at the center of the board with its armpit in the quarter where the missing square is (see Figure 7 in Section 5.1), and invoke the algorithm recursively four times-once on each of the 2n-l x 2n-l boards, each of which has one square missing (either because it was missing to begin with, or because it is covered by the central triomino). 43. Essentially all we do is write down the definition as a procedure. procedure ackermann(m, n: nonnegative integers) if m = 0 then return 2 · n else if n = 0 then return 0 else if n = 1 then return 2 else return ackermann(m - 1, ackermann(m, n - 1)) 45. We assume that sorting is to be done into alphabetical order. First the list is split into the two lists b, d, a, f, g and h, z,p, o, k, and each of these is sorted by merge sort. Let us assume for a moment that this has been done, so the two lists are a, b, d, f, g and h, k, o, p, z. Then these two lists are merged into one sorted list, as follows. We compare a with h and find that a is smaller; thus a comes first in the merged list, and we pass on to b. Comparing b with h, we find that b is smaller, so b comes next in the merged list, and we pass on to d. We repeat this process (using Algorithm 10) until the lists are merged into one sorted list, a, b, d, f, g, h, k, o,p, z. (It was just a coincidence that every element in the first of these two lists came before every element in the second.) Let us return to the question of how each of the 5-element lists was sorted. For the list b, d, a, f, g, we divide it into the sublists b, d, a and f, g. Again we sort each piece by the same algorithm, producing a, b, d and f, g, and we merge them into the sorted list a, b, d, f, g. Going one level deeper into the recursion, we see that sorting b, d, a was accomplished by splitting it into b, d and a, and sorting each piece by the same algorithm. The first of these required further splitting into b and d. One element lists are already sorted, of course. Similarly, the other 5-element list was sorted by a similar recursive process. A tree diagram for this problem is displayed below. The top half of the picture is a tree showing the splitting part of the algorithm. The bottom half shows the merging part as an upside-down tree. bdefghzpok bdef g hzpok ~ fg bde A bd (\d e /'\ f /-.__ hzp g A/\ p h z ok A o k Section 5.4 Recursive Algorithms 181 h~v hkopz ebdf ghkopz 47. All we have to do is to make sure that one of the lists is exhausted only when the other list has only one element left in it. In this case, a comparison is needed to place every element of the merged list into place, except for the last element. Clearly this condition is met if and only if the largest element in the combined list is in one of the initial lists and the second largest element is in the other. One such pair of lists is {1, 2, ... , m - 1, m + n} and {m, m + 1, ... , m + n - 1}. 49. We use strong induction on n, showing that the algorithm works correctly if n = 1, and that if it works correctly for n = 1 through n = k , then it also works correctly for n = k + 1 . If n = 1 , then the algorithm does nothing, which is correct, since a list with one element is already sorted. If n = k + 1, then the list is split into two lists, L 1 and L 2 . By the inductive hypothesis, mergesort correctly sorts each of these sublists, and so it remains only to show that merge correctly merges two sorted lists into one. This is clear, from the code given in Algorithm 10, since with each comparison, the smallest element in L 1 U L2 not yet put into L is put there. 51. We need to compare every other element with a 1 . Thus at least n-1 comparisons are needed (we will assume for Exercises 53 and 55 that the answer is exactly n - 1 ). The actual number of comparisons depends on the actual encoding of the algorithm. With any reasonable encoding, it should be O(n). 53. In our analysis we assume that a 1 is considered to be put between the two sublists, not as the last element of the first sublist (which would require an extra pass in some cases). In the worst case, the original list splits into lists of length 3 and 0 (with a 1 between them); by Exercise 51, this requires 4 - 1 = 3 comparisons. No comparisons are needed to sort the second of these lists (since it is empty). To sort the first, we argue in the same way: the worst case is for a splitting into lists of length 2 and 0, requiring 3 - 1 = 2 comparisons. Similarly, 2 - 1 = 1 comparison is needed to split the list of length 2 into lists of length 1 and 0. In all, then, 3 + 2 + 1 = 6 comparisons are needed in this worst case. (One can prove that this discussion really does deal with the worst case by looking at what happens in the various other cases.) 55. In our analysis we assume that a 1 is considered to be put between the two sublists, not as the last element of the first sublist (which would require an extra pass in some cases). We claim that the worst case complexity is n( n - 1) /2 comparisons, and we prove this by induction on n. This is certainly true for n = 1, since no comparisons are needed. Otherwise, suppose that the initial split is into lists of size k and n - k - 1. By the inductive hypothesis, it will require (k(k -1 )/2) + ((n - k - l)(n - k - 2)/2) comparisons in the worst case to finish the algorithm. This quadratic function of k attains its maximum value if k = 0 (or k = n - 1), namely the value (n - l)(n - 2)/2. Also, it took n - 1 comparisons to perform the first splitting. If we add these two quantities ((n - l)(n - 2)/2 and n - l) and do the algebra, then we obtain n(n -1)/2, as desired. Thus in the worst case the complexity is O(n 2 ). 182 Chapter 5 SECTION 5.5 Induction and Recursion Program Correctness Entire books have been written on program verincation; obviously here we barely scratch the surface. In some sense program verincation is just a very careful stepping through a program to prove that it works correctly. Tliere should be no problem verifying anything except loops; indeed it may seem that there is nothing to prove. Loops are harder to deal with. The trick is to find the right invariant. Once you have the invariant, it again is really a matter of stepping through one pass of the loop to make sure that the invariant is satisned at the end of that pass, given that it was satisfied at the beginning. Analogous to our remark in the comments for Section 1. 7, there is a deep theorem of logic (or theoretical computer science) that says essentially that there is no algorithm for proving correct programs correct, so the task is much more an art than a science. Your proofs must be valid proofs, of course. You may use the rules of inference discussed in Section 1.6. What is special about proofs of program correctness is the addition of some special rules for this setting. These exercises (and the examples in the text) may seem overly simple, but unfortunately it is extremely hard to prove all but the simplest programs correct. 1. We suppose that initially x = 0. The segment causes two things to happen. First y is assigned the value of 1. Next the value of x + y is computed to be 0 + 1 = 1, and so z is assigned the value 1. Therefore at the end z has the value 1, so the final assertion is satisfied. 3. We suppose that initially y = 3. The effect of the first two statements is to assign x the value 2 and z the value 2 + 3 = 5. Next, when the if. .. then statement is encountered, since the value of y is 3, and 3 > 0 is true, the statement z := z + 1 assigns the value 5 + 1 = 6 to z (and the else clause is not executed). Therefore at the end, z has the value 6, so the final assertion z =6 is true. 5. We generalize the rule of inference for the if. .. then ... else statement, given before Example 3. Let p be the initial assertion, and let q be the final assertion. If condition 1 is true, then 5 1 will get executed, so we need (p A condition 1 ){ Si}q. Similarly, if condition 2 is true, but condition 1 is false, then 5 2 will get executed, so we need (p A •(condition 1) A condition 2){S2 }q. This pattern continues, until the last statement we need is (p A •(condition 1) A •(condition 2) A · · · /\ •(condition n - 1)) {Sn }q. Given all of these, we can conclude that pTq, where T is the entire statement. In symbols, we have (p /\ cond1.tion 1){S1 }q (p /\•(condition 1) /\ condition 2){S2 }q (p /\•(condition 1) /\•(condition 2) /\ · · · /\•(condition n - l)){Sn}q .·. p{if condition 1 then 5 1 else if condition 2 then 5 2 ..• else Sn}q. 7. The problem is similar to Example 4. We will use the loop invariant p: '"power= x 2 - 1 and i ::=; n+ l." Now p is true initially, since before the loop starts, i = 1 and power = 1 = x 0 = x 1 - 1 . (There is a technicality here: we define o0 to equal 1 in order for this to be correct if a; = 0. There is no harm in this, since n > 0, so if x = 0, then the program certainly computes the correct answer xn = 0.) We must now show that if p is true and i ::=; n before some pass through the loop, then p remains true after that pass. The loop increments i by one. Hence since i ::=; n before this pass through the loop, i ::=; n + 1 after this pass. Also the loop assigns power · x to power. By the inductive hypothesis, power started with the value x 2 - 1 (the old value of i). Therefore its new value is :r'- 1 · x = x' = x n. At termination we have (i ::=; n + 1) /\ •(i ::=; n), so i = n + 1. Hence power= x(n+l)-l = xn, as desired. Review Questions 183 9. We will break the problem up into the various statements that are left unproved in Example 5. We must show that p{ Si }q, where p is the assertion that m and n are integers, and q is the proposition p /\ (a= lnl). This follows from Example 3 and the fact that the values of m and n have not been tampered with. We must show that q{ S2}r, where r is the proposition q /\ (k = 0) /\ (x = 0). This is clear, since in S2, none of m, n, or a have been altered, but k and x have been assigned the value 0. We must show that (x = mk) /\ (k:::; a) is an invariant for the loop in S 3 . Assume that this statement is true before a pass through the loop. In the loop, k is incremented by 1. If k < a (the condition of the loop), then at the end of the pass, k 0; then the loop will be executed again. Within the loop x and y are replaced by y and x mod y, respectively. According to Lemma 1 in Section 4.3, gcd(x, y) = gcd(y,x mod y). Therefore after the execution of the loop, the value of gcd(x, y) remains what it was before. Furthermore, since y is a remainder, it is still greater than or equal to 0. Hence p remains true-it is a loop invariant. Furthermore, if the loop terminates, then it must be the case that y = 0. In this case we know that gcd(x,y) = x, the desired final assertion. Therefore the program, which gives x as its output, has correctly computed gcd(a, b). Finally (although this is not necessary to establish partial correctness), we can prove that the loop must terminate, since each iteration causes the value of y to decrease by at least 1 (by the definition of mod). Thus the loop can be iterated at most b times. GUIDE TO REVIEW QUESTIONS FOR CHAPTER 5 1. a) no b) Sometimes yes. If the given formula is correct, then it is often possible to prove it using the principle of mathematical induction (although it would be wishful thinking to believe that every such true formula could be so proved). If the formula is incorrect, then induction would not work, of course; thus an incorrect formula could not be shown to be incorrect using the principle. c) See Exercise 9 in Section 5.1. Chapter 5 184 Induction and Recursion 2. a) n 2 7 b) For the basis step we just check that 11 · 7 + 17 :S 27 . Fix n 2 7, and assume the inductive hypothesis, that lln + 17 :S 2n. Then ll(n + 1) + 17=(lln+17) + 11:S2n+11 < 2n + 2n = 2n+i. The strict inequality here follows from the fact that n ~ 4. 3. a) Carefully considering all the possibilities shows that the amounts of postage less than 32 cents that can be achieved are 0, 5, 9, 10, 14, 15, 18, 19, 20, 23, 24, 25, 27, 28, 29, and 30. All amounts greater than or equal to 32 cents can be achieved. b) To prove this latter statement, we check the basis step by noting that 32 = 9 + 9 + 9 + 5. Assume that we can achieve n cents, and consider n + 1 cents, where n ~ 32. If the stamps used for n cents included a 9-cent stamp, then replacing it by two 5-cent stamps gives us n + 1 cents, as desired. Otherwise only 5-cent stamps were used to achieve n cents, and since n > 30, there must be at least seven such stamps. Replace seven of the 5-cent stamps by four 9-cent stamps; this increases the amount of postage by 4 · 9 - 7 · 5 = 1 cent, again as desired. c) We check the base cases 32 = 3 · 9 + 5, 33 = 2 · 9 + 3 · 5, 34 = 9 + 5 · 5, 35 = 7 · 5, and 36 = 4 · 9. Fix n 2 37 and assume that all amounts from 32 to n - 1 can be achieved. To achieve n cents postage, take the stamps used for n - 5 cents (since n 2 37, n - 5 2 32, so the inductive hypothesis applies) and adjoin a 5-cent stamp. d) Let n be an integer greater than or equal to 32. We want to express n as a sum of a nonnegative multiple of 5 and a nonnegative multiple of 9. Divide n by 5 to obtain a quotient q and remainder r such that n = 5q + r and 0::::; r :S 4. Note that since n ~ 32, q 2 6. If r = 0, then we already have n expressed in the desired form. If r = 1, then n 2 36, so q 2 7; thus we can write n = 5q + 1 = 5(q - 7) + 4 · 9 to get the desired decomposition. If r = 2, then we rewrite n = 5q + 2 = 5(q - 5) + 3 · 9. If r = 3, then we rewrite n = 5q + 3 = 5(q - 3) + 2 · 9. And if r = 4, then we rewrite n = 5q + 4 = 5(q - 1) + 9. In each case we have the desired sum. 4. See Examples 2 and 3 in Section 5.2. 5. a) Seep. 314 and Appendix 1 (Axiom 4 for the positive integers). b) Let S be the set of positive integers that cannot be written as the product of primes. If S #- 0, then S has a least element, c. Clearly c #- 1, since 1 is the product of no primes. Thus c is greater than 1. Now c cannot be prime, since as such it would already be written as the product of primes (namely itself). Therefore c is a composite number, say c =ab, where a and b are both positive integers less than c. Since c is the smallest element of S, neither a nor b is in S. Therefore both a and b can be written as the product of primes. But multiplying these products together patently shows that c is the product of primes. This is a contradiction to the choice of c. Therefore our assumption that S #- 0 was wrong, and the theorem is proved. b) J(l) = 2, and f(n) = (n + l)f(n - 1) for all n 2 2 6. a) See Exercise 56 in Section 5.3. 7. a) See the top of p. 347. b) See Example 4 in Section 5.3. b) an = 3 · 2n- 3 for n ~ 3 8. a) See Exercise 57 in Section 5.3. 9. See Examples 8 and 9 in Section 5.3. b) See Example 12 in Section 5.3. 10. a) See Example 7 in Section 5.3. 11. a) See the beginning of Section 5.4. b) Call the sequence a 1 , a 2 , 12. See Example 3 in Section 5.4. ... , an. If n = 1, then the sum(a1) = ai. Otherwise sum(a1,a2, ... ,an) = Supplementary Exercises 185 13. a) See p. 367. b) We split the list into the two halves: 4, 10, 1, 5, 3 and 8, 7, 2, 6, 9. We then merge sort each half by applying this algorithm recursively and merging the results. For the first half, for example, this means splitting 4, 10, 1, 5, 3 into the two halves 4, 10, 1 and 5, 3, recursively sorting each half, and merging. For the second half of this, for example, it means splitting into 5 and 3, recursively sorting each half, and merging. Since these two halves are already sorted, we just merge, into the sorted list 3, 5. Similarly, we will get 1, 4, 10 for the result of merge sort applied to 4, 10, 1. When we merge 1, 4, 10 and 3, 5, we get 1, 3, 4, 5, 10. Finally, we merge this with the sorted second half, 2, 6, 7, 8, 9, to obtain the completely sorted list 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. c) O(nlogn); see pp. 369-370. 14. a) no b) No-you also need to show that it halts for all inputs, and the initial and final assertions for which you provide a proof of partial correctness need to be appropriate ones (i.e., relevant to the question of whether the program produces the correct output). 15. See the rules displayed in Section 5.5. 16. See p. 375. SUPPLEMENTARY EXERCISES FOR CHAPTER 5 1. Let P(n) be the statement that this equation holds. The basis step consists of verifying that P(l) is true, which is trivial because 2/3 = 1 - (1/3 1 ). For the inductive step we assume that P(k) is true and try to prove P(k + 1). We have 22 2 2 2 - + - + - + .. · + - + - 3 9 27 3n 3n+l 1 2 = 1 - -3n + 3n+I = (by the inductive hypothesis) 3 2 1 - 3n+l + 3n+l 1 = 1- 3n+l' as desired. 3. We prove this by induction on n. If n = 1 (basis step), then the equation reads 1·2° is the true statement 1 = 1. Assume that the statement is true for n: 1 · 2° + 2 · 21 + 3 · 22 + · · · + n · 2n-l We must show that it is true for n + 1. = (1-1) · 21 +1, = (n - 1) · 2n + 1 Thus we have 1·2°+2 · 21 +3 · 22 + .. · + n · 2n-l + (n + 1) · 2n = (n - 1) · 2n + 1+(n+1) · 2n = (2n) · 2n + 1 +1 1) - 1) · 2n+l + 1 , = n · 2n+I = ( (n + exactly as desired. (by the inductive hypothesis) which Chapter 5 186 Induction and Recursion 5. We prove this by induction on n. If n = 1 (basis step), then the equation reads 1/(1·4)=1/4, which is true. Assume that the statement is true for n: 1 1 1 n -+-+···+----1·4 4·7 (3n - 2)(3n + 1) 3n+ 1 We must show that it is true for n + 1. Thus we have 1 1 1 1 - - + - - + ... + + -c------.,--,...----~ 1·4 4-7 (3n-2)(3n+l) (3(n+l)-2)(3(n+l)+l) n 3n+l n --3n + 1 1 = -- + = + ------- (3(n+l)-2)(3(n+l)+l) (by the inductive hypothesis) 1 (3n + 1)(3n + 4) = 3n ~ 1 ( n + 3n ~ 4) 2 = _1_ (3n +4n+1) 3n + 1 3n+4 = _1_ ((3n + l)(n + 1)) 3n + 1 3n+4 n+l 3n+4 n+l 3(n+l)+l' exactly as desired. 7. Let P( n) be the statement 2n > n 3 . We want to prove that P( n) is true for all n > 9. The basis step is n = 10, in which we have 210 = 1024 > 1000 = 103 . Assume P(n); we want to show P(n + 1). Then we have (n + 1)3 = n 3 + 3n 2 + 3n + 1 ~ n 3 + 3n2 + 3n 2 + 3n2 = n 3 + 9n (since n 2': 1) 2 3 < n + n 3 (since n > 9) = 2n 3 < 2 · 2n (by the inductive hypothesis) = 2n+l, as desired. 9. This problem deals with factors in algebra. We have to be just a little clever. Let P(n) be the statement that a - b is a factor of an - bn . We want to show that P( n) is true for all positive integers n, and of course we will do so by induction. If n = 1, then we have the trivial statement that a - b is a factor of a - b. Next assume the inductive hypothesis, that P( n) is true. We want to show P( n + 1), that a - b is a factor of an+l - bn+l. The trick is to rewrite an+l - bn+l by subtracting and adding abn (and hence not changing its value). We obtain an+l - bn+l = an+l - abn + abn - bn+l = a(an - bn) + bn(a - b). Now this expression contains two terms. By the inductive hypothesis, a - b is a factor of the first term. Obviously a - b is a factor of the second. Therefore a - b is a factor of the entire expression, and we are done. 11. This should be similar to Example 9 in Section 5.1. First we check the basis step: When n = 1, 5n+l + 72 n-l = 36 + 7 = 43, which is certainly divisible by 43. Assume the inductive hypothesis, that 43 divides 5n+l + 72 n-l; we must show that 43 divides 5n+ 2 + 72 n+l. We have 5n+ 2 + 72 n+l = 6 · 5n+l + 49 · 72 n-l = 6 · 5n+l + 6 · 72 n-l + 43 · 72 n-l = 6(6n+l + 72 n-l) + 43 · 72 n-l. Now the first term is divisible by 43 because the inductive hypothesis guarantees that its second factor is divisible by 43. The second term is patently divisible by 43. Therefore the sum is divisible by 43, and our proof by mathematical induction is complete. 187 Supplementary Exercises 13. Let P( n) be the given equation. It is certainly true for n P(n) is true: = 0, since it reads a = a a+ (a+ d) +···+ (a+n d) in that case. Assume that (n+l)(2a+nd) -----'-2 =-'-----'--'--- Then a + (a + d) + · · · + (a + nd) + (a + (n + 1)d) = (n + 1) (~a + nd) + (a + (n + 1)d) (by the inductive hypothesis) (n + 1)(2a + nd) + 2(a + (n + l)d) 2 (n + 1)(2a + nd) + 2a + nd + nd + 2d 2 (n + 2)(2a + nd) + (n + 2)d 2 (n + 2)(2a + (n + l)d) 2 which is exactly P( n + 1). 15. We use induction. If n = 1, then the left-hand side has just one term, namely 5/6, and the right-hand side is 10/12, which is the same number. Assume that the equation holds for n = k, and consider n = k+ l. (Do not get confused by the choice of letters here! The index of summation in the problem as stated is just a dummy variable, and since we want to use k in the inductive hypothesis, we have changed the dummy summation index to i.) Then we have k+l i + 4 i + 4 k ~i(i+l)(i+2) = ~i(i+l)(i+2) k+5 + (k+l)(k+2)(k+3) k(3k + 7) k +5 (k + l)(k + ) + (k + l)(k + 2)(k + 3) 2 2 1 = (k + l)(k + 2) . (k(3k+7) 2 (by the inductive hypothesis) k+5) + k+ 3 1 2(k + l)(k + 2)(k + 3) . (k(3k + 7)(k + 3) + 2(k + 5)) 2(k + l)(k ~ 2)(k + 3) . (3k3 + 16k2 + 23k + 10) 1 2(k + l)(k + 2)(k + 3) . (3k + lO)(k + l) 2 1 2(k + 2)(k + 3) . (3k + lO)(k + 1) (k + 1)(3(k + 1) + 7) 2((k + 1) + l)((k + 1) + 2)' as desired. 17. When n = 1, we are looking for the derivative of g( x) = xex, which, by the product rule, is x · ex + ex = (x + 1)e, so the statement is true for n = 1. Assume that the statement is true for n = k, that is, the kth derivative is given by g(k) = (x + k)ex. Differentiating by the product rule gives us the (k + l)st derivative: g(k+l) = (x + k)ex +ex= (x + (k + l))ex, as desired. 19. We look at the first few Fibonacci numbers to see if there is a pattern: Jo = 0 (even), Ji = 1 (odd), h = 1 (odd), f3 = 2 (even), f 4 = 3 (odd), f 5 = 5 (odd), .... The pattern seems to be even-odd-odd, repeated forever. Since the pattern has period 3, we can formulate our conjecture as follows: f n is even if Chapter 5 188 Induction and Recursion n = 0 (mod 3), and is odd in the other two cases. Let us prove this by mathematical induction. There are two base cases, n = 0 and n = 1. The conjecture is certainly true in each of them, since 0 O (mod 3) and Jo is even. and 1 -;j. 0 (mod 3) and Jo is odd. So we assume the inductive hypothesis and consider a given = n+ 1. There are three cases to consider, depending on the value of (n+ 1) mod 3. If n+ 1 = 0 (mod 3), then n - 1 and n are congruent to 1 and 2 modulo 3, respectively. By the inductive hypothesis, both Jn-l and Jn are odd. Therefore f n+I. which is the sum of these two numbers, is even, as desired. The other two cases are similar. If n + 1 1 (mod 3), then n - 1 and n are congruent to 2 and 0 modulo 3, respectively. By the = inductive hypothesis, J n-l is odd and Jn is even. Therefore J n+l • which is the sum of these two numbers, is odd, as desired. On the other hand, if n + 1 =2 (mod 3), then n - 1 and n are congruent to 0 and 1 modulo 3, respectively. By the inductive hypothesis, Jn-l is even and Jn is odd. Therefore Jn+l, which is the sum of these two numbers, is odd, as desired. 21. The important point to note here is that k can be thought of as a universally quantified variable for each n. Thus the statement we wish to prove is P(n): for every k, fkJn + Jk+iJn+i = Jn+k+l · We use mathematical induction. If n = 0 (the first base case), then we want to prove P(O): for every k, fkJo + Jk+ifi = Jo+k+i' which reduces to the identity fk+ 1 = fk+1, since Jo = 0 and Ji = 1. If n = 1 (the second base case), then we want to prove P(l): for every k, fkfi + fk+ 1h = fi+k+l, which reduces to the defining recurrence Jk + fk+i = fk+ 2, since Ji = 1 and h = 1. Now we assume the inductive hypothesis P(n) and try to prove P(n + 1). It is a straightforward calculation, using the inductive hypothesis and the recursive definition of the Fibonacci numbers: fkfn+l + fk+1fn+2 + fn) + fk+1Un + fn+i) = fkJ n-l + fkJ n + fk+ifn + Jk+lfn+l = (fkJn-l + Jk+ifn) + (fkJn + fk+ifn+l) = Jn-l+k+l + Jn+k+l = Jn+k+2, = fkUn-l as desired. 23. Let P(n) be the statement z5 + Zi + · · ·+ z; = lnln+l + 2. We easily verify the two base cases, P(O) and P(l), since 22 = 2 · 1 + 2 and 22 + 12 = 1 · 3 + 2. Next assume the inductive hypothesis and consider P( n + 1). We have Z5 + Zi + · · · + z;, + z;,+ 1 = lnln+i + 2 + z;+ 1 = ln+1(ln + ln+l) + 2 = ln+lln+2 + 2, which is exactly what we wanted. 25. The identity is clearly true for n = 1. Let us expand the right-hand side for + 1, invoking the inductive hypothesis at the appropriate point (and using the suggested trigonometric identities as well as the fact that i 2 = -1 ): n + isin(nx + x) = cos nx cos x - sin nx sin x + i (sin nx cos x + cos nx sin x) = cos x (cos nx + i sin nx) + sin x ( - sin nx + i cos nx) = cos x (cos nx + i sin nx) + i sin x (i sin nx + cos nx) = (cos nx + i sin nx) (cos x + i sin x) cos(n + l)x + isin(n + l)x = cos(nx + x) = (cos x + i sin x r (cos x + i sin x) = (cos x + i sin x) n+l Supplementary Exercises 189 27. First let's rewrite the right-hand side to make it simpler to work with, namely as 2n+ 1 (n 2 - 2n + 3) - 6. We use induction. If n = 1, then the left-hand side has just one term, namely 2, and the right-hand side is 4 · 2 - 6 = 2 as well. Assume that the equation holds for n = k, and consider n = k + 1 . Then we have k+l k I:J221 = I:J221+(k+1) 2 2k+ 1 J=l J=l = = 2k+l(k 2 - 2k + 3) - 6 + (k 2 + 2k + 1)2k+ 1 2k+l(2k 2 + 4) - 6 = 2k+ 2 (k 2 + 2) - 6 = 2k+ 2 ((k + 1) 2 - 2(k + 1) + 3) - (by the inductive hypothesis) 6, as desired. 29. One solution here is to use partial fractions and telescoping. First note that j2 c ~ 1 = ~ ~ 1- j ~ 1) . Therefore when summing from 1 to n, the terms being added and the terms being subtracted all cancel out except for 1/(j -1) when j = 2 and 3, and 1/(j + 1) when j = n - 1 and n. Thus the sum is just ~(~+~-~-n~l) · which simplifies, with a little algebra, to the expression given on the right-hand side of the formula in the exercise. In the spirit of this chapter, however, we also give a proof by mathematical induction. Let P(n) be the formula in the exercise. The basis step is for n = 2, in which case both sides reduce to 1/3. For the inductive step assume that the equation holds for n = k, and consider n = k + 1 . Then we have k+l 1 k .L p _ 1 =.LP J=l J=l = 1 1 -1+(k+1)2 -1 (k-1)(3k+2) 1 + (k + l) 2 4k(k + l) 1 (by the inductive hypothesis) (k-1)(3k+2) 1 (k-1)(3k+2) 1 = 4k(k + 1) + k 2 + 2k = 4k(k + 1) + k(k + 2) (k - 1)(3k + 2)(k + 2) + 4(k + 1) 4k(k + l)(k + 2) 3k 3 + 5k 2 4k(k + l)(k + 2) k(3k + 5) 4(k + l)(k + 2) which is exactly what P(k + 1) asserts. _ 3k 2 + 5k 4(k + l)(k + 2) ((k + 1) -1)(3(k + 1) + 2) 4(k + l)(k + 2) 31. Let P(n) be the assertion that at least n+ 1 lines are needed to cover the lattice points in the given triangular region. Clearly P(O) is true, because we need at least one line to cover the one point at (0, 0). Assume the inductive hypothesis, that at least k + 1 lines are needed to cover the lattice points with x ~ 0, y ~ 0, and x + y ::; k. Consider the triangle of lattice points defined by x ~ 0, y ~ 0, and x + y ::; k + 1. Because this set includes the previous set, at least k + 1 lines are required just to cover the smaller set (by the inductive hypothesis). By way of contradiction, assume that k + 1 lines could cover this larger set as well. Then these lines must also cover the k + 2 points on the line x + y = k + 1, namely (0, k + 1), (1, k), (2, k - 1), ... , (k, 1), (k + 1, 0). But only the line x + y = k + 1 itself can cover more than one of these points, because Chapter 5 190 Induction and Recursion two distinct lines intersect in at most one point, and this line does nothing toward covering the lattice points in the smaller triangle. Therefore none of the k + 1 lines that are needed to cover the lattice points in the smaller triangle can cover more than one of the points on the line x + y = k + 1 , and this leaves at least one point uncovered. Therefore our assumption that k + 1 line could cover the larger set is wrong, and our proof is complete. 33. The basis step is the given statement defining B. Assume the inductive hypothesis, that Bk = MA kM- 1 . We want to prove that Bk+l = MAk+ 1M- 1 . By definition Bk+ 1 = BBk = MAM- 1Bk = MAM- 1MAkM- 1 by the inductive hypothesis. But this simplifies, using rules for matrices, to MAIAkM- 1 = MAAkM- 1 = MA k+l M- 1 , as desired. 35. It takes some luck to be led to the solution here. We see that we can write 3l = 3+2+ 1. We also have a recursive definition of factorial, that (n + 1) ! = ( n + 1)n!, so we might hope to multiply each of the divisors we got at the previous stage by n + 1 to get divisors at this stage. Thus we would have 4! = 4 · 3! = 4(3+2+1) = 12 + 8 + 4, but that gives us only three divisors in the sum, and we want four. That last divisor, which is n + 1 can, however, be rewritten as the sum of n and 1, so our sum for 4l is 12 + 8 + 3 + 1. Let's see if we can continue this. We have 5l = 5 · 4l = 5(12 + 8 + 3 + 1) = 50 + 40 + 15 + 5 = 50 + 40 + 15 + 4 + 1. It seems to be working. The basis step n = 3 is already done, so let's see if we can prove the inductive step. Assume that we can write kl as a sum of the desired form, say kl = a 1 + a2 + · · · + ak, where each ai is a divisor of k! and the divisors are listed in strictly decreasing order, and consider (k + 1)!. Then we have (k + l)l = (k + l)k! = (k + l)(a1 + a2 + · · · + ak) = (k + l)a1 + (k + l)a2 + · · · + (k + l)ak = (k + l)a1 + (k + l)a2 + · · · + k · ak + ak. Because each a, was a divisor of k!, each (k + l)ai is a divisor of (k + 1)!, but what about those last two terms? We don't seem to have any way to know that k · ak is a factor of (k + 1) ! . Hold on, in our exploration we always had the last divisor in our sum being 1. If so, then k · ak = k, which is a divisor of (k + l)l, and ak = 1, so the new last summand is again 1. (Notice also that our list of summands is still in strictly decreasing order.) So our proof by mathematical induction needs to be of the following stronger result: For every n ~ 3, we can write n! as the sum of n of its distinct positive divisors, one of which is 1 . The argument we have just given proves this by mathematical induction. 37. When n = 1 the statement is vacuously true. If n = 2 there must be a woman first and a man second, so the statement is true. Assume that the statement is true for n = k, where k ~ 2, and consider k + 1 people standing in a line, with a woman first and a man last. If the kth person is a woman, then we have that woman standing in front of the man at the end, and we are done. If the kth person is a man, then the first k people in line satisfy the conditions of the inductive hypothesis for the first k people in line, so again we can conclude that there is a woman directly in front of a man somewhere in the line. 39. (It will be helpful for the reader to draw a diagram to help in following this proof.) When n = 1 there is one circle, and we can color the inside blue and the outside red to satisfy the conditions. Assume the inductive hypothesis that if there are k circles, then the regions can be 2-colored such that no regions with a common boundary have the same color, and consider a situation with k+ 1 circles. Remove one of the circles, producing a picture with k circles, and invoke the inductive hypothesis to color it in the prescribed manner. Then replace the removed circle and change the color of every region inside this circle (from red to blue, and from blue to red). It is clear that the resulting figure satisfies the condition, since if two regions have a common boundary, then either that boundary was an arc of the new circle, in which case the regions on either side used to be the same region and now the inside portion is colored differently from the outside, or else the boundary did not involve the new circle, in which case the regions are colored differently because they were colored differently before the new circle was restored. 191 Supplementary Exercises 41. We use induction. If n = 1 then the equation reads 1 · 1 = 1 · 2/2, which is true. Assume that the equation is true for n and consider it for n + 1. (We use the letter n rather than k, because k is used for something else here.) Then we have, with some messy algebra (including an application of Example 2 in Section 5.1 in line 4), n+l (n+l 1) ?;(2j - 1) ~ k n = ?;(2j - 1) n . =2:( 2J-l) J=l = = (n+l 1) 1 ~ k + (2(n + 1) - 1) · n + 1 ( 1 n+l 1) n +Lk 2n + 1 + n+l k=J n - 1 ~(2j - 1) ) + ( n+lL.,, J=l ( n ~(2j - 1) L.,, J=l 1 ( -- . n2) + n(n + l) + 2n + 1 n+l 2 n+l ( n -1)) + _n_ 2 + 1 ~ L.,,k k=J n+l (by the inductive hypothesis) 2n 2 + n(n + 1) 2 + (4n + 2) 2(n + 1) 2(n + 1) 2 + n(n + 1) 2 2(n + 1) (n+l)(n+2) 2 as desired. 43. Let T( n) be the statement that the sequence of towers of 2 is eventually constant modulo n. We will use strong induction to prove that T(n) is true for all positive integers n. Basis step: When n = 1 (and n = 2), the sequence of towers of 2 modulo n is the sequence of all O's. Inductive step: Suppose that k is an integer with k ::'.': 2. Suppose that T(j) is true for 1 :::; j :::; k - 1. In the proof of the inductive step we denote the rth term of the sequence modulo n by ar. We will split the proof of the inductive step into two cases, based on the parity of k. Suppose k is even. Let k = 28 q where s 2: 1 and q < k is odd. When j is large enough, a1 _2 2: s, 2 and for such j, a1 = 22a 1 _ is a multiple of 28 • It follows that for sufficiently large j, a1 = 0 (mod 28 ) . Hence, for large enough i, 28 divides ai+ 1 - a,. By the inductive hypothesis T(q) is true, so the sequence a 1 , a 2, a 3 , ... is eventually constant modulo q. This implies that for large enough i, q divides a,+l - a,. Because gcd(q, 28 ) = 1 and for sufficiently large i both q and 28 divide a,+ 1 - a,, k = 2 8 q divides a,+ 1 - a, for sufficiently large i. Hence, for sufficiently large i , ai+ 1 - a, 0 (mod k) . This means that the sequence is eventually constant modulo k. = Finally, suppose k is odd. Then gcd(2, k) = 1, so by Euler's theorem (found in elementary number theory books, such as the author's), we know that 2is Euler's phi function (see preamble to Exercise 21 in Section 4.3). Let r = ¢(k). Because r < k, by the inductive hypothesis T(r), the sequence a 1 ,a 2,a 3 , ... is eventually constant modulo r, say equal to c. Hence for large enough i, for some integer ti, a,= t,r + c. Hence ai+l = 2a, = 2t,r+c = (2r)t,2c = 2c (mod k). This shows that a 1 ,a2, ... is eventually = constant modulo k. = 102 - 10 = 92 b) M(lOl) = 101 - 10 = 91 M(99) = M(M(99 + 11)) = M(M(llO)) = M(lOO) = M(M(lll)) = M(lOl) = 91 M(97) = M(M(108)) = M(98) = M(M(109)) = M(99) = 91 (using part (c)) 45. a) M(102) c) d) Chapter 5 192 Induction and Recursion e) This one is too long to show in its entirety here, but here is what is involved. First, M(87) = M(M(98)) = M(91), using part (d). Then M(91) = M(M(102)) = M(92) from part (a). In a similar way, we find that M(92) = 1\,/(93), and so on, until it equals M(97), which we found in part (d) to be 91. Hence the answer is 91. f) Using what we learned from part (e), we have M(76) = M(M(87)) = M(91) = 91. 47. The basis step is wrong. The statement makes no sense for n = 1, since the last term on the left-hand side would then be 1/ (0 · 1), which is undefined. The first n for which it makes sense is n = 2, when it reads 1 3 1 -- Of course this statement is false, since ~ true. # --- 1. 2 2 2 1 . Therefore the basis step fails, and so the "theorem" is not 49. We will prove by induction that n circles divide the plane into n 2 - n + 2 regions. One circle certainly divides the plane into two regions (the inside and the outside), and 12 - 1 + 2 = 2. Thus the statement is correct for n = 1. We assume that the statement is true for n circles, and consider it for n + 1 circles. Let us imagine an arrangement of n + 1 circles in the plane, each pair intersecting in exactly two points, no point common to three circles. If we remove one circle, then we are left with n circles, and by the inductive hypothesis they divide the plane into n 2 - n + 2 regions. Now let us draw the circle that we removed, starting at a point at which it intersects another circle. As we proceed around the circle, every time we encounter a point on one of the circles that was already there, we cut off a new region (in other words, we divide one old region into two). Therefore the number of regions that are added on account of this circle is equal to the number of points of intersection of this circle with the other n circles. We are told that each other circle intersects this one in exactly two points. Therefore there are a total of 2n points of intersection, and hence 2n new regions. Therefore the number of regions determined by n+l circles is n 2 -n+2+2n = n 2 +n+2 = (n+l) 2 -(n+l)+2 (the last equality is just algebra). Thus we have derived that the statement is also true for n + 1, and our proof is complete. 51. We will give a proof by contradiction. Let us consider the set B = { b../2 I b and b../2 are positive integers}. Clearly B is a subset of the set of positive integers. Now if v'2 is rational, say v'2 =pf q, then B # 0, since q..,/2 = p E B. Therefore by the well-ordering property, B contains a smallest element, say a = b../2. Then a../2-a = a../2-b../2 =(a- b)../2. Since a../2 = 2b and a are both integers, so is this quantity. Furthermore, it is a positive integer, since it equals a(../2-1) and v'2 - 1 > 0. Therefore a../2 - a EB. But clearly a v'2 - a < a, since v'2 < 2 . This contradicts our choice of a to be the smallest element of B . Therefore our original assumption that v'2 is rational is false. 53. a) We use the following lemma: A positive integer d is a common divisor of a 1 , a 2 , ... , an if and only if d is a divisor of gcd(a 1, a2, ... , an). [Proof: The prime factorization of gcd(a1, a2, ... , an) is f1p~', where ei is the minimum exponent of Pi among a 1 , a 2 , ... , an. Clearly d divides every a3 if and only if the exponent of Pi in the prime factorization of d is less than or equal to e, for every i, which happens if and only if d I gcd( a 1, a 2, ... , an).] Now let d = gcd( a 1, a2, ... , an). Then d must be a divisor of each a,, and hence must be a divisor of gcd(an_ 1 , an) as well. Therefore d is a common divisor of al, a2, ... , an-2, gcd(an-1, an). To show that it is the greatest common divisor of these numbers, suppose that e is any common divisor of these numbers. Then e is a divisor of each a, for 1 ::::; i ::::; n - 2, and, being a divisor of gcd( an-I, an) , it is also a divisor of an-I and an. Therefore e is a common divisor of all the a, and hence a divisor of their common divisor, d. This shows that d is the greatest common divisor of a1, a2, ... , an-2, gcd(an-1, an). b) If n = 2, then we just apply the Euclidean algorithm to a 1 and a 2 . Otherwise, we apply the Euclidean algorithm to an-l and an, obtaining an answer d, and then apply this algorithm recursively to al, a2, ... , an-2, d. Note that this last sequence has only n - 1 numbers in it. Supplementary Exercises 193 55. We begin by computing f(n) for the first few values of n, using the recursive definition. Thus we have f(l) = 1, /(2) = /(1)+4-1=1+4-1=4, /(3) = /(2)+6-1=4+6-1=9, /(4) = /(3)+8-1=9+8-1=16. The pattern seems clear, so we conjecture that f(n) = n 2 . Now we prove this by induction. The base case we have already verified. So assume that f(n) = n 2 . All we have to do is show that f(n + 1) = (n + 1) 2 . By the recursive definition we have f(n + 1) = f(n) + 2(n + 1) - 1. This equals n 2 + 2(n + 1) - 1 by the inductive hypothesis, and by algebra we have n 2 + 2(n + 1) - 1=(n+1) 2 , as desired. 57. The recursive definition says that we can "grow" strings in S by appending O's on the left and 1's on the right, as many as we wish. a) The only string of length 0 in S is A. There are two strings of length 1 in S, obtained either by appending a 0 to the front of A or a 1 to the end of ,\, namely the strings 0 and 1 . The strings of length 2 in S come from the strings of length 1 by appending either a 0 to the front or a 1 to the end; they are 00, 01, and 11 . Similarly, we can append a 0 to the front or a 1 to the end of any of these strings to get the strings of length 3 in S, namely 000, 001, 011, and 111. Continuing in this manner, we see that the other strings in S of length less than or equal to 5 are 0000 , 0001 , 0011 , 0111 , 1111 , 00000 , 00001 , 00011 , 00111 , 01111 , and 11111. b) The simplest way to describe these strings is { om1 n m and n are nonnegative integers}. J 59. Applying the first recursive step once to ,\ tells us that () E B. Then applying the second recursive step to this string tells us that ()() E B. Finally, we apply the first recursive step once more to get (()()) E B. To see that ( ())) is not in B, we invoke Exercise 62. Since the number of left parentheses does not equal the number of right parentheses, this string is not balanced. 61. There is of course the empty string, with 0 symbols. By the first recursive rule, we get the string (). If we apply the first recursive rule to this string, then we get ( ()), and if we apply the second recursive rule, then we get () () . These are the only strings in B with four or fewer symbols. 63. The definition simply says that N of a string is a count of the parentheses, with each left parenthesis counting +1 and each right parenthesis counting -1 . a) There is one left parenthesis and one right parenthesis, so N (0) = 1 - 1 = 0. b} There are 3 left parentheses and 5 right parentheses, so N ())) ()) ( () = 3 - 5 = - 2. c) There are 4 left parentheses and 2 right parentheses, so N ( (() (()) =4- 2 = 2. d) There are 6 left parentheses and 6 right parentheses, so N (0 ((())) (())) = 6 - 6 = 0. 65. The basic idea, of course, is to turn the definition into a procedure. The recursive part of the definition tells us how to find elements of B from shorter elements of B. The naive approach, however, is not very good, because we end up adding to B strings that already are there. For example, the string ()()() occurs in two different ways from the rule "xy E B if x, y E B": by letting x = () () and y = () , and by letting x = () and y= ()(). To avoid this problem, we will keep two lists of strings, whose union is the set B(n) of balanced strings of parentheses of length not exceeding n. The set S(n) will be those balanced strings w of length at most n such that w = uv, where u, v =f ,\ and u and v are balanced. The set T( n) will be all other balanced strings of length at most n. Note that, for example, ,\ET, ()ET, (())ET, but ()()ES. Since all the strings in B are of even length, we really only need to work with even values of n, dragging the odd values along for the ride. 194 Chapter 5 Induction and Recursion procedure generate(n: nonnegative integer) if n is odd then S := S(n - 1) {the S constructed by generate(n - 1)} T := T(n - 1) {the T constructed by generate(n - 1)} else if n = 0 then 8:=0 T := {>.} else S' := S(n - 2) {the S constructed by generate(n - 2)} T' := T(n - 2) {the T constructed by generate(n - 2)} T := T' U { (x) Ix ET' US' /\ length(x) = n - 2} S := S' U { xy Ix ET'/\ y ET' US' /\ length(xy) = n} { T U S is the set of balanced strings of length at most n } 67. There are two cases. If x :::; y initially, then the statement x := y is not executed, so x and y remain unchanged and x :::; y is a true final assertion. If x > y initially, then the statement x := y is executed, so x = y at the end, and thus x -S y is again a true final assertion. These are the only two possibilities associated with the initial condition T (true), so our proof is complete. 69. If the list has just one element in it, then the number of O's is 1 if the element is 0 and is 0 otherwise. That forms the basis step of our algorithm. For the recursive step, the number of occurrences of 0 in a list L is the same as the number of occurrences in the list L without its last term if that last term is not a 0, and is one more than this value if it is. We can write this in pseudocode as follows. procedure zerocount(a1, a2, ... , an: list of integers) if n = 1 then if a 1 = 0 then return 1 else return 0 else if an= 0 then return zerocount(a1, az, ... , an-1) else return zerocount(a1, a3, ... , an-1) +1 71. From the numerical evidence in Exercise 70, it appears that a( n) is a natural number and a( n) :::; n for all n. We prove that a is well-defined by showing that this observation is in fact true. Obviously the proof is by mathematical induction. The basis step is n = 0, for which the statement is obviously true, since a(O) = 0. Now assume that a(n - 1) is a natural number and a(n - 1) :::; n - 1. Then a(a(n -1)) is a applied to some natural number less than or equal to n - 1; by the inductive hypothesis this value is some natural number less than or equal to n - 1. Therefore a( a( n - 1)) is also some natural number less than or equal to n - 1 (again by the inductive hypothesis). Therefore n - a(a(n - 1)) is n minus some natural number less than or equal to n - 1, which is some natural number less than or equal to n, and we are done. 73. From Exercise 72 we know that a( n) = l (n + 1) µ J and that a( n - 1) = lnµ J . Since µ is less than 1, these two values are either equal or they differ by 1. First suppose that µn - lµn J < 1 - µ. This is equivalent to µ(n + 1) < 1 + lµn J. If this is true, then clearly lµ(n + l)J = lµn J. On the other hand, if µn - lµnj : '.:'. 1- µ, then µ(n+ 1) ::'.:'. 1 + lµnJ, so lµ(n+ l)J = lµnJ + 1, as desired. Writing Projects 195 75. We apply the definition: m(O) =0 m(l) = 1 - f(m(O)) = 1- f(O) = 1 - 1=0 m(2) = 2 - f(m(l)) = 2 - f(O) = 2 - 1 = 1 m(3) = 3 - f(m(2)) = 3 - f(l) = 3 - 1 = 2 m(4) = 4 - f(m(3)) = 4 - f(2) = 4 - 2 = 2 m(5) = 5 - f(m(4)) = 5 - /(2) = 5 - 2 = 3 m(6) = 6 - f(m(5)) = 6 - f(3) = 6 - 2 = 4 m(7) = 7 - f(m(6)) = 7 - f(4) = 7 - 3 = 4 m(8) = 8 - f(m(7)) = 8 - f(4) = 8 - 3 = 5 m(9) = 9 - f(m(8)) = 9 - /(5) = 9 - 3 = 6 f (0) = 1 f(l) = 1- m(f(O)) f(2) = 2 - m(f(l)) f(3) = 3 - m(f(2)) f(4) = 4 - m(f(3)) f(5) = 5 - m(f(4)) f(6) = 6 - m(f(5)) f(7) = 7 - m(f(6)) f(8) = 8 - m(f(7)) f(9) = 9 - m(f(8)) = = = = 1 - m(l) = 1 - 0 = 1 2 - m(l) = 2 - 0 = 2 3 - m(2) = 3 - 1 = 2 4 - m(2) = 4 - 1 = 3 = 5 - m(3) = 5 - 2 = 3 = = = = 6 - m(3) = 6 - 2 = 4 7 - m(4) = 7 - 2 = 5 8 - m(5) = 8 - 3 = 5 9 - m(5) = 9 - 3 = 6 77. By Exercise 76 the sequence starts out 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, ... , and we see that f(l) = 1 (since the last occurrence of 1 is in position 1), f(2) = 3 (since the last occurrence of 2 is in position 3), /(3) = 5 (since the last occurrence of 3 is in position 5), /(4) = 8 (since the last occurrence of 4 is in position 8), and so on. Since the sequence is nondecreasing, the last occurrence of n must be in the position for which the total number of ls, 2s, 3s, ... , n's all together is that position number. But since ak gives the number of occurrences of k, this is just 2=~=l ak, as desired. For example, 6 L.>k = 1 + 2 + 2 + 3 + 3 + 4 = 15 = f (6)' k=l the position where the last 6 occurs. Since we just saw that f (n) is the sum of the first n terms of the sequence, f (! (n)) must be the sum of the first f (n) terms of the sequence. But since f (n) is the last term whose value is n, this means the sum of all the terms of the sequence whose value is at most n. Since there are ak terms of the sequence whose value is k, this sum must be 2=~=l k · ak, as desired. For example, 3 2: k · ak = 1·1 + 2 · 2 + 2 · 3 = 11 = J(f(3)) = f(5), k=l the position where the last 5 occurs. WRITING PROJECTS FOR CHAPTER 5 Books and articles indicated by bracketed symbols below are listed near the end of this manual. You should also read the general comments and advice you will find there about researching and writing these essays. 1. Start with the historical footnote in the text. The standard history of mathematics references, such as [Bo4] and [Ev3], might have something or might provide a hint of where to look next. 2. There is a nice chapter on this in [He]. A Web search should also turn up useful pages, such as this one: www-cgrl.cs.mcgill.ca/-godfried/teaching/cg-projects/97/0ctavian/compgeom.html 3. There are several textbooks on computational geometry, such as [O'R]. A comprehensive website on the subject can be found here: compgeom. cs. ui uc. edu;- j eff e/ compgeom/ 196 Chapter 5 Induction and Recursion 4. The ratio of successive Fibonacci numbers approaches a value known as the "golden ratio,'' so it would be useful to search for this topic as well. A recent and somewhat controversial book on the subject [Li] debunks some of the more outrageous claimed applications. This website seems to have a wealth of information on applications of Fibonacci numbers: www. cs. ri t. edu;-pga/Fibo/f act_sheet. html 5. You can find some references, as well as an historical discussion of the Ackermann function and an iterative algorithm for computing it, in [GrZe]. 6. Try searching your library's on-line catalog or the Web under keywords like program correctness or verification. Or look at [Bal], [Di], or [Hol]. 7. As in Writing Project 6, a key-word search might turn up something. One book to look at is [Del]. Section 6.1 197 The Basics of Counting CHAPTER6 Counting SECTION 6.1 The Basics of Counting The secret to solving counting problems is to look at the problem the right way and apply the correct rules (usually the product rule or the sum rule), often with some common sense and cleverness thrown in. This is usually easier said than done, but it gets easier the more problems you do. Sometimes you need to count more than you want and then subtract the overcount. (This notion is made more precise in Section 8.5, where the inclusion-exclusion principle is discussed explicitly.) At other times you compensate by dividing; see Exercise 73, for example. Counting problems are sometimes ambiguous, so it is possible that your answer, although different from the answer we obtain, is the correct answer to a different interpretation of the problem; try to figure out whether that is the case. If you have trouble with a problem, simplify the parameters to make them more manageable (if necessary) and try to list the set in question explicitly. This will often give you an idea of what is going on and suggest a general method of attack that will solve the problem as given. For example, in Exercise 11 you are asked about bit strings of length 10. If you are having difliculty, investigate the analogous question about bit strings of length 2 or 3, where you can write down the entire set, and see if a pattern develops. (Some people define mathematics as the study of patterns.) Sometimes tree diagrams make the analysis in these small cases easier to keep track of. See the solution to Exercise 47 for a discussion of the powerful tool of symmetry, which you will often find helpful. Another useful trick is gluing; see the solution to Exercise 65. Finally, do not be misled, if you find these exercises easy, into thinking that combinatorial problems are a piece of cake. It is very easy to ask combinatorial questions that look just like the ones asked here but in fact are extremely diflicult, if not impossible. For example, try your hand at the following problem: how many strings are there, using 10 A's, 12 B's, 11 C's, and 15 D's, such that no A is followed by a B, and no C is followed by a D ? 1. This problem illustrates the difference between the product rule and the sum rule. If we must make one choice and then another choice, the product rule applies, as in part (a). If we must make one choice or another choice, the sum rule applies, as in part (b). We assume in this problem that there are no double majors. a) The product rule applies here, since we want to do two things, one after the other. First, since there are 18 mathematics majors, and we are to choose one of them, there are 18 ways to choose the mathematics major. Then we must choose the computer science major from among the 325 computer science majors, and that can clearly be done in 325 ways. Therefore there are, by the product rule, 18 · 325 = 5850 ways to pick the two representatives. b) The sum rule applies here, since we want to do one of two mutually exclusive things. Either we can choose a mathematics major to be the representative, or we can choose a computer science major. There are 18 ways to choose a mathematics major, and there are 325 ways to choose a computer science major. Since these two actions are mutually exclusive (no one is both a mathematics major and a computer science major), and since we want to do one of them or the other, there are 18 + 325 = 343 ways to pick the representative. Chapter 6 198 Counting 3. a) The product rule applies, since the student will perform each of 10 tasks, one after the other. There are 4 ways to do each task. Therefore there are 4 · 4 · · · 4 = 4 10 = 1,048,576 ways to answer the questions on the test. b) This is identical to part (a), except that now there are 5 ways to answer each question-give any of the 4 answers or give no answer at all. Therefore there are 5 10 = 9, 765,625 ways to answer the questions on the test. 5. The product rule applies here, since a flight is determined by choosing an airline for the flight from New York to Denver (which can be done in 6 ways) and then choosing an airline for the flight from Denver to San Francisco (which can be done in 7 ways). Therefore there are 6 · 7 = 42 different possibilities for the entire flight. 7. Three-letter initials are determined by specifying the first initial ( 26 ways), then the second initial ( 26 ways), and then the third initial ( 26 ways). Therefore by the product rule there are 26 · 26 · 26 = 26 3 = 17,576 possible three-letter initials. 9. There is only one way to specify the first initial, but as in Exercise 7, there are 26 ways to specify each of the other initials. Therefore there are, by the product rule, 1 · 26 · 26 = 26 2 = 676 possible three-letter initials beginning with A. 11. A bit string is determined by choosing the bits in the string, one after another, so the product rule applies. We want to count the number of bit strings of length 10, except that we are not free to choose either the first bit or the last bit (they are mandated to be 1's ). Therefore there are 8 choices to make, and each choice can be made in 2 ways (the bit can be either a 1 or a 0). Thus the product rule tells us that there are 28 = 256 such strings. 13. This is a trick question, since it is easier than one might expect. Since the string is given to consist entirely of l's, there is nothing to choose except the length. Since there are n + 1 possible lengths not exceeding n (if we include the empty string, of length 0), the answer is simply n + 1. Note that the empty string consists--vacuously-entirely of 1's. 15. By the sum rule we can count the number of strings of length 4 or less by counting the number of strings of length i, for 0 :::; i :::; 4, and then adding the results. Now there are 26 letters to choose from, and a string of length i is specified by choosing its characters, one after another. Therefore, by the product rule there are 26' 4 strings of length i. The answer to the question is thus I: 26' = 1 + 26 + 676 + 17576 + 456976 = 475,255. 1=0 17. The easiest way to count this is to find the total number of ASCII strings of length five and then subtract off the number of such strings that do not contain the @character. Since there are 128 characters to choose from in each location in the string, the answer is 1285 - 1275 = 34,359,738,368 - 33,038,369,407 = 1,321,368,961. 19. Recall that an RNA sequence is a sequence of letters, each of which is one of A, C, G, or U. Thus by the product rule there are 46 RNA sequences of length six if we impose no restrictions. a) If U is excluded, then each position can be chosen from among three letters, rather than four. Therefore the answer is 36 = 729. b) If the last two letters are specified, then we get to choose only four letters, rather than six, so the answer is 44 = 256. c) If the first letter is specified, then we get to choose only five letters, rather than six, so the answer is 45 = 1024. Section 6.1 The Basics of Counting 199 d) If only A or U is allowed in each position, then there are just two choices at each of six stages, so the answer is 26 = 64. 21. Because neither 100 nor 50 is divisible by either 7 or 11, whether the ranges are meant to be inclusive or exclusive of their endpoints is moot. a) There are L100/7J = 14 integers less than 100 that are divisible by 7, and L50/7J = 7 of them are less than 50 as well. This leaves 14 - 7 = 7 numbers between 50 and 100 that are divisible by 7. They are 56, 63, 70, 77, 84, 91 , and 98. b) There are L100/11J = 9 integers less than 100 that are divisible by 11, and L50/11J = 4 of them are less than 50 as well. This leaves 9 - 4 66, 77, 88, and 99. =5 numbers between 50 and 100 that are divisible by 11. They are 55, c) A number is divisible by both 7 and 11 if and only if it is divisible by their least common multiple, which is 77. Obviously there is only one such number between 50 and 100, namely 77. We could also work this out as we did in the previous parts: L100/77J - L50/77J = 1 - 0 = 1. Note also that the intersection of the sets we found in the previous two parts is precisely what we are looking for here. 23. This problem deals with the set of positive integers between 100 and 999, inclusive. Note that there are exactly 999 - 100 + 1 = 900 such numbers. A second way to see this is to note that to specify a three-digit number, we need to choose the first digit to be nonzero (which can be done in 9 ways) and then the second and third digits (which can each be done in 10 ways), for a total of 9 · 10 · 10 = 900 ways, by the product rule. A third way to see this (perhaps most relevant for this problem) is to note that a number of the desired form is a number less than or equal to 999 (and there are 999 such numbers) but not less than or equal to 99 (and there are 99 such numbers); therefore there are 999 - 99 = 900 numbers in the desired range. a) Every seventh number- 7, 14, and so on-is divisible by 7. Therefore the number of positive integers less than or equal to n and divisible by 7 is Ln/7J (the floor function is used-we have to round down-because the first six positive integers are not multiples of 7; for example there are only L20 /7 J = 2 multiples of 7 less than or equal to 20). So we find that there are L999/7J = 142 multiples of 7 not exceeding 999, of which L99/7J = 14 do not exceed 99. Therefore there are exactly 142 - 14 = 128 numbers in the desired range divisible by 7. b) This is similar to part (a), with 7 replaced by 2, but with the added twist that we want to count the numbers not divisible by 2. Mimicking the analysis in part (a), we see that there are L999/2J = 499 even numbers not exceeding 999, and therefore 999 - 499 = 500 odd ones; there are similarly 99 - L99 /2 J = 50 odd numbers less than or equal to 99. Therefore there are 500 - 50 = 450 odd numbers between 100 and 999 inclusive. c) There are just 9 possible digits that a three-digit number can start with. If all of its digits are to be the same, then there is no choice after the leading digit has been specified. Therefore there are 9 such numbers. d) This is similar to part {b), except that 2 is replaced by 4. Following the analysis there, we find that there are 999 - L999 / 4J = 750 positive integers less than or equal to 999 not divisible by 4, and 99 - l99 / 4J = 75 such positive integers less than or equal to 99. Therefore there are 750 - 75 = 675 three-digit integers not divisible by 4. e) The method is similar to that used in the earlier parts. There are L999 /3 J - L99 /3 J = 300 three-digit numbers divisible by 3, and l 999 / 4J - l99 / 4 J = 225 three-digit numbers divisible by 4. Moreover there are L999/12J - L99/12j = 75 numbers divisible by both 3 and 4, i.e., divisible by 12. In order to count each number divisible by 3 or 4 once and only once, we need to add the number of numbers divisible by 3 to the number of numbers divisible by 4, and then subtract the number of numbers divisible by both 3 and 4 so as not to count them twice. Therefore the answer is 300 + 225 - 75 = 450. f) In part ( e) we found that there were 450 three-digit integers that are divisible by either 3 or 4. The Chapter 6 200 Counting others, of course, are not. Therefore there are 900 - 450 = 450 three-digit integers that are not divisible by either 3 or 4. g) We saw in part ( e) that there are 300 three-digit numbers divisible by 3 and that 75 of them are also divisible by 4. The remainder of those 300 numbers, therefore, are not divisible by 4. Thus the answer is 300 - 75 = 225. h) We saw in part ( e) that there are 75 three-digit numbers divisible by both 3 and 4. 25. This problem involves 1000 possible strings, since there is a choice of 10 digits for each of the three positions in the string. a) This is most easily done by subtracting from the total number of strings the number of strings that violate the condition. Clearly there are 10 strings that consist of the same digit three times ( 000, 111, ... , 999). Therefore there are 1000 - 10 = 990 strings that do not. b) If we must begin our string with an odd digit, then we have only 5 choices for this digit. We still have 10 choices for each of the remaining digits. Therefore there are 5 · 10 · 10 = 500 such strings. Alternatively, we note that by symmetry exactly half the strings begin with an odd digit (there being the same number of odd digits as even ones). Therefore half of the 1000 strings, or 500 of them, begin with an odd digit. c) Here we need to choose the position of the digit that is not a 4 (3 ways) and choose that digit (9 ways). Therefore there are 3 · 9 = 27 such strings. 27. There are 50 choices to make, each of which can be done in 3 ways, namely by choosing the governor, choosing the senior senator, or choosing the junior senator. By the product rule the answer is therefore 350 ::::: 7.2x1023 • 29. By the sum rule we need to add the number of license plates of the first type and the number of license plates of the second type. By the product rule there are 26 · 26 · 10 · 10 · 10 · 10 = 6, 760,000 license plates consisting of 2 letters followed by 4 digits; and there are 10 · 10 · 26 · 26 · 26 · 26 = 45,697,600 license plates consisting of 2 digits followed by 4 letters. Therefore the answer is 6,760,000 + 45,697,600 = 52,457,600. 31. First let us compute the number of ways to choose the letters. By the sum rule this is the sum of the number of ways to use two letters and the number of ways to use three letters. By the product rule there are 26 2 ways to choose two letters and 263 ways to choose three letters. Therefore there are 26 2 + 263 ways to choose the letters. By similar reasoning there are 10 2 + 103 ways to choose the digits. Thus the answer to the question is (26 2 + 263 )(10 2 + 103 ) = 18252 · 1100 = 20,077,200. 33. We take as known that there are 26 letters including 5 vowels in the English alphabet. a) There are 8 slots, each of which can be filled with one of the 26 - 5 = 21 nonvowels (consonants), so by the product rule the answer is 21 8 = 37,822,859,361. b) There are 21 choices for the first slot in our string, but only 20 choices for the second slot, 19 for the third, and so on. So the answer is 21 · 20 · 19 · 18 · 17 · 16 · 15 · 14 = 8,204, 716,800. c) There are 26 choices for each slot except the first, for which there are 5 choices, so the answer is 5 · 26 7 = 40, 159,050,880. d) This is similar to (b), except that there are only five choices in the first slot, and we are free to choose from all the letters not used so far, rather than just the consonants. Thus the answer is 5 · 25 · 24 · 23 · 22 · 21·20·19 = 12,113,640,000. e) We subtract from the total number of strings ( 268 ) the number that do not contain at least one vowel ( 21 8 , the answer to (a)), obtaining the answer 26 8 - 21 8 = 208,827,064,576 - 37,822,859,361=171,004,205,215. f) The best way to do this is first to decide where the vowel goes (8 choices), then to decide what the vowel is to be (A, E, I, 0, or U-5 choices), and then to fill the remaining slots with any consonants (21 7 choices, since one slot has already been filled). Therefore the answer is 8 · 5 · 21 7 = 72,043,541,640. Section 6.1 The Basics of Counting 201 g) We can ignore the first slot, since there is no choice. Now the problem is almost identical to (e), except that there are only 7 slots to fill. So the answer is 26 7 - 21 7 = 8,031,810,176 - 1,801,088,541 = 6,230, 721,635. h) The problem is almost identical to (g), except that there are only 6 slots to fill. So the answer is 26 6 - 21 6 = 308,915,776 - 85,766,121 = 223,149,655. 35. For each part of this problem, w~ need to find the number of one-to-one functions from a set with 5 elements to a set with k elements. To specify such a function, we need to make 5 choices, in succession, namely the values of the function at each of the 5 elements in its domain. Therefore the product rule applies. The first choice can be made in k ways, since any element of the codomain can be the image of the first element of the domain. After that choice has been made, there are only k - 1 elements of the codomain available to be the image of the second element of the domain, since images must be distinct for the function to be one-to-one. Similarly, for the third element of the domain, there are k - 2 possible choices for a function value. Continuing in this way, and applying the product rule, we see that there are k(k - l)(k - 2)(k - 3)(k - 4) one-to-one functions from a set with 5 elements to a set with k elements. a) By the analysis above the answer is 4 · 3 · 2 · 1 · 0 = 0, what we would expect since there are no one-to-one functions from a set to a strictly smaller set. b) By the analysis above the answer is 5 · 4 · 3 · 2 · 1 = 120. c) By the analysis above the answer is 6 · 5 · 4 · 3 · 2 = 720. d) By the analysis above the answer is 7 · 6 · 5 · 4 · 3 = 2520. 37. a) There can clearly be no one-to-one function from {1, 2, ... , n} to {O, 1} if n > 2. If n = 1, then there are 2 such functions, the one that sends 1 to 0, and the one that sends 1 to 1 . If n = 2 , then there are again 2 such functions, since once it is determined where 1 is sent, the function must send 2 to the other value in the codomain. b) If the function assigns 0 to both 1 and n, then there are n - 2 function values free to be chosen. Each can be chosen in 2 ways. Therefore, by the product rule (since we have to choose values for all the elements of the domain) there are 2n- 2 such functions, as long as n > 1. If n = 1, then clearly there is just one such function. c) If n = 1, then there are no such functions, since there are no positive integers less than n. So assume n > 1. In order to specify such a function, we have to decide which of the numbers from 1 to n - 1, inclusive, will get sent to 1 . There are n - 1 ways to make this choice. There is no choice for the remaining numbers from 1 to n - 1, inclusive, since they all must get sent to 0. Finally, we are free to specify the value of the function at n, and this may be done in 2 ways. Hence, by the product rule the final answer is 2(n - 1). 39. The easiest way to view a partial function in terms of counting is to add an additional element to the codomain of the function-let's call it u for "undefined"- and then imagine that the function assigns a value to all elements of the domain. If the original function f had previously been undefined at x, we now say that f(x) = u. Thus all we have done is to increase the size of the codomain from n elements to n + 1 elements. By Example 6 we conclude that there are (n + l)m such partial functions. 41. The trick here is to realize that a palindrome of length n is completely determined by its first In/21 bits. This is true because once these bits are specified, the remaining bits, read from right to left, must be identical to the first ln/2 J bits, read from left to right. Furthermore, these first j n/21 bits can be specified at will, and by the product rule there are 2rn/ 2 l ways to do so. 43. Recall that an RNA sequence is a sequence of letters, each of which is one of A, C, G, or U. Thus by the product rule there are 44 RNA sequences of length four if we impose no restrictions. a) There are 34 RNA sequences that use only letters other than U, so the answer is 44 - 34 = 175. 202 Chapter 6 Counting b) We "contain the sequence'' to mean that those letters must be consecutive. We compute the number of sequences that do contain CUG. There are two cases: these are the first three bases, or these are the last three. In either case, there are four ways to fill in the remaining base, so there are 4 + 4 = 8 such sequences. Therefore there are 44 - 8 = 248 sequences that do not. c) We first count the number of sequences that do contain all four bases. All that matters is the order of the bases. There are four choices for which base to put first, three choices fo~ which base to put second, then two choices for the third position, and one choice for the last position. By the product rule, the answer to this subproblem is 4 · 3 · 2 · 1 = 24. Therefore the answer to the given question is 44 - 24 = 232. d) We need to choose two the two bases to be included, and this can be done in six ways (AU, AC, AG, UC, UG, CG). Once we make this choice (say AU), we can count the sequences that use those two bases. There are 24 = 16 ways to choose which base goes at which position (two choices at each of the four positions), but two of these in fact use only one base, so there are 14 sequences that use exactly those two bases. Therefore the answer is 6 · 14 = 84. 45. We can use the division rule here; see Example 20. If we imagine the places at the table as fixed, then there are 6 · 5 · 4 · 3 · 2 · 1 = 6! ways to seat the six people-choose one of the six people for seat #1, choose one of the five remaining people for seat #2, and so on. However, this overcounts by a factor of 6, corresponding to rotating the table (which does not change a person's neighbors), and by a factor of 2, because any given arrangement is the "same" under the stated rules as the arrangement that reverses the order of the people (changing clockwise to counterclockwise). Therefore the answer is 6!/(6 · 2) = 60. An alternative way to look at it is as follows. Without loss of generality, have person A take a seat. Choose his two neighbors in one of 5 · 4/2 = 10 ways and have them sit on either side of him. Now place the other three people in one of the 3! ways possible in the remaining seats. The number of ways, then, is 10 · 6 = 60. 47. a) Here is a good way (but certainly not the only way) to approach this problem. Since the bride and groom must stand next to each other, let us treat them as one unit. Then the question asks for the number of ways to arrange five units in a row (the bride-and-groom unit and the four other people). We can think of filling five positions one at a time, so by the product rule there are 5 · 4 · 3 · 2 · 1 = 120 ways to make these choices. This is not quite the answer, however, since there are also two ways to decide on which side of the groom the bride will stand. Therefore the final answer is 120 · 2 = 240. b) There are clearly 6 · 5 · 4 · 3 · 2 · 1 = 720 arrangements in all. We just determined in part (a) that 240 of them involve the bride standing next to the groom. Therefore there are 720 - 240 = 480 ways to arrange the people with the bride not standing next to the groom. c) Of the 720 arrangements of these people (see part (b)), exactly half must have the bride somewhere to the left of the groom. (We are invoking symmetry here-a useful tool for solving some combinatorial problems.) Therefore the answer is 720 / 2 = 360 . 49. There are 27 bit strings of length 10 that begin with three O's, since each of the remaining seven bits has two possible values. Similarly, there are 28 bit strings of length 10 that end with two O's. Furthermore, there are 25 bit strings of length 10 that both begin with three O's and end with two O's, since each of the five "middle" bits can be specified in two ways. Using the principle of inclusion-exclusion, we conclude that there are 27 + 28 - 25 = 352 such strings. The idea behind this principle here is that the strings that both begin with three O's and end with two O's were counted twice when we added 27 and 28 , so we need to subtract for the overcounting. It is definitely not the case that we are subtracting because we do not want to count such strings at all. 51. First let us count the number of 8-bit strings that contain three consecutive O's. We will organize our count by looking at the leftmost bit that contains a 0 followed by at least two more O's. If this is the first bit, Section 6.1 The Basics of Counting 203 then the second and third bits are determined (namely, they are both 0), but bits 4 through 8 are free to be specified, so there are 25 = 32 such strings. If it is the second, third, or fourth bits, then the bit preceding it must be a 1 and the two bits after it must be O's, but the other four bits are free. Therefore there are 24 = 16 such strings in each of these three cases, or 48 in all. Next let us suppose that the substring of three or more O's starts at bit 5. Then bit 4 must be a 1. Bits 1 through 3 can be anything other than three O's (if it were three O's, then we already counted this string); thus there are 23 - 1 = 7 ways to specify them. Bit 8 is free. Therefore there are 7 · 2 = 14 such strings. Finally, suppose that the substring 000 starts in bit 6, so that bit 5 is a 1. There are 24 = 16 possibilities for the first four bits, but three of them contain three consecutive O's (0000, 0001, and 1000); therefore there are only 13 such strings. Adding up all the cases we have discussed, we obtain the final answer of 32 + 48 + 14 + 13 = 107 for the number of 8-bit strings that contain three consecutive O's. Next we need to compute the number of 8-bit strings that contain four consecutive l's. The analysis is very similar to what we have just done. There are 24 = 16 such strings starting with 1111; there are 23 = 8 starting 01111; there are 23 = 8 starting .rOllll (where x is either 0 or 1 ); and there are similarly 8 starting each of xyOllll and xyzOllll. This gives us a total of 16 + 4 · 8 = 48 strings containing four consecutive 1's. Finally, we need to count the number of strings that contain both three consecutive O's and four consecutive l's. It is easy enough to just list them all: 00001111, 00011111, 00011110, 10001111, 11110000, 11111000, 01111000, and 11110001, eight in all. Now applying the principle of inclusion-exclusion to what we have calculated above, we obtain the answer to the entire problem: 107 + 48 - 8 = 147. There are only 256 bit strings of length eight altogether, so this answer is somewhat surprising, in that more than half of them satisfy the stated condition. 53. We can solve this problem by computing the number of positive integers not exceeding 100 that are divisible by 4, the number of them divisible by 6, and the number divisible by both 4 and 6; and then applying the principle of inclusion-exclusion. There are clearly 100/4 = 25 multiples of 4 in this range, since every fourth number is divisible by 4. The number of integers in this range divisible by 6 is l 100/6J = 16; we needed to round down because the multiples of 6 occur at the end of each consecutive block of 6 integers ( 6, 12, 18, etc.). Furthermore a number is divisible by both 4 and 6 if and only if it is divisible by their least common multiple, namely 12. Therefore there are l100/12j = 8 numbers divisible by both 4 and 6 in this range. Finally, applying inclusion-exclusion, we see that the number of positive integers not exceeding 100 that are divisible either by 4 or by 6 is 25 + 16 - 8 = 33. 55. a) We are told that there are 26 + 26 + 10 + 6 = 68 available characters. A password of length k using these characters can be formed in 68k ways. Therefore the number of passwords with the specified length restriction is 68 8 + 68 9 + 68 10 + 68 11 + 68 12 sextillion. = 9,920,671,339,261,325,541,376, which is about 9.9 x 10 21 or about ten b) For a password not to contain one of the special characters, it must be constructed from the other 62 characters. There are 62 8 + 62 9 + 62 10 + 62 11 + 62 12 = 3,279,156,377,874,257,103,616 of these. Thus there are 6,641,514,961,387,068,437,760 ~ 6.6 x 1021 (about seven sextillion) passwords that do contain at least one occurrence of one of the special symbols. c) Assuming no restrictions, it will take one nanosecond (one billionth of a second, or 10- 9 sec) for each password. We just multiply this by our answer in part (a) to find the number of seconds the hacker will require. We can convert this to years by dividing by 60 · 60 · 24 · 365.2425 (the average number of seconds in a year). It will take about 314,374 years. 57. Suppose the name has length k, where 1 ::; k ::; 65535. There are 26 + 26 + 1+1+10 = 64 choices for each character, except that the first character cannot be a digit, so there are only 54 choices for the first character. Chapter 6 204 Counting By the product rule there are 54 · 54k-l choices for such a string. To get the final answer, we need to sum this over all lengths, for a total of 65535 I:: 54. 54k- 1 . k=l Applying the formula for the sum of a geometric series gives 54(64 65536 -1)/63, which is about 5.5 x 10 118369 . A programmer will never run out of variable names! 59. By the result of Example 8, there are C = 6,400,000,000 possible numbers of the form NXX-NXX-XXXX. To determine the number of different telephone numbers worldwide, then, we need to determine how many country codes there are and multiply by C. There are clearly 10 country codes of length 1, 100 country codes of length 2 , and 1000 country codes of length 3 . Thus there are 10 + 100 + 1000 = 1110 country codes in all, by the sum rule. Our final answer is 1110 · C = 7,104,000,000,000. 61. There are 16 hexadecimal digits. We just apply the sum rule and the product rule to obtain the answer 16 10 + 16 26 + 1658 >:::: 6.9 x 1069 . Almost all of this comes from the last term ( 16 58 ). 63. Every fourth number is divisible by 4, and every sixth number is divisible by 6. Therefore L999,999/4J = 249,999 numbers in the given range are divisible by 4, and l999,999/6J = 166,666 numbers in the given range are divisible by 6. We want to exclude these from the 999,999 numbers we have. However, numbers can be divisible by both 4 and 6; namely those divisible by 12, the least common multiple of 4 and 6. There are L999,999 /12 J = 83,333 such numbers. Using the principle of inclusion-exclusion, we must add this number back in to avoid overcounting. Therefore our answer is 999,999 - 249,999 - 166,000 + 83,000 = 666,667. 65. We assume that what is intended is that each of the 4 letters is to be used exactly once. There are at least two ways to do this problem. First let us break it into two cases, depending on whether the a comes at the end of the string or not. If a is not at the end, then there are 3 places to put it. After we have placed the a, there are only 2 places to put the b, since it cannot go into the position occupied by the a and it cannot go into the position following the a. Then there are 2 positions in which the c can go, and only 1 position for the d. Therefore, there are by the product rule 3 · 2 · 2 · 1 = 12 allowable strings in which the a does not come last. Second, if the a comes last, then there are 3 · 2 · 1 = 6 ways to arrange the letters b, c, and d in the first three positions. The answer, by the sum rule, is therefore 12 + 6 = 18. Here is another approach. Ignore for a moment the restriction that a b cannot follow an a. Then we need to choose the letter that comes first (which can be done in 4 ways), then the letter that comes second (which can be done in 3 ways, since one letter has already been used), then the letter that comes third (which can be done in 2 ways, since two of the letters have already been used), and finally the letter that comes last (which can only be done in 1 way, since there is only one unused letter at that point). Therefore there are, by the product rule, 4 · 3 · 2 · 1 = 24 such strings. Now we need to subtract from this total the number of strings in which the a is immediately followed by the b. To count these, let us imagine the a and b glued together into one superletter, ab. (This gluing technique often comes in handy.) Now there are 3 things to arrange. We can choose any of them (the letters c or d or the superletter ab) to come first, and that can be done in 3 ways. We can choose either of the other two to come second (which can be done in 2 ways), and we are forced to choose the remaining one to come third. By the product rule there are 3 · 2 · 1 = 6 ways to make these choices. Therefore our final answer is 24 - 6 = 18. 67. There are at least two approaches that are effective here. In our first tree, we let each branching point represent a decision as to whether to include the next element in the set (starting with the largest element). At the top of the tree, for example, we can either choose to include 24 or to exclude it (denoted ·24). We branch one Section 6.1 205 The Basics of Counting way for each possibility. In the first figure below, the entire subtree to the right represents those sets that do not include 24, and the subtree to the left represents those that do. At the point below and to the left of the 24, we have only one branch, •11, since after we have included 24 in our set, we cannot include 11, because the sum would not be less than 28 if we did. At the point below and to the right of the 24, however, we again branch twice, since we can choose either to include 11 or to exclude it. To answer the question, we look at the points in the last row of the tree. Each represents a set whose sum is less than 28. For example, the sixth point from the right represents the set {11, 3}. Since there are 17 such points, the answer to the problem is 17. 0 Our other solution is more compact. In the tree below we show branches from a point only for the inclusion of new numbers in the set. The set formed by including no more numbers is represented by the point itself. This time every point represents a set. For example, the point at the top represents the empty set, the point below and to the right of the number 11 represents the set { 11} , and the left-most point on the bottom row represents the set {3, 7, 9}. In general the set that a point represents is the set of numbers found on the path up the tree from that point to the root of the tree (the point at the top). We only included branches when the sum would be less than 28. Since there are 17 points altogether in this figure, the answer to the problem is 17. 24 ~z4 ~11 69. a) The tree shown here enumerates the possible outcomes. First we branch on gender, then on size, and finally on color. There are 22 ends, so the answer to the question is 22. women men wrb wrb wrb wrb b) First we apply the sum rule: the number of shoes is the sum of the number of men's shoes and the number of women's shoes. Next we apply the product rule. For a woman's shoe we need to specify size (4 choices) and then for each choice of size, we need to specify color (3 choices). Therefore there are 4 · 3 = 12 possible women's models. Similarly, there are 5 · 2 = 10 men's models. Therefore the answer is 12 + 10 = 22. 206 Chapter 6 Counting 71. We want to prove P( m) , the sum rule for m tasks, which says that if tasks T1 , T2 , ... , Tm can be done in ni , n2. . .. , nm ways, respectively, and no two of them can be done at the same time, then there are n 1 + n 2 + · · · + nm ways to do one of the tasks. The basis step of our proof by mathematical induction is m = 2, and that has already been given. Now assume that P(m) is true, and we want to prove P(m + 1). There are m + 1 tasks, no two of which can be done at the same time; we want to do one of them. Either we choose one from among the first m, or we choose the task Tm+I · By the sum rule for two tasks, the number of ways we can do this is n + nm+I . where n is the number of ways we can do one of the tasks among the first m. But by the inductive hypothesis n = n 1 + n 2 + · · · + nm. Therefore the number of ways we can do one of the m + 1 tasks is ni + n2 + · · · + nm + nm+I , as desired. 73. A diagonal joins two vertices of the polygon, but they must be vertices that are not already joined by a side of the polygon. Thus there are n - 3 diagonals emanating from each vertex of the polygon (we've excluded two of the n - 1 other vertices as possible targets for diagonals). If we multiply n - 3 by n, the number of vertices, we will have counted each diagonal exactly twice-once for each endpoint. We compensate for this overcounting by dividing by 2. Therefore there are n( n - 3) /2 diagonals. (Note that the convexity of the polygon had nothing to do with the problem-we were counting the diagonals, whether or not we could be sure that they all lay inside the polygon.) SECTION 6.2 The Pigeonhole Principle The pigeonhole principle seems so trivial that it is difficult to realize how powerful it is in solving some mathematical problems. As usual with combinatorial problems, the trick is to look at things the right way, which usually means coming up with the clever insight, perhaps after hours of agonizing and frustrating exploration with a problem. Try to solve these problems by invoking the pigeonhole principle explicitly, even if you can see other ways of doing them; you will gain some insights by formulating the problem and your solution in this way. The trick, of course, is to figure out what should be the pigeons and what should be the pigeonholes. Many of the the hints of Section 6.1 apply here, as well as general problem-solving techniques, especially the willingness to play with a problem for a Jong time before giving up. Many of the elegant applications are quite subtle and difficult, and there are even more subtle and difficult applications not touched on here. Not every problem, of course, fits into the model of one of the examples in the text. In particular, Exercise 42 looks deceptively like a problem amenable to the technique discussed in Example 10. Keep in mind that the process of grappling with problems such as these is worthwhile and educational in itself. even if you never find the solution. 1. There are six classes: these are the pigeons. There are five days on which classes may meet (Monday through Friday): these are the pigeonholes. Each class must meet on a day (each pigeon must occupy a pigeonhole). By the pigeonhole principle at least one day must contain at least two classes. 3. a) There are two colors: these are the pigeonholes. We want to know the least number of pigeons needed to insure that at least one of the pigeonholes contains two pigeons. By the pigeonhole principle the answer is 3 . If three socks are taken from the drawer, at least two must have the same color. On the other hand two socks are not enough, because one might be brown and the other black. Note that the number of socks was irrelevant (assuming that it was at least 3). b) He needs to take out 14 socks in order to insure at least two black socks. If he does so, then at most 12 of them are brown, so at least two are black. On the other hand, if he removes 13 or fewer socks, then 12 of them could be brown, and he might not get his pair of black socks. This time the number of socks did matter. Section 6.2 The Pigeonhole Principle 207 5. There are four possible remainders when an integer is divided by 4 (these are the pigeonholes here): 0, 1, 2, or 3. Therefore, by the pigeonhole principle at least two of the five given remainders (these are the pigeons) must the same. 7. Let the n consecutive integers be denoted x + 1 , x + 2, ... , x + n, where x is some integer. We want to show that exactly one of these is divisible by n. There are n possible remainders when an integer is divided by n, namely O, 1, 2, ... , n - 1. There are two possibilities for the remainders of our collection of n numbers: either they cover all the possible remainders (in which case exactly one of our numbers has a remainder of 0 and is therefore divisible by n ), or they do not. If they do not, then by the pigeonhole principle, since there are then fewer than n pigeonholes (remainders) for n pigeons (the numbers in our collection), at least one remainder must occur twice. In other words, it must be the case that x + i and x + j have the same remainder when divided by n for some pair of numbers i and j with 0 < i < j :S n. Since x + i and x + j have the same remainder when divided by n, if we subtract x + i from x + j, then we will get a number divisible by n. This means that j - i is divisible by n. But this is impossible, since j - i is a positive integer strictly less than n. Therefore the first possibility must hold, that exactly one of the numbers in our collection is divisible by n. 9. The generalized pigeonhole principle applies here. The pigeons are the students (no slur intended), and the pigeonholes are the states, 50 in number. By the generalized pigeonhole principle if we want there to be at least 100 pigeons in at least one of the pigeonholes, then we need to have a total of N pigeons so that IN/501 ~ 100. This will be the case as long as N ~ 99 · 50 + 1 = 4951. Therefore we need at least 4951 students to guarantee that at least 100 come from a single state. 11. We must recall from analytic geometry that the midpoint of the segment whose endpoints are (a, b, c) and (d, e, f) is ((a+d)/2, (b+e)/2, (c+ J)/2). We are concerned only with integer values of the original coordinates. Clearly the coordinates of these fractions will be integers as well if and only if a and d have the same parity (both odd or both even), band e have the same parity, and c and f have the same parity. Thus what matters in this problem is the parities of the coordinates. There are eight possible triples of parities: (odd, odd, odd) , (odd, odd, even), (odd, even, odd), ... , (even, even, even). Since we are given nine points, the pigeonhole principle guarantees that at least two of them will have the same triple of parities. The midpoint of the segment joining these two points will therefore have integer coordinates. 13. a) We can group the first eight positive integers into four subsets of two integers each, each subset adding up to 9: {l, 8}, {2, 7}, {3, 6}, and {4, 5}. If we select five integers from this set, then by the pigeonhole principle (at least) two of them must come from the same subset. These two integers have a sum of 9, as desired. b) No. If we select one element from each of the subsets specified in part (a), then no sum will be 9 . For example, we can select 1 , 2, 3, and 4. 15. We can apply the pigeonhole principle by grouping the numbers cleverly into pairs (subsets) that add up to 7, namely {1,6}, {2,5}, and {3,4}. Ifwe select four numbers from the set {1,2,3,4,5,6}, then at least two of them must fall within the same subset, since there are only three subsets. Two numbers in the same subset are the desired pair that add up to 7. We also need to point out that choosing three numbers is not enough, since we could choose {l, 2, 3}, and no pair of them add up to more than 5. 17. The given information tells us that there are 50 · 85 · 5 = 21,250 bins. If we had this many products, then each could be stored in a separate bin. By the pigeonhole principle, however, if there are at least 21,251 products, then at least two of them must be stored in the same bin. This is the number the problem is asking us for. 208 Chapter 6 Counting 19. a) If this statement were not true, then there would be at most 8 from each class standing, for a total of at most 24 students. This contradicts the fact that there are 25 students in the class. b) If this statement were not true, then there would be at most 2 freshmen, at most 18 sophomores, and at most 4 juniors, for a total of at most 24 students. This contradicts the fact that there are 25 students in the class. 21. One way to do this is to have the sequence contain four groups of four numbers each, so that the numbers within each group are decreasing, and so that the numbers between groups are increasing. For example, we could take the sequence to be 4, 3, 2, 1; 8, 7, 6, 5; 12, 11, 10, 9; 16, 15, 14, 13. There can be no increasing subsequence of five terms, because any increasing subsequence can have only one element from each of the four groups. There can be no decreasing subsequence of five terms, because any decreasing subsequence cannot have elements from more than one group. 23. The key here is that 25 is an odd number. If there were an even number of boys and the same even number of girls, then we could position them around the table in the order BBGGBBGG ... and never have a person both of whose neighbors are boys. But with an odd number of each sex, that cannot happen. Here is one nice way to see why when there are 25 of each. Number the seats around the table from 1 to 50, and think of seat 50 as being adjacent to seat 1. There are 25 seats with odd numbers and 25 seats with even numbers. If no more than 12 boys occupied the odd-numbered seats, then at least 13 boys would occupy the even-numbered seats, and vice versa. Without loss of generality, assume that at least 13 boys occupy the 25 odd-numbered seats. Then at least two of those boys must be in consecutive odd-numbered seats. The person sitting between those two boys will have boys as both of his or her neighbors. 25. This is actually a fairly hard problem, in terms of what we need to keep track of. Call the given sequence ai , a2, ... , an. We will keep track of the lengths of long increasing or decreasing subsequences by assigning values ik and dk for each k from 1 to n, indicating the length of the longest increasing subsequence ending with ak and the length of the longest decreasing subsequence ending with ak, respectively. Thus ii = d 1 = 1, since a 1 is both an increasing and a decreasing subsequence of length 1. If a 2 < a 1 , then i 2 = 1 and d2 = 2, since the longest increasing subsequence ending at a 2 is just a 2 , but the longest decreasing subsequence ending at a2 is ai, a2. If a2 > a 1 , then it is the other way around: i2 = 2 and d 2 = 1. In general, we can determine ik in the following manner (the determination of dk is similar, with the roles of i and d, and the roles of< and >,reversed). We look at the numbers a 1 , a2, ... , ak-l · For each aj that is less than ak, we know that the value of ik is at least i1 + 1, since the increasing subsequence of length ij ending at a1 can be extended by following it by ak , resulting in an increasing subsequence of length ij + 1, ending at ak. Furthermore, there is no other way of producing an increasing subsequence ending at ak, other than the subsequence of length 1. Thus we set ik equal to either 1 or the maximum of the numbers i 1 + 1 for those values of j < k for which a1 < ak. Finally, once we have determined all the values ik and dk, we choose the largest of these 2n numbers as our answer. The procedure just described, however, does not keep track of what the longest subsequence is, so we need to use two more sets of variables, iprevk and dprevk. These will point back to the terms in the sequence that caused the values of ik and dk to be what they are. To retrieve the longest increasing or decreasing subsequence, once we know which type it is and where it ends, we follow these pointers, thereby exhibiting the subsequence backwards. We will not write the pseudocode for this final phase of the algorithm. (See the answer in the back of the textbook for an alternative procedure, which explicitly computes the sequence.) Section 6.2 The Pigeonhole Principle 209 procedure long subsequence(a 1 , a2, ... , an : distinct integers) fork:= 1 ton ik := 1; dk := 1 iprevk := k; dprevk := k for j := 1 to k - 1 if a1 < ak and i1 + 1 > ik then ik := iJ + 1 iprevk := j if a1 > ak and d1 + 1 > dk then dk := dJ + 1 dprevk := j {at this point correct values of ik and dk have all been assigned} longest := 1 fork:= 2 ton if ik > longest then longest := ik if dk > longest then longest := dk { longest is the length of the longest increasing or decreasing subsequence} 27. We can prove these statements using both the result and the method of Example 13. First note that the role of "mutual friend" and "mutual enemy" is symmetric, so it is really enough to prove one of these statements; the other will follow by interchanging the roles. So let us prove that in every group of 10 people, either there are 3 mutual friends or 4 mutual enemies. Consider one person; call this person A. Of the 9 other people, either there must be 6 enemies of A, or there must be 4 friends of A (if there were 5 or fewer enemies and 3 or fewer friends, that would only account for 8 people). We need to consider the two cases separately. First suppose that A has 6 enemies. Apply the result of Example 13 to these 6 people: among them either there are 3 mutual friends or there are 3 mutual enemies. If there are 3 mutual friends, then we are done. If there are 3 mutual enemies, then these 3 people, together with A, form a group of 4 mutual enemies, and again we are done. That finishes the first case. The second case was that A had 4 friends. If some pair of these people are friends, then they, together with A, form the desired group of 3 mutual friends. Otherwise, these 4 people are the desired group of 4 mutual enemies. Thus in either case we have found either 3 mutual friends or 4 mutual enemies. 29. We need to show two things: that if we have a group of n people, then among them we must find either a pair of friends or a subset of n of them all of whom are mutual enemies; and that there exists a group of n - 1 people for which this is not possible. For the first statement, if there is any pair of friends, then the condition is satisfied, and if not, then every pair of people are enemies, so the second condition is satisfied. For the second statement, if we have a group of n - 1 people all of whom are enemies of each other, then there is neither a pair of friends nor a subset of n of them all of whom are mutual enemies. 31. First we need to figure out how many distinct combinations of initials and birthdays there are. The product rule tells us that since there are 26 ways to choose each of the 3 initials and 366 ways to choose the birthday, there are 26 · 26 · 26 · 366 = 6,432,816 such combinations. By the generalized pigeonhole principle, with these combinations as the pigeonholes and the 37 million people as the pigeons, there must be at least f37,000, 000/6,432,8161 = 6 people with the same combination. 33. The numbers from 1 to 200,000 are the pigeonholes, and the inhabitants of Paris are the pigeons, which number at least 800,001. Therefore by Theorem 1 there are at least two Parisians with the same number of hairs on their heads; and by Theorem 2 there are at least f800,001/200,0001 = 5 Parisians with the same number of hairs on their heads. Chapter 6 210 Counting 35. The 38 time periods are the pigeonholes, and the 677 classes are the pigeons. By the generalized pigeonhole principle there is some time period in which at least 1677 /381 = 18 classes are meeting. Since each class must meet in a different room, we need 18 rooms. 37. Let c, be the number of computers that the ith computer is connected to. Each of these integers is between 0 and 5, inclusive. The pigeonhole principle does not allow us to conclude immediately that two of these numbers must be the same, since there are six numbers (pigeons) and six possible values (pigeonholes). However, if not all of the values are used, then the pigeonhole principle would allow us to draw the desired conclusion. Let us therefore show that not all of the numbers can be used. The only way that the value 5 can appear as one of the ci's is if one computer is connected to each of the others. In that case, the number 0 cannot appear, since no computer could be connected to none of the others. Thus not both 5 and 0 can appear in our list, and the above argument is valid. 39. This is similar to Example 9. Label the computers C 1 through C1oo, and label the printers P 1 through P20 . If we connect Ck to Pk for k = 1, 2, ... , 20 and connect each of the computers C 21 though C 100 to all the printers, then we have used a total of 20 + 80 · 20 = 1620 cables. Clearly this is sufficient, because if computers C 1 through C20 need printers, then they can use the printers with the same subscripts, and if any computers with higher subscripts need a printer instead of one or more of these, then they can use the printers that are not being used, since they are connected to all the printers. Now we must show that 1619 cables are not enough. Since there are 1619 cables and 20 printers, the average number of computers per printer is 1619 /20, which is less than 81. Therefore some printer must be connected to fewer than 81 computers (the average of a set of numbers cannot be bigger than each of the numbers in the set). That means it is connected to 80 or fewer computers, so there are at least 20 computers that are not connected to it. If those 20 computers all needed a printer simultaneously, then they would be out of luck, since they are connected to at most the 19 other printers. 41. This problem is similar to Example 10, so we follow the method of solution suggested there. Let a1 be the number of matches held during or before the jth hour. Then a 1 , a 2 , ... , a 75 is an increasing sequence of distinct positive integers, since there was at least one match held every hour. Furthermore 1 ::::; a1 ::::; 125, since there were only 125 matches altogether. Moreover, a 1 + 24, a 2 + 24, ... , a 75 + 24 is also an increasing sequence of distinct positive integers, with 25 a, + 24 149. s s Now the 150 positive integers a 1 , a2, ... , a15, a 1 + 24, a 2 + 24, ... , a 75 + 24 are all less than or equal to 149. Hence by the pigeonhole principle two of these integers are equal. Since the integers a 1 , a2, ... , a15 are all distinct, and the integers a 1 + 24, a 2 + 24, ... , a 75 + 24 are all distinct, there must be distinct indices i and j such that a1 =a,+ 24. This means that exactly 24 matches were held from the beginning of hour i + 1 to the end of hour j , precisely the occurrence we wanted to find. 43. This is exactly a restatement of the generalized pigeonhole principle. The pigeonholes are the elements in the co domain (the elements of the set T), and the pigeons are the elements of the domain (the elements of the set S). To say that a pigeon s is in pigeonhole t is just to say that J(s) = t. The elements s 1 , s2, ... , Sm are just the m pigeons guaranteed by the generalized pigeonhole principle to occupy a common pigeonhole. 45. Let d1 be jx - N(jx), where N(jx) is the integer closest to jx, for 1::::; j::::; n. We want to show that ld1 I < l/n for some j. Note that each d1 is an irrational number strictly between -1/2 and 1/2 (since jx is irrational and every irrational number is closer than 1/2 to the nearest integer). The proof is slightly messier if n is odd, so let us assume that n is even. Consider the n intervals ~) ( 0, n ' (~ ' ~) nn ' ... ' ((n/2) - 1 ' ~) ' n 2 (-_!_ ,0 ) ' (-~ , __!_) ' n n n ... ' (-~2' _ (n/2) n -1) . Section 6.3 Permutations and Combinations 211 The intervals are the pigeonholes and the d1 's are the pigeons. If the interval (0, 1/ n) or ( -1 / n, 0) is occupied, then we are done, since the d1 in that interval tells us which j makes fd1 I < l/n. If not, then there are n pigeons for at most n-2 pigeonholes, so by the pigeonhole principle there is some interval, say ( (k-1) / n, k / n) , with two pigeons in it, say dr and d8 , with r < s. Now we will consider sx - rx and show that it is within 1/ n of its nearest integer; that will complete our proof, since sx - rx = ( s - r )x, and s - r is a positive integer less than n. d8 We can write rx = N(rx) + dr and sx = N(sx) + d 8 , where (k - l)/n S dr < k/n and (k - l)/n S k/n. Subtracting, we have that sx - rx = [N(sx) - N(rx)] + [ds - dr]. Now the quantity in the first < pair of square brackets is an integer. Furthermore the quantity in the second pair of square brackets is the difference of two numbers in the interval ((k - 1)/n,k/n) and hence has absolute value less than 1/n (the extreme case would be when one of them is very close to (k - l)/n and the other is very close to k/n). Therefore, by definition of "closest integer" sx - rx is at most a distance 1/n from its closest integer, i.e., l(sx - rx) - N(sx - rx)I < 1/n, as desired. (The case in which n is odd is similar, but we need to extend our intervals slightly past ±1/2, using n + 1 intervals rather than n. This is okay, since when we subtract 2 from n + 1 we still have more pigeons than pigeonholes.) 47. a) Assuming that each ik Sn, there are only n pigeonholes (namely 1, 2, ... , n) for the n 2 + 1 numbers i1, iz, .. ., in2+1. Hence, by the generalized pigeonhole principle at least l(n 2 +1)/nl = n + 1 of the numbers are in the same pigeonhole, i.e., equal. b) If ak1 < ak 1 + 1 , then the subsequence consisting of ak1 followed by a maximal increasing subsequence of length ik1 + 1 starting at ak1 + 1 contradicts the fact that ik 1 = ik1 + 1 • Hence ak1 > ak1 + 1 • c) If there is no increasing subsequence of length greater than n, then parts (a) and (b) apply. Therefore we have akn+i > akn > · · · > ak 2 > ak 1 , a decreasing subsequence of length n + 1. SECTION 6.3 Permutations and Combinations In this section we look at counting problems more systematically than in Section 6.1. We have some formulae that apply in many instances, and the trick is to recognize the instances. If an ordered arrangement without repetitions is asked for, then the formula for permutations usually applies; if an unordered selection without repetition is asked for, then the formula for combinations usually applies. Of course the product rule and the sum rule (and common sense and cleverness) are still needed to solve some of these problems-having formulae for permutations and combinations definitely does not reduce the solving of counting problems to a mechanical algorithm. Again the general comments of Section 6.1 apply. Try to solve problems more than one way and come up with the same answer-you will learn from the process of looking at the same problem from two or more different angles, and you will be (almost) sure that your answer is correct. 1. Permutations are ordered arrangements. Thus we need to list all the ordered arrangements of all 3 of these letters. There are 6 such: a,b,c; a,c,b; b,a,c; b,c,a; c,a,b; and c,b,a. Note that we have listed them in alphabetical order. Algorithms for generating permutations and combinations are discussed in Section 6.6. 3. If we want the permutation to end with a, then we may as well forget about the a, and just count the number of permutations of {b, c, d, e, f, g}. Each permutation of these 6 letters, followed by a, will be a permutation of the desired type, and conversely. Therefore the answer is P(6, 6) = 6! = 720. Chapter 6 212 Counting 5. We simply plug into the formula P( n, r) = n( n - 1) (n - 2) · · · (n - r + 1), given in Theorem l. Note that there are r terms in this product, starting with n. This is the same as P(n, r) = n!/(n-r)!, but the latter formula is not as nice for computation, since it ignores the fact that each of the factors in the denominator cancels one factor in the numerator. Thus to compute n! and (n - r) ! and then to divide is to do a lot of extra arithmetic. Of course if the denominator is 1, then there is no extra work, so we note that P( n, n) = P( n, n - 1) = n!. b) P(6,5)=6l=720 c) P(8,1)=8 d) P(8, 5) = 8 · 7 · 6 · 5 · 4 = 6720 e) P(8, 8) = 8! = 40,320 f) P(lO, 9) = 10! = 3,628,800 a) P(6,3)=6·5·4=120 7. This is P(9, 5) = 9 · 8 · 7 · 6 · 5 = 15,120 by Theorem l. 9. We need to pick 3 horses from the 12 horses in the race, and we need to arrange them in order (first, second, and third), in order to specify the win, place, and show. Thus there are P(l2, 3) = 12 · 11 · 10 = 1320 possibilities. 11. a) To specify a bit string of length 10 that contains exactly four l's, we simply need to choose the four positions that contain the l's. There are C(10,4) = 210 ways to do that. b) To contain at most four l's means to contain four l's, three l's, two l's, one 1, or no l's. Reasoning as in part (a), we see that there are C(lO, 4)+C(10, 3)+C(10, 2)+C(10, l)+C(lO, 0) = 210+ 120+45+10+1 = 386 such strings. c) To contain at least four l's means to contain four l's, five l's, six l's, seven l's, eight l's, nine l's, or ten l's. Reasoning as in part (b), we see that there are C(lO, 4) + C(lO, 5) + C(lO, 6) + C(lO, 7) + C(lO, 8) + C(lO, 9) + C(lO, 10) = 210 + 252 + 210 + 120 + 45 + 10 + 1 = 848 such strings. A simpler approach would be to figure out the number of ways not to have at least four l's (i.e., to have three l's, two l's, one 1, or no l's) and then subtract that from 210 , the total number of bit strings of length 10. This way we get 1024 - (120 + 45 + 10 + 1) = 848, fortunately the same answer as before. Solving a combinatorial problem in more than one way is a useful check on the correctness of the answer. d) To have an equal number of O's and l's in this case means to have five l's. Therefore the answer is C(lO, 5) = 252. Incidentally, this gives us another way to do part (b ). If we don't have an equal number of O's and l's, then we have either at most four l's or at least six l's. By symmetry, having at most four l's occurs in half of these cases. Therefore the answer to part (b) is (2 10 - C(lO, 5))/2 = 386, as above. 13. We assume that the row has a distinguished head. Consider the order in which the men appear relative to each other. There are n men, and all of the P( n, n) = n! arrangements is allowed. Similarly, there are n! arrangements in which the women can appear. Now the men and women must alternate, and there are the same number of men and women; therefore there are exactly two possibilities: either the row starts with a man and ends with a woman (MWMW ... MW) or else it starts with a woman and ends with a man ( W MW Al ... W l\I). We have three tasks to perform, then: arrange the men among themselves, arrange the women among themselves, and decide which sex starts the row. By the product rule there are n!·n!·2 = 2(n!) 2 ways in which this can be done. 15. We assume that a combination is called for, not a permutation, since we are told to select a set, not form an arrangement. We need to choose 5 things from 26, so there are C(26,5) = 26 · 25 · 24 · 23 · 22/5! = 65,780 ways to do so. 17. We know that there are 2100 subsets of a set with 100 elements. All of them have more than two elements except the empty set, the 100 subsets consisting of one element each, and the C(lOO, 2) = 4950 subsets with two elements. Therefore the answer is 2100 - 5051 ~ 1.3 x 1030 . Section 6.3 Permutations and Combinations 19. a) Each flip can be either heads or tails, so there are 2 10 213 = 1024 possible outcomes. b) To specify an outcome that has exactly two heads, we simply need to choose the two flips that came up heads. There are C(lO, 2) = 45 such outcomes. c) To contain at most three tails means to contain three tails, two tails, one tail, or no tails. Reasoning as in part (b), we see that there are C(lO, 3) + C(lO, 2) + C(lO, 1) + C(lO, 0) = 120 + 45 + 10 + 1 = 176 such outcomes. d) To have an equal number of heads and tails in this case means to have five heads. Therefore the answer is C(lO, 5) = 252. 21. a) If BCD is to be a substring, then we can think of that block of letters as one superletter, and the problem is to count permutations of five items~the letters A, E, F, and G, and the superletter BCD. Therefore the answer is P(5, 5) = 5! = 120. b) Reasoning as in part (a), we see that the answer is P(4,4) = 4! = 24. c) As in part (a), we glue BA into one item and glue GF into one item. Therefore we need to permute five items, and there are P(5, 5) = 5! = 120 ways to do it. d) This is similar to part (c). Glue ABC into one item and glue DE into one item, producing four items, so the answer is P(4,4) = 4! = 24. e) If both ABC and CDE are substrings, then ABCDE has to be a substring. So we are really just permuting three items: ABCDE, F, and G. Therefore the answer is P(3,3) = 3! = 6. f) There are no permutations with both of these substrings, since B cannot be followed by both A and E at the same time. position the men relative to each other. Since there are eight men, there are P(8, 8) ways to do this. creates nine slots where a woman (but not more than one woman) may stand: in front of the first between the first and second men, ... , between the seventh and eight men, and behind the eighth We need to choose five of these positions, in order, for the first through fifth woman to occupy (order matters, because the women are distinct people). This can be done is P(9, 5) ways. Therefore the answer is P(8, 8) · P(9, 5) = 8! · 9!/4! = 609,638,400. 23. First This man, man. 25. a) Since the prizes are different, we want an ordered arrangement of four numbers from the set of the first 100 positive integers. Thus there are P(lOO, 4) = 94,109,400 ways to award the prizes. b) If the grand prize winner is specified, then we need to choose an ordered set of three tickets to win the other three prizes. This can be done is P(99, 3) = 941,094 ways. c) We can first determine which prize the person holding ticket 47 will win (this can be done in 4 ways), and then we can determine the winners of the other three prizes, exactly as in part (b). Therefore the answer is 4P(99, 3) = 3,764,376. d) This is the same calculation as in part (a), except that there are only 99 viable tickets. Therefore the answer is P(99, 4) = 90,345,024. Note that this answer plus the answer to part ( c) equals the answer to part (a), since the person holding ticket 47 either wins a prize or does not win a prize. e) This is similar to part ( c). There are 4 · 3 = 12 ways to determine which prizes these two lucky people will win, after which there are P(98, 2) = 9506 ways to award the other two prizes. Therefore the answer is 12. 9506 = 114,072. f) This is like part ( e). There are P( 4, 3) = 24 ways to choose the prizes for the three people mentioned, and then 97 ways to choose the other winner. This gives 24 · 97 = 2328 ways in all. g) Here it is just a matter of ordering the prizes for these four people, so the answer is P( 4, 4) = 24. h) This is similar to part (d), except that this time the pool of viable numbers has only 96 numbers in it. Therefore the answer is P(96,4) = 79,727,040. Chapter 6 214 Counting i) There are four ways to determine the grand prize winner under these conditions. Then there are P(99, 3) ways to award the remaining prizes. This gives an answer of 4P(99. 3) = 3, 764,376. j) First we need to choose the prizes for the holder of 19 and 47. Since there are four prizes, there are P(4, 2) = 12 ways to do this. Then there are 96 people who might win the remaining prizes, and there are P(96, 2) = 9120 ways to award these prizes. Therefore the answer is 12 · 9120 = 109,440. 27. a) Since the order of choosing the members is not relevant (the offices are not differentiated), we need to use a combination. The answer is clearly C(25, 4) = 12,650. b) In contrast, here we need a permutation, since the order matters (we choose first a president, then a vice president, then a secretary, then a treasurer). The answer is clearly P(25,4) = 303,600. 29. a) In this part the permutation 5, 6, 32, 7, for example, is to be counted. since it contains the consecutive numbers 5, 6 , and 7 in their correct order (even though separated by the 32). In order to specify such a 4-permutation, we first need to choose the 3 consecutive integers. They can be anything from {1, 2, 3} to {98, 99, 100}; thus there are 98 possibilities. Next we need to decide which slot is to contain a number not in this set; there are 4 possibilities. Finally, we need to decide which of the 97 other positive integers not exceeding 100 is to fill this slot, and there are of course 97 choices. Thus our first attempt at an answer gives us, by the product rule, 98 · 4 · 97. Unfortunately, this answer is not correct, because we have counted some 4-permutations more than once. Consider the 4-permutation 4, 5, 6, 7, for example. We cannot tell whether it arose from choosing 4, 5, and 6 as the consecutive numbers, or from choosing 5, 6, and 7. (These are the only two ways it could have arisen.) In fact, every 4-permutation consisting of 4 consecutive numbers. in order, has been double counted. Therefore to correct our count, we need to subtract the number of such 4-permutations. Clearly there are 97 of them (they can begin with any number from 1 to 97). Further thought shows that every other 4-permutation in our collection arises in a unique way (in other words, there is a unique subsequence of three consecutive integers). Thus our final answer is 98 · 4 · 97 - 97 = 37.927. b) In this part we are insisting that the consecutive numbers be consecutive in the 4-permutation as well. The analysis in part (a) works here, except that there are only 2 places to put the fourth number-in slot 1 or in slot 4. Therefore the answer is 98 · 2 · 97 - 97 = 18,915. 31. We need to be careful here, because strings can have repeated letters. a) We need to choose the position for the vowel. and this can be done in 6 ways. Next we need to choose the vowel to use, and this can be done in 5 ways. Each of the other five positions in the string can contain any of the 21 consonants. so there are 21 5 ways to fill the rest of the string. Therefore the answer is 6 . 5 . 21 5 = 122,523,030. b) We need to choose the position for the vowels, and this can be done in C(6, 2) 15 ways (we need to choose two positions out of six). We need to choose the two vowels ( 5 ways). Each of the other four positions in the string can contain any of the 21 consonants, so there are 21 4 ways to fill the rest of the string. Therefore the answer is 15 · 5 2 · 21 4 = 72,930,375. = 2 c) The best way to do this is to count the number of strings with no vowels and subtract this from the total number of strings. We obtain 26 6 - 21 6 = 223,149,655. d) As in part ( c), we will do this by subtracting from the total number of strings, the number of strings with no vowels and the number of strings with one vowel (this latter quantity having been computed in part (a)). We obtain 26 6 - 21 6 - 6 · 5 · 21 5 = 223149655 - 122523030 = 100,626,625. 33. We are told that we must select three of the 10 men and three of the 15 women. This can be done is C(lO, 3)C(15, 3) = 54,600 ways. Section 6.4 Binomial Coefficients and Identities 215 35. To implement the condition that every 0 be immediately followed by a 1, let us think of "gluing" a 1 to the right of each 0. Then the objects we have to work with are eight blocks consisting of the string 01 and two l's. The question is, then, how many strings are there consisting of these ten objects? This is easy to calculate, for we simply have to choose two of the ''positions" in the string to contain the l's and fill the remaining "positions" with the 01 blocks. Therefore the answer is C(lO, 2) = 45. 37. Perhaps the most straightforward way to do this is to look at the several cases. The string might contain three l's and seven O's, four l's and six O's, five of each, six l's and four O's, or seven l's and three O's. In each case we can determine the number of strings by calculating a binomial coefficient, since we simply need to choose the positions for the l's. Therefore the answer is C(lO, 3) + C(lO, 4) + C(lO, 5) + C(lO, 6) + C(lO, 7) = 120 + 210 + 252+210+120 = 912. 39. To specify such a license plate we need to write down a 3-permutation of the set of 26 letters and follow it by a 3-permutation of the set of 10 digits. By the product rule the answer is therefore P(26, 3) · P(lO, 3) = 26. 25. 24. 10. 9. 8 = 11,232,000. 41. Designate the head of the table and seat the people clockwise. Clearly there are P(n, r) ways to do this. Because rotations of the table do not make for a "different" seating, this overcounts by a factor of r. Therefore the answer is P(n, r)/r = n!/(r(n - r )!) . 43. If there are no ties, then there are 3! = 6 possible finishes. If two of the horses tie and the third has a different time, then there are 3 ways to decide which horse is not tied and then 2 ways to decide whether that horse finishes first or last. That gives 3 · 2 = 6 possibilities. Finally, all three horses can tie. So the answer is 6+6+1=13. 45. We can solve this problem by breaking it down into cases depending on the ties. There are four basic cases. (1) If there are unique gold and silver winners, then we can choose these winners in 6 · 5 = 30 ways. Any nonempty subset of the remaining four runners can win the bronze medal. There are 24 - 1 = 15 ways to choose these people, giving us 30 · 15 = 450 ways in all for this case. (2) If there is a 2-way tie for first place, then there are C(6, 2) = 15 ways to choose the gold medalists. Any nonempty subset of the remaining four runners can win the bronze medal, so there are 24 - 1 = 15 ways to choose these people, giving us 15 · 15 = 225 ways in all for this case. (3) If there is a k-way tie for first with k 2: 3, then there are C(6,k) ways to choose the gold medalists (there are no other medals in this case). This gives us C(6, 3) + C(6, 4) + C(6, 5) + C(6, 6) = 20 + 15 + 6 + 1 = 42 more possibilities. (4) The only other case is that there is a single gold medal winner and a k-way tie for second with k 2: 2. We can choose the winner in 6 ways and the silver medalists in 25 - C(5, 1) - C(5, 0) = 32 - 5 - 1 = 26 ways. This gives us 6 · 26 = 156 possibilities. Putting this all together, the answer is 450 + 225 + 42 + 156 = 873. SECTION 6.4 Binomial Coefficients and Identities In this section we usually write the binomial coefficients using the (~) notation, rather than the C(n, r) notation. These numbers tend to come up in many parts of discrete mathematics. 216 Chapter 6 Counting 1. a) When (x + y) 4 = (x + y)(x + y)(x + y)(x + y) is expanded, all products of a term in the first sum, a term in the second sum, a term in the third sum, and a term in the fourth sum are added. Terms of the form x 4 , x 3y, x 2y 2 , xy 3 and y 4 arise. To obtain a term of the form x 4 , an x must be chosen in each of the sums, and this can be done in only one way. Thus, the x 4 term in the product has a coefficient of 1. (We can think of this coefficient as (!) .) To obtain a term of the form x 3 y, an x must be chosen in three of the four sums (and consequently a y in the other sum). Hence, the number of such terms is the number of 3-combinations of four objects, namely (~) = 4. Similarly, the number of terms of the form x 2y 2 is the number of ways to pick two of the four sums to obtain x's (and consequently take a y from each of the other two factors). This can be done in (~) = 6 ways. By the same reasoning there are (;) = 4 ways to obtain the xy 3 terms, and only one way (which we can think of as (6)) to obtain a y 4 term. Consequently, the product is x 4 + 4x 3 y + 6x 2 y 2 + 4xy 3 + y 4 . b) This is explained in Example 2. The expansion is (6) x 4 + (i) x 3y + @x 2y 2 + (j) xy 3 + (!) y4 = x4 + 4x3y + 6x 2y 2 + 4xy 3 + y 4 . Note that it does not matter whether we think of the bottom of the binomial coefficient expression as corresponding to the exponent on x, as we did in part (a), or the exponent on y, as we do here. 3. The coefficients are the binomial coefficients (~) , as i runs from 0 to 6, namely 1, 6, 15, 20, 15, 6, 1. Therefore (x + y) 6 6 = L (~)x 6 -'y' = x 6 + 6x 5 y + 15x4 y2 + 20x 3y3 + 15x 2y4 + 6xy 5 + y 6 . i=O 5. There is one term for each i from 0 to 100, so there are 101 terms. 7. By the binomial theorem the term involving x 9 in the expansion of (2 + (-x)) 19 is (1i)2 10 (-x) 9 . Therefore the coefficient is (1i)2 10 (-1) 9 = -2 10 (1i) = -94,595,072. 9. Using the binomial theorem, we see that the term involving x 101 in the expansion of ((2x) (29°~) (2x ) 101 ( -3y )99 . Therefore the coefficient is ( 2~9°) 2101 ( -3) 99 = -2 101 399 0(200, 99). + (-3y)) 200 is 11. Let us apply the binomial theorem to the given binomial: 100 (x2 _ x-1 )100 = (1~0) (x2)100-1 (-x-1 )J J=O J 100 100 = (l~O) (-1)1x200-21-1 = L L L (l~O) (-l)lx200-31 1=0 1=0 J Thus the only nonzero coefficients are those of the form 200 - 3j where j is an integer between 0 and 100, inclusive, namely 200, 197, 194, ... , 2, -1, -4, ... , -100. If we denote 200 - 3j by k, then we have j = (200- k)/3. This gives us our answer. The coefficient of xk is zero fork not in the list just given (namely those vales of k between -100 and 200, inclusive, that are congruent to 2 modulo 3), and for those values . t.' 100 ) · . the l"is t , th e coeffi c1en is ( - 1)(200-k)/3( (zoo-k)/ of k m 3 13. We are asked simply to display these binomial coefficients. Each can be computed from the formula in Theorem 2 in Section 6.3. Alternatively, we can apply Pascal's identity to the last row of Figure l(b), adding successive numbers in that row to produce the desired row. We thus obtain 1 9 36 84 126 126 84 36 9 1. 15. There are many ways to see why this is true. By Corollary 1 the sum of all the positive numbers (~), as k runs from 0 to n, is 2n, so certainly each one of them is no bigger than this sum. Another way to see this is to note that (~) counts the number of subsets of an n-set having k elements, and 2n counts even more--the number of subsets of an n-set with no restriction as to size; so certainly the former is smaller than the latter. Section 6.4 Binomial Coefficients and Identities 17. We know that 217 = n(n - l)(n - 2) .. · (n - k + 1). k(k-l)(k-2) ·2 Now if we make the numerator of the right-hand side larger by raising each factor up to n, and make the denominator smaller by lowering each factor to 2, then we have certainly not decreased the value, so the left-hand side is less than or equal to this altered expression. But the result is precisely nk /2k-l, as desired. n) (k 00 19. Using the formula (Theorem 2 in Section 6.3) we have (k: 1) + G) = (k - l)!(nn~ (k -1))! + k!(nn~ k)! n!k+n!(n-k+l) k!(n-k + 1)! (having found a common denominator) (n+l)n! (n+l)! - k!((n + 1) - k)! - k!((n + 1) - k)! (n+l) k · 21. a) We show that each side counts the number of ways to choose from a set with n elements a subset with k elements and a distinguished element of that set. For the left-hand side, first choose the k-set (this can be done in (~) ways) and then choose one of the k elements in this subset to be the distinguished element (this can be done in k ways). For the right-hand side, first choose the distinguished element out of the entire n-set (this can be done in n ways), and then choose the remaining k - 1 elements of the subset from the remaining ways). n - 1 elements of the set (this can be done in G::::D b) This is straightforward algebra: n) n! n·(n-1)! (n-1) k ( k =k· k!(n-k)! = (k-l)!(n-k)! =n k-1 · 23. This identity can be proved algebraically or combinatorially. Algebraically, we compute as follows, starting with the right-hand side (we use twice the fact that (x + l)x! = (x + 1)!): (n+l)n! (k - l)!(n - (k - l))!k (n + 1)! k!(n - (k - 1))! (n + 1)! For a combinatorial argument, we need to construct a situation in which both sides count the same thing. Suppose that we have a set of n + 1 people, and we wish to choose k of them. Clearly there are (nkl) ways to do this. On the other hand, we can choose our set of k people by first choosing one person to be in the set (there are n + 1 choices), and then choosing k - 1 additional people to be in the set, from the n people remaining. This can be done in (k~ 1 ) ways. Therefore apparently there are (n + l)(k~ 1 ) ways to choose the set of k people. However, we have overcounted: there are k ways that every such set can be chosen, since once we have the set, we realize that any of the k people could have been chosen first. Thus we have overcounted by a factor of k, and the real answer is (n + 1) (k~ 1 ) / k (we correct for the overcounting by dividing by k ). Comparing our two approaches, one yielding the answer (nt 1 ), and the other yielding the answer (n + l)(k::_ 1 )/k, we conclude that (nt 1 ) = (n + l)(k::_ 1 )/k. 218 Chapter 6 Counting Finally, we are asked to use this identity to give a recursive definition of the (~) 's. Note that this identity expresses G) in terms of (;) for values of i and j less than n and k, respectively (namely i = n - 1 and j = k - 1 ). Thus the identity will be the recursive part of the definition. We need the base cases to handle n = 0 or k = 0. Our full definition becomes if k = 0 if k > 0 and n = 0 if n > 0 and k > 0. Actually, if we assume (as we usually do) that k ::::; n, then we do not need the second line of the definition. Note that (~) = 0 for n < k under the definition given here, which is consistent with the combinatorial definition, since there are no ways to choose k different elements from a set with fewer than k elements. 25. We use Pascal's identity twice (Theorem 2 of this section) and Corollary 1 of the previous section: 2n ) ( n+l + (2n) (2nn+l+ 1) n = = ~ ( 2 = ~( (2nn+l+ 1) + (2nn+l+ 1)) (2:: 11) (2n: 1)) ~ (2::12)) + = ( 27. The reason this is called the "hockey stick identity" is that the binomial coefficients being summed lie along a line in Pascal's triangle, and the sum is the entry in the triangle that, together with that line, forms a shape vaguely resembling a hockey stick. a) We need to find something to count so that the left-hand side of the equation counts it in one way and the right-hand side counts it in a different way. After much thought, we might try the following. We will count the number of bit strings of length n + r + 1 containing exactly r O's and n + 1 l's. There are (n+;+ 1 ) such strings, since a string is completely specified by deciding which r of the bits are to be the O's. To see that the left-hand side of the identity counts the same thing, let l + 1 be the position of the last 1 in the string. Since there are n + 1 1's, we know that l cannot be less than n. Thus there are disjoint cases for each l from n to n + r. For each such l, we completely determine the string by deciding which of the l positions in the string before the last 1 are to be O's. Since there are n l's in this range, there are l - n O's. Thus there are C~n) n+r ways to choose the positions of the O's. Now by the sum rule the total number of bit strings will be By making the change of variable k =l- 2:: ( 1 ~n). l=n n, this transforms into the left-hand side, and we are finished. b) We need to prove this by induction on r; Pascal's identity will enter at the crucial step. We let P(r) be the statement to be proved. The basis step is clear, since the equation reduces to (~) = (n6l), which is the true proposition 1=1. Assuming the inductive hypothesis, we derive P(r + 1) in the usual way: __ (n + rr + 1) + (n +r +r + 1) (n + (r + l) + 1 = r+l 1 ) (by the inductive hypothesis) (by Pascal's identity) 29. We will follow the hint and count the number of ways to choose a committee with leader from a set of n people. Note that the size of the committee is not specified, although it clearly needs to have at least one person (its leader). On the one hand, we can choose the leader first, in any of n ways. We can then choose the rest of the committee, which can be any subset of the remaining n - 1 people; this can be done in 2n-l ways since there are this many subsets. Therefore the right-hand side of the proposed identity counts this. Section 6.4 Binomial Coefficients and Identities 219 On the other hand, we can organize our count by the size of the committee. Let k be the number of people who will serve on the committee. The number of ways to select a committee with k people is clearly G), and once we have chosen the committee. there are clearly k ways in which to choose its leader. By the sum rule the left-hand side of the proposed identity therefore also counts the number of such committees. Since the two sides count the same quantity, they must be equal. G) + (;) - · · · ± (~) = 0. If we put all the negative terms on the other side, we obtain (~) + G) + G) + · · · = (~) + (;) + · · · (one side ends at (~) and the other side ends at (,,~ 1 )-which is which depends on whether n is even or odd). Now the left-hand side counts the number of subsets with even cardinality of a set with n elements, and the right-hand side counts the number of subsets with odd cardinality of the same set. That these two quantities are equal is precisely what we wanted to prove. 31. Corollary 2 says that (~) - 33. a) Clearly a path of the desired type must consist of rn moves to the right and n moves up. Therefore each such path can be represented by a bit string consisting of rn O's and n l's, with the O's representing moves to the right and the l's representing moves up. Note that the total length of this bit string is rn + n. b) We know from this section that the number of bit strings of length +n containing exactly n l's is (m~n), since one need only specify the positions of the l's. Note that this is the same as (m,-;;:n). rn 35. We saw in Exercise 33 that the number of paths of length n was the same as the number of bit strings of length n, which we know to be 2", the right-hand side of the identity. On the other hand, a path of length n must end up at some point the sum of whose coordinates is n, say at (n - k, k) for some k from 0 ton. We saw in Exercise 33 that the number of paths ending up at (n - k, k) was equal to ("-z+k) = G). Therefore the left-hand side of the identity counts the number of such paths, too. 37. The right-hand side of the identity we are asked to prove counts, by Exercise 33, the number of paths from (0, 0) to (n + 1, r). Now let us count these paths by breaking them down into r + 1 cases, depending on how many steps upward they begin with. Let k be the number of steps upward they begin with before taking a step to the right. Then k can take any value from 0 to r. The number of paths from (0, 0) to (n + 1, r) that begin with exactly k steps upward before turning to the right is clearly the same as the number of paths from (1, k) to (n + 1, r). since after these k upward steps and the move to the right we have reached (1, k). This latter quantity is the same as the number of paths from (0, 0) to (n + 1- 1, r - k) = (n, r - k), since we can relabel our diagram to make (1, k) the origin. From Exercise 33, this latter quantity is (n~:J;k). Therefore the total number of paths is the desired sum tc;::k) =t(n;k), k=O k=O where the equality comes from changing the dummy variable from k to r - k. Since both sides count the same thing, they are equal. 39. a) This looks like the third negatively sloping diagonal of Pascal's triangle, starting with the leftmost entry in the second row and reading down and to the right. In other words, the nth term of this sequence is (~~D = (ntl) . b) This looks like the fourth negatively sloping diagonal of Pascal's triangle, starting with the leftmost entry in the third row and reading down and to the right. In other words, the nth term of this sequence is (~~i) = (n!2) . c) These seem to be the entries reading straight down the middle of the Pascal's triangle. Only every other row has a middle element. The first entry in the sequence is (g), the second is (i), the third is the fourth is m' and so on. m, In general, then, the nth 2 term is (~~__:-1 ). 220 Chapter 6 Counting d) These seem to be the entries reading down the middle of the Pascal's triangle. Only every other row has an exact middle element, but in the other rows, there are two elements sharing the middle. The first entry in the sequence is (g) , the second is @ , the third is (i) , the fourth is (i) ' the fifth is the fourth is @ ' and so on. In general, then, the nth term is (l(n~~~/zJ). m' e) One pattern here is a wandering through Pascal's triangle according to the following rule. The nth term is in the nth row of the triangle. We increase the position in that row as we go down, but as soon as we are about to reach the middle of the row, we jump back to the start of the next row. For example, the fifth term is the first entry in row 5; the sixth term is the second entry in row 6; the seventh term is the third entry in row 7; the eighth term is the fourth entry in row 8. The next entry following that pattern would take us to the middle of the ninth row, so instead we jump back to the beginning, and the ninth term is the first entry of row 9. To come up with a formula here, we see that the nth entry is (~:::i) for a particular k; let us determine k as a function of n. A little playing around with the pattern reveals that k is n minus the largest power of 2 less than n (where for this purpose we consider 0 to be the largest power of 2 less than 1). For example, the 14th term has k = 14 - 8 = 6, so it is (153 ) = 1287. f) The terms seem to come from every third row, so the nth term is (3 n; 3 ) for some k. A little observation indicates that in fact these terms are (~), SECTION 6.5 (D, m, G), (~ ), and so on. Thus the nth term is (3:_::2 3 1 ). Generalized Permutations and Combinations As in Section 6.3, we have formulae that give us the answers to some combinatorial problems, if we can figure out which formula applies to which problem, and in what way it applies. Here, even more than in previous sections, the ability to see a problem from the right perspective is the key to solving it. Expect to spend several minutes staring at each problem before any insight comes. Reread the examples in the section and try to imagine yourself going through the thought processes explained there. Gradually your mind will begin to think in the same terms. In particular, ask yourself what is being selected from what, whether ordered or unordered selections are to be made, and whether repetition is allowed. In most cases, after you have answered these questions, you can find the appropriate formula from Table 1. 1. Since order is important here, and since repetition is allowed, this is a simple application of the product rule. There are 3 ways in which the first element can be selected, 3 ways in which the second element can be selected, and so on, with finally 3 ways in which the fifth element can be selected, so there are 35 = 243 ways in which the 5 elements can be selected. The general formula is that there are nk ways to select k elements from a set of n elements, in order, with unlimited repetition allowed. 3. Since we are considering strings, clearly order matters. The choice for each position in the string is from the set of 26 letters. Therefore, using the same reasoning as in Exercise 1, we see that there are 26 6 = 308,915, 776 strings. 5. We assume that the jobs and the employees are distinguishable. For each job, we have to decide which employee gets that job. Thus there are 5 wayH in which the first job can be assigned, 5 ways in which the second job ran be assigned, and 5 ways in which the third job can be assigned. Therefore, by the multiplication principle (just as in Exercise 1) there are 53 = 125 ways in which the assignments can be made. (Note that we do not require that every employee get at least one job.) 7. Since the selection is to be an unordered one, Theorem 2 applies. We want to choose r = 3 items from a set with n = 5 elements. Theorem 2 tells us that there are C(5 + 3 - 1, 3) = C(7, 3) = 7 · 6 · 5/(3 · 2) = 35 ways to do so. (Equivalently, this problem is asking us to count the number of nonnegative integer solutions to :r 1 + x 2 + x 3 + x 4 + x 5 = 3, where x, represents the number of times that the ith element of the 5-element set gets selected.) Section 6.5 221 Generalized Permutations and Combinations 9. Let bi, b2, ... , b8 be the number of bagels of the 8 types listed (in the order listed) that are selected. Order does not matter: we are presumably putting the bagels into a bag to take home, and the order in which we put them there is irrelevant. a) If we want to choose 6 bagels, then we are asking for the number of nonnegative solutions to the equation bi+ b2 + · · · + b8 = 6. Theorem 2 applies, with n = 8 and r = 6, giving us the answer C(8 + 6 -1,6) = C(13, 6) = 1716. b) This is the same as part (a), except that r = 12 rather than 6. Thus there are C(8 + 12 - 1, 12) = C(l9, 12) = C(19, 7) = 50,388 ways to make the selection. (Note that C(19, 7) was easier to compute than C(19, 12), and since they are equal, we chose the latter form.) c) This is the same as part (a), except that r = 24 rather than 6. Thus there are C (8 + 24 - 1, 24) = C(31, 24) = C(31, 7) = 2,629,575 ways to make the selection. d) This one is more complicated. Here we want to solve the equation b1 + b2 + · · · + bs = 12, subject to the constraint that each b, ;:: 1. We reduce this problem to the form in which Theorem 2 is applicable with the following trick. Let b~ = b, - 1; then b~ represents the number of bagels of type i, in excess of the required 1, that are selected. If we substitute b, = b~ + 1 into the original equation, we obtain (b~ + 1) + (b; + 1) + · · · + (b~ + 1) = 12, which reduces to b~ + b; + · · · + b~ = 4. In other words, we are asking how many ways are there to choose the 4 extra bagels (in excess of the required 1 of each type) from among the 8 types, repetitions allowed. By Theorem 2 the number of solutions is C(8 + 4 - 1, 4) = C(ll, 4) = 330. e) This final part is even trickier. First let us ignore the restriction that there can be no more than 2 salty bagels (i.e., that b4 ::; 2). We will take into account, however, the restriction that there must be at least 3 egg bagels (i.e., that b3 ;:: 3 ). Thus we want to count the number of solutions to the equation b1 +b2 +· · ·+bs = 12, subject to the condition that b2 ;:: 0 for all i and b3;:: 3. As in part (d), we use the trick of choosing the 3 egg bagels at the outset, leaving only 9 bagels free to be chosen; equivalently, we set b~ = b3 - 3, to represent the extra egg bagels, above the required 3, that are chosen. Now Theorem 2 applies to the number of solutions of b1 + b2 + b~ + b4 + · · · + bs = 9, so there are C(8 + 9 - 1, 9) = C(16, 9) = C(16, 7) = 11,440 ways to make this selection. Next we need to worry about the restriction that b4 ::; 2. We will impose this restriction by subtracting from our answer so far the number of ways to violate this restriction (while still obeying the restriction that b3 ~ 3). The difference will be the desired answer. To violate the restriction means to have b4 ~ 3. Thus we want to count the number of solutions to b1 + b2 + · · · + b8 = 12, with b3 ~ 3 and b4 ~ 3. Using the same technique as we have just used, this is equal to the number of nonnegative solutions to the equation bi+ b2 + b~ + b~ + bs + · · · + b8 = 6 (the 6 on the right being 12 - 3 - 3). By Theorem 2 there are C(8 + 6 - 1, 6) = C(13, 6) = 1716 ways to make this selection. Therefore our final answer is 11440 - 1716 = 9724. 11. This can be solved by common sense. Since the pennies are all identical and the nickels are all identical, all that matters is the number of each type of coin selected. We can select anywhere from 0 to 8 pennies (and the rest nickels); since there are nine numbers in this range, the answer is 9. (The number of pennies and nickels is irrelevant, as long as each is at least eight.) If we wanted to use a high-powered theorem for this problem, we could observe that Theorem 2 applies, with n = 2 (there are two types of coins) and r = 8. The formula gives C(2 + 8 - 1, 8) = C(9, 8) = 9. 13. Assuming that the warehouses are distinguishable, let w, be the number of books stored in warehouse i. Then we are asked for the number of solutions to the equation w1 + w2 + w 3 = 3000. By Theorem 2 there are C(3 + 3000 - 1, 3000) = C(3002, 3000) = C(3002, 2) = 4,504,501 of them. 15. a) Let x 1 = x~ + 1; thus x~ is the value that x 1 has in excess of its required 1. Then the problem 222 Chapter 6 asks for the number of nonnegative solutions to x~ + x 2 + :r 3 + x 4 + .r 5 C(5 + 20 - l, 20) = C(24. 20) = C(24, 4) = 10,626 of them. = 20. Counting By Theorem 2 there are b) Substitute :r, = J''. + 2 into the equation for each i; thus .r; is the value that :r, has in excess of its required 2. Then the problem asks for the number of nonnegative solutions to x~ + x; + .r~ + :r~ + x~ = 11. By Theorem 2 there are C(.5 + 11 - 1, 11) = C(15, 11) = C(15, 4) = 1365 of them. c) There are C(5 + 21 - 1, 21) = C(25, 21) = C(25, 4) = 12650 solutions with no restriction on x 1 . The restriction on x 1 will be violated if x 1 2: 11. Following the procedure in part (a), we find that there are C(5 + 10 - 1, 10) = C(14. 10) = C(14, 4) = 1001 solutions in which the restriction is violated. Therefore there are 12650 - 1001 = 11,649 solutions of the equation with its restriction. d) First let us impose the restrictions that :r 3 2: 15 and .r2 2: 1. Then the problem is equivalent to counting J'; the number of solutions to :r 1 + + x~ + :r 4 + x 5 = 5, subject to the constraints that x 1 :::; 3 and x; :::; 2 (the latter coming from the original restriction that .r 2 < 4). Note that these two restrictions cannot be violated simultaneously. Thus if we count the number of solutions to x 1 + J'~ + x~ + .T4 + :r 5 = 5, subtract the number of its solutions in which :r 1 ?: 4, and subtract the numbers of its solutions in which ?: 3, then we will have the answer. By Theorem 2 there are C(5 + 5 - 1, 5) = C(9. 5) = 126 solutions of the x; unrestricted equation. Applying the first restriction reduces the equation to :r~ + x~ + x~ + :r 4 + x 5 = 1, which has C(5 + 1 - 1, 1) = C(5, 1) = 5 solutions. Applying the second restriction reduces the equation to .r 1 +.r~ +x~ +.r 4 +J'5 = 2, which has C(5+2- l,2) = C(6,2) = 15 solutions. Therefore the answer is 126-5-15=106. 17. Theorem 3 applies here, with n = 10 and k = 3. The answer is therefore 10! -,-,-, = 2520 . 2.3.5. 19. Theorem 3 applies here, with n n5 = = 14, n 1 = n 2 3 (the triplets), n 3 = 714 2 (the twins), and n 7 = 1. The answer is therefore 14! 3!3!2!2!2!1!1! = 302, 702,400. 21. If we think of the balls as doing the choosing, then this is asking for the number of ways to choose six bins from the nine given bins, with repetition allowed. (The number of times each bin is chosen is the number of balls in that bin.) By Theorem 2 with n = 9 and r = 6, this choice can be made in C(9+6-1.6) = C(14,6) = 3003 ways. 23. There are several ways to count this. We can first choose the two objects to go into box #1 ( C(12, 2) ways), then choose the two objects to go into box #2 ( C(lO, 2) ways, since only 10 objects remain), then choose the two objects to go into box #3 ( C(8, 2) ways), and so on. So the answer is C(12. 2) · C(lO, 2) · C(8, 2) · C(6, 2) · C(4. 2) · C(2, 2) = (12·11/2)(10 · 9/2)(8 · 7/2)(6 · 5/2)(4·3/2)(2·1/2) = 12!/26 = 7.484,400. Alternatively, just line up the 12 objects in a row ( 12! ways to do that), and put the first two into box #1, the next two into box #2, and so on. This overcounts by a factor of 26 , since there are that many ways to swap objects in the permutation without affecting the result (swap the first and second objects or not, and swap the third and fourth objects or not, and so on). So this results in the same answer. Here is a third way to get this answer. First think of pairing the objects. Think of the objects as ordered (a first, a second, and so on). There are 11 ways to choose a mate for the first object, then 9 ways to choose a mate for the first unused object, then 7 ways to choose a mate for the first still unused object, and so on. This gives 11 · 9 · 7 · 5 · 3 ways to do the pairing. Then there are 6! ways to choose the boxes for the pairs. So the answer is the product of these two quantities. which is again 7,484,400. Section 6.5 223 Generalized Permutations and Combinations 25. Let d 1 , d2, ... , d6 be the digits of a natural number less than 1,000,000; they can each be anything from 0 to 9 (in particular, we may as well assume that there are leading O's if necessary to make the number exactly 6 digits long). If we want the sum of the digits to equal 19, then we are asking for the number of solutions to the equation d 1 + d 2 + · · · + d5 = 19 with 0 ::; di ::; 9 for each i. Ignoring the upper bound restriction, there are, by Theorem 2, C(6 + 19 - 1, 19) = C(24, 19) = C(24, 5) = 42504 of them. We must subtract the number of solutions in which the restriction is violated. If the digits are to add up to 19 and one or more of them is to exceed 9, then exactly one of them will have to exceed 9, since 10 + 10 > 19. There are 6 ways to choose the digit that will exceed 9. Once we have made that choice (without loss of generality assume it is d 1 that is to be made greater than or equal to 10 ), then we count the number of solutions to the equation by counting the number of solutions to d~ + d2 + · · · + d 6 = 19 - 10 = 9; by Theorem 2 there are C(6 + 9 - 1, 9) = C(14, 9) = C(14, 5) = 2002 of them. Thus there are 6 · 2002 = 12012 solutions that violate the restriction. Subtracting this from the 42504 solutions altogether, we find that 42504 - 12012 = 30,492 is the answer to the problem. 27. We assume that each problem is worth a whole number of points. Then we want to find the number of integer solutions to x 1 + x 2 + · · · + x 10 = 100, subject to the constraint that each Xi ::'.'. 5. Letting x~ be the number of points assigned to problem i in excess of its required 5, and substituting Xi = x~ + 5 into the equation, we obtain the equivalent equation x~ + x~ + · · · + x~ 0 = 50. By Theorem 2 the number of solutions is given by C(lO + 50 - 1, 50) = C(59, 50) = C(59, 9) = 12,565,671,261. 29. There are at least two good ways to do this problem. First we present a solution in the spirit of this section. Let us place the l's and some gaps in a row. A 1 will come first, followed by a gap, followed by another 1, another gap, a third 1, a third gap, a fourth 1, and a fourth gap. Into the gaps we must place the 12 O's that are in this string. Let 91, 92, 93, and 94 be the numbers of O's placed in gaps 1 through 4, respectively. The only restriction is that each 9i ::'.'. 2. Thus we want to count the number of solutions to the equation 91 +92 + 9 3 + 94 = 12, with 9i ::'.'. 2 for each i. Letting 9i = + 2, we want to count, equivalently, the number of nonnegative solutions to g~ + g~ + g~ + g~ = 4. By Theorem 2 there are C( 4+4-1, 4) = C(7, 4) = C(7, 3) = 35 solutions. Thus our answer is 35. g; Here is another way to solve the problem. Since each 1 must be followed by two O's, suppose we glue 00 to the right end of each 1. This uses up 8 of the O's, leaving 4 unused O's. Now we have 8 objects, namely 4 O's and 4 lOO's. We want to find the number of strings we can form with these 8 objects, starting with a 100. After placing the 100 first, there are 7 places left for objects, 3 of which have to be lOO's. Clearly there are C(7, 3) = 35 ways to choose the positions for the lOO's, so our answer is 35. 31. This is a direct application of Theorem 3, with n = 11, n 1 = 5, n 2 = 2, n 3 = n 4 = 1, and n 5 represents the number of A's, etc.). Thus the answer is 11!/(5!2!1!1!2!) = 83,160. = 2 (where n 1 33. We need to use the sum rule at the outermost level here, adding the number of strings using each subset of letters. There are quite a few cases. First, there are 3 strings of length 1, namely 0, R, and N. There are several strings of length 2. If the string uses no O's, then there are 2; if it uses 1 0, then there are 2 ways to choose the other letter, and 2 ways to permute the letters in the string, so there are 4; and of course there is just 1 string of length 2 using 2 O's. Strings of length 3 can use 1, 2, or 3 O's. A little thought shows that the number of such strings is 3! = 6, 2 · 3 = 6, and 1, respectively. There are 3 possibilities of the choice of letters for strings of length 4. If we omit an 0, then there are 4!/2! = 12 strings; if we omit either of the other letters (2 ways to choose the letter), then there are 4 strings. Finally, there are 5!/3! = 20 strings of length 5. This gives a total of 3 + 2 + 4 + 1 + 6 + 6 + 1 + 12 + 2 · 4 + 20 = 63 strings using some or all of the letters. Chapter 6 224 Counting 35. We need to consider the three cases determined by the number of characters used in the string: 7, 8, or 9. If all nine letters are to be used, then Theorem 3 applies and we get 9! 4!2!1!1!1! = 7560 strings. If only eight letters are used, then we need to consider which letter is left out. In each of the cases in which the V, G, or N is omitted, Theorem 3 tells us that there are 8! 4!2!1!1! = 840 strings, for a total of 2520 for these cases. If an R is left out, then Theorem 3 tells us that there are 8! 4!1!1!1! = 1680 strings, and if an E is left out, then Theorem 3 tells us that there are 8! 3!2!1!1! = 3360 strings. This gives a total of 2520 + 1680 + 3360 = 7560 strings of length 8. (It was not an accident that there are as many strings of length 8 as there are of length 9, since there is a one-to-one correspondence between these two sets, given by associating with a string of length 9 its first 8 characters.) For strings of length 7 there are even more cases. We tabulate them here: omitting omitting omitting omitting omitting omitting omitting omitting omitting omitting omitting omitting VG VN GN VR GR NR RR EV EG EN ER EE 7!/(4!2!1!) = 105 strings 7!/(4!2!1!) = 105 strings 7!/(4!2!1!) = 105 strings 7!/(4!1!1!1!) = 210 strings 7!/(4!1!1!1!) = 210 strings 7!/(4!1!1!1!) = 210 strings 7!/(4!1!1!1!) = 210 strings 7!/(3!2!1!1!) = 420 strings 7!/(3!2!1!1!) = 420 strings 7!/(3!2!1!1!) = 420 strings 7!/(3!1!1!1!1!) = 840 strings 7!/(2!2!1!1!1!) = 1260 strings Adding up these numbers we see that there are 4515 strings of length 7. Thus the answer is 7560 + 7560 + 4515 = 19.635. 37. We assume that all the fruit is to be eaten; in other words, this process ends after 7 days. This is a permutation problem since the order in which the fruit is consumed matters (indeed, there is nothing else that matters here). Theorem 3 applies, with n = 7, n 1 = 3, n 2 = 2, and n3 = 2. The answer is therefore 7!/(3!2!2!) = 210. 39. We can describe any such travel in a unique way by a sequence of 4 x's, 3 y's, and 5 z's. By Theorem 3 there are 12! -.3.5. 4' ,' = 27720 such sequences. 41. This is like Example 8. If we approach it as is done there, we see that the answer is C( 52 7)C( 45 7 )C( 38 7 )C( 31 7)C( 24 7) 52! 45! 38! 31! 24! 52! 7 0 1034 , , , ' ' = 7!45! . 7!38! . 7!31! . 7!24! . 7!17! = 7!7!7!7!7!17! ::::::: · x . Applying Theorem 4 will yield the same answer; in this approach we think of the five players and the undealt cards as the six distinguishable boxes. Section 6.5 Generalized Permutations and Combinations 225 43. We assume that we are to care about which player gets which cards. For example, a deal in which Laurel gets a royal flush in spades and Blaine gets a royal flush in hearts will be counted as different from a deal in which Laurel gets a royal flush in hearts and Blaine gets a royal flush in spades (and the other four players get the same cards each time). The order in which a player receives his or her cards is not relevant, however, so we are dealing with combinations. We can look at one player at a time. There are C(48, 5) ways to choose the cards for the first player, then C( 43, 5) ways to choose the cards for the second player (because five of the cards are gone), and so on. So the answer, by the multiplication principle, is C(48,5) · C(43,5) · C(38,5) · C(33, 5) · C(28, 5) · C(23, 5) = 649,352,163,073,816,339,512,038,979,194,880 ~ 6.5 x 1032 . 45. a) All that matters is how many copies of the book get placed on each shelf. Letting x, be the number of copies of the book placed on shelf i, we are asking for the number of solutions to the equation xi + x 2 + · · · + x k = n, with each x, a nonnegative integer. By Theorem 2 this is C(k + n - 1, n). b) No generality is lost if we number the books bi, b2 , ... , bn and think of placing book bi, then placing b2 , and so on. There are clearly k ways to place bi , since we can put it as the first book (for now) on any of the shelves. After bi is placed, there are k + 1 ways to place b2 , since it can go to the right of bi or it can be the first book on any of the shelves. We continue in this way: there are k + 2 ways to place b3 (to the right of bi , to the right of b2 , or as the first book on some shelf), k + 3 ways to place b4 , ... , k + n - 1 ways to place bn. Therefore the answer is the product of these numbers, which can more easily be expressed as (k + n - 1)!/(k - 1)!. Another, perhaps easier, way to obtain this answer is to think of first choosing the locations for the books, which is what we counted in part (a), and then choose a permutation of the n books to put into those locations (shelf by shelf, from the top down, and from left to right on each shelf). Thus the answer is C(k + n - 1, n) · n!, which evaluates to the same thing we obtained with our other analysis. 47. The first box holds ni objects, and there are C(n, ni) ways to choose those objects from among the n objects in the collection. Once these objects are chosen, we can choose the objects to be placed in the second box in C(n - ni, n2) ways, since there are n - ni objects not yet placed, and we need to put n 2 of them into the second box. Similarly, there are then C(n - ni - n2, n 3) ways to choose objects for the third box. We continue in this way, until finally there are C(n - ni - n 2 - · · · - nk-i, nk) ways to choose the objects to put in the last ( kth) box. Note that this last expression equals C( nk, nk) = 1, since ni + n 2 + · · · + nk = n. Now by the product rule the number of ways to make the entire assignment is We use the formula for combinations to write this as n! (n - ni)! (n - ni - n2)! ni!(n - ni)! . n2!(n - ni - n2)! . n3!(n - ni - n2 - n3)! which simplifies after the telescoping cancellation to n! ni!n2! · · · nk! (we use the fact that n - ni - n2 - · · · - nk-1 = nk, since ni + n2 + · · · + nk = n ), as desired. 49. a) The sequence was nondecreasing to begin with. By adding k - 1 to the kth term, we are adding more to each term than was added to the previous term. Hence even if two successive terms in the sequence were originally equal, the second term must strictly exceed the first after this addition is completed. Therefore the sequence is made up of distinct numbers. The smallest can be no smaller than 1+(1-1) = 1, and the largest can be no larger than n + (r - 1) = n + r - 1 ; therefore the terms all come from T . b) If we are given an increasing sequence of r terms from T, then by subtracting k - 1 from the kth term we have a nondecreasing sequence of r terms from S, repetitions allowed. (The kth term in the original sequence 226 Chapter 6 Counting must be between k and n + r - 1 - (r - k) = n + (k - 1), so subtracting k - 1 leaves a number between 1 and n, inclusive. Furthermore, only 1 more is subtracted from a term than is subtracted from the previous term; thus no term can become strictly smaller than its predecessor, since it exceeded it by at least 1 to start with.) This operation exactly inverts the operation described in part (a), so the correspondence is one-to-one. c) The first two parts show that there are exactly as many r-combinations with repetition allowed from S as there are r-combinations (without repetition) from T. Since T has n is clearly C(n + r - 1, r). +r - 1 elements, this latter quantity 51. We use the formula for the Stirling numbers of the second kind stated near the end of this section, which gives the number of ways to distribute n distinguishable objects into j indistinguishable boxes with no box empty: S(n,j) In this case, n = 6 and j ~! ( 8(6, 4) = 1 J-1 ( .) = --:r 2::)-1)' J. J (j - i)n i 1=0 = 4, so we have G) G) G) 6 4 - 6 3 + 6 2 _ (:) 6 1 ) = ~! (4096 _ 2916 + 384 _ 4) = 65. If we want to work this out from scratch, we can argue as follows. There are two patterns possible. We can put three of the objects into one box and each of the remaining objects into a separate box; there are C(6, 3) = 20 ways to choose the objects for the crowded box. Alternatively, we can choose a pair of objects for one box ( C(6, 2) = 15 ways) and a pair of remaining objects for the second box ( C(4, 2) = 6 ways) and put the other two objects into separate boxes, but divide by 2 because of the overcounting caused by the indistinguishability of the first two boxes, for a total of 45 ways. Therefore the answer is 20 + 45 = 65. 53. We assume that people are distinguishable, so this problem is identical to Exercise 51. There are 65 ways to place the employees. 55. Since each box has to contain at least one object, we might as well put one object into each box to begin with. This leaves us with just two more objects, and there are only two choices: we can put them both into the same box (so that the partition we end up with is 6 = 3 + 1+1+1 ), or we can put them into different boxes (so that the partition we end up with is 6 = 2 + 2 + 1 + 1). So the answer is 2. 57. Since each box has to contain at least two DVDs, we might as well put two DVDs into each box to begin with. This leaves us with just three more DVDs, and there are only three choices: we can put them all into the same box (so that the partition we end up with is 9 = 5 + 2 + 2), or we can put two into one box and one into another (so that the partition we end up with is 9 = 4 + 3 + 2), or we can put them all into different boxes (so that the partition we end up with is 9 = 3 + 3 + 3). So the answer is 3. 59. To begin, notice that because each box must have at least one ball, there are only two basic arrangements: to put three balls into one box and one ball into each of the other two boxes (denoted 3-1-1), or to put one ball into one box and two balls into each of the other two boxes (denoted 1-2-2). a) For the 3-1-1 arrangement, there are 3 ways to choose the crowded box, C(5, 3) = 10 ways to choose the balls to be put there, and 2 ways to decide where the other balls go, for a total of 3 · 10 · 2 = 60 possibilities. For the 1-2-2 arrangement, there are 3 ways to choose the box that will have just one ball, 5 ways to choose which ball goes there, and C(4, 2) = 6 ways to decide which two balls go into the lower-numbered remaining box, for a total of 3 · 5 · 6 = 90 possibilities. Thus the answer is 60 + 90 = 150. b) There are C(5, 3) = 10 ways to choose the balls for the crowded box in the 3-1-1 arrangement. For the 1-2-2 arrangement there are 5 ways to choose the lonely ball and 3 ways to choose the partner of the lowest-numbered remaining ball. Therefore the answer is 10 + 5 · 3 = 25. Section 6.6 227 Generating Permutations and Combinations c) There are 3 ways to choose the crowded box for the 3-1-1 arrangement, and there are 3 ways to choose the solo box for the 1-2-2 arrangement. Therefore the answer is 3 + 3 = 6. d) There are just the 2 possibilities we have been discussing: 3-1-1 and 1-2-2. 61. Without the restriction on site X, we are simply asking for the number of ways to order the ten symbols V, V, W. W. X, X, Y, Y, Z, Z (the ordering will give us the visiting schedule). By Theorem 3 this can be done in 10!/(2!) 5 = 113,400 ways. If the inspector visits site X on consecutive day::;, then in effect we are ordering nine symbols (including only one X), where now the X means to visit site X twice in a row. There are 9!/(2!) 4 = 22,680 ways to do this. Therefore the answer is 113,400 - 22,680 = 90,720. + .r 2 + · · · + Xm )" 1 2 is expanded, each term will clearly be of the form Cx~ x~ • • • x;;;" , for some constants C that depend on the exponents, where the exponents sum to n. Thus the form of the given formula is correct, and the only question is whether the constants are correct. We need to count the number 63. When (x 1 of ways in which a product of one term from each of the n factors can be J'~' 1 x~ 2 • • • x~" . In order for this to happen, we must choose n 1 x 1 's, n2 x2 's, ... , nm x m's. By Theorem 3 this can be done in C(n; n1. n2, ... , nm) = n! 1 1 ···nm.1 n1.n2. ways. 65. By the multinomial theorem. given in Exercise 63, the coefficient is 10! 10 . 9 . 8 . 7 . 6 C(lO; 3, 2, 5) = - - - = = 2520. 1 1 1 3.2.5. 12 SECTION 6.6 Generating Permutations and Combinations This section is quite different from the rest of this chapter. It is really about algorithms and programming. These algorithms are not easy. and it would be worthwhile to ''play computer" v.·ith them to get a feeling for how they work. In constructing such algorithms yourself. try assuming that .vou will list the permutations or combinations in a nice order (such as lexicographic order); then figure out how to find the "next" one in this order. 1. Lexicographic order is the same as numerical order in this case, so the ordering from smallest to largest is 14532, 15432. 21345. 23451, 23514, 31452, 31542, 43521, 45213, 45321. 3. Our list will have 3 · 3 · 3 · 2 = 54 items in it. Here it is in lexicographic order: AACl, AAC2, ABAl, ABA2. ABBl. ABB2, ABCl, ABC2, ACAl, ACA2, BAAl, BAA2. BABl, BAB2, BACl, BAC2, BBAl, BBA2, BBBl, BBB2, BCBl, BCB2, BCCl, BCC2, AAAl. CAA2, CABl, CAB2, CACI, CAC2. CBCl. CBC2. CCAl, CCA2, CCBl, CCB2, CCCl. CCC2. AAAl, AAA2, ACBl. ACB2, BBCl, BBC2, CBAl, CBA2, AABl, ACCl, BCAl. CBBl. AAB2, ACC2. BCA2, CBB2, Chapter 6 228 Counting 5. We use Algorithm 1 to find the next permutation. Our notation follows that algorithm, with j being the largest subscript such that a1 < a1+1 and k being the subscript of the smallest number to the right of a1 that is larger than a1 . a) Since 4 > 3 > 2, we know that the 1 is our a1 . The smallest integer to the right of 1 and greater than 1 is 2, so k = 4. We interchange a1 and ak, giving the permutation 2431, and then we reverse the entire substring to the right of the position now occupied by the 2, giving the answer 2134. b) The first integer from the right that is less than its right neighbor is the 2 in position 4. Therefore j = 4 here, and of course k has to be 5. The next permutation is the one that we get by interchanging the fourth and fifth numbers, 54132. (Note that the last phase of the algorithm, reversing the end of the string, was vacuous this time-there was only one element to the right of position 4, so no reversing was necessary.) c) Since 5 > 3 , we know that the 4 is our a1 . The smallest integer to the right of 4 and greater than 4 is ak = 5. We interchange a1 and ak, giving the permutation 12543, and then we reverse the entire substring to the right of the position now occupied by the 5, giving the answer 12534. d) Since 3 > 1. we know that the 2 is our a1 . The smallest integer to the right of 2 and greater than 2 is ak = 3. We interchange a 1 and ak, giving the permutation 45321, and then we reverse the entire substring to the right of the position now occupied by the 3, giving the answer 45312. e) The first integer from the right that is less than its right neighbor is the 3 in position 6. Therefore j = 6 here, and of course k has to be 7. The next permutation is the one that we get by interchanging the sixth and seventh numbers, 6714253. As in part (b), no reversing was necessary. f) Since 8 > 7 > 6 > 4, we know that the 2 is our a1 , so j = 4. The smallest integer to the right of 2 and greater than 2 is as = 4. We interchange a4 and as, giving the permutation 31548762, and then we reverse the entire substring to the right of the position now occupied by the 4, giving the answer 31542678. 7. We begin with the permutation 1234. Then we apply Algorithm 1 23 times in succession, giving us the other 23 permutations in lexicographic order: 1243, 1324, 1342, 1423, 1432, 2134, 2143, 2314, 2341, 2413, 2431, 3124, 3142, 3214, 3241, 3412, 3421, 4123, 4132, 4213, 4231, 4312, and 4321. The last permutation is the one entirely in decreasing order. Each application of Algorithm 1 follows the pattern in Exercise 5. 9. We begin with the first 3-combination, namely {1, 2, 3}. Let us trace through Algorithm 3 to find the next. Note that n = 5 and r = 3; also a 1 = 1, a 2 = 2, and a3 = 3. We set i equal to 3 and then decrease i until + i. This inequality is already satisfied for i = 3, since a 3 -:/=- 5. At this point we increment ai by 1 (so that now a 3 = 4), and fill the remaining spaces with consecutive integers following ai (in this case there are no more remaining spaces). Thus our second 3-combination is {1, 2, 4}. The next call to Algorithm 3 works the same way. producing the third 3-combination, namely {1, 2, 5}. To get the fourth 3-combination, we again call Algorithm 3. This time the i that we end up with is 2, since 5 = a3 = 5 - 3 + 3. Therefore the second element in the list is incremented, namely goes from a 2 to a 3, and the third element is the next larger element after 3, namely 4. Thus this 3-combination is { 1, 3, 4}. Another call to the algorithm gives us {1, 3, 5}, and another call gives us {1, 4, 5}. Now when we call the algorithm, we find i = 1 at the end of the while loop, since in this case the last two elements are the two largest elements in the set. Thus a 1 is increased to 2, and the remainder of the list is filled with the next two consecutive integers, giving us {2, 3, 4}. Continuing in this manner, we get the rest of the 3-combinations: {2, 3, 5}, {2, 4, 5}, {3, 4, 5}. a 2 -:/=- 5 - 3 11. Clearly the next larger r-combination must differ from the old one in position i, since positions i + 1, i + 2, ... , r are occupied by the largest possible numbers (namely i + n - r + 1 to n ). Also a 2 + 1 is the smallest possible number that can be put in position i if we want an r-combination greater than the given one, and then similarly a 2 + 2, a 2 + 3, ... , ai + r - i + 1 are the smallest allowable numbers for positions i + 1 to r. Therefore there is no r-combination between the given one and the one that Algorithm 3 produces, which is exactly what we had to prove. Section 6.6 Generating Permutations and Combinations 229 13. One way to do this problem (and to have done Exercise 12) is to generate the r-combinations using Algorithm 3, and then to find all the permutations of each, using Algorithm 1 (except that now the elements to be permuted are not the integers from 1 to r, but are instead the r elements of the r-combination currently being used). Thus we start with the first 3-combination, {1, 2, 3}, and we list all 6 of its permutations: 123, 132, 213, 231, 312, 321. Next we find the next 3-combination, namely {1, 2, 4}, and list all of its permutations: 124, 142, 214, 241, 412, 421. We continue in this manner to generate the remaining 48 3-permutations of {l, 2, 3, 4, 5}: 125, 152, 215, 251, 512, 521; 134, 143, 314, 341, 413, 431; 135, 153, 315, 351, 513, 531; 145, 154, 415, 451, 514, 541; 234, 243, 324, 342, 423, 432; 235, 253, 325, 352, 523, 532; 245, 254, 425, 452, 524, 542; 345, 354, 435, 453, 534, 543. There are of course P( 5, 3) = 5 · 4 · 3 = 60 items in our list. 15. One way to show that a function is a bijection is to find its inverse, since only bijections can have inverses. Note that the sizes of the two sets in question are the same, since there are n! nonnegative integers less than n!, and there are n! permutations of {1, 2, ... , n}. In this case, since Cantor expansions are unique, we need to take the digits a 1 , a 2 , ... , an-l of the Cantor expansion of a nonnegative integer m less than n! (so that m = a 1 1! + a 2 2! + · · · + an-i(n - 1)!), and produce a permutation with these ak's satisfying the definition given before Exercise 12--indeed the only such permutation. We will fill the positions in the permutation one at a time. First we put n into position n - an-1; clearly an-l will be the number of integers less than n that follow n in the permutation, since exactly an-1 positions remain empty to the right of where we put the n. Next we renumber the free positions (the ones other than the one into which we put n ), from left to right, as 1, 2, ... , n - 1. Under this numbering, we put n - 1 into position (n -1) - an_ 2 . Again it is clear that an_ 2 will be the number of integers less than n -1 that follow n - 1 in the permutation. We continue in this manner, renumbering the free positions, from left to right, as 1, 2, ... , n - k + 1, and then placing n - k + 1 in position (n - k + 1) - an-k, for k = 1, 2, ... , n - 1. Finally we place 1 in the only remaining position. 17. The algorithm is really given in our solution to Exercise 15. To produce all the permutations, we find the permutation corresponding to i, where 0 :::; i < n!, under the correspondence given in Exercise 15. To do this, we need to find the digits in the Cantor expansion of i, starting with the digit an-l. In what follows, that digit will be called c. We use k to keep track of which digit we are working on; as k goes from 1 to n - 1, we will be computing the digit an-k in the Cantor expansion and inserting n - k + 1 into the proper location in the permutation. (At the end, we need to insert 1 into the only remaining position.) We will call the positions in the permutation p 1 , p 2 , ... , Pn. We write only the procedure that computes the permutation corresponding to i; obviously to get all the permutations we simply call this procedure for each i from 0 to n! -1. 230 Chapter 6 Counting procedure Cantor permutation(n, i: integers with n 2 1 and 0 :S: z < n!) .r := n {to help in computing Cantor digits} for j := 1 to n {initialize permutation to be all O's} P1 := 0 for k := 1 to n - 1 {figure out where to place n - k + 1 } r := lx/(n - k)!J {the Cantor digit} :r := .r - c(n - k)! {what's left of :r} h := n {now find the (c+ l)th free position from the right} while Ph =J 0 h := h - 1 for j := 1 to c h := h - 1 while Ph =J 0 h := h- l Ph := n - k + 1 {here is the key step} h := 1 {now find the last free position} while Ph# 0 h := h + 1 Ph:= 1 { P1. P2 . ... , Pn is the permutation corresponding to i } GUIDE TO REVIEW QUESTIONS FOR CHAPTER 6 1. 1 + 2 + 2. 2 + 2. 2. 2 + ... + 2 10 = 2047 2. Subtract 11 from the answer to the previous review question, since that do not have at least one 0 bit. 3. a) See Example 6 in Section 6.1. b) 105 >., 1, 11, ... , 11 ... 1 are the bit strings c) See Example 7 in Section 6.1. e) 0 d) 10·9·8·7·6 4. with a tree diagram; see Example 22 in Section 6.1 (extended to larger tree) 5. Using the inclusion-exclusion principle. we get 27 + 27 6. a) See p. 399. b) 11 pigeons, 10 holes (digits) 7. a) See p. 401. b)N=91,k=10 - 24 ; see Example 18 in Section 6.1. 8. a) Permutations are ordered arrangements; combinations are unordered (or just arbitrarily ordered for convenience) selections. b) P(n,r) = C(n.r) 9. a) See pp. 418-419. · r! (see the proof of Theorem 2 in Section 6.3) c) C(25, 6) d) P(25, 6) b) by adding the two numbers above each number in the new row 10. A combinatorial proof is a proof of an algebraic identity that shows that both sides count the same thing (in some application). An algebraic proof is totally different-it shows that the two sides are equal by doing formal manipulations with the unknowns. with no reference to what the expressions might mean in an application. 11. See p. 418. 12. a) See p. 416. b) See p. 416. 13. a) See Theorem 2 in Section 6.5. d) C(5 + 12 -1.12) - C(5 + 7 - 1. 7) c) 2100 .5 101 C(201, 101) + 12 - 1, 12) c) C(5 + 9 - 1, 9) e) C(5 + 10 - 1, 10) - C(5 + 6 - 1, 6) b) C(5 231 Supplementary Exercises 14. a) See Example 5 in Section 6.5. b) C( 4 + 17 - 1, 17) c) C(4 + 13 - 1, 13) (see Exercise 15a in Section 6.5) 15. a) See Theorem 3 in Section 6.5. b) 14!/(2!2!1!3!1!1!3!1!) 16. See pp. 435-436. 17. a) C(52, 5) · C(47, 5) · C(42, 5) · C(37, 5) · C(32, 5) · C(27, 5) b) See Theorem 4 in Section 6.5. 18. See pp. 437-438. SUPPLEMENTARY EXERCISES FOR CHAPTER 6 1. In each part of this problem we have n = 10 and r = 6. a) If the items are to be chosen in order with no repetition allowed, then we need a simple permutation. Therefore the answer is P(lO, 6) = 10 · 9 · 8 · 7 · 6 · 5 = 151,200. b) If repetition is allowed, then this is just a simple application of the product rule, with 6 tasks, each of which can be done in 10 ways. Therefore the answer is 106 = 1,000,000. c) If the items are to be chosen without regard to order but with no repetition allowed, then we need a simple combination. Therefore the answer is C(lO, 6) = C(lO, 4) = 10 · 9 · 8 · 7 · /(4 · 3 · 2) = 210. d) Unordered choices with repetition allowed are counted by C(n + r -1, r), which in this case is C(15, 6) = 5005. 3. The student has 3 choices for each question: true, false, and no answer. There are 100 questions, so by the product rule there are 3 100 ~ 5.2 x 1047 ways to answer the test. 5. We will apply the inclusion-exclusion principle from Section 6.1. First let us calculate the number of these strings with exactly three a's. To specify such a string we need to choose the positions for the a's, which can be done in C(lO, 3) ways. Then we need to choose either a b or a c to fill each of the other 7 positions in the string, which can be done in 27 ways. Therefore there are C(lO, 3) · 27 = 15360 such strings. Similarly, there are C(l0,4) · 26 = 13440 strings with exactly four b's. Next we need to compute the number of strings satisfying both of these conditions. To specify a string with exactly three a's and exactly four b's, we need to choose the positions for the a's, which can be done in C(lO, 3) ways, and then choose the positions for the b's, which can be done in C(7,4) ways (only seven slots remain after the a's are placed). Therefore there are C(lO, 3) · C(7, 4) = 4200 such strings. Finally, by the inclusion-exclusion principle the number of strings having either exactly three a's or exactly four b's is 15360 + 13440 - 4200 = 24,600. 7. a) We want a combination with repetition allowed, with n = 28 and r = 3. By Theorem 2 of Section 6.5, there are C(28 + 3 - 1, 3) = C(30, 3) = 4060 possibilities. b) This is just a simple application of the product rule. There are 28 ways to choose the ice cream, 8 ways to choose the sauce, and 12 ways to choose the topping, so there are 28 · 8 · 12 = 2688 possible small sundaes. c) By the product rule we have to multiply together the number of ways to choose the ice cream, the number of ways to choose the sauce, and the number of ways to choose the topping. There are C(28 + 3 - 1, 3) ways to choose the ice cream, just as in part (a). There are C(8, 2) ways to choose the sauce, since repetition is not allowed. There are similarly C(12, 3) ways to choose the toppings. Multiplying these numbers together, we find that the answer is 4060 · 28 · 220 = 25,009,600 different large sundaes. Chapter 6 232 Counting 9. We can solve this problem by counting the number of numbers that have the given digit in 1, 2, or 3 places. a) The digit 0 appears in 1 place in some two-digit numbers and in some three-digit numbers. There are clearly 9 two-digit numbers in which 0 appears, namely 10, 20, ... , 90. We can count the number of threedigit numbers in which 0 appears exactly once as follows: first choose the place in which it is to appear ( 2 ways, since it cannot be the leading digit), then choose the left-most of the remaining digits (9 ways, since it cannot be a 0), then choose the final digit (also 9 ways). Therefore there are 9 + 2 · 9 · 9 = 171 numbers in which the 0 appears exactly once, accounting for 171 appearances of the digit 0. Finally there are another 9 numbers in which the digit 0 appears twice, namely 100, 200, ... , 900. This accounts for 18 more O's. And of course the number 1000 contributes 3 0 's. Therefore our final answer is 171 + 18 + 3 = 192. b) The analysis for the digit 1 is not the same as for the digit 0, since we can have leading l's but not leading O's. One 1 appears in the one-digit numbers. Two-digit numbers can have a 1 in the ones place (and there are 9 of these, namely 11, 21, ... , 91), or in the tens place (and there are 10 of these, namely 10 through 19). Of course the number 11 is counted in both places, but that is proper, since we want to count each appearance of a l. Therefore there are 10 + 9 = 19 l's appearing in two-digit numbers. Similarly, the three-digit numbers have 90 l's appearing in the ones place (every tenth number, and there are 900 numbers), 90 l's in the tens place ( 10 per decade, and there are 9 decades), and 100 1's in the hundreds place ( 100 through 199); therefore there are 280 ones appearing in three-digit numbers. Finally there is a 1 in 1000, so the final answer is 1 + 19 + 280 + 1 = 301. c) The analysis for the digit 2 is exactly the same as for the digit 1, with the exception that we do not get any 2's in 1000. Therefore the answer is 301 - 1 = 300. d) The analysis for the digit 9 is exactly the same as for the digit 2, so the answer is again 300. Let us check all of the answers to this problem simultaneously. There are 300 each of the digits 2 through 9, for a total of 2400 digits. There are 192 O's and 301 l's. Therefore 2400+192 + 301 = 2893 digits are used altogether. Let us count this another way. There are 9 one-digit numbers, 90 two-digit numbers, 900 three-digit numbers, and 1 four-digit number, so the total number of digits is 9 · 1+90 · 2+900·3+1·4 = 2893. This agreement tends to confirm our analysis. 11. This is a negative instance of the generalized pigeonhole principle. The worst case would be if the student gets each fortune 3 times, for a total of 3 x 213 = 639 meals. If the student ate 640 or more meals, then the student will get the same fortune at least 1640/2131 = 4 times. 13. We have no guarantee ahead of time that this will work, but we will try applying the pigeonhole principle. Let us count the number of different possible sums. If the numbers in the set do not exceed 50, then the largest possible sum of a 5-element subset will be 50 + 49 + 48 + 4 7 + 46 = 240. The smallest possible sum will be 1 + 2 + 3 + 4 + 5 = 15. Therefore the sum has to be a number between 15 and 240, inclusive, and there are 240 - 15 + 1 = 226 such numbers. Now let us count the number of different subsets. That is of course C(lO. 5) = 252. Since there are more subsets (pigeons) than sums (pigeonholes), we know that there must be two subsets with the same sum. 15. We assume that the drawings of the cards is done without replacement (i.e., no repetition allowed). a) The worst case would be that we drew 1 ace and the 48 cards that are not aces, a total of 49 cards. Therefore we need to draw 50 cards to guarantee at least 2 aces (and it is clear that 50 is sufficient, since at worst 2 of the 4 aces would then be left in the deck). b) The same analysis as in part (a) applies, so again the answer is 50. c) In this problem we can use the pigeonhole principle. If we drew 13 cards, then they might all be of different kinds (ranks). If we drew 14 cards, however, then since there are only 13 kinds we would be assured of having at least two of the same kind. (The drawn cards are the pigeons and the kinds are the pigeonholes.) 233 Supplementary Exercises d) If we drew 16 cards, we might get one of each kind except, say, aces, together with four aces. So 16 is not sufficient. If we drew 17 cards, however, then there must be at least two cards of each of two different kinds. 17. This problem can be solved using the pigeonhole principle if we look at it correctly. Let Si be the sum of the first i of these numbers, where 1 ::; i ::; m. Now if Si 0 (mod m) for some i, then we have our desired consecutive terms whose sum is divisible by m. Otherwise the numbers s 1 mod m, s 2 mod m, ... , Sm mod m are all integers in the set {1, 2, ... , m -1}. By the pigeonhole principle we know that two of them are the same, say Si mod m = s1 mod m with i < j. Then s1 - Si is divisible by m. But s1 - Si is just the sum of the (i + l)th through /h terms in the sequence, and we are done. = 19. The decimal expansion of a rational number a/b (we can assume that a and b are positive integers) can be obtained by long division of the number b into the number a, where a is written with a decimal point and an arbitrarily long string of O's following it. The basic step in long division is finding the next digit of the quotient, which is just lr /b J , where r is the current remainder with the next digit of the dividend brought down. Now in our case, eventually the dividend has nothing but O's to bring down. Furthermore there are only b possible remainders, namely the numbers from 0 to b - 1. Thus at some point in our calculation after we have passed the decimal point, we will, by the pigeonhole principle, be looking at exactly the same situation as we had previously. From that point onward, then, the calculation must follow the same pattern as it did previously. In particular, the digits of the quotient will repeat. For example, to compute the decimal expansion of the rational number 349/11, we divide 11 into 349.00. . . . The first digit of the quotient is 3, and the remainder is 1. The next digit of the quotient is 1 and the remainder is 8. At this point there are only O's left to bring down. The next digit of the quotient is a 7 with a remainder of 3, and then a quotient digit of 2 with a remainder of 8. We are now in exactly the same situation as at the previous appearance of a remainder of 8, so the quotient digits 72 repeat forever. Thus 349/11=31.72. 21. a) This is a simple combination, so the answer is C(20, 12) = 125,970. b) The only choice is the choice of a variety, so the answer is 20. c) We assume that order does not matter (all the donuts will go into a bag). Therefore, since repetitions are allowed, Theorem 2 of Section 6.5 applies, and the answer is C(20 + 12 - 1, 12) = C(31, 12) = 141,120,525. d) We can simply subtract from our answer to part (c) our answer to part (b), which asks for the number of ways this restriction can be violated. Therefore the answer is 141,120,505. e) We put the 6 blueberry filled donuts into our bag, and the problem becomes one of choosing 6 donuts with no restrictions. In analogy with part ( c), we obtain the answer C(20 + 6 - 1, 6) = C(25, 6) = 177,100. f) There are C(20 +5- 1, 5) = C(24, 5) = 42504 ways to choose at least 7 blueberry donuts among our dozen (the calculation is essentially the same as that in part ( e)). Our answer is therefore 42504 less than our unrestricted answer to part (c): 141120525 - 42504 = 141,078,021. 23. a) The given equation is equivalent to n( n - 1) /2 = 45, which reduces to n 2 - n - 90 = 0. The quadratic formula (or factoring) tells us that the roots are n = 10 and n = -9. Since n is assumed to be nonnegative, the only relevant solution is n = 10. b) The given equation is equivalent to n(n - l)(n - 2)/6 = n(n - 1). Since P(n, 2) is not defined for n < 2, we know that neither n nor n - 1 is 0, so we can divide both sides by these factors, obtaining n - 2 = 6, whence n = 8. (Alternatively, one can think of P( n, k) and C( n, k) as being defined to be 0 if n < k, in which case all n less than 2 also satisfy this equation, as well as the equation in part ( c).) c) Recall the identity C( n, k) = C( n, n - k). The given equation fits that model if n = 7 and k = 5. Hence n = 7 is a solution. That there are no more solutions follows from the fact that C(n, k) is an increasing 234 Chapter 6 Counting function in k for 0 :::; k :::; n/2, and decreasing for n/2 :::; k :::; n, and hence there are no numbers k' other than k and n - k for which C(n, k') = C(n, k). 25. Following the hint, we see that each element of S falls into exactly one of three categories: either it is an element of A, or else it is not an element of A but is an element of B (in other words, is an element of B-A ), or else it is not an element of B either (in other words, is an element of S - B ). So the number of ways to choose sets A and B to satisfy these conditions is the same as the number of ways to place each element of S into one of these three categories. Therefore the answer is 3n . For example, if n = 2 and S = {x, y}, then thereare 9 pairs: (0,0), (0,{x}), (0,{y}), (0,{x,y}), ({x},{x}), ({x},{x,y}), ({y},{y}), ({y},{x,y}), ({x,y},{x,y}). 27. We start with the right-hand side and use Pascal's identity three times to obtain the left-hand side: C(n + 2,r + 1) - 2C(n + l,r + 1) + C(n,r + 1) = C(n + 1, r + 1) + C(n + 1, r) - 2C(n + 1, r + 1) + C(n, r + 1) = C(n + 1, r) - C(n + 1, r + 1) + C(n, r + 1) = [C(n, r) + C(n, r - l)] - [C(n, r + 1) + C(n, r)] + C(n, r + 1) = C(n,r-1) 29. Substitute x identity. = 1 and y = 3 into the binomial theorem (Theorem 1 in Section 6.4) and we obtain exactly this 31. We just have to notice that the summation runs over exactly all the triples (i, j, k) such that 1 :::; i < j < k :::; n. Since we are adding 1 for each such triple, the sum simply counts the number of such triples, which is just all the ways of choosing three distinct numbers from {l, 2, 3, ... , n}. Therefore the sum must equal C(n, 3). 33. The trick to the analysis here is to imagine what such a string has to look like. Every string of O's and 1's can be thought of as consisting of alternating blocks-a block of l's (possibly empty) followed by a block of O's followed by a block of l's followed by a block of O's, and so on, ending with a block of O's (again, possibly empty). If we want there to be exactly two occurrences of 01, then in fact there must be exactly six such blocks, the middle four all being nonempty (the transitions from O's to l's create the 01 's) and the outer two possibly being empty. In other words, the string must look like this: x 1 l's - x 2 O's - X3 l's - X4 O's - x 5 l's - x 6 O's, where x 1 + x2 + · · · + x 6 = n and x 1 2 0, X5 2 0, and Xi 2 1 for i = 2, 3, 4, 5. Clearly such a string is totally specified by the values of the Xi's. Therefore we are simply asking for the number of solutions to the equation x 1 + x 2 + · · ·+ x 6 = n subject to the stated constraints. This kind of problem is solved in Section 6.5 (Example 5 and several exercises). The stated problem is equivalent to finding the number of solutions to x 1 + x~ + x~ + x~ + x~ + x 6 = n - 4 where each variable here is nonnegative (we let Xi = x~ + 1 for i = 2, 3, 4, 5 in order to insure that these Xi's are strictly positive). The number of such solutions is, by the results just cited, C(6 + n - 4 - 1, n - 4), which simplifies to C(n + 1, n - 4) or C(n + 1, 5). 35. An answer key is just a permutation of 8 a 's, 3 b's, 4 e's, and 5 d's. We know from Theorem 3 in Section 6.5 that there are 20! 8!3!4!5! = 3,491,888,400 such permutations. Supplementary Exercises 235 37. We assume that each student is to get one advisor, that there are no other restrictions, and that the students and advisors are to be considered distinct. Then there are 5 ways to assign each student, so by the product rule there are 524 ~ 6.0 x 10 16 ways to assign all of them. 39. For all parts of this problem, Theorem 2 in Section 6.5 is used. a) We let x 1 = x~ + 2, x 2 = x; + 3, and x 3 = x~ + 4. Then the restrictions are equivalent to requiring that each of the x~ 's be nonnegative. Therefore we want the number of nonnegative integer solutions to the equation x~ + x~ + x3 = 8. There are C(3 + 8 - 1, 8) = C(lO, 8) = C(lO. 2) = 45 of them. b) The number of solutions with x 3 > 5 is the same as the number of solutions to x 1 + x 2 + x3 = 11, where = x3 + 6. There are C(3 + 11 - 1, 11) = C(13, 11) = C(13, 2) = 78 of these. Now we want to subtract the number of solutions for which also x 1 ;::=: 6. This is equivalent to the number of solutions to x~ + x2 + x~ = 5, where x 1 = x~ + 6. There are C(3 + 5 - 1, 5) = C(7, 5) = C(7, 2) = 21 of these. Therefore the answer to the problem is 78 - 21 = 57. X3 c) Arguing as in part (b), we know that there are 78 solutions to the equation x 1 + x 2 + x3 = 11, which is equivalent to the number of solutions to x 1 + x 2 + x 3 = 17 with x 3 > 5. We now need to subtract the number of these solutions that violate one or both of the restrictions x 1 < 4 and x 2 < 3. The number of solutions with x 1 ;::=: 4 is the number of solutions to x~ + x2 + x~ = 7, namely C(3 + 7 - 1, 7) = C(9, 7) = C(9, 2) = 36. The number of solutions with x2 2: 3 is the number of solutions to x 1 + x~ + x3 = 8, namely C(3 + 8 - 1, 7) = C(lO, 8) = C(lO, 2) = 45. However, there are also solutions in which both restrictions are violated, namely the solutions to x~ + x~ + x3 = 4. There are C(3 + 4 - 1, 4) = C(6, 4) = C(6, 2) = 15 of these. Therefore the number of solutions in which one or both conditions are violated is 36 + 45 - 15 = 66; we needed to subtract the 15 so as not to count these solutions twice. Putting this all together, we see that there are 78 - 66 = 12 solutions of the given problem. 41. a) We want to find the number of r-element subsets for r = 0, 1, 2, 3, 4 and add. Therefore the answer is C(lO, 0) + C(lO, 1) + C(lO, 2) + C(lO, 3) + C(lO, 4) = 1+10 + 45 + 120 + 210 = 386. b) This time we want C(lO, 8) + C(lO, 9) + C(lO, 10) = C(lO, 2) + C(lO, 1) + C(lO, 0) = 45+10 + 1 = 56. c) This time we want C(lO, 1) + C(lO, 3) + C(lO, 5) + C(lO, 7) + C(lO, 9) = C(lO, 1) + C(lO, 3) + C(lO, 5) + C(lO, 3) + C(lO, 1) = 10 + 120 + 252 + 120 + 10 = 512. We can also solve this problem by using the fact from Exercise 31 in Section 6.4 that a set has the same number of subsets with an even number of elements as it has subsets with an odd number of elements. Since the set has 2 10 = 1024 subsets altogether, half of these-512 of them-must have an odd number of elements. 43. Since the objects are identical, all that matters is the number of objects put into each container. If we let Xi be the number of objects put into the ith container, then we are asking for the number of solutions to the equation x 1 + x 2 + · · · + Xm = n with the restriction that each x, :;:: 1. By the usual trick this is equivalent to asking for the number of nonnegative integer solutions to x~ + x~ + · · · + x~ = n - m, where we have set Xi = x; + 1 to insure that each container gets at least one object. By Theorem 2 in Section 6.5, there are C(m + (n - m) - 1, n - m) = C(n - 1, n - m) solutions. This can also be written as C(n - 1, m - 1), since (n - 1) - (n - m) = m - 1. (Of course if n < m, then there are no solutions, since it would be impossible to put at least one object in each container. Our answer is consistent with this observation if we think of C(x, y) as being 0 if y > x . ) 45. a) This can be done with the multiplication principle. There are five choices for each ball, so the answer is 56 = 15,625. b) This is like Example 10 in Section 6.5, and we can use the formula for the Stirling numbers of the second 236 Chapter 6 Counting kind given near the end of that section: with n = 6 and k = 5. We get 16 1 6 6 1 6 6 6 1 6 6 6 6 1 6 6 6 6 6 l!l +21(1·2 -2·1 )+3!(1·3 -3·2 +3·1)+4!(1·4 -4·3 +6·2 -4·1 )+5!(1·5 -5·4 +10·3 -10·2 +5·1 ), which is 1 + 31 + 90 + 65 + 15 = 202. The command in Maple for this, using the "combinat" package, is sum(stirling2(6,j),j=1 .. 5);. c) We saw in the discussion surrounding Example 9 in Section 6.5 that the number of ways to distribute n unlabeled objects into k labeled boxes is C(n + k - 1, k - 1), because this is really the same as the problem of choosing an n-combination from the set of k boxes, with repetitions allowed. In this case we have n = 6 and k = 5, so the answer is C(l0,4) = 210. d) Since both the boxes and the objects are indistinguishable, what is really being asked is how many different ways there are to write 6 as the sum of five nonnegative integers, with order ignored. We will just enumerate the possibilities and count them. We have 6 = 6 + 0 + 0 + 0 + 0; 6 = 5 + 1 + 0 + 0 + 0; 6 = 4 + 2 + 0 + 0 + 0; 6=4+1+1+0+0;6=3+3+0+0+0;6=3+2+1+0+0;6=3+1+1+1+0;6=2+2+2+0+0; 6 = 2 + 2 + 1 + 1 + 0: and 6 = 2 + 1 + 1 + 1 + 1. There are ten ways in all. Notice that we are allowing some of the boxes to be empty. 47. a) If there are just two tables, then the only choice involved is the person to sit alone. Therefore c(3, 2) = 3. b) There are two possibilities. If two people sit at each table, then there are three ways to decide who sits with person A. If one person sits alone, there are four ways to choose that person and then two ways to arrange the other three people at the second table. So c(4, 2) = 3 + 4 · 2 = 11. c) There must be two people sitting alone and one pair sitting together. No other choices are involved, so c(4,3) = C(4, 2) = 6. d) This is similar to the previous case. There must be three people sitting alone and one pair sitting together, so c(5, 4) = C(5, 2) = 10. 49. Here is one approach. There are two possibilities for seating n people at n - 2 tables. We might have three of them at one table with everyone else sitting alone. This can be done in 2C(n, 3) ways, because after choosing the table-mates we have to seat them clockwise or counterclockwise. Or we might choose two groups of two people to sit together and have everyone else sit alone. This can be done in C(n, 2) · C(n - 2, 2)/2 ways (the division by 2 is to account for overcounting, because the order in which we pick the pairs is irrelevant). Therefore c(n, n - 2) = C(n ) C(n, 2) · C(n - 2, 2) = n(n - l)(n - 2) ~. n(n - 1) . (n - 2)(n - 3) = n 4 2 3 ' + 2 3 + 2 2 2 8 _ 5n 3 3n 2 12 + 8 _ .!!:._. 12 Expanding (3n - l)C(n, 3)/4 gives the same polynomial. 51. Following the hint, we observe that there are (2n)!/2n permutations of 2n objects of n different types, two of each type. Because this must be an integer, the denominator must divide the numerator, which is exactly what we are asked to prove. 53. Because the second list contains GAAAG (which does not end in C or U), those letters must end the string. Because it contains GGU, there must be two G's together followed by a U, and, looking at the first list of fragments, we infer that CCGGUCCG must be a substring. It follows that the original chain was CCGGUCCGAAAG. Writing Projects 237 55. For convenience let us assume that the finite set is { 1, 2, ... , n}. If we call a permutation a 1 a 2 ... ar, then we simply need to allow each of the variables a2 to take on all n of the values from 1 to n. This is essentially just counting in base n, so our algorithm will be similar to Algorithm 2 in Section 6.6. The procedure shown here generates the next permutation. To get all the permutations, we just start with 11 ... 1 and call this procedure rn - 1 times. procedure next permutation(n: positive integer, a 1 , a2, ... , ar : positive integers ::; n) {this procedure replaces the input with the next permutation, repetitions allowed, in lexicographic order; assume that there is a next permutation, i.e., a 1 a 2 ... ar #- nn ... n} i := r while a 2 = n a,:= 1 i := i - 1 a,:= a,+ 1 { a 1a2 ... ar is the next permutation in lexicographic order} 57. We must show that if there are R(m, n - 1) + R(m - 1, n) people at a party, then there must be at least m mutual friends or n mutual enemies. Consider one person; let's call him Jerry. Then there are R(m - 1, n) + R(m, n - 1) -1 other people at the party, and by the pigeonhole principle there must be at least R(m - 1, n) friends of Jerry or R(m, n -1) enemies of Jerry among these people. First let's suppose there are R(m-1, n) friends of Jerry. By the definition of R, among these people we are guaranteed to find either m - 1 mutual friends or n mutual enemies. In the former case these m - 1 mutual friends together with Jerry are a set of m mutual friends; and in the latter case we have the desired set of n mutual enemies. The other situation is similar: Suppose there are R( m, n - 1) enemies of Jerry; we are guaranteed to find among them either m mutual friends or n - 1 mutual enemies. In the former case we have the desired set of m mutual friends, and in the latter case these n - 1 mutual enemies together with Jerry are a set of n mutual enemies. WRITING PROJECTS FOR CHAPTER 6 Books and articles indicated by bracketed symbols below are listed near the end of this manual. You should also read the general comments and advice you will find there about researching and writing these essays. 1. You might start with the standard history of mathematics books, such as [Bo4] or [Ev3]. 2. To learn about telephone numbers in North America, refer to books on telecommunications, such [Fr]. The term to look for in an index is the North American Numbering Plan. 3. See [Fe]. 4. A lot of progress has been made recently by research mathematicians such as Herbert Wilf in finding general methods of proving essentially all true combinatorial identities, more or less mechanically. See whether you can find some of this work by looking in Mathematical Reviews (MathSciNet on the Web) or the book [PeWi]. There is also some discussion of this in [Wi2], a book on generating functions. Also, a classical book on combinatorial identities is [Ri2]. 5. Students who have had an advanced physics course will be at an advantage here. Maybe you have a friend who is a physics major! In any case, it should not be hard to find a fairly elementary textbook on this subject. 6. More advanced combinatorics textbooks usually deal with Stirling numbers, at least in the exercises. See [Rol], for instance. Other sources here are a chapter in [MiRo] and the amazing [GrKn]. Chapter 6 238 Counting 7. See the comments for Writing Project 6. 8. There are entire books devoted to Ramsey theory, dealing not only with the classical Ramsey numbers, but also with applications to number theory. graph theory. geometry, linear algebra, etc. For a fairly advanced such book, see [GrRo]: for a gentler introduction, see the relevant sections of [Rol] or the chapter in [MiRo]. Up-to-the-minute results can be found with a \Veb search. 9. Try hoob with titles such as "combinatorial algorithms"-that's what methods of generating permutations are. after all. See [Evl] or [ReNi], for example. Another fascinating source (which deals with combinatorial algorithms as well as many other topics relevant to this text) is [GrKn]. Volume 2 of Knuth's classic [Kn] should have some relevant material. There is also an older article you might want to check out, [Lel]. An interesting related problem is to generate a random permutation; this is needed, for example, when using a computer to simulate the shuffiing of a deck of cards for playing card games. 10. See the comments for Writing Project 9. Section 7.1 An Introduction to Discrete Probability 239 CHAPTER 7 Discrete Probability SECTION 7 .1 An Introduction to Discrete Probability Calculating probabilities is one of the most immediate applications of combinatorics. Many people play games in which discrete probability plays a role, such as card games like poker or bridge, board games, casino games, and state lotteries. Probability is also important in making decisions in such areas as business and medicinefor example, in deciding how high a deductible to have on your automobile insurance. This section only scratches the surface, of course, but it is surprising how many useful calculations can be made using just the techniques discussed in this textbook. The process is basically the same in each problem. First count the number of possible, equally likely, outcomes; this is the denominator of the probability you are seeking. Then count the number of ways that the event you are looking for can happen; this is the numerator. We have given approximate decimal (or percentage) answers to many of the problems, since the human mind can comprehend the magnitude of a number much better this way than by looking at a fraction with large numerator and denominator. 1. There are 52 equally likely cards to be selected, and 4 of them are aces. Therefore the probability is 4/52 = 1/13:::::; 7.73. 3. Among the first 100 positive integers there are exactly 50 odd ones. Therefore the probability is 50/100 = 1/2. 5. One way to do this is to look at the 36 equally likely outcomes of the roll of two dice, which we can represent by the set of ordered pairs (i, j) with 1 ::::; i, j ::::; 6. A better way is to argue as follows. Whatever the number of spots showing on the first die, the sum will be even if and only if the number of spots showing on the second die has the same parity (even or odd) as the first. Since there are 3 even faces (2, 4, and 6) and 3 odd faces (1, 3, and 5), the probability is 3/6=1/2. 7. There are 26 = 64 possible outcomes, represented by all the sequences oflength 6 of H's and T's. Only one of those sequences, HHHHHH, represents the event under consideration, so the probability is 1/64:::::; 0.016. 9. We saw in Example 11 of Section 6.3 that there are C(52, 5) possible poker hands, and we assume by symmetry that they are all equally likely. In order to solve this problem, we need to compute the number of poker hands that do not contain the queen of hearts. Such a hand is simply an unordered selection from a deck with 51 cards in it (all cards except the queen of hearts), so there are C(51, 5) such hands. Therefore the answer to the question is the ratio C(51, 5) = 47:::::; go. 4o/c. C(52, 5) 52 ° 11. This question completely specifies the poker hand, so there is only one hand satisfying the conditions. Since there are C(52, 5) equally likely poker hands (see Example 11 of Section 6.3), the probability of drawing this one is 1/C(52, 5), which is about 1 out of 2.5 million. Chapter 7 240 Discrete Probability 13. Let us compute the probability that the hand contains no aces and then subtract from 1 (invoking Theorem 1). A hand with no aces must be drawn from the 48 nonace cards, so there are C (48, 5) such hands. Therefore the probability of drawing such a hand is C( 48, 5) /C(52, 5), which works out to about 66%. Thus the probability of holding a hand with at least one ace is 1 - (C( 48, 5)/C(52, 5)), or about 34%. 15. We need to compute the number of ways to hold two pairs. To specify the hand we first choose the kinds (ranks) the pairs will be (such as kings and fives); there are C(13, 2) = 78 ways to do this, since we need to choose 2 kinds from the 13 possible kinds. Then we need to decide which 2 cards of each of the kinds of the pairs we want to include. There are 4 cards of each kind ( 4 suits), so there are C(4, 2) = 6 ways to make each of these two choices. Finally, we need to decide which card to choose for the fifth card in the hand. We cannot choose any card in either of the 2 kinds that are already represented (we do not want to construct a full house by accident), so there are 52 - 8 = 44 cards to choose from and hence C(44, 1) = 44 ways to make the choice. Putting this all together by the product rule, there are 78 · 6 · 6 · 44 = 123,552 different hands classified as "two pairs.'' Since each hand is equally likely, and since there are C(52, 5) = 2,598,960 different hands (see Example 11 in Section 6.3), the probability of holding two pairs is 123552/2598960 = 198/4165 ~ 0.0475. 17. First we need to compute the number of ways to hold a straight. We can specify the hand by first choosing the starting (lowest) kind for the straight. Since the straight can start with any card from the set {A, 2, 3, 4, 5, 6, 7, 8, 9, 10}, there are C(lO, 1) = 10 ways to do this. Then we need to decide which card of each of the kinds in the straight we want to include. There are 4 cards of each kind (4 suits), so there are C(4,1) = 4 ways to make each of these 5 choices. Putting this all together by the product rule, there are 10 · 45 = 10,240 different hands containing a straight. (For poker buffs, it should be pointed out that a hand is classified as a ''straight" in poker if it contains a straight but does not contain a straight flush, which is a straight in which all of the cards are in the same suit. Since there are 10 · 4 = 40 straight flushes, we would need to subtract 40 from our answer above in order to find the number of hands classified as a "straight." Also, some poker books do not count A, 2, 3, 4, 5 as a straight.) Since each hand is equally likely, and since there are C(52, 5) = 2,598,960 different hands (see Example 11 in Section 6.3). the probability of holding a hand containing a straight is 10240/2598960 = 128/32487 ~ 0.00394. 19. First we can calculate the number of hands that contain cards of five different kinds (this is Exercise 14). All that is required to specify such a hand is to choose the five kinds (which can be done in C(13, 5) ways, since there are 13 kinds in all), and then for each of those cards to specify a suit (which can be done in 45 ways, since there are four possible suits for each card). Thus there are C(13, 5) · 45 = 1317888 hands of this type. Now we need to figure out how many of them violate the conditions-in other words, how many of them contain a flush or a straight. To obtain a flush (this is Exercise 16) we need to choose a suit and then choose 5 cards from the 13 in this suit, so there are 4 · C(l3, 5) = 5148 different flushes. We solved the problem of straights in Exercise 17; there are 10240 straights. Furthermore, there are 40 hands that are both straights and flushes (such a hand can have its lowest card be any of the ten kinds A, 2, ... , 10, and be in any of the four suits). Now we are ready to put this all together. The number of hands that are flushes or straights is, by the principle of inclusion-exclusion, 5148 + 10240 - 40 = 15348. Subtracting this from the number of hands containing five different kinds, we see that there are 1317888 - 15348 = 1302540 hands of the desired type. Therefore the probability of drawing such a hand is 1302540/C(52, 5) = 1302540/2598960 = 1277 /2548, which works out to just a hair over 50%. 21. Looked at properly, this is the same as Exercise 7. There are 2 equally likely outcomes for the parity on the roll of a die-even and odd. Of the 26 = 64 parity outcomes in the roll of a die 6 times, only one consists of Section 7.1 An Introduction to Discrete Probability 241 6 odd numbers. Therefore the probability is 1/64. 23. We need to count the number of positive integers not exceeding 100 that are divisible by 5 or 7. Using an analysis similar to Exercise 23e in Section 6.1, we see that there are l 100/5J = 20 numbers in that range divisible by 5 and l 100/7J = 14 divisible by 7. However, we have counted the numbers 35 and 70 twice, since they are divisible by both 5 and 7 (i.e., divisible by 35 ). Therefore there are 20 + 14 - 2 = 32 such numbers. (We needed to subtract 2 to compensate for the double counting.) Now since there are 100 equally likely numbers in the set, the probability of choosing one of these 32 numbers is 32/100 = 8/25 = 0.32. 25. In each case, if the numbers are chosen from the integers from 1 to n, then there are C (n, 6) possible entries, only one of which is the winning one, so the answer is l/C(n, 6). a) 1/C(50, 6) = 1/15890700 ~ 6.3 x 10- 8 b) 1/C(52, 6) = 1/20358520 ~ 4.9 x 10- 8 8 c) 1/C(56, 6) = 1/32468436 ~ 3.1x10d) 1/C(60, 6) = 1/50063860 ~ 2.0 x 10- 8 27. In each case, there are C(n, 6) possible choices of winning numbers. If we want to choose exactly one of them correctly, then we have 6 ways to specify which number it is to be, and then C(n - 6, 5) ways to pick five losing numbers from the n - 6 losing numbers. Thus the probability is 6C(n - 6, 5)/C(n, 6) in each case. We will calculate these numbers for the various values of n. Note that the probability decreases as n increases (it gets harder to choose one of the winning numbers as the pool of numbers grows). a) b) c) d) = 6 · C(34, 5)/C(40, 6) = 6 · 278256/3838380 = 139128/319865 ~ 0.435 6C(48 - 6, 5)/C(48, 6) = 6 · C(42, 5)/C(48, 6) = 6 · 850668/12271512 = 212667 /511313 ~ 0.416 6C(56 - 6, 5)/C(56, 6) = 6 · C(50, 5)/C(56, 6) = 6 · 2118760/32468436 = 151340/386529 ~ 0.392 6C(64 - 6, 5)/C(64, 6) = 6 · C(58, 5)/C(64, 6) = 6 · 4582116/74974368 = 163647/446276 ~ 0.367 6C(40 - 6, 5)/C(40, 6) 29. There is only one winning choice of numbers, namely the same 8 numbers the computer chooses. Therefore the probability of winning is 1/C(lOO, 8) ~ 1/(1.86 x 10 11 ). 31. Since the drawing is done at random, and there are three winners and 97 losers, Michelle's chance of winning is 3/100. To see this more formally, we reason as follows, thinking of the winners as drawn in order (first, second, third). There are 100·99·98 equally likely outcomes of the drawing. The number of possible outcomes in which Michelle wins first prize is 1 · 99 · 98. The number of possible outcomes in which Michelle wins second prize is 99·1·98 (99 people other than Michelle could have won first prize). The number of possible outcomes in which Michelle wins third prize is 99 · 98 · 1. Adding, we see that there are 3 · 99 · 98 ways for Michelle to win a prize. Therefore the probability we seek is (3 · 99 · 98)/(100 · 99 · 98) = 3/100. 33. a) There are 200 · 199 · 198 equally likely outcomes of the drawings. In only one of these Sylvia win the first, second, and third prizes, respectively. Therefore the probability is 1/7880400. b) There are 200 · 200 · 200 equally likely outcomes of the drawings. In only one of these Sylvia win the first, second, and third prizes, respectively. Therefore the probability is 1/8000000. do Abby, Barry, and 1/(200 · 199 · 198) = do Abby, Barry, and 1/(200 · 200 · 200) = 35. a) There are 18 red numbers and 38 numbers in all, so the probability is 18/38 = 9/19 ~ 0.474. b) There are 38 2 equally likely outcomes for two spins, since each spin can result in 38 different outcomes. Of these, 18 2 are a pair of black numbers. Therefore the probability is 18 2 /38 2 = 81/361 ~ 0.224. c) There are 2 outcomes being considered here, so the probability is 2/38 = 1/19. d) There are 385 equally likely outcomes in five spins of the wheel. Since 36 outcomes on each spin are not 0 or 00, there are 36 5 outcomes being considered. Therefore the probability is 36 5 /38 5 0.763. = 1889568/24 76099 ~ Chapter 7 242 Discrete Probability e) There are 38 2 equally likely outcomes for two spins. The number of outcomes that meet the conditions specified here is 6 · (38 - 6) = 192 (by the product rule). Therefore the probability is 192/38 2 = 48/361 >::::: 0.133. 37. Reasoning as in Example 2, we see that there are 4 ways to get a total of 9 when two dice are rolled: (6, 3), (5, 4), (4, 5), and (3, 6). There are 62 = 36 equally likely possible outcomes of the roll of two dice, so the probability of getting a total of 9 when two dice are rolled is 4/36 >::::: 0.111. For three dice, there are 63 = 216 equally likely possible outcomes, which we can represent as ordered triples (a, b, c). We need to enumerate the possibilities that give a total of 9. This is done in a more systematic way in Section 6.5, but we will do it here by brute force. The first die could turn out to be a 6, giving rise to the 2 triples (6, 2, 1) and (6, 1, 2). The first die could be a 5, giving rise to the 3 triples (5, 3, 1), (5, 2, 2), and (5, 1, 3). Continuing in this way, we see that there are 4 triples giving a total of 9 when the first die shows a 4, 5 triples when it shows a 3, 6 triples when it shows a 2, and 5 triples when it shows a 1 (namely (1, 6, 2), (1, 5, 3), (1, 4, 4), (1, 3, 5), and (1, 2, 6) ). Therefore there are 2 + 3 + 4 + 5 + 6 + 5 = 25 possible outcomes giving a total of 9. This tells us that the probability of rolling a 9 when three dice are thrown is 25/216 >::::: 0.116, slightly larger than the corresponding value for two dice. Thus rolling a total of 9 is more likely when using three dice than when using only two. 39. It's hard to know how to respond to this argument, other than to say that the claim-that the probabilities that the prize is behind each of the doors are equal-is nonsense. For example, if one flips a thumbtack, then it would be silly to say that the probability that it lands with the point up must equal the probability that it lands with the point down-there is no symmetry in the situation to justify such a conclusion. (It is as absurd as claiming that every time you enter a contest you have a 50% probability of winning, since there are only two outcomes-either you win or you lose.) Here, too, there is a lack of symmetry, since the door you chose was chosen by you at random, without knowing where the prize was, and the door chosen by the host was not chosen at random-he carefully avoided opening the door with the prize. (In fact, if the host's algorithm were to choose one of the other two doors at random, then whenever he opens a nonprize door, the probability that the prize is behind your door does become ! . Of course in this case, sometimes the game won't advance that far, since the door he chooses might contain the prize.) 41. a) There are 64 possible outcomes when a die is rolled four times. There are 54 outcomes in which a 6 does not appear, so the probability of not rolling a 6 is 54 /6 4 . Therefore the probability that at least one 6 does appear is 1- 5 4 /6 4 = 671/1296, which is about 0.518. possible outcomes when a pair of dice is rolled 24 times. There are 35 24 outcomes in which a double 6 does not appear, so the probability of not rolling a double 6 is 3524 /36 24 . Therefore the probability that at least one double 6 does appear is 1- 35 24 /36 24 , which is about 0.491. No, the probability is not greater than 1/2. b) There are 36 24 c) From our answers above we see that the former is more likely, since 0.518 > 0.491. SECTION 7.2 Probability Theory This section introduced several basic concepts from probability. You should be able to apply the definitions to do the kinds of computations shown in the examples. Students interested in further work in probability, especially as it applies to statistics, should consult an elementary probability and statistics textbook. It is advisable (almost imperative) for all mathematics, engineering, and computer science majors to take a good statistics course. Section 7.2 Probability Theory 243 = 3p(T). We also know that p(H) + p(T) = 1. since heads and tails are the only two outcomes. Solving these simultaneous equations, we find that p(T) = 1/4 and p(H) = 3/4. An interesting example of an experiment in which intuition would tell you that outcomes should be equally likely but in fact they are not is to spin a penny on its edge on a smooth table and let it fall. Repeat this experiment 50 times or so, and you will be amazed at the outcomes. Make sure to count only those trials in which the coin spins freely for a second or more, not bumping into any objects or falling off the table. 1. We are told that p(H) 3. Let us denote by t the probability that a 2 or 4 appears. Then the given information tells us that t = 3(1-t), since 1- t is the probability that some other number appear. Solving this equation gives t = 3/ 4. We assume from the statement of the problem that 2 and 4 are equally likely. Since together they have probability 3/4, each of them must have probability 3/8. Similarly, each of the other numbers (1, 3, 5, or 6) must have probability (1- t)/4. which works out to 1/16. 5. There are six ways to roll a sum of 7. We can denote them as (L6), (2,5), (3,4), (4.3), (5,2), and (6, 1), where ( i, j) means rolling i on the first die and j on the second. We need to compute the probability of each of these outcomes and then add them to find the probability of rolling a 7. The two dice are independent, so we can argue as follows, using the given information about the probability of each outcome on each die: p((l,6)) = ~·~ = 4~; p((2,5)) = ~·~ = }9; p((3,4)) = ~·~ = 4~; p((4,3)) = ~·~ = :9; p((5,2)) = ~·~ = p( (6, 1)) = ~ · ~ = 419 • Adding, we find that the probability of rolling a 7 as the sum is 9/ 49. 1 4 9; 7. We exploit symmetry in answering many of these. a) Since 1 has either to precede 4 or to follow it, and there is no reason that one of these should be any more likely than the other, we immediately see that the answer is 1/2. We could also use brute force here, list all 24 permutations, and count that 12 of them have 1 preceding 4. b) By the same reasoning as in part (a), the answer is again 1/2. c) We could list all 24 permutations, and count that 8 of them have 4 preceding both 1 and 2. But here is a better argument. Among the numbers 1, 2, and 4, each is just as likely as the others to occur first. Thus by symmetry the answer is 1/3. d) We could list all 24 permutations, and count that 6 of them have 4 preceding 1, 2, and 3 (i.e., 4 occurring first); or we could argue that there are 3! = 6 ways to write down the rest of a permutation beginning with 4. But here is a better argument. Each of the four numbers is just as likely as the others to occur first. Thus by symmetry the answer is 1/4. e) We could list all 24 permutations, and count that 6 of them have 4 preceding 3. and 2 preceding 1. But here is a better argument. Between 4 and 3, each is just as likely to precede the other, so the probability that 4 precedes 3 is 1/2. Similarly, the probability that 2 precedes 1 is 1/2. The relative position of 4 and 3 is independent of the relative position of 2 and 1, so the probability that both happen is the product (1/2)(1/2) = 1/4. 9. Note that there are 26! permutations of the letters, so the denominator in all of our answers is 26!. To find the numerator, we have to count the number of ways that the given event can happen. Alternatively, in some cases we may be able to exploit symmetry. a) There is only one way for this to happen, so the answer is 1/26!. b) There are 25! ways to choose the rest of the permutation after the first letter has been specified to be z. Therefore the answer is 25!/26! = 1/26. Alternatively, each of the 26 letters is equally likely to be first, so the probability that z is first is 1/26. c) Since z has either to precede a or to follow it, and there is no reason that one of these should be any more likely than the other. we immediately see that the answer is 1/2. 244 Chapter 7 Discrete Probability d) In effect we are forming a permutation of 25 items-the letters b through y and the double letter combination az. There are 25! ways to do this, so the answer is 25!/26! = 1/26. Here is another way to reason. For a to immediately precede z in the permutation, we must first make sure that z does not occur in the first spot (since nothing precedes it), and the probability of that is clearly 25/26. Then the probability that a is the letter immediately preceding z given that z is not first is 1/25, since each of the 25 other letters is equally likely to be in the position in front of z. Therefore the desired probability is (25/26)(1/25) = 1/26. Note that this "product rule" is essentially just the definition of conditional probability. e) We solve this by the first technique used in part ( d). In effect we are forming a permutation of 24 items, one of which is the triple letter combination amz. There are 24! ways to do this, so the answer is 24!/26! = 1/650. f) If m, n, and o are specified to be in their original positions, then there are only 23 letters to permute, and there are 23! ways to do this. Therefore the probability is 23!/26! = 1/15600. :=; 1. If we apply Theorem 2 from Section 7.1, we can rewrite this as p(E) + p(F) - p(E n F) :=; 1, or 0.7 + 0.5 - p(E n F) :=; 1. Solving for p(E n F) gives p(E n F) ?_ 0.2. 11. Clearly p(E U F) ?_ p(E) = 0.7. Also, p(E U F) 13. The items in this inequality suggest that it may have something to do with the formula for the probability of the union of two events given in this section: p(E u F) = p(E) + p(F) - p(E n F) We know that p(E U F) :=; 1, since no event can have probability exceeding 1. Thus we have 1 2 p(E) + p(F) - p(E n F). A little algebraic manipulation easily transforms this to the desired inequality. 15. Let us start with the simplest nontrivial case, namely n = 2. We want to show that We know from the formula for the probability of the union of two events given in this section that Since p( E 1 n E 2 ) ;:: 0, the desired inequality follows immediately. We can use this as the basis step of a proof by mathematical induction. (Technically, we should point out that for n = 1 there is nothing to prove, since p(E1) :=; p(E1).) For the inductive step, assume the stated inequality for n. Then p(E1 u E2 u ... u En u En+l) :=; p(E1 u E2 u ... u En)+ p(En+l) :=; p(E1) + p(E2) + ... + p(En) + p(En+d' as desired. The first inequality follows from the case n hypothesis. = 2, and the second follows from the inductive 17. There are various ways to prove this algebraically. Here is one. Since EU E is the entire sample space S, we can break the event F up into two disjoint events, F =Sn F = (EU E) n F = (En F) U (En F), using the distributive law. Therefore p(F) = p((E n F) U (En F)) = p(E n F) + p(E n F), since these two events are disjoint. Subtracting p(E n F) from both sides, using the fact that p(E n F) = p(E) · p(F) (our hypothesis that E and F are independent), and factoring, we have p(F)(l - p(E)) = p(E n F). Since 1 - p(E) = p(E), this says that p(E n F) = p(E) · p(F), as desired. 19. As instructed, we are assuming here that births are independent and the probability of a birth in each month is 1/12. Although this is clearly not exactly true (for example, the months do not all have the same lengths), it is probably close enough for our answers to be approximately accurate. Section 7.2 Probability Theory 245 a) The probability that the second person has the same birth month as the first person (whatever that was) is 1/12. b) We proceed as in Example 13. The probability that all the birth months are different is 11 10 13-n Pn = 12 . 12 ... 1 2 since each person after the first must have a different birth month from all the previous people in the group. Note that if n ~ 13, then Pn = 0 since the 12th fraction is 0 (this also follows from the pigeonhole principle). The probability that at least two are born in the same month is therefore 1 - Pn. c) We compute 1 - Pn for n = 2, 3, ... and find that the first time this exceeds 1/2 is when n = 5, so that is our answer. With five people, the probability that at least two will share a birth month is about 62%. 21. If n people are chosen at random, then the probability that all of them were born on a day other than April 1 is (365/366r. To compute the probability that exactly one of them is born on April 1, we note that this can happen in n different ways (it can be any of the n people), and the probability that it happens for each particular person is (1/366)(365/366)n-l, since the other n - 1 people must be born on some other day. Putting this all together, the probability that two of them were born on April 1 is 1 - (365/366)n n(l/366)(365/366)n-l. Using a calculator or computer algebra system, we find that this first exceeds 1/2 when n = 614. Interestingly, if the problem asked about exactly two April 1 birthdays, then the probability is C(n, 2)(1/366) 2 (365/366r- 2 , which never exceeds 1/2. 23. There are 16 equally likely outcomes of flipping a fair coin five times in which the first flip comes up heads (each of the other flips can be either heads or tails). Of these only four will result in four heads appearing, namely H H H HT, H H HT H, H HT H H, and HT H H H. Therefore by the definition of conditional probability the answer is 4/16, or 1/4. 25. There are 16 equally likely bit strings of length 4, but only 8 of them start with a 1. Three of these contain at least two consecutive O's, namely 1000, 1001, and 1100. Therefore by the definition of conditional probability the answer is 3/8. 27. In each case we need to compute p(E), p(F), and p(EnF). Then we need to compare p(E) ·p(F)to p(EnF); if they are equal, then by definition the events are independent, and otherwise they are not. We assume that boys and girls are equally likely, and that successive births are independent. (Medical science suggests that neither of these assumptions is exactly correct, although both are reasonably good approximations.) a) If the family has only two children, then there are four equally likely outcomes: BB, BG, GB, and GG. There are two ways to have children of both sexes, so p(E) = 2/4. There are three ways to have at most one boy, so p( F) = 3 / 4. There are two ways to have children of both sexes and at most one boy, so p(E n F) = 2/4. Since p(E) · p(F) = 3/8-=/:- 2/4, the events are not independent. b) If the family has four children, then there are 16 equally likely outcomes, since there are 16 strings of length 4 consisting of B's and G's. All but two of these outcomes give children of both sexes, so p(E) = 14/16. Only five of them result in at most one boy, so p(F) = 5/16. There are four ways to have children of both sexes and at most one boy, so p(E n F) = 4/16. Since p(E) · p(F) = 35/128 -=/:- 4/16, the events are not independent. c) If the family has five children, then there are 32 equally likely outcomes, since there are 32 strings of length 5 consisting of B's and G's. All but two of these outcomes give children of both sexes, so p(E) = 30/32. Only six of them result in at most one boy, so p(F) = 6/32. There are five ways to have children of both sexes and at most one boy, so p(E n F) = 5/32. Since p(E) · p(F) = 45/256 -=/:- 5/32, the events are not independent. Chapter 7 246 Discrete Probability 29. We can model this problem using the binomial distribution. We have here n = 6 Bernoulli trials (the six coins being flipped), with p = 1/2 (the probability of heads, which we will arbitrarily call success). There are two ways in which there could be an odd person out. Either there could be five heads and one tail, or there could be one head and five tails. Thus we want to know the probability that the number of successes is either k = 5 or k = 1 . According to the formula developed in this section, 1 5 b(5;6, 1 ) = C(6,5) (1) 2 2 ( 1- 21) 3 32' and by a similar calculation, b(l; 6, 1/2) = 3/32. Therefore the probability that there is an odd man out is 2 · (3/32) = 3/16, or about one in five. 31. In each case we need to calculate the probability of having five girls. By the independence assumption, this is just the product of the probabilities of having a girl on each birth. a) Since the probability of a girl is 1/2, the answer is (1/2) 5 = 1/32 ~ 0.031. b) The is the same as part (a), except that the probability of a girl is 0.49. Therefore the answer is 0.49 5 ~ 0.028. c) Plugging in i = 1, 2, 3, 4, 5, we see that the probability of having boys on the successive births are 0.50, 0.49, 0.48, 0.47, and 0.46. Therefore the probability of having girls on the successive births are 0.50, 0.51, 0.52, 0.53, and 0.54. The answer is thus 0.50 · 0.51 · 0.52 · 0.53 · 0.54 ~ 0.038. 33. In each case we need to calculate the probability that the first child is a boy (call this p(E)) and the probability that the last two children are girls (call this p( F)). Then the desired answer is p( E U F) , which equals p(E) + p(F) - p(E) · p(F). This last product comes from the fact that events E and F are independent. a) Clearly p(E) = 1/2 and p(F) = (1/2) · (1/2) = 1/4. Therefore the answer is 1 1 1 1 5 2+4-2·4=8. b) Clearly p(E) = 0.51 and p(F) = 0.49·0.49 = 0.2401. Therefore the answer is 0.51+0.2401-0.51·0.2401 = 0.627649. c) Plugging in i = 1, 2, 3, 4, 5, we see that the probability of having boys on the successive births are 0.50, 0.49, 0.48, 0.47, and 0.46. Thus p(E) = 0.50 and p(F) = 0.53 · 0.54 = 0.2862. Therefore the answer is 0.50 + 0.2862 - 0.50 . 0.2862 = 0.6431. 35. We need to use the binomial distribution, which tells us that the probability of k successes is b(k; n,p) = C(n, k)pk(l - p)n-k. a) Here k = n, since we want all the trials to result in success. b(n;n,p) = 1 ·pn. (1-p)o =pn. Plugging in and computing, we have b) There is at least one failure if and only if it is not the case that there are no failures. Thus we obtain the answer by subtracting the probability in part (a) from 1, namely 1 - pn. c) There are two ways in which there can be at most one failure: no failures or one failure. We already computed that the probability of no failures is p". Plugging in k = n - 1 (one failure means n - 1 successes), we compute that the probability of exactly one failure is b( n - 1; n, p) = n · pn-l · ( 1 - p) . Therefore the answer is pn + npn- l ( 1 - p) . This formula only makes sense if n > 0, of course; if n = 0, then the answer is clearly 1. d) Since this event is just that the event in part (c) does not happen, the answer is 1- [pn + npn- 1 (1 - p)]. Again, this is for n > 0; the probability is clearly 0 if n = 0. Section 7.3 Bayes' Theorem 247 37. By Definition 2, the probability of an event is the sum of the probabilities of the outcomes in that event. Thus p(LJ: 1 E,) is the sum of p( s) for each outcome s in LJ: 1 E,. Since the E, 's are pairwise disjoint, this is the sum of the probabilities of all the outcomes in any of the E, 's, which is what 1 p( E,) is. Thus the issue is really whether one can rearrange the summands in an infinite sum of positive numbers and still get the same answer. Note that the series converges absolutely, because all terms are positive and all partial sums are at most 1. From calculus, we know that rearranging terms is legitimate in this case. An alternative proof could be based on the hint, since lim,_, 00 p(E,) is necessarily 0. I:::, 39. a) Since E is the event that for every set S with k players there is a player who has beaten all k of them, E is the event that for some set S with k players there is no player who has beaten all k of them. Thus for E to happen, some F3 must happen, so E = LJ7~7',k) F 3 . The given inequality now follows from Boole's inequality (Exercise 15). b) The probability that a particular player not in the jth set beats all k of the players in the jth set is (l/2)k = 2-k. Therefore the probability that this player does not have such a perfect record is 1 - 2-k, so the probability that all m - k of the players not in the jth set are unable to boast of a perfect record is (1 - rk)m-k. That is precisely p(F3 ). c) The first inequality follows immediately, since all the summands are the same and there are C(m, k) = (';) of them. If this probability is less than 1, then it must be possible that E fails, i.e., that E happens. So there is a tournament that meets the conditions of the problem as long as the second inequality holds. d) We ask a computer algebra system to compute C(m, 2)(1-2- 2 )m- 2 and C(m, 3)(1-2- 3 r- 3 for successive values of m to determine which values of m make the expression less than 1. We conclude that such a tournament exists for k = 2 when m ;::: 21, and for k = 3 when m ;::: 91. In fact, however, these are not the smallest values of m for which such a tournament exists. Indeed, for k = 2, we can take the tournament in which Barb beats Laurel, Laurel beats David, and David beats Barb ( m = 3), and according to The Probabilistic Method, second edition, by Noga Alon and Joel Spencer (Wiley, 2000), there is a tournament with seven players meeting the condition when k = 3. 41. The input to this algorithm is the integer n > 1 to be tested for primality and the number k of iterations desired. If the output is "composite" then we know for sure that n is composite. If the output is "probably prime" then we do not know whether or not n is prime, and of course it makes no sense to talk about the probability that n is prime (either it is or it isn't!-there is no chance involved). What we do know is that the chance that a composite number would produce the output "probably prime" is at most 1/4k. procedure probabilistic prime(n, k) composite :=false i := 0 while composite = false and i < k i := i + 1 choose b uniformly at random with 1 < b < n apply Miller's test to base b if n fails the test then composite = true if composite = true then print ("composite") else print ("probably prime") SECTION 7.3 Bayes' Theorem Bayes' theorem is extremely useful, as you have seen in applications featured in this section. Most of the exercises are similar to examples in the textbook. Make sure to write everything down precisely and follow the formulae exactly-this is one area in which the notation can be your salvation! We have rounded all numerical results to three decimal places. Chapter 7 248 Discrete Probability = p(F n E)/p(E), so we need to find those two quantities. We are given p(E) = 1/3. To compute p(F n E), we can use the fact that p(F n E) = p(F)p(E I F). We are given that p(F) = 1/2 and that p(E I F) = 2/5; therefore p(F n E) = (1/2)(2/5) = 1/5. Putting this together, we have p(F IE)= 1. We know that p(F I E) (1/5)/(1/3) = 3/5. 3. Let F be the event that Frida picks the first box. Thus we know that p(F) = p(F) = 1/2. Let B be the event that Frida picks a blue ball. Because of the contents of the boxes, we know that p(B I F) = 3/5 (three of the five balls in the first box are blue) and p(B IF)= 1/5. We are asked for p(F I B). We use Bayes' theorem: 3 (3/5)(1/2) F B p(B I F)p(F) p( I ) - p(B I F)p(F) + p(B I F)p(F) 4 (3/5)(1/2) + (1/5)(1/2) 5. Let S be the event that a randomly chosen racer uses steroids. We know that p(S) = 0.08 and therefore p(S) = 0.92. Let P be the event that a randomly chosen person tests positive for steroid use. We are told that p(P I S) = 0.96 and p(P I S) = 0.09 (this is a "false positive" test result). We are asked for p(S I P). We use Bayes' theorem: s p( p - I )- p(P I S)p(S) p(P I S)p(S) + p(P I S)p(S) (0.96)(0.08) ~ 0.481 (0.96)(0.08) + (0.09)(0.92) 7. Let 0 be the event that a randomly chosen person uses opium. We are told that p(O) = 0.01 and therefore p( 0) = 0.99. Let P be the event that a randomly chosen person tests positive for opium use. We are told that p(P I 0) = 0.02 ("false positive") and p(P I 0) = 0.05 ("false negative"). From these we can conclude that p(P I 0) = 0.98 ("true negative") and p(P I 0) = 0.95 ("true positive"). a) We are asked for p(O I P). We use Bayes' theorem: p( 0 P = I ) p(P I O)p(O) = (0.98)(0.99) ~ p(P I O)p(O) + p(P I O)p(O) (0.98)(0.99) + (0.05)(0.01) o. 999 b) We are asked for p( 0 I P). We use Bayes' theorem: 0 p( p p(P I O)p(O) I ) - p(P I O)p(O) + p(P I O)p(O) (0.95)(0.01) ~ 0. 24 3 (0.95) (0.01) + (0.02) (0.99) 9. Let H be the event that a randomly chosen person in the clinic is infected with HIV. We are told that p(H) = 0.08 and therefore p(H) = 0.92. Let P be the event that a randomly chosen person tests positive for HIV on the blood test. We are told that p(P I H) = 0.98 and p(P I H) = 0.03 ("false positive"). From these we can conclude that p(P I H) = 0.02 ("false negative") and p(P I H) = 0.97. a) We are asked for p(H I P). We use Bayes' theorem: H p p( I )- p(P I H)p(H) p(P I H)p(H) + p(P I H)p(H) (0.98)(0.08) ~0 4 7 0 (0.98) (0.08) + (0.03) (0.92) ~ . b) In part (a) we found p(H IP). Here we are asked for the probability of the complementary event (given a positive test result). Therefore we have simply p(H IP)= 1 - p(H IP)~ 1 - 0.740 = 0.260. c) We are asked for p(H IP). We use Bayes' theorem: p (H Ip = ) p(P I H)p(H) p(P I H)p(H) + p(P I H)p(H) = (0.02)(0.08) ~ 0 002 (0.02)(0.08) + (0.97)(0.92) . d) In part (c) we found p(H IP). Here we are asked for the probability of the complementary event (given a negative test result). Therefore we have simply p(H IP)= 1- p(H IP)~ 1 - 0.002 = 0.998. Section 7.3 Bayes' Theorem 249 11. Let S be the event that a randomly chosen product actually is a success. We are told that p(S) = 0.6 and therefore p(S) = 0.4. Let P be the event that a randomly chosen product is predicted to be successful. We are told that p(P IS)= 0.7 and p(P IS)= 0.4. We are asked for p(S IP). We use Bayes' theorem: s p - I )- p( p(P I S)p(S) p(P I S)p(S) + p(P I S)p(S) (0.7)(0.6) ~ 0.724 (0.7)(0.6) + (0.4)(0.4) 13. By the generalized version of Bayes' theorem, p(F1 I E) p(E I F1)p(F1) = p(E I F1)p(Fi) + p(E I F2)p(F2) + p(E I F3)p(F3) (1/8)(1/4) (1/8)(1/4) + (1/4)(1/4) + (1/6)(1/2) 3 17 15. a) Because the winning door was chosen uniformly at random, your chance of winning, p(W = i), is 1/3, no matter which door you chose. b) If you have chosen a door other than the winning door (i.e., i -1- k), then Monty opens the other nonwinning door. If you have chosen the winning door (i.e., i = k ), then Monty opens the other two doors with equal likelihood (we are told that he selects ''at random"). Thus p( M = j I W = k) = 1 if i , j , and k are distinct; p( M = j I W = k) = 0 if j = k or j = i; and p( M = j I W = k) = 1/2 if i = k and j -1- i. c) Without loss of generality, assume that i = 1, j = 2, and k = 3 (we would get the same answer for any combination of distinct values). By Bayes' theorem, p(W = 3 IM= 2) p(M p(M = 2 I w = 3)p(W = 3) = 2 I W = l)p(W = 1) + p(M = 2 I W = 2)p(W = 2) + p(M = 2 I W = 3)p(W = 3) 1 . (1/3) (1/2) . (1/3) + 0. (1/3) + 1. (1/3) 1 3/2 2 3 d) You should change doors, because you now have a 2/3 chance to win by switching. (A similar calculation to that in part ( c) shows that your chance of winning if you do not switch doors is 1/3.) 17. The proof is basically the same as the proof of Theorem 1. The definition of conditional probability tells us that p(F1 I E) = p(E n F1 )/p(E). For the numerator, again using the definition of conditional probability, we have p(E n F1) = p(E I F1 )p(F1 ), as desired. For the denominator we show that p(E) = L~=l p(E I Fi)p(F,). Just as in the proof of Theorem 1, the events En F, partition the event E; that is (En F,i) n (En F, 2 ) = 0 when i, -/- i 2 (because the Fi 's are mutually exclusive), and LJ~=l (En F,) = E (because the LJ~= 1 ·F, = S). Therefore p(E) = L~=l p(E n F,) = L~=l p(E I Fi)p(F,), and our proof is complete. 175/1000 = 0.175 and 19. We follow the procedure in Example 3. We first compute that p(opportunity) q(opportunity) = 20/400 = 0.05. Then we compute that p( opportunity) . ) r (opportumty = - - - - - - - - - - - p( opportunity) + q( opportunity) 0.175 ---0.175 + 0.05 ~ 0.778. Because r( opportunity) is less than the threshold 0.9, an incoming message containing "opportunity'' would not be rejected. 21. We follow the procedure in Example 4. We first compute that p(enhancement) = 1500/10000 = 0.15, q(enhancement) = 20/5000 = 0.004, p(herbal) = 800/10000 = 0.08, and q(herbal) = 200/5000 = 0.04. Then, Chapter 7 250 Discrete Probability assuming the necessary independence, we compute p(enhancement)p(herbal) r (en h ancement, h er b a1) = - - - - - - - - - - - - - - - - - - - - p( enhancement )p(herbal) + q( enhancement )q(herbal) (0.15)(0.08) (0.15)(0.08) + (0.004)(0.04) ~ 0 ·987 . Because r( enhancement, herbal) is greater than the threshold 0.9, an incoming message containing "enhancement'' and "herbal" will be rejected. 23. First, by Bayes' theorem, we have Next, because we are assuming no prior knowledge about whether a message is or is not spam, we set p(S) = p(S) = 0.5, and so the equation above simplifies to Finally, because of the assumed independence of E 1 , E 2 , and S, we have p( E 1 n E 2 I S) = p( E 1 I S) ·p( E 2 I S) , and similarly for the S. Thus the equation is equivalent to what we were asked to show. SECTION 7.4 Expected Value and Variance This section concludes the discussion of probability theory. The linearity of expectation is a surprisingly powerful tool, as Exercises 25 and 43, for example, illustrate. 1. By Theorem 2 with p = 1/2 and n = 5, we see that the expected number of heads is 2.5. 3. By Theorem 2 the expected number of successes for n Bernoulli trials is np. In the present problem we have n = 10 and p = 1/6. Therefore the expected number of successes (i.e., appearances of a 6) is 10 · (1/6) = 1 ~. 5. This problem involves a lot of computation. It is similar to Example 3, which relied on the results of Example 12 in Section 7.2. We need to compute the probability of each outcome in order to be able to apply Definition 1 (expected value). It is easy to see that the given information implies that for one roll of such a die p(3) = 2/7 and p(l) = p(2) = p(4) = p(5) = p(6) = 1/7 (this was Exercise 2 in Section 7.2). Next we need to do several computations similar to those required in Exercise 5 in Section 7.2, in order to compute p(X = k) for each k from 2 to 12, where the random variable X represents the sum (for example, X(3,5) = 8). The probability of a sum of 2, p(X = 2), is ~ · ~ = 419 , since the only way to achieve a sum of 2 is to roll a 1 on each die, and the two dice are independent. Similarly, p(X = 3) = ~ · ~ + ~ · ~ = 429 , since both of the outcomes (1, 2) and (2, 1) give a sum of 3. We perform similar calculations for the other outcomes of the sum. Here is the Section 7.4 251 Expected Value and Variance entire set of values: 1 1 1 49 p(X = 2) = 7.7 = p(X = 3 ) = T. 7 + T. T = 49 p(X = 4 ) = 7.7+ 7.7+ 7.7 = 1 2 2 p(X = 5 ) = 7 .7+ 7 .7+ 7 .7+ 7 .T= 1 1 2 2 1 1 1 6 49 p(X = 6 ) = 7 . 7 + 7 . 7 + 7 . 7 + 7 . T+ T. T = 1 1 1 1 2 2 1 1 1 1 8 49 p( x = 7) = 7.7+ 7.7+ 7.7+ 7.7+ 7.7+ 7.7 = 1 1 1 1 2 1 2 1 1 1 1 p(X = 8 ) = 7.7+ 7.7+ 7.7+ 7.7+ 7.T= 1 1 2 1 1 2 1 1 7 49 p(X = 9 ) = 7 .7+ 7. 7+ 7.7+ 7 .T= 1 1 1 1 1 1 1 1 2 1 1 5 49 21111112 111111 p(X = lO) = 7.7+ 7.7+ 7.7 = p( x = 11 ) = 7.7+ 7.7= p(X = 12 ) = T. 7 = 1 1 1 1 1 1 1 8 49 6 49 3 49 2 49 1 49 A check on our calculation is that the sum of the probabilities is 1. Finally, we need to add the values of X times the corresponding probabilities: 1 2 5 6 8 8 7 6 3 2 1 336 E(X) =2·-+3·-+4·-+5·-+6·-+7·-+8·-+9·-+10·-+ll·-+12·- = ~6.86 49 49 49 49 49 49 49 49 49 49 49 49 This is a reasonable answer (you should always ask yourself if the answer is reasonable!). since the dice are not very different from ordinary dice, and with ordinary dice the expectation is 7. 7. By Theorem 3 we know that the expectation of a sum is the sum of the expectations. In the current exercise we can let X be the random variable giving the score on the true-false questions and let Y be the random variable giving the score on the multiple choice questions. In order to compute the expectation of X and of Y, let us for a moment ignore the point values, and instead just look at the number of true-false or multiple choice questions that Linda gets right. The expected number of true-false questions she gets right is the expectation of the number of successes when 50 Bernoulli trials are performed with p = 0.9. By Theorem 2 the expectation for the number of successes is np = 50 · 0.9 = 45. Since each problem counts 2 points, the expectation of X is 45 · 2 = 90. Similarly, the expected number of multiple choice questions she gets right is the expectation of the number of successes when 25 Bernoulli trials are performed with p = 0.8, namely 25 · 0.8 = 20. Since each problem counts 4 points, the expectation of Y is 20 · 4 = 80. Therefore her expected score on the exam is E(X + Y) = E(X) + E(Y) = 90 + 80 = 170. 9. In Example 8 we found that the answer to this question when the probability that x is in the list is p is p(n + 2) + (2n + 2)(1 - p). Plugging in p = 2/3 we have 2 3 · (n + 2) + (2n + 2) · 4n + 6 = - · 3 3 1 Chapter 7 252 Discrete Probability 11. There are 10 different outcomes of our experiment (it really doesn't matter whether we get a 6 on the last roll or not). Let the random variable X be the number of times we roll the die. For i = 1, 2, ... , 9, the probability that X = i is (5/6)'- 1 (1/6), since to roll the die exactly i times requires that we obtain something other than a 6 exactly i - 1 times followed by a 6 on the ith roll. Furthermore p(X = 10) = (5/6) 9 . We need to compute 2=~~ 1 i · p(X = i). A computer algebra system gives the answer as 50700551/10077696 ~ 5.03. Note that this is reasonable, since if there were no cut-off then the expected number of rolls would be 6. 13. The random variable that counts the number of rolls has a geometric distribution with p = 1/6, since the probability of getting a sum of 7 when a pair of dice is rolled is 1/6. According to Theorem 4 the expected value is 1/(1/6) = 6. 15. For a geometric distribution p(X 00 p(X;::;, j) = LP(X k=J = k) = (1 - 00 = k) = L(l - p)k-lp for k • = 1, 2, 3, .... Therefore 00 p)k-lp = p(l - k=J . p)1-1 L(l - p)k k=O = p(l - 1 p)l-1 1- 1( p) = (1- p)1-1, where we have used the formula for the sum of a geometric series at the end. 17. The random variable that counts the number of integers we need to select has a geometric distribution with p = 1/2302. According to Theorem 4 the expected value is 1/(1/2302) = 2302. 19. We know from Examples 1 and 4 that E(X) = 7/2 and E(Y) = 7. To compute E(XY) we need to find the value of XY averaged over the 36 equally likely possible outcomes. The following table shows the value of XY. For example, when the outcome is (3, 4), then X = 3 and Y = 7, so XY = 21. 1 2 3 4 5 6 We compute the average to be E(XY) 1 2 6 12 20 30 42 2 3 8 15 24 35 48 = 329 /12; 3 4 10 18 28 40 54 4 5 12 21 32 45 60 5 6 14 24 36 50 66 6 7 16 27 40 55 72 and (7 /2) · 7 -1- 329 /12. 21. Given that the sum is at least 9, there are four possible outcomes (sums of 9, 10, 11, or 12) with relative probabilities of 4, 3, 2, and 1. Therefore p(X = 9) = 0.4, p(X = 10) = 0.3, p(X = 11) = 0.2, p(X = 12) = 0.1, and the conditional expectation is 9 · 0.4 + 10 · 0.3 + 11 · 0.2 + 12 · 0.1 = 10. 23. The relevant calculation from the formula given is 4200 · 0.12 + 1100 · 0.88 the usual concept of weighted average. = 1472 pounds. This is really just 25. We follow the hint. Let ! 1 = 1 if a run begins at the lh Bernoulli trial and ! 1 = 0 otherwise. Note that for ! 1 to equal 1, we must have the lh trial result in S and either the (j - 1)st trial result in F or j = 1 . Clearly the number of runs is the sum R = I:;=l ! 1 , since exactly one ! 1 is 1 for each run. Now E(Ii) = p, the probability of Son the first trial, and E(I1 ) = p(l - p) for 1 < j::; n since we need success on the jth trial and failure on the (j - 1)st trial. By linearity (Theorem 3, which applies even when these random variables are not independent, which they certainly are not here) we have E(R) = p+ I:;= 2p(l -p) = p+ (n- l)p(l-p). 27. In Example 18 we saw that the variance of the number of successes in n Bernoulli trials is npq. Here n = 10 and p = q = 1/2. Therefore the variance is 5/2. Note that the unit for stating variance is not flips here, but (flips) 2 • To restate this in terms of flips, we must take the square root to compute the standard deviation. The standard deviation is J2.5 ~ 1.6 flips. Section 7.4 Expected Value and Variance 253 29. The question is asking about the signed difference. For example, if n = 6 and we get five tails and one head, then X 6 = 4, whereas if we get five heads and one tail, then X 6 = -4. The key here is to notice that Xn is just n minus twice the number of heads. a) The expected number of heads is n/2. Therefore the expected value of twice the number of heads is twice this, or n, and the expected value of n minus this is n - n = 0. This is not surprising; if it were not zero, then there would be a bias favoring heads or favoring tails. b) Since the expected value is 0, the variance is the expected value of the square of Xn, which is the same as the square of twice the number of heads. This is clearly four times the square of the number of heads, so its expected value is 4 · n/4 = n, from Example 18, since p = q = 1/2. Therefore the answer is n. We are implicitly using here the result of Exercise 29 in the supplementary exercises for this chapter. 31. This is certainly not true if X and Y are not independent. For example, if Y = -X, then X + Y = 0, so it has expected absolute deviation 0, whereas X and Y can have nonzero expected absolute deviation. For a more concrete example, let X be the number of heads in one flip of a fair coin, and let Y be the number of tails for that same flip. Each takes values 0 and 1 with probability 0.5. Then E(X) = 0.5, Ix - E(X) I = 0.5 for each outcome x, and therefore A(X) = 0.5. Similarly, A(Y) = 0.5, so A(X) + A(Y) = 1. On the other hand, X + Y has constant value 1, so l(x + y) - E(X + Y)I = 0 for each pair of outcomes (x, y), and A(X + Y) = 0. It is not hard to come up with a counterexample even when X and Y are independent; see the answer in the back of the text book. 33. a) The probabilities that (X1,X2,X3) = (x 1,x 2,x 3) are as follows, because with probability 1 we have that X3 = (X1 + X 2) mod 2: 1 1 1 p(O, 0, 0) = "2 · "2 · 1 = 4 ~ · ~ ·0 = 0 p(O,O, 1) = p(O, 1, 0) = 2" · 2" · 0 = 0 1 1 1 1 1 1 1 1 1 1 "2 · "2 · 1 = 4 1 1 = 2 . 2 .0 = 0 p(O, 1, 1) = p(l, 0, 0) 1 p(l, 0, 1) = 2. 2 . 1 = 4 p(l, 1, 0) = 2. 2 .1 = 4 p(l, 1, 1) = 2. 2. 0 = 0 1 1 We must show that X1 and X2 are independent, that X 1 and X3 are independent, and that X2 and X3 are independent. We are told that X 1 and X 2 are independent. To see that X 1 and X 3 are independent, we note from the list above that p(X1 = 0 /\ X 3 = 0) = 1/4 + 0 = 1/4, that p(X1 = 0) = 1/2, and that p(X3 = 0) = 1/2, so it is true that p(X 1 = O/\X3 = 0) = p(X1 = O)p(X3 = 0). Essentially the same calculation shows that p(X1 = 0 /\ X3 = 1) = p(X1 = O)p(X3 = 1), p(X1 = 1 /\ X3 = 0) = p(X1 = l)p(X3 = 0), and p(X1 = 1 /\ X 3 = 1) = p(X1 = l)p(X3 = 1). Therefore by definition, X 1 and X 3 are independent. The same reasoning shows that X 2 and X 3 are independent. To see that X 3 and X 1 + X 2 are not independent, we observe that p(X3 = 1 /\ X 1 + X 2 = 2) = 0, because 2 mod 2 =I- 1. But p(X3 = l)p(X 1 + X 2 = 2) = (1/2)(1/4) = 1/8. b) We see from the table in part (a) that X 1 , X 2 , and X 3 are all Bernoulli random variables, so the variance of each is (1/2)(1/2) = 1/4 by Example 14. Therefore V(X1 ) + V(X2 ) + V(X3 ) = 3/4. We see from the table above that p(X1 + X2 + X3 = 0) = 1/4, p(X1 + X2 + X3 = 1) = 0, p(X1 + X2 + X3 = 2) = 3/4, and 254 Chapter 7 Discrete Probability p(X 1 + X2 + X3 = 3) = 0. Therefore the expected value of X 1 + X2 + X 3 is (1/4)(0) + (3/4)(2) = 3/2, and the variance of X 1 + X 2 + X 3 is (1/4)(0 - 3/2) 2 + (3/4)(2 - 3/2) 2 = 3/4. c) If we attempt to prove this by mathematical induction, then presumably we would like the inductive step to be V((X1 + X2 + · · · + Xk) + Xk+1) = V(X1 + X2 + · · · + Xk) + V(Xk+l) (by the n = 2 case of Theorem 7, which was proved in the text), which then equals (V(Xi) + V(X 2) + · · · + V(Xk)) + V(Xk+i) by the inductive hypothesis. However, in order to invoke Theorem 7, we must have that X 1 + X 2 + · · · + Xk and Xk+l are independent, and we see from part (a) that this is not a valid conclusion if all we know is the pairwise independence of the variables. Notice that the conclusion (that the variance of the sum is the sum of variances) is true assuming only pairwise independence; it's just that we cannot prove it in this manner. See Exercise 34. 35. We proceed as in Example 19, applying Chebyshev's inequality with V(X) We have p(IX(s) - E(X)I :'.". 5fo)::; V(X)/r 2 = (n/4)/(5fo) 2 = 1/100. = n/4 by Example 18 and r = 5fo. 37. For simplicity we suppress the argument and write simply X for X(s). As in the proof of Theorem 5, E(X) =Err· p(X = r). Dividing both sides by a we obtain E(X)/a = 2-:r(r/a) · p(X = r). Now this sum is at least as great as the subsum restricted to those values of r :'.". a, and for those values, r /a :'.". 1. Thus we have E(X)/a :'.". Lr~a 1 · p(X = r). But this last expression is just p(X :'.".a), as desired. 39. It is interesting to note that Markov was Chebyshev's student in Russia. One note of caution-the variance is not 10,000 cans; it is 10,000 square cans (the units for the variance of X are the square of the units for X). So a measure of how much the number of cans recycled per day varies is about the square root of this, or about 100 cans. a) We have E(X) = 50.000 and we take a= 55,000. Then p(X :'.". 55,000)::; 50,000/55,000 not a terribly good estimate. b) We apply Theorem 8, with r = 10/11. This is 10,000. The probability that the number of cans recycled will differ from the expectation of 50,000 by at least 10,000 is at most 10,000/10,0002 = 0.0001. Therefore the probability is at least 0.9999 that the center will recycle between 40,000 and 60,000 cans. This is also not a very good estimate, since if the number of cans rec.ycled per day usually differs by only about 100 from the mean of 50,000, it is virtually impossible that the difference would ever be over 100 times this amount-the probability is much, much less than 1 in 10,000. = 41. a) Each of the n! permutations occurs with probability 1/n!, so clearly E(X) is the average number of comparisons, averaged over all these permutations. b) In Example 5 of Section 3.3, we noted that the version of bubble sort that continues n -1 rounds regardless of whether new changes were made uses n(n - 1)/2 comparisons, so X in this problem is always at most n(n - 1)/2. It follows from the formula for expectation that E(X)::; n(n -1)/2. c) An inversion in a permutation is a pair of integers a1 and ak with j < k (so that a1 < ak) such that ak precedes a1 in the permutation (the elements are out of order). Because the bubble sort works by comparing adjacent elements and then swapping them if they are out of order, the only way that these elements can end up in their correct positions is if they are swapped, and therefore they must be compared. d) For each permutation P, we know from part (c) that X(P) :'.". I(P). It follows from the definition of expectation that E(X) :'.". E(I). e) This summation just counts 1 for every instance of an inversion. f) This follows from the linearity of expectation (Theorem 3). g) By Theorem 2 with n = 1, the expectation of 11 ,k is the probability that ak precedes a1 in the permutation. But by symmetry, since the permutation is randomly chosen, this is clearly 1/2. (There are n!/2 permutations in which ak precedes a1 and n!/2 permutations in which a1 precedes ak out of the n! permutations in all.) 255 Review Questions h) The summation in part (f) consists of C(n, 2) = n(n - 1)/2 terms, each equal to 1/2, so the sum is (n(n - 1)/2)(1/2) = n(n - 1)/4. i) From part (b) we know that E(X), the object of interest, is at most n(n -1)/2, and from part (d) and part (h) we know that E(X) is at least n( n - 1) / 4. Since both of these are 8( n 2 ), the result follows. 43. Following the hint, we let X = X 1 + X 2 + · · · + Xn, where X, = 1 if the permutation fixes the ith element and X, = 0 otherwise. Then X is the number of fixed elements, so we are being asked to compute V(X). By Theorem 6, it suffices to compute E(X 2)-E(X) 2 . Now E(X) = E(X1)+E(X2 )+· · ·+E(Xn) = n·(l/n) = 1, since the probability that the ith element stays in its original position is clearly 1/n by symmetry. To compute E(X 2 ) we first multiply out: x 2 = (X1 +X2 + · ·· +Xn) 2 = n L:x? + L:x,x1 z=l z/=J x; Now since = X,, E(X?) = l/n. Next note that X,X1 = 1 if both the ith and the ;th elements are left fixed, and since there are (n - 2)! permutations that do this, the probability that X,X1 = 1 is (n - 2)!/n! = 1/(n(n - 1)). Of course X,X1 = 0 otherwise. Therefore E(X,X1 ) = 1/(n(n - 1)). Note also that there are n summands in the first sum of the displayed equation and n( n - 1) in the second. So E(X 2) = n(l/n) + n(n - 1) · l/(n(n - 1)) = 1+1 = 2. Therefore V(X) = E(X 2 ) - E(X) 2 = 2 - 12 = 1. 45. We can prove this by doing some algebra, using Theorems 3 and 6 and Exercise 44: V(X + Y) = E((X + Y) 2 ) - E(X + Y) 2 = E(X 2 + 2X · Y + Y 2 ) - (E(X) + E(Y)) 2 = E(X 2 ) + 2E(X · Y) + E(Y 2 ) - E(X) 2 - 2E(X)E(Y) - E(Y) 2 = (E(X 2 ) = V(X) + 2 Cov(X, Y) + V(Y) - E(X) 2 ) + 2(E(X · Y) - E(X)E(Y)) + (E(Y 2 ) - E(Y) 2 ) 4 7. The probability that a particular ball fails to go into the first bin is (n - 1) / n. Since these choices are assumed to be made independently, the probability that the first bin remains empty is then ((n - 1)/n)m. 49. Let X = X 1 +X2 +· · ·+Xn, where X, = 1 ifthe ith bin remains empty and X, = 0 otherwise. Then Xis the number of bins that remain empty, so we are being asked to compute E(X). From Exercise 47 we know that p(X, = 1) = ((n - 1)/nr if m balls are distributed, so E(X,) = ((n - 1)/nr. By linearity of expectation (Theorem 3), the expected number of bins that remain empty is therefore n((n -1)/n)m = (n- l)m/nm- 1 . GUIDE TO REVIEW QUESTIONS FOR CHAPTER 7 1. a) See p. 446. b) 1/C(50, 6) n 2. a) \t'i(O:::; p(x,):::; 1) and LP(x,) = 1 b) p(H) = 3/4, p(T) = 1/4 z=l 3. a) See p. 456. b) 1/3 4. a) See p. 457. b) yes 5. a) See p. 460. b) 1, 2, 3, 4, 5, 6 6. a) See p. 478. 11 161 1 3 5 7 9 b) 1 . - + 2 . - + 3 . - + 4 . - + 5 . - + 6 . - = 36 36 36 36 36 36 36 ~ 4.4 7 Chapter 7 256 7. a) See p. 482. b) (5n + 6)/3 (see Example 8 in Section 7.4) 8. a) See p. 458. b) See Theorem 2 in Section 7.2. 9. a) See p. 480. b) See Example 6 in Section 7.4. c) See Theorem 2 in Section 7.4. 10. a) See the discussion of Monte Carlo algorithms on p. 463. . 470· 11. See p ' p (F I E) = p(E I F)p(F) p(E I F)p(F) + p(E I F)p(F) 12. a) See pp. 484-485. 13. a) See p. 487. Discrete Probability b) See Example 16 in Section 7.2. (1/3)(2/3) (1/3)(2/3) + (1/4)(1/3) 8 11 b) See Theorem 4 in Section 7.4. b) See Example 14 in Section 7.4. 14. a) See Theorem 7 in Section 7.4. b) See Example 18 in Section 7.4. 15. See p. 491. SUPPLEMENTARY EXERCISES FOR CHAPTER 7 1. There are 35 outcomes in which the numbers chosen are consecutive, since the first of these numbers can be anything from 1 to 35. There are C( 40, 6) = 3,838,380 possible choices in all. Therefore the answer is 35/3838380 = 1/109668. 3. There are 0(59, 5) · C(39, 1) = 195,249,054 possible outcomes of the draw, so that is the denominator for all the fractions giving the desired probabilities. You can check your answers to these exercises with Powerball's website: www. power ball. com/powerball/pb_prizes. asp a) There is only one way to win, so the probability of winning is 1/195,249,054. b) There are 38 ways to win in this case (you must not match the sixth ball), so the answer is 38/195,249,054 = 1/5,138,133. c) To match three of the first five balls, there are 0(5, 3) ways to choose the matching numbers and C(54, 2) ways to choose the non-matching numbers; therefore the numerator for this case is 0(5, 3) · C(54, 2). Similarly, matching four of the first five balls but not the sixth ball can be done in C(5, 4) · C(54, 1) · 38 ways. Therefore the answer is 45 1 0(5, 3) · C(54, 2) + 0(5, 4) · C(54, 1) · 38 357,599 ~ 7947. 0(59, 5) · C(39, 1) d) To not win a prize requires matching zero, one, or two of the first five numbers, and not matching the sixth number. Therefore the answer is (C(5, 0) · 0(54, 5) 1 - + C(5, 1) · 0(54, 4) + 0(5, 2) · C(54, 3)) · 38 0(59, 5). C(39, 1) 536 = 18,821 1 ~ 35. 5. Each probability is of the form s/t where s is the number of hands of the described type and t is the total number of hands, which is clearly C(52, 13) = 635,013,559,600. Hence in each case we will count the number of hands and divide by this value. a) There is only one hand with all 13 hearts, so the probability is 1/t, which is about 1.6 x 10- 12 . b) There are four such hands, since there are four ways to choose the suit, so the answer is 4/t, which is about 6.3 x 10- 12 . c) To specify such a hand we need to choose 7 spades from the 13 spades available and then choose 6 clubs from the 13 clubs available. Thus there are C(13, 7)C(13, 6) = 2944656 such hands. The probability is therefore 2944656/t ~ 4.6 x 10- 6 . Supplementary Exercises 257 d) This event is 12 times more likely than the event in part (c), since there are P(4,2) = 12 ways to choose the two suits. Thus the answer is 35335872/t ~ 5.6 x 10- 5 . e) This is similar to part (c), but with four choices to make. C(13, 1)/t = 1244117160/635013559600 ~ 2.0 x 10- 3 . The answer is C(13, 4)C(13, 6)C(13, 2) f) There are P(4, 4) = 24 ways to specify the suits, and then there are C(13, 4)C(13, 6)C(13, 2)C(13, 1) ways to choose the cards from these suits to construct the desired hand. Therefore the answer is 24 times as big as the answer to part (e), namely 29858811840/635013559600 ~ 0.047. 7. a) Each of the outcomes 1 through 8 occurs with probability 1/8, so the expectation is (1/8)(1+2+3 + ···+8)=9/2. b) We compute V(X) = E(X 2 ) - E(X) 2 = (1/8) (1 2 + 22 + 32 + · · · + 82 ) - (9 /2) 2 = (51/2) - (81/ 4) = 21/ 4. 9. a) Since expected value is linear, the expected value of the sum is the sum of the expected values, each of which is 9/2 by Exercise 7a. Therefore the answer is 9. b) Since variance is linear for independent random variables, and clearly these variables are independent, the variance of the sum is the sum of the variances, each of which is 21/4 by Exercise 7b. Therefore the answer is 21/2. 11. a) Since expected value is linear, the expected value of the sum is the sum of the expected values, which are 7/2 by Example 1 in Section 7.4 and 9/2 by Exercise 7a. Therefore the answer is (7 /2) + (9/2) = 8. b) Since variance is linear for independent random variables, and clearly these variables are independent, the variance of the sum is the sum of the variances, which are 35/12 by Example 15 in Section 7.4 and 21/4 by Exercise 7b. Therefore the answer is (35/12) + (21/4) = 49/6. 13. a) There are 2n possible outcomes of the flips. In order for the odd person out to be decided, we must have one head and n - 1 tails, or one tail and n - 1 heads. The number of ways for this to happen is clearly 2n (choose the odd person and choose whether it is heads or tails). Therefore the probability that there is an odd person out is 2n/2n = n/2n-l. Call this value p. b) Clearly the number of flips has a geometric distribution with parameter p = n/2n-l, from part (a). Therefore the probability that the odd person out is decided with the kth flip is p(l - p)k-l. c) By Theorem 4 in Section 7.4, the expectation is 1/p = 2n-l /n. 15. We start by counting the number of positive integers less than mn that are divisible by either m or n. Certainly all the integers m, 2m, 3m, ... , nm are divisible by m. There are n numbers in this list. All but one of them are less than mn. Therefore n - 1 positive integers less than mn are divisible by m. Similarly, m - 1 positive integers less than mn are divisible by n. Next we need to see how many numbers are divisible by both m and n. A number is divisible by both m and n if and only if it is divisible by the least common multiple of m and n. Let L = lcm( m, n) . Thus the numbers divisible by both m and n are L, 2L, ... , mn. This list has gcd(m, n) numbers in it, since we know that lcm(m, n) ·gcd(m, n) = mn. Therefore gcd(m, n)-1 positive integers strictly less than mn are divisible by both m and n. Using the inclusion-exclusion principle, we deduce that (n - 1) + (m - 1) - (gcd(m, n) - 1) = n + m - gcd(m, n) - 1 positive integers less than mn are divisible by either m or n. Therefore (mn - 1) - (n + m - gcd(m, n) - 1) = mn - n - m + gcd(m, n) = (m - 1) (n - 1) + gcd( m, n) - 1 numbers in this range are not divisible by either m or n. This gives us our answer: (m - l)(n - 1) + gcd(m, n) - 1 mn-l Chapter 7 258 Discrete Probability 17. a) Label the faces of the cards Fl, Bl, F2, B2, F3, and B3 (here F stands for front, B stands for back, and the numeral stands for the card number). Without loss of generality, assume that Fl, Bl, and F2 are the black faces. There are six equally likely outcomes of this experiment, namely that we are looking at each of these faces. Then the event that we are looking at a black face is the event E 1 = {Fl, Bl, F2} . The event that the other side is also black is the event E2 ={Fl, Bl}. We are asked for p(E2 I E 1 ), which is by definition p(E2 n E 1 )/p(E1 ) = p( {Fl, Bl} )/p( {Fl, Bl, F2}) = (2/6)/(3/6) = 2/3. b) The argument in part (a) works for red as well, so the answer is again 2/3. This seeming paradox comes up in other contexts, such as the Law of Restricted Choice in the game of bridge. 19. There are 210 bit strings. There are 25 palindromic bit strings, since once the first five bits are specified arbitrarily, the remaining five bits are forced. If a bit string is picked at random, then, the probability that it is a palindrome is 25 /2 10 = 1/32. 21. a) We assume that the coin is fair, so the probability of a head is 1/2 on each flip, and the flips are independent. The probability that one wins 2n dollars (i.e., p(X = 2n)) is l/2n, since that happens precisely when the player gets n - 1 tails followed by a head. The expected value of the winnings is therefore the sum of 2n times l/2n as n goes from 1 to infinity. Since each of these terms is 1, the sum is infinite. In other words, one should be willing to wager any amount of money and expect to come out ahead in the long run. The catch, of course, and that is partly why it is a paradox, is that the long run is too long, and the bank could not actually pay 2n dollars for large n anyway (it would exceed the world's money supply). It would not make sense for someone to pay a million dollars to play this game just once. b) Now the expectation is (1/2) (2 1 )+(1/2 2 ) (2 2 )+(1/2 3 ) (2 3 )+(1/2 4 )(2 4 )+(1/2 5 )(2 5 )+(1/2 6 ) (2 6 )+(1/2 7 ) (2 7 )+ (1/2 7 )(2 8 ) = 9. Therefore a fair wager would be $9. 23. a) The intersection of two sets is a subset of each of them, so the largest p(A n B) could be would occur when the smaller is a subset of the larger. In this case, that would mean that we want B ~ A, in which case An B = B, so p(A n B) = p(B) = 1/3. To construct an example, we find a common denominator of the fractions involved, namely 12, and let the sample space consist of 12 equally likely outcomes, say numbered 1 through 12. We let B = {1,2,3,4} and A= {1,2,3,4,5,6, 7,8,9}. The smallest intersection would occur when AU B is as large as possible, since p(A U B) = p(A) + p(B) - p(A n B). The largest AU B could ever be is the entire sample space, whose probability is 1, and that certainly can occur here. So we have 1 = (3/4) + (1/3) -p(AnB), which gives p(AnB) = 1/12. To construct an example, again we find a common denominator of these fractions, namely 12, and let the sample space consist of 12 equally likely outcomes, say numbered 1 through 12. We let B = {l, 2, 3, 4} and A= {4, 5, 6, 7, 8, 9, 10, 11, 12}. Then An B = {4}, and p(A n B) = 1/12. b) The largest p( AU B) could ever be is 1, which occurs when A U B is the entire sample space. As we saw in part (a), that is possible here, using the second example above. The union of two sets is a superset of each of them, so the smallest p(A U B) could be would occur when the smaller is a subset of the larger. In this case, that would mean that we want B ~ A, in which case AU B = A, so p(A U B) = p(A) = 3/4. This occurs in the first example given above. 25. a) We need three conditions for two of the events at once and one condition for all three: p(E1 n E2) = p(Ei)p(E2) p(E1 n E3) p(E2 n E3) p(E1 n E2 n E3) = p(Ei)p(E3) = p(E2)p(E3) = p(E1)p(E2)p(E3) Supplementary Exercises 259 b) Intuitively, it is clear that these three events are independent, since successive flips do not depend on the results of previous flips. Mathematically, we need to look at the various events. There are 8 possible outcomes of this experiment. In four of them the first flip comes up heads, so p(E1 ) = 4/8 = 1/2. Similarly, p( E2) = 1/2 and p( E 3) = 1/2. In two of these outcomes the first flip is a head and the second flip is a tail, so p(E1 nE2 ) = 2/8=1/4. Similarly, p(E1 nE3 )=1/4 and p(E2 nE3 ) = 1/4. Only one outcome has all three events happening, so p(E1 n E 2 n E 3) = 1/8. We now need to plug these numbers into the four equations displayed in part (a) and check the they are satisfied: 1 1 1 1 1 1 1 1 1 1 1 1 = 4 = 2·2 = p(E1 n E3) = 4 = 2·2= p(E2 n E3) = 4= 2·2= p(E1 n E2) p(E1 n E2 n E3) = p(E1)p(E2) p(Ei)p(E3) p(E2)p(E3) 1 8 = 2 . 2 . 2 = p(Ei)p(E2)p(E3) The first three lines show that E1 , E 2 , and E3 are pairwise independent, and these together with the last line show that they are mutually independent. c) We need to compute the following quantities, which we do by counting outcomes. p(E1 ) = 4/8 = 1/2, p(E2) = 4/8 = 1/2, p(E3) = 4/8 = 1/2, p(E1 n E2) = 2/8 = 1/4, p(E1 n E3) = 2/8 = 1/4, p(E2 n E3) = 2/8 = 1/4, and p(E1 n E 2 n E 3 ) = 1/8. Note that these are the same values obtained in part (b). Therefore when we plug them into the defining equations for independence, we must again get true statements, so these events are both pairwise and mutually independent. d) We need to compute the following quantities, which we do by counting outcomes. p(E1 ) = 4/8 = 1/2, p(E2) = 4/8 = 1/2, p(E3) = 4/8 = 1/2, p(E1 n E2) = 2/8 = 1/4, p(E1 n E3) = 2/8 = 1/4, p(E2 n E3) = 2/8 = 1/4, and p(E1 n E 2 n E 3) = 0/8. Note that these are the same values obtained in part (b), except that now p(E1 n E 2 n E3) = 0/8. Therefore when we plug them into the defining equations for independence, we again get true statements for the first three, but not for the last one. Therefore, these events are pairwise independent, but they are not mutually independent. e) There will be one condition for each subset of the set of events, other than subsets consisting of no events or just one event. There are 2n subsets of a set with n elements, and n + 1 of them have fewer than two elements. Therefore there are 211 - n - 1 subsets of interest and that many conditions to check. 27. a) We know nothing about the second child, and its gender is independent of the gender of the first child (under the usual assumptions for such situations), so we can conclude that the probability that the other child is male is 1/2 (again under the usual assumptions about genders of human births). On the other hand, before we met Mr. Smith there were four possible genders for his children, in order of birth: MM, MF, FM, and FF, all equally likely. We know that the fourth is not possible, so the other child is a son in one of the three remaining cases. Therefore the answer is 1/3. b) Let M be the event that both of Mr. Smith's children are boys and let B be the event that Mr. Smith chose a boy for today's walk. Then we know that p(M) = 1/4, p(B IM) = 1, and p( B - I M) 2 = 1 1 1 3 . 2 + 3 .0 = 3 ' and we want to determine p(M I B). Applying Bayes' theorem, we have (M I B) p(B I M)p(M) p - p(B I M)p(M) + p(B I M)p(M) (1)(1/4) (1)(1/4) + (1/3)(3/4) 1 - 2 c) In this variation, we are back to the second interpretation discussed in part (a), so the answer is unambiguously 1/3. 260 Chapter 7 Discrete Probability 29. Using Theorems 3 and 6 of Section 7.4 and the fact that the expectation of a constant is itself (this is easy to prove from the definition), we have V(aX + b) = E((aX + b) 2) - E(aX + b) 2 2 2 2 2 = E(a X + 2abX + b ) - (aE(X) + b) = E(a 2X 2) + E(2abX) + E(b 2) - (a 2E(X) 2 + 2abE(X) + = a2E(X 2) + 2abE(X) + b2 - a2E(X) 2 - 2abE(X) - b2 ) b2) = a2(E(X 2) - E(X) 2 ) = a2V(X). 31. This is essentially an application of inclusion-exclusion (Section 8.5). To count every element in the sample space exactly once, we want to include every element in each of the sets and then take away the double counting of the elements in the intersections. Thus p(E1 UE2U· · ·UEm) = p(E1 )+p(E2)+ · ·+p(Em)-p(E1 nE2)-p(E1 n E3)- · · · -p(E1 nEm)-p(E2nE3)-p(E2nE4)- · · ·-p(E2nEm)-· · · -p(Em-1 nEm) = qm-(m(m-1)/2)r, since C(m, 2) terms are being subtracted. But p(E1 UE2 U · · · UEm) = 1, so we have qm-(m(m-1)/2)r = 1. Since r 2 0 , this equation tells us that qm 2 1 , so q 2 1/ m. Since q ::; 1 , this equation also implies that (m(m-1)/2)r = qm- l::; m-1, from which it follows that r::; 2/m. 33. a) We purchase the cards until we have gotten one of each type. That means we have purchased X cards in all. On the other hand, that also means that we purchased X 0 cards until we got the first type we got (of course X 0 = 1 in all cases), and then purchased X 1 more cards until we got the second type we got, and so on. Thus X is the sum of the X 1 's. b) Once j distinct types have been obtained, there are n - j new types available out of a total of n types available. Since it is equally likely that we get each type, the probability of success on the next purchase (getting a new type) is (n - j) / n. c) This follows immediately from the definition of geometric distribution, the definition of X 1 , and part (b). d) From part ( c) it follows that E(X1 ) = n/(n - j). Thus by linearity of expectation from part (a) we have E(X) = E(Xo) + E(X1) + · · · + E(Xn-i) = ?!'. + _n_ + ... + ?!'. = n n n-1 1 e) If n = 50, (_!_n + _l_ + ... + n-1 ~). 1 then L-:1 ~ n(ln n + 'Y) ~ 50(ln 50 + 0.57721) ~ 224.46. n E(X) =n J=l J We can compute the exact answer using a computer algebra system: 13943237577224054960759 224 95 · 61980890084919934128 ~ 35. We see from Exercise 42 in Section 6.5 (applying the idea in Example 8 of that section) that there are 52!/13! 4 possible ways to deal the cards. In order to answer this question, we need to find the number of ways to deal them so that each player gets an ace. There are 4! = 24 ways to distribute the aces so that each player receives one. Once this is done, there are 48 cards left, 12 to be dealt to each player, so using the idea in Example 8 in Section 6.5 again, there are 48!/12! 4 possible ways to deal these cards. Taking the quotient of these two quantities will give us the desired probability: 24. (48!/12! 4 ) 52!/13! 4 24. 13 4 52. 51. 50. 49 = 2197 1 20825 ~ 10 Writing Projects 261 WRITING PROJECTS FOR CHAPTER 7 Books and articles indicated by bracketed symbols below are listed near the end of this manual. You should also read the general comments and advice you will find there about researching and writing these essays. 1. A general mathematics history text should cover this topic well. Introductory probability books might also have a few words on the subject. 2. It will be instructive to see whether the advice given in popular gambling books (which is where to go for this project) is correct! Your university library might not be a good place to look for this project; try your local bookstore instead. 3. As in the previous project, you should consult popular books on this subject. James Thorpe was one of the first persons to realize that the player can win against the house in blackjack by using the right strategy (which involves keeping track of the cards that have already been used, as well as doing the right thing in terms of drawing additional cards on each hand). 4. See the comments for Writing Project 2. 5. Google gives about five million hits on the phrase "spam filter" (in quotation marks). You might also want to include the word "successful" to narrow the search. 6. There is an article on this in an old issue of The American Statistician [Sc]. 7. See the classical book on the probabilistic method, in which Erdos has written an appendix, [AlSp]. 8. Modern books on algorithms, such as [CoLe], are good sources here. Chapter 8 262 Advanced Counting Techniques CHAPTERS Advanced Counting Techniques SECTION 8.1 Applications of Recurrence Relations This section picks up where Section 2.4 left off; recurrence relations were first introduced there. In addition this section is related to Section 5.3, in that recurrence relations are in some sense really recursive or inductive definitions. Many of the exercises in this set provide practice in setting up such relations from a given applied situation. In each problem of this type, ask yourself how the nth term of the sequence can be related to one or more previous terms; the answer is the desired recurrence relation. Exercise 21 is interesting and challenging, and shows that the inductive step may be quite nontrivial. Exercise 29 deals with onto functions; another-totally different-approach to counting onto functions is given in Section 8.6. Exercises 30-45 deal with additional interesting applications. 1. We want to show that Hn = 2" - 1 is a solution to the recurrence relation Hn = 2Hn-1 + 1 with initial condition H 1 = 1. For n = 1 (the base case), this is simply the calculation that 21 - 1 = 1. Assume that Hn = 2n - 1. Then by the recurrence relation we have Hn+l = 2Hn + 1, whereupon if we substitute on the basis of the inductive hypothesis we obtain 2(2" - 1) + 1 = 211 +1 - 2 + 1 = 2n+l - 1, exactly the formula for the case of n + 1. Thus we have shown that if the formula is correct for n, then it is also correct for n + 1, and our proof by induction is complete. 3. a) Let an be the number of ways to deposit n dollars in the vending machine. We must express an in terms of earlier terms in the sequence. If we want to deposit n dollars, we may start with a dollar coin and then deposit n - 1 dollars. This gives us an-l ways to deposit n dollars. We can also start with a dollar bill and then deposit n - 1 dollars. This gives us an-l more ways to deposit n dollars. Finally, we can deposit a five-dollar bill and follow that with n - 5 dollars: there are an_ 5 ways to do this. Therefore the recurrence relation is a 11 = 2an-1 + an-5. Note that this is valid for n ?: 5, since otherwise an-5 makes no sense. b) We need initial conditions for all subscripts from 0 to 4. It is clear that ao = 1 (deposit nothing) and a 1 = 2 (deposit either the dollar coin or the dollar bill). It is also not hard to see that a 2 = 22 = 4, a 3 = 23 = 8, and a 4 = 24 = 16, since each sequence of n C's and B's corresponds to a way to deposit n dollars-a C meaning to deposit a coin and a B meaning to deposit a bill. c) We will compute a 5 through aw using the recurrence relation: = a5 = a7 = a8 = a9 = aw = a5 2a4 + ao = 2 · 16 + 1 = 33 2a5 + al = 2 · 33 + 2 = 68 + a2 = 2 · 68 + 4 = 140 2a 7 + a 3 = 2 · 140 + 8 = 288 2a 8 + a 4 = 2 · 288 + 16 = 592 2ag + a5 = 2 · 592 + 33 = 1217 2a5 Thus there are 1217 ways to deposit $10. 5. Since this problem concerns a bill of 17 pesos, we can ignore all denominations greater than 17. Therefore we assume that we have coins for 1, 2, 5, and 10 pesos, and bills for 5 and 10 pesos. Then we proceed as in Section 8.1 263 Applications of Recurrence Relations Exercise 13 to write down a recurrence relation and initial conditions for an, the number of ways to pay a bill of n pesos (order mattering). If we want to achieve a total of n pesos, we can start with a I-peso coin and then pay out n - 1 pesos. This gives us an-l ways to pay n pesos. Similarly, there are an-2 ways to pay starting with a 2-peso coin, an_ 5 ways to pay starting with a 5-peso coin, an-lO ways to pay starting with a 10-peso coin, an_ 5 ways to pay starting with a 5-peso bill, and an-lo ways to pay starting with a 10-peso bill. This gives the recurrence relation an = an-l + an-2 + 2an-5 + 2an-W, valid for all n 2: 10. As for initial conditions, we see immediately that a 0 = 1 (there is one way to pay nothing, namely by using no coins or bills), a 1 = 1 (use a 1-peso coin), a 2 = 2 (use a 2-peso coin or two 1-peso coins), a 3 = 3 (use only 1-peso coins, or use a 2-peso coin either first or second), and a 4 = 5 (the bill can be paid using the schemes 1111, 112, 121, 211, or 22, with the obvious notation). For n = 5 through n = 9, we can iterate the recurrence relation an = an-l + an-2 + 2an-5, since no 10-peso bills are involved. This yields: a5 = a4 + a3 + 2ao = 5 + 3 + 2 · 1 = 10 a5 = a5 + a4 + 2a1 = 10 + 5 + 2 · 1 = 17 a1 = a5 + a5 + 2a2=17+10 + 2 · 2 = 31 as = a1 + a5 + 2a3 = 31 + 17 + 2 · 3 = 54 ag = as + a1 + 2a4 = 54 + 31 + 2 · 5 = 95 Next we iterate the full recurrence relation to get up to n = 17: aw = a9 + as + 2a 5 + 2ao = 95 + 54 + 2 · 10 + 2 · 1 = 171 au = aw + ag + 2a6 + 2a1 = 171 + 95 + 2 · 17 + 2 · 1 = 302 a12 = au +aw + 2a1 + 2a2 = 302 + 171 + 2 · 31 + 2 · 2 = 539 a13 = a12 + au + 2as + 2a3 = 539 + 302 + 2 · 54 + 2 · 3 = 955 a14 = a13 + a12 + 2ag + 2a 4 = 955 + 539 + 2 · 95 + 2 · 5 = 1694 a15 = a14 + a13 + 2aw + 2a5 = 1694 + 955 + 2 · 171 + 2 · 10 = 3011 a15 = a15 + a14 + 2au + 2a5 = 3011 + 1694 + 2 · 302 + 2 · 17 = 5343 a17 = a15 + a15 + 2a12 + 2a1 = 5343 + 3011+2·539+2 · 31 = 9494 Thus the final answer is that there are 9494 ways to pay a 17-peso debt using the coins and bills described here, assuming that order matters. 7. a) Let an be the number of bit strings of length n containing a pair of consecutive O's. In order to construct a bit string of length n containing a pair of consecutive O's we could start with 1 and follow with a string of length n - 1 containing a pair of consecutive O's, or we could start with a 01 and follow with a string of length n - 2 containing a pair of consecutive O's, or we could start with a 00 and follow with any string of length n - 2. These three cases are mutually exclusive and exhaust the possibilities for how the string might start. From this analysis we can immediately write down the recurrence relation, valid for all n 2: 2: an= an-l + an-2 + 2n- 2 . (Recall that there are 2k bit strings of length k.) b) There are no bit strings of length 0 or 1 containing a pair of consecutive O's, so the initial conditions are ao=a1=0. c) We will compute a 2 through a1 using the recurrence relation: a2 = a1 + ao + 2° = 0 + 0 + 1 a3 = a2 + a1 + 2 = 1 + 0 + a4 = a3 + a2 + 22 = 3 + 1 + a5 = a4 + a3 + 23 = 8 + 3 + 1= 1 2= 3 4= 8 8 = 19 4 a5 = a5 + a4 + 2 = 19 + 8 + 16 = 43 a1 = a5 +as+ 25 = 43 + 19 + 32 = 94 Chapter 8 264 Advanced Counting Techniques Thus there are 94 bit strings of length 7 containing two consecutive O's. 9. a) This problem is very similar to Example 3, with the recurrence required to go one level deeper. Let an be the number of bit strings of length n that do not contain three consecutive O's. In order to construct a bit string of length n of this type we could start with 1 and follow with a string of length n - 1 not containing three consecutive O's, or we could start with a 01 and follow with a string of length n - 2 not containing three consecutive O's, or we could start with a 001 and follow with a string of length n - 2 not containing three consecutive O's. These three cases are mutually exclusive and exhaust the possibilities for how the string might start, since it cannot start 000. From this analysis we can immediately write down the recurrence relation, valid for all n 2: 3: an = an-1 + an-2 + an-3. b) The initial conditions are a 0 = 1, a 1 = 2, and a 2 conditions (recall that the empty string has length 0). = 4, since all strings of length less than 3 satisfy the c) We will compute a 3 through a1 using the recurrence relation: = a2 + al + ao = 4 + 2 + 1 = 7 a4 = a3 + a2 + al = 7 + 4 + 2 = 13 a 5 = a4 + a3 + a2 = 13 + 7 + 4 = 24 a3 + a4 + a3 a5 + a5 + a4 a5 = a5 = 24 + 13 + 7 = 44 a1 = = 44 + 24 + 13 = 81 Thus there are 81 bit strings of length 7 that do not contain three consecutive O's. 11. a) Let an be the number of ways to climb n stairs. In order to climb n stairs, a person must either start with a step of one stair and then climb n - 1 stairs (and this can be done in an-l ways) or else start with a step of two stairs and then climb n - 2 stairs (and this can be done in an- 2 ways). From this analysis we can immediately write down the recurrence relation, valid for all n 2: 2: an = an-1 + an-2. b) The initial conditions are a 0 = 1 and a 1 = 1. since there is one way to climb no stairs (do nothing) and clearly only one way to climb one stair. Note that the recurrence relation is the same as that for the Fibonacci sequence, and the initial conditions are that ao =Ji and ai = f2, so it must be that an= fn+i for all n. c) Each term in our sequence {an} is the sum of the previous two terms, so the sequence begins ao = 1, a 1 = 1, a 2 = 2, a 3 = 3, a 4 = 5, a5 = 8, a5 = 13, a1 = 21, as= 34. Thus a person can climb a flight of 8 stairs in 34 ways under the restrictions in this problem. 13. a) Let an be the number of ternary strings of length n that do not contain two consecutive O's. In order to construct a bit string of length n of this type we could start with a 1 or a 2 and follow with a string of length n - 1 not containing two consecutive O's, or we could start with 01 or 02 and follow with a string of length n - 2 not containing two consecutive O's. There are clearly 2an-l possibilities in the first case and 2an_ 2 possibilities in the second. These two cases are mutually exclusive and exhaust the possibilities for how the string might start, since it cannot start 00. From this analysis we can immediately write down the recurrence relation, valid for all n 2: 2: an = 2an-1 + 2an-2. b) The initial conditions are a0 = = 1 (for the empty string) and a 1 3 (all three strings of length 1 fail to contain two consecutive O's). c) We will compute a 2 through a 6 using the recurrence relation: a 2 = 2a 1 + 2ao = 2 · 3 + 2 · 1 = 8 + 2a1 = 2 · 8 + 2 · 3 = 22 2a3 + 2a2 = 2 · 22 + 2 · 8 = 60 2a4 + 2a3 = 2 · 60 + 2 · 22 = 164 a 3 = 2a2 a4 = a5 = a 6 = 2a5 + 2a4 = 2 · 164 + 2 · 60 = 448 Section 8.1 Applications of Recurrence Relations 265 Thus there are 448 ternary strings of length 6 that do not contain two consecutive O's. 15. a) Let an be the number of ternary strings of length n that do not contain two consecutive O's or two consecutive l's. In order to construct a bit string of length n of this type we could start with a 2 and follow with a string of length n - 1 not containing two consecutive O's or two consecutive l's, or we could start with 02 or 12 and follow with a string of length n - 2 not containing two consecutive O's or two consecutive l's, or we could start with 012 or 102 and follow with a string of length n - 3 not containing two consecutive O's or two consecutive l's, or we could start with 0102 or 1012 and follow with a string of length n - 4 not containing two consecutive O's or two consecutive l's, and so on. In other words, once we encounter a 2, we can, in effect, start fresh, but the first 2 may not appear for a long time. Before the first 2 there are always two possibilities-the sequence must alternate between O's and l's, starting with either a 0 or a 1. Furthermore, there is one more possibility-that the sequence contains no 2's at all, and there are two cases in which this can happen: 0101 ... and 1010 .... Putting this all together we can write down the recurrence relation, valid for all n 2: 2: an = an-l + 2an-2 + 2an-3 + 2an-4 + · · · + 2ao + 2 (It turns out that the sequence also satisfies the recurrence relation a,, = 2an-l + an-z, which can be derived algebraically from the recurrence relation we just gave by subtracting the recurrence for a,,_ 1 from the recurrence for an. Can you find a direct argument for it?) b) The initial conditions are that a 0 = 1 (the empty string satisfies the conditions) and a 1 = 3 (the condition cannot be violated in so short a string). c) We will compute a 2 through a 6 using the recurrence relation: = a 1 + 2a0 + 2 = 3 + 2 · 1 + 2 = 7 a3 = a2 + 2a1 + 2ao + 2 = 7 + 2 · 3 + 2 · 1 + 2 = 17 a4 = a3 + 2a 2 + 2a 1 + 2ao + 2 = 17 + 2 · 7 + 2 · 3 + 2 · 1 + 2 = 41 as = a4 + 2a3 + 2a2 + 2a 1 + 2a0 + 2 = 41 + 2 · 17 + 2 · 7 + 2 · 3 + 2 · 1 + 2 = 99 a6 = as + 2a 4 + 2a 3 + 2a2 + 2a 1 + 2a0 + 2 = 99 + 2 · 41 + 2 · 17 + 2 · 7 + 2 · 3 + 2 · 1 + 2 = 239 az Thus there are 239 ternary strings of length 6 that do not contain two consecutive O's or two consecutive l's. 17. a) Let an be the number of ternary strings that do not contain consecutive symbols that are the same. By symmetry we know that an/3 of these must start with each of the symbols 0, 1, and 2. Now to construct such a string, we can begin with any symbol ( 3 choices), but we must follow it with a string of length n - 1 not containing two consecutive symbols that are the same and not beginning with the symbol with which we began (~an-I choices). This tells us that an= 3 ·~an-I, or more simply an = 2an_ 1 , valid for every n 2: 2. b) The initial condition is clearly that a 1 = 3. (We could also mention that a 0 = 1, but the recurrence only goes one level deep.) c) Here it is easy to compute the terms in the sequence, since each is just 2 times the previous one. Thus 2 4 3 a6 = 2as = 2 a4 = 2 a3 = 2 a2 = 2sa1 = 2s · 3 = 96. 19. a) This problem is really the same as ("isomorphic to," as a mathematician would say) Exercise 11, since a sequence of signals exactly corresponds to a sequence of steps in that exercise. Therefore the recurrence relation is an = an-1 + an-2 for all n 2: 2. b) The initial conditions are again the same as in Exercise 11, namely a 0 = 1 (the empty message) and ai = l. c) Continuing where we left off our calculation in Exercise 11, we find that a 9 =as+ a1 = 34 + 21 = 55 and then a 10 = a 9 + as = 55 + 34 = 89. (If we allow only part of the time period to be used, and if we rule out the empty message, then the answer will be 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 + 55 + 89 = 231.) 266 Chapter 8 Advanced Counting Techniques 21. a) This problem is related to Exercise 62 in Section 5.1. Consider the plane already divided by n - 1 lines into Rn-l regions. The nth line is now added, intersecting each of the other n - 1 lines in exactly one point, n - 1 intersections in all. Think of drawing that line, beginning at one of its ends (out at "infinity"). (You should be drawing a picture as you read these words!) As we move toward the first point of intersection, we are dividing the unbounded region of the plane through which it is passing into two regions; the division is complete when we reach the first point of intersection. Then as we draw from the first point of intersection to the second, we cut off another region (in other words we divide another of the regions that were already there into two regions). This process continues as we encounter each point of intersection. By the time we have reached the last point of intersection, the number of regions has increased by n - 1 (one for each point of intersection). Finally. as we move off to infinity, we divide the unbounded region through which we pass into two regions, increasing the count by yet 1 more. Thus there are exactly n more regions than there were before the nth line was added. The analysis we have just completed shows that the recurrence relation we seek is R,, = Jl,,_ 1 + n. The initial condition is Ilo = 1 (since there is just one region-the whole plane-when there are no lines). Alternately, we could specify R 1 = 2 as the initial condition. b) The recurrence relation and initial condition we have are precisely those in Exercise 9c, so the solution is Rn= (n 2 +n+2)/2. 23. This problem is intimately related to Exercise 50 in the supplementary set of exercises in Chapter 5. It also will use the result of Exercise 21 of the present section. a) Imagine n - 1 planes meeting the stated conditions, dividing space into Sn-l solid regions. (This may be hard to visualize once n gets to be more than 2 or 3, but you should try to see it in your mind, even if the picture is blurred.) Now a new plane is drawn, intersecting each of the previous n - 1 planes in a line. Look at the pattern these lines form on the new plane. There are n - 1 lines, each two of which intersect and no three of which pass through the same point (because of the requirement on the "general position" of the planes). According to the result of Exercise 21b, they form ((n - 1) 2 + (n - 1) + 2)/2 = (n 2 - n + 2)/2 regions in the new plane. Now each of these planar regions is actually splitting a former solid region into two. Thus the number of new solid regions this new plane creates is (n 2 - 2n + 2) /2. In other words, we have our recurrence relation: Sn = Sn-l + (n 2 - n + 2)/2. The initial condition is S 0 = 1 (if there are no planes, we get one region). Let us verify this for some small values of n. If n = 1, then the recurrence relation gives S 1 = So+ (1 2 - 1 + 2)/2 = 1+1 = 2, which is correct (one plane divides space into two half-spaces). Next S 2 = S 1 + (22 - 2 + 2) / 2 = 2 + 2 = 4, and again it is easy to see that this is correct. Similarly, S3 = S 2 + (3 2 - 3 + 2) /2 = 4 + 4 = 8, and we know that this is right from our familiarity with 3-dimensional graphing (space has eight octants). The first surprising case is n = 4, when we have S 4 = S3 + (42 - 4 + 2) /2 = 8 + 7 = 15. This takes some concentration to see (consider the plane x + y + z = 1 passing through space. It splits each octant into two parts except for the octant in which all coordinates are negative, because it does not pass through that octant. Thus 7 regions become 14, and the additional region makes a total of 15. b) The iteration here gets a little messy. We need to invoke two summation formulae from Table 2 in Section2.4: 1+2+3+···+n=n(n+l)/2and1 2 +2 2 +3 2 +···+n 2 =n(n+1)(2n+l)/6. We proceed as follows: n2 n sn = -2 - -2 + 1 + sn -1 2 2 2 2 n n ((n-1) (n-1) ) = - - - + 1+ - -- + 1 + 2 2 2 2 sn -2 2 (n-1) (n-2) = -n - -n + 1 + ((n-1) - - + 1) + ((n-2) - - + 1) + S -3 2 2 2 2 2 2 n Section 8.1 Applications of Recurrence Relations 267 2 2 _n - - -n+ 1 + ((n-1) - (n-1) + 2 2 2 2 2 + ( = ~ 2 21 - - = ~ (n(n+ 1)(2n+ 1) _ n(n+ n3 2 + ((n-2) - (n-2) + 2 2 i) +··· 1 ) "2+1 +So ((n 2 + (n -1) 2 + .. · + 12 ) 2 i) 6 2 (n + (n - 1) + .. · + 1)) + (1+1+ .. ·+1) + 1 1)) +n + 1 + 5n + 6 (after a little algebra). 6 Note that this answer agrees with that given in supplementary Exercise 50 of Chapter 5. 25. The easy way to do this problem is to invoke symmetry. A bit string of length 7 has an even number of O's if and only if it has an odd number of 1 's, since the sum of the number of O's and the number of 1's, namely 7, is odd. Because of the symmetric role of 0 and 1, there must be just as many 7-bit strings with an even number of O's as there are with an odd number of O's, each therefore being 27 /2 (since there are 27 bit strings altogether). Thus the answer is 21 - 1 = 64. The solution can also be found using recurrence relations. Let en be the number of bit strings of length n with an even number of O's. A bit string of length n with an even number of O's is either a bit string that starts with a 1 and is then followed by a bit string of length n - 1 with an even number of O's (of which there are en-l ), or else it starts with a 0 and is then followed by a bit string of length n -1 with an odd number of O's (of which there are 2n- 1 -en-1 ). Therefore we have the recurrence relation en = en-1 +(2n- 1 -en-1) = 2n- 1 . In other words, it is a recurrence relation that is its own solution. In our case, n = 7, so there are 21 - 1 = 64 such strings. (See also Exercise 31 in Section 6.4.) 27. We assume that the walkway is one tile in width and n tiles long, from start to finish. Thus we are talking about ternary sequences of length n that do not contain two consecutive O's, say. This was studied in Exercise 13, so the answers obtained there apply. We let an represent the desired quantity. a) As in Exercise 13, we find the recurrence relation to be an = 2an-l + 2an_ 2 . b) As in Exercise 13, the initial conditions are a 0 = 1 and a 1 = 3. c) Continuing the computation started in the solution to Exercise 13, we find a1 = 2a6 + 2a 5 = 2 · 448 + 2 · 164 = 1224. Thus there are 1224 such colored paths. 29. If the codomain has only one element, then there is only one function (namely the function that takes each element of the domain to the unique element of the codomain). Therefore when n = 1 we have S(m, n) = S(m, 1) = 1, the initial condition we are asked to verify. Now assume that m 2 n > 1, and we want to count S(m, n), the number of functions from a domain with m elements onto a codomain with n elements. The form of the recurrence relation we are supposed to verify suggests that what we want to do is to look at the non-onto functions. There are nm functions from the m-set to the n-set altogether (by the product rule, since we need to choose an element from the n-set, which can be done in n ways, a total of m times). Therefore we n-l must show that there are L C(n. k)S(m, k) functions from the domain to the codomain that are not onto. k=l First we use the sum rule and break this count down into the disjoint cases determined by the number of elements-let us call it k-in the range of the function. Since we want the function not to be onto, k can have any value from 1 to n - 1, but k cannot equal n. Once we have specified k, in order to specify a function we need to first specify the actual range, and this can be done in C(n, k) ways, namely choosing the subset of k elements from the codomain that are to constitute the range; and second choose an onto function from 268 Chapter 8 Advanced Counting Techniques the domain to this set of k elements. This latter task can be done in S(m, k) ways, since (and here is the key recursive point) we are defining S(m, k) to be precisely this number. Therefore by the product rule there are C(n, k)S(m, k) different functions with our original domain having a range of k elements, and so by the n-l sum rule there are I: C(n, k)S(m, k) non-onto functions from our original domain to our original codomain. k=l Note that this two-dimensional recurrence relation can be used to compute S(m, n) for any desired positive integers m and n. Using it is much easier than trying to list all onto functions. 31. We will see that the answer is too large for us to list all the possibilities by hand with a reasonable amount of effort. a) We know from Example 5 that C0 = 1, C1 = 1, and C3 = 5. It is also easy to see that C2 = 2, since there are only two ways to parenthesize the product of three numbers. We know from Exercise 30 that C4 = 14. Therefore the recurrence relation tells us that C5 = C 0 C 4 + C 1 C 3 + C 2 C 2 + C 3 C 1 + C 4C 0 1 . 14 + 1 . 5 + 2 . 2 + 5 . 1 + 14 . 1 = 42. b) Here n = 5, so the formula gives tC(lO, 5) = t ·10 · 9 · 8 · 7 · 6/5! = 42. 33. Obviously J(l) = 1. When n = 2, the second person is killed, so J(2) = 1. When n = 3, person 2 is killed off, then person 3 is skipped, so person 1 is killed, making J(3) = 3. When n = 4, the order of death is 2, 4, 3; so J(4) = 1. For n = 5, the order of death is 2, 4, 1, 5; so J(5) = 3. With pencil and paper (or a computer, if we feel like writing a little program), we find the remaining values: n 1 2 3 4 5 6 7 8 .JJ.nl 1 1 3 1 3 5 7 1 .JJ.nl n g 3 10 11 12 13 14 5 13 15 15 16 1 7 g 11 35. If the number of players is even (call it 2n), then after we have gone around the circle once we are back at the beginning, with two changes. First, the number assigned to every player has been changed, since all the even numbers are now missing. The first remaining player is 1, the second remaining player is 3, the third remaining player is 5, and so on. In general, the player in location i at this point is the player whose original number was 2i - 1 . Second, the number of players is half of what it used to be; it's now n. Therefore we know that the survivor will be the player currently occupying spot J(n), namely 2J(n) - 1. Thus we have shown that J(2n) = 2J(n) - 1. The argument when there are an odd number of players is similar. If there are 2n + 1 players, then after we have gone around the circle once and then killed off player 1, we will have n players left. The first remaining spot is occupied by player 3, the second remaining player is 5, and so on-the ith remaining player is 2i + 1. Therefore we know that the survivor will be the player currently occupying spot J(n), namely 2J(n) J(l) + 1. Thus we have shown that J(2n + 1) = 2J(n) + 1. The base case is clearly = 1. 37. We use the conjecture from Exercise 34: If n = 2m + k, where k < 2m, then J(n) = 2k + 1. Thus J(lOO) = J(2 6 + 36) = 2 · 36 + 1 = 73; J(lOOO) = J(2 9 + 488) = 2 · 488 + 1 = 977; and J(lOOOO) = J(2 13 + 1808) = 2 . 1808 + 1 = 3617. 39. It is not too hard to find the winning moves (here a~c means to move disk b from peg a to peg c, where we label the smallest disk 1 and the largest disk 4): 1____!:__,2, 1_2_.3, 2____!:__,3, 1~2, 1~4, 2~4, 3____!:__,2, Section 8.1 269 Applications of Recurrence Relations 3~4, 2____!:__.4. We can argue that at least seven moves are required no matter how many pegs we have: three to unstack the disks, one to move disk 4, and three more to restack them. We need to show that at least two additional moves are required because of the congestion caused by there being only four pegs. Note that in order to move disk 4 from peg 1 to peg 4, the other three disks must reside on pegs 2 and 3. That requires at least one move to restack them and one move to unstack them. This completes the argument. 41. It is helpful to do Exercise 40 first to get a feeling for what is going on. The base cases are obvious. If n > 1, then the algorithm consists of three stages. In the first stage, by the inductive hypothesis, it takes R(n - k) moves to transfer the smallest n - k disks to peg 2. Then by the usual Tower of Hanoi algorithm, it takes 2k - 1 moves to transfer the largest k disks (i.e., the rest of them) to peg 4, avoiding peg 2. Then again by induction, it takes R( n - k) moves to transfer the smallest n - k disks to peg 4; all the pegs are available for this work, since the largest disks, now residing on peg 4, do not interfere. The recurrence relation is therefore established. 43. First write R(n) = :L::;=l (R(j) - R(j - 1)), which is immediate from the telescoping nature of the sum (and the fact that R(O) = 0. By the result from Exercise 42, this is the sum of 2k'- 1 for this range of values of j (here j is playing the role that n played in Exercise 42, and k' is the value selected by the algorithm for j). But k' is constant (call this constant i) for i successive values of j. Therefore this sum is L~=l i2'- 1 , except that if n is not a triangular number, then the last few values when i = k are missing, and that is what the final term in the given expression accounts for. 45. By Exercise 43, R(n) is no greater than :L:::=l i2'- 1 . By using algebra and calculus, we can show that this equals (k+ 1)2k -2k+ 1 +1, so it is no greater than (k+ 1)2k. (The proof is to write the formula for a geometric series :L::7=o x' = (1 - xk+l) / ( 1 - x) , differentiate both sides, and simplify.) Since n > k( k - 1) /2, we see from ~ V i < 1 + ffn for all n > 1 . Therefore R( n) is bounded above by (1 + ffn + 1)21+v'2ri :::; 8 · Vii, 2v'2ri for all n > 2. This shows that R( n) is 0( Vii, 2v'2ri), as desired. the quadratic formula that k < + 2n + 47. We have to do Exercise 46 before we can do this exercise. a) We found that the first differences were 'Van= 0. Therefore the second differences are given by \7 2an 0- 0 = 0. b) We found that the first differences were \7 an given by \7 2 an = 2 - 2 = 0. = 2n - 2 (n c) We found that the first differences were 'Van = n 2 - = - 1) = 2. Therefore the second differences are (n - 1) 2 = 2n - 1. Therefore the second differences 2 are given by \7 an = (2n -1) - (2(n -1) -1) = 2. d) We found that the first differences were 'Van = 2n - 2n-l = 2n-l. Therefore the second differences are given by \72an = 2n-I - 2n-2 = 2n-2. 49. This is just an exercise in algebra. The right-hand side of the given expression is by definition an - 2Van + 'Van - 'Van-I =an - 'Van - 'Van-l =an - (an - an-I) - (an-I - an-2). Everything in this expression cancels except the last term, yielding an-2, as desired. 51. In order to express the recurrence relation an = an-I + an-2 in terms of an, Van, and \7 2an, we use the results of Exercise 48 (that an-l =an - Van) and Exercise 49 (that an-2 =an - 2Van + V 2 an)· Thus the given recurrence relation is equivalent to an = (an - \7 an)+ (an - 2\7 an+ \7 2an), which simplifies algebraically to an= 3\i'an - \7 2an. 53. Modify Algorithm 1 so that in addition to storing the value T(j) , the maximum number of attendees possible for an optimal schedule of the first j talks, we also store, for each j, a set S(j), which consists of the subscripts Chapter 8 270 Advanced Counting Techniques of a set of talks among the first j talks that can be scheduled to achieve a total of T(j) attendees. Initially we set S(O) equal to the empty set. At the point at which we compute T(j), we set S(j) equal to S(j - 1) if T(j) was set to T(j - 1), and we set S(j) equal to S(p(j)) U {j} otherwise. (If those two values are the same, then we have our choice-from a practical point of view, it would probably be better to see which choice resulted in more talks.) 55. We record the information in tabular form, filling in T(j) and S(j) line by line. For each j, if w 1 +T(p(j)):::; T(j -1), then in the lh line we just copy the information from the previous line. If w 1 +T(p(j)) > T(j-1), then we put w 1 + T(p(j)) in the T(j) column and put S(p(j)) U {j} in the S(j) column. a) J_ 0 1 2 3 4 5 6 7 IDl 0 0 1 0 0 2 4 ~ 20 10 50 30 15 25 40 I.ill 0 20 20 70 70 70 70 110 m.:u 0 {l} {1} {1,3} {1,3} {L 3} {1,3} {1,3,7} b) This time the answer is not unique. When we had to compute T(7) and S(7) we could achieve an attendance of 140 either with talks 1 and 6 or with talks 1, 3, and 7. J_ 0 1 2 3 4 5 6 7 1ilil 0 0 1 0 0 2 4 JJ2.ill I.ill Mil 100 5 10 20 25 --10 30 0 100 100 110 110 110 140 140 0 {l} {1} {1,3} {1,3} {1,3} {L6} {1,6} c) Here when we had to compute T(6) and S(6) we could achieve an attendance of 10 either with talks 1 and 3 or with talks 2 and 6. But the final answer is unique. i 0 1 2 3 4 5 6 7 mJl 0 0 1 0 0 2 4 ~ I.ill m.:u 2 3 8 5 4 7 10 0 2 3 10 10 10 10 20 0 {l} {2} {1,3} {1,3} {1,3} {1,3} {1,3, 7} Section 8.1 d) 271 Applications of Recurrence Relations .i 1ilil Jill.il Iill 0 0 0 0 10 10 8 7 10 17 {1} {1} 25 20 30 25 25 40 40 0 1 2 3 4 5 6 7 1 0 0 2 4 5 _§_ill {1,3} {4} {4} {1,6} {1,6} 57. a) By Example 5 the number of ways to parenthesize the product to determine the order in which to perform the multiplications is the Catalan number Cn. By Exercise 41 in Section 8.4, Cn > 2n-l. Therefore the brute-force method (to test all possible orders of multiplication) has exponential time complexity. b) The last step in computing A,1 is to multiply the m, x mk+l matrix A,k by the mk+l x m 1 +1 matrix Ak+l,J for some k between i and j - 1 inclusive, which will require m,mk+1m1 +1 integer multiplications, independent of the manner in which A,k and Ak+l,J are computed. Therefore to minimize the total number of integer multiplications, each of those two factors must be computed in the most efficient manner. c) This follows immediately from part (b) and the definition of M (i, j). We just try all j - i possible ways of splitting the product into two factors. d) In the algorithm shown here, M(i,j) is as defined in part (b), and where(i,j) is the value of k such that the calculation of A,j should be broken into the calculation of A,kAk+ 1,1 in order to achieve the fewest possible number of integer multiplications. Once all these values are computed, it is a simple matter to read off, using where(i,j), the proper order in which to carry out the matrix multiplications. (First, where(l,n) tells us which two subproducts to compute first, say A 1 r and Ar+l,n. Then where(l, r) and where(r + 1, n) tell us where to break those subproducts, and so on.) Notice that the main loop is indexed by d, which represents j - i in the notation of part ( c). procedure matrixorder(m 1 , ... , mn+I : positive integers) for i := 1 ton M(i, i) := 0 for d : = 1 to n - 1 for i := 1 to n - d min:= 0 for k := i to i + d new:= M(i, k) + M(k + 1, i + d) + m,mk+lmz+d+l if new < min then min:= new where(i, i + d) := k M(i, i + d) :=min e) The work in this algorithm is done by three nested loops, each of which is indexed over at most n values. 272 Chapter 8 SECTION 8.2 Advanced Counting Techniques Solving Linear Recurrence Relations In many ways this section is extremely straightforward. Theorems 1-6 give an algorithm for solving linear homogeneous recurrence relations with constant coefficients. The only difficulty that som etimes occurs is that the algebra involved becomes messy or impossible. (Although the fundam ental theorem of algebra says that every nth degree polynomial equation has exactly n roots (counting multiplicities), there is in general no way to find their exact values. For example, there is nothing analogous to the quadratic formula for equations of degree 5. Also, the roots may be irrational, as we saw in Example 4, or complex, as is discussed in Exercises 38 and 39. Patience is required with the algebra in s uch cases.) Many other techniques are available in other special cases, in analogy to the situation with differential equations; see Exercises 48-50, for example. If you have access to a computer algebra package, you should investigate how good it is at solving recurrences. See the solution to Exercise 49 for the kind of command to use in Maple. 1. a) This is linear (the terms ai all appear to the first power) , has constant coefficients ( 3, 4, and 5 ), and is homogeneous (no terms are functions of just n) . It has degree 3 , since an is expressed in terms of an-1, an-2 , and an-3 . b) This does not have constant coefficients, since the coefficient of an- I is the nonconstant 2n. c) This is linear, homogeneous, with constant coefficients. It has degree 4, since an is expressed in terms of an-l , an-2, an-3 and an- 4 (the fact that the coefficient of an-2 , for example, is 0 is irrelevant- the degree is the largest k such that an-k is present). d) This is not homogeneous because of the 2 . e) This is not linear, since the t erm a~_ 1 appears. f) This is linear, homogeneous, with constant coefficients . It has degree 2. g) This is linear but not homogeneous because of the n. 3. a) We can solve this problem by iteration (or even by inspection), but let us use the techniques in this section instead . The characteristic equation is r - 2 = 0, so the only root is r = 2 . T herefore the general solution to the recurrence relation, by Theorem 3 (with k = 1), is an= a2n for some constant a:. We plug in the initial condition to solve for a. Since a0 = 3 we have 3 = a:2°, whence a: = 3 . Therefore the solution is an = 3 · 2n . b) Again this is trivial to solve by inspection, but let us use the algorithm. The characteristic equation is r - 1 = 0 , so the only root is r = 1 . Therefore the general solution to the recurrence relation, by Theorem 3 (with k = 1), is an= a:ln =a for some constant a:. In other words, the sequence is const ant. We plug in the initial condition to solve for a: . Since ao = 2 we have a: = 2. Therefore the solution is an = 2 for all n. c) T he characteristic equation is r 2 - 5r + 6 = 0, which factors as (r - 2)(r - 3) = 0 , so the roots are r = 2 and r = 3. Therefore by Theorem 1 the general solution to the recurrence relation is an = Q1 2n + a: 2 3n for some constants Q1 and Q2 . 'vVe plug in the initial condition to solve for the Q's . Since a0 = 1 we have 1 = a 1 + a 2 , and since a 1 = 0 we have 0 = 2a: 1 + 3Q2 . These linear equations are easily solved to yield a 1 = 3 and a: 2 = - 2. Therefore the solution is an = 3 · 2n - 2 · 3n. d) The characteristic equation is r 2 - 4r +4 = 0 , which factors as (r - 2) 2 = 0, so t here is only one root, r = 2, which occurs with multiplicity 2 . Therefore by T heorem 2 the general solution to the recurrence relation is an = Q1 2n + a: 2 n2n for some constants a: 1 and a: 2 . We plug in the initial conditions to solve for the Q's . Since a0 = 6 we have 6 = a 1 , and since a 1 = 8 we have 8 = 2Q 1 + 2a: 2 . These linear equations are easily solved to yield a 1 = 6 and Q2 = -2 . Therefore the solution is an = 6 · 2n - 2 · n2n = (6 - 2n)2n. Incidentally, there is a good way to check a solution to a recurrence relation problem, namely by calculating the next t erm in two ways. In this exercise, the recurrence relation tells us that a 2 = 4a 1 - 4ao = 4 · 8 - 4 · 6 = 8, whereas the solution tells us that a 2 = (6 - 2 · 2)2 2 = 8. Since these answers agree, we a.re somewhat confident t hat our solution is correct. We could calculate a 3 in two ways for another confirmation. e) This time the characteristic equation is r 2 + 4r + 4 = 0, which factors as (r + 2) 2 = 0, so again t here is only one root, r = -2, which occurs with multiplicity 2. Therefore by Theorem 2 the general solution to Section 8.2 Solving Linear Recurrence Relations 273 the recurrence relation is an = a: 1 (-2)n + a: 2 n( -2)n for some constants a: 1 and a: 2 . We plug in the initial conditions to solve for the a:'s. Since a0 = 0 we have 0 = a: 1 , and since a 1 = 1 we have 1 = -2a: 1 - 2a: 2 . These linear equations are easily solved to yield a: 1 = 0 and a: 2 = - 1/2. Therefore the solution is an = (-1/2)n(-2)n = n(-2)n-l. f) The characteristic equation is r 2 - 4 = 0, so the roots are r = 2 and r = -2. Therefore the solution is an = a: 12n + a: 2(-2)n for some constants a: 1 and a: 2 . We plug in the initial conditions to solve for the a: 's. 'vVe have 0 = a: 1 + a: 2 , and 4 = 2a: 1 - 2a: 2 . These linear equations are easily solved to yield a: 1 = 1 and 0:2 = -1. Therefore the solution is an = 2n - ( -2)n. g) The characteristic equation is r 2 - 1/ 4 = 0, so the roots are r = 1/2 and r = -1/2. Therefore the solution is an = a: 1(1/2)n + a: 2(-l/2)n for some constants a: 1 and a: 2 . We plug in the initial conditions to solve for the a:'s. 'vVe have 1 = a: 1 + a: 2 , and 0 = a: 1/2 - a: 2/2. These linear equations are easily solved to yield a: 1 =0:2=1/2. Therefore the solution is an= (l/2)(1/2)n + (1/2)(-l/2)n = (l/2)n+l - (-1/2)n+ 1 . 5. The recurrence relation found in Exercise 19 of Section 8.1 was an = an-I + an- 2 , with initial conditions a0 = a 1 = 1. To solve this, we look at the characteristic equation r 2 - r - 1 = 0 (exactly as in Example 4) and obtain, by the quadratic formula, the roots r 1 = (1 + v'5) /2 and r 2 = (1- v'5) /2. Therefore from Theorem 1 we know that the solution is given by an = 0:1 ( 1 +-J5) n + 0:2 2 1 ---J5) n , 2 ( for some constants a: 1 and a: 2 . The initial conditions a0 = 1 and a 1 = 1 allow us to determine these constants. We plug them into the equation displayed above and obtain 1=ao=0:1 + 0:2 1=a1=0:1(1+2v'5)+0:2 e-2v'5) By algebra we solve these equations (one way is to solve the first for a: 2 in terms of a: 1 , and plug that into the second equation to get one equation in a: 1 , which can then be solved-the fact that these coefficients are messy irrational numbers involving J5 does not change the rules of algebra, of course) . The solutions are a: 1 = (5 + v'5) / 10 and 0:2 = (5 - v'5) /10. Therefore the specific solution is given by a = 5+J5 (l+J5) n 10 n 2 + 5-J5 (l-J5)n 10 2 Alternatively, by not rationalizing the denominators when we solve for a: 1 and a: 2 , we get a: 1 = (1 +J5) / (2v'5) and a: 2 = -(1- v'5)/(2v'5). With these expressions, we can write our solution as a =-1 n J5 l+v'5 ( 2 ) n+l __ l J5 ( l-v'5 2 ) n+l . 7. First we need to find a recurrence relation and initial conditions for the problem. Let tn be the number of ways to tile a 2 x n board with 1 x 2 and 2 x 2 pieces. To obtain the recurrence relation , imagine what tiles are placed at the left-hand end of the board. We can place a 2 x 2 tile there, leaving a 2 x (n - 2) board to be tiled, which of course can be done in tn_ 2 ways. We can place a 1 x 2 tile at the edge, oriented vertically, leaving a 2 x (n - 1) board to be tiled, which of course can be done in tn-l ways. Finally, we can place two 1x2 tiles horizontally, one above the other, leaving a 2 x (n -2) board to be tiled, which of course can be done in tn_ 2 ways. These three possibilities are disjoint. Therefore our recurrence relation is tn = tn-l + 2tn_ 2 . The initial conditions are t 0 = t 1 = 1 , since there is only one way to tile a 2 x 0 board (the way that uses 274 Chapter 8 Advanced Counting Techniques no tiles) and only one way to tile a 2 x 1 board. This recurrence relation is the same one that appeared in Example 3; it has characteristic roots 2 and -1, so the general solution is tn = a12n + a2(-lt. To determine the coefficients we plug in the initial conditions, giving us the equations 1 =to= a1 Solving these yields a 1 = 2/3 and a 2 = + a2 1 = ti = 2a1 - a2 . 1/3, so our final solution is t,,, 9. a) The amount Pn in the account at the end of the nth = 2n+i /3 + (-1r /3. year is equal to the amount at the end of the previous year (Pn-l ), plus the 20% dividend on that amount (0.2P,,_ 1 ) plus the 45% dividend on the amount at the end of the year before that (0.45Pn-2). Thus we have Pn = l.2Pn-1 +0.45Pn_ 2 . We need two initial conditions, since the equation has degree 2. Clearly Po = 100000. The other initial condition is that P 1 = 120000, since there is only one dividend at the end of the first year. b) Solving this recurrence relation requires looking at the characteristic equation r 2 - l.2r - 0.45 = 0. By the quadratic formula, the roots are r1 = 1.5 and r2 = -0.3. Therefore the general solution of the recurrence relation is Pn = a 1(1.5)n + a 2(-0.3)n. Plugging in the initial conditions gives us the equations 100000 = a 1 + a 2 and 120000 = 1.5a1 - 0.3a2. These are easily solved to give a 1 = 250000/3 and a 2 = 50000/3. Therefore the solution of our problem is Pn = 250;00 (1. 5 )" + 50~00 (-0. 3 )n. 1 we have L 1 = 1 = 0 + 1 = f o + h; and for n = 2 we have L2 = 3 = 1 + 2 = Ji + h. Assume the inductive hypothesis that Lk = fk-1 + fk+l for k < n. We must show that Ln = f n-1 + fn+l · To do this, we let k = n - 1 and k = n - 2: Ln-1 = fn-2 +Jn 11. a) We prove this by induction on n. We need to verify two base cases. For n Ln-2 = = + Jn-1 · fn-3 If we add these two equations, we obtain Ln-1 + Ln-2 = Un-2 + fn-3) +Un+ fn-1)' which is the same as Ln = Jn-1 + fn+l as desired, using the recurrence relations for the Lucas and Fibonacci numbers. b) To find an explicit formula for the Lucas numbers, we need to solve the recurrence relation and initial conditions. Since the recurrence relation is the same as that of the Fibonacci numbers, we get the same general solution as in Example 4, namely Ln = a1 ( 1 +2 JS) n + 0'.2 ( 1 -2 JS) n ' for some constants a 1 and a 2 . The initial conditions are different, though. When we plug them in we get the system 2 =Lo= a1 + a2 1 = L1 = a1 ( 1 By algebra we solve these equations, yielding a 1 Ln = ( 1 +2 JS) + +2 = a 1 = 1. JS) a2 ( 1 - JS) 2 Therefore the specific solution is given by n + ( 1 -2 JS) n Section 8.2 275 Solving Linear Recurrence Relations 13. This is a third degree equation. The characteristic equation is r 3 - 7r - 6 = 0. Assuming the composer of the problem has arranged that the roots are nice numbers, we use the rational root test, which says that rational roots must be of the form ±p/ q, where p is a factor of the constant term ( 6 in this case) and q is a factor of the coefficient of the leading term (the coefficient of r 3 is 1 in this case). Hence the possible rational roots are ±1, ±2, ±3, ±6. We find that r = -1 is a root, so one factor of r 3 - 7r + 6 is r + 1. Dividing r + 1 into r 3 - 7r - 6 by long (or synthetic) division, we find that r 3 - 7r - 6 = (r + l)(r 2 - r - 6). By inspection we factor the rest, obtaining r 3 - 7r -6 = (r+ l)(r-3)(r+2). Hence the roots are -1, 3, and -2, so the general solution is an = a 1 ( + a 2 3n + a 3 ( To find these coefficients, we plug in the initial conditions: -1 r -2r. 9 = ao = a1 + 0:2 + 0:3 10 = a1 = -0:1 + 30:2 - 20:3 32 = a3 = a1 + 9a2 + 4a3 . Solving this system of equations (by elimination, for instance), we get a 1 Therefore the specific solution is an = 8(-l)n + 4 · 3n - 3(-2)n. 4, and a 3 -3. 15. This is a third degree recurrence relation. The characteristic equation is r 3 - 2r 2 - 5r + 6 = 0. By the rational root test, the possible rational roots are ±1,±2,±3.±6. We find that r = 1 is a root. Dividing r - l into r 3 - 2r 2 - 5r + 6, we find that r 3 - 2r 2 - 5r + 6 = (r - l)(r 2 - r - 6). By inspection we factor the rest, obtaining r 3 - 2r 2 - 5r + 6 = (r - l)(r - 3)(r + 2). Hence the roots are 1, 3, and -2, so the general solution is an = 0:11 n + a23n + a3(-2r, or more simply an = a 1 + 0:23" + a3(-2r. To find these coefficients, we plug in the initial conditions: 7 = ao = 0:1 + a2 + 0:3 + 3a2 - 2a3 a1 + 9a2 + 4a3 . -4 = ai = a1 8 = a2 = Solving this system of equations, we get a 1 an = 5 - 3n + 3(-2)n. = 5, a 2 = -1 , and a 3 = 3. Therefore the specific solution is 17. We almost follow the hint and let an+I be the right-hand side of the stated identity. Clearly a1 = C(O, 0) = 1 and a 2 = C (1, 0) = 1. Thus a 1 = Ji and a 2 = h. Now if we can show that the sequence {an} satisfies the same recurrence relation that the Fibonacci numbers do, namely an+l = an + an-1, then we will know that an = fn for all n 2 1 (precisely what we want to show), since the solution of a second degree recurrence relation with two initial conditions is unique. To show that an+I = an +an-I, we start with the right-hand side, which is, by our definition, C(n l,O)+C(n-2,l)+···+C(n-l-k,k)+C(n-2,0)+C(n-3,l)+···+C(n-2-l,l), where k = L(n-1)/2j and l = L(n - 2)/2j. Note that k = l if n is even, and k = l + 1 if n is odd. Let us first take the case in which k = l = (n - 2)/2. By Pascal's identity, we regroup the sum above and rewrite it as C(n - 1, 0) + [C(n - 2, 0) + C(n - 2, 1)] + [C(n - 3, 1) + C(n - 3, 2)] + · · · + [C(n - 2 - ((n - 2)/2 - 1), (n - 2)/2 - 1) + C(n - 1 - (n - 2)/2, (n - 2)/2)] + C(n - 2 - (n - 2)/2, (n - 2)/2) = C(n - 1,0) + C(n -1, 1) + C(n - 2,2) + · · · + C(n - (n - 2)/2, (n - 2)/2) = 1 + C(n - 1, 1) + C(n - + C(n - 1, 1) + + C(n - 2 - (n - 2)/2, (n - 2)/2) + · · · + C(n - (n - 2)/2, (n - 2)/2) + 1 C(n - 2, 2) + · · · + C(n - (n - 2)/2, (n - 2)/2) + 2, 2) = C(n, 0) = C(n, 0) + C(n - 1, 1) + C(n - 2, 2) + · · · + C(n - j,j), C(n - n/2, n/2) where j = n/2 = Ln/2j. This is precisely an+l • as desired. In case n is odd, so that k = (n - 1)/2 and l = (n - 3)/2, we have a similar calculation (in this case the sum involving k has one more term than the Chapter 8 276 Advanced Counting Techniques sum involving l): C(n - 1, 0) + [C(n - 2, 0) + C(n - 2, 1)] + [C(n - 3, 1) + C(n - 3, 2)] + · · · + [C(n - 2 - (n - 3)/2, (n - 3)/2) + C(n - 1 - (n - 1)/2, (n - 1)/2)] = C(n - 1, 0) + C(n = 1, 1) + C(n - 2, 2) + · · · + C(n - (n - 1)/2, (n - 1)/2) 1 + C(n - 1, 1) + C(n - 2, 2) + .. · + C(n - (n - 1)/2, (n - 1)/2) = C(n, 0) + C(n - 1, 1) + C(n - 2, 2) + .. · + C(n - j,j), where j = (n - 1)/2 = ln/2J. Again, this is precisely an+ 1 , as desired. 19. This is a third degree recurrence relation. The characteristic equation is r 3 + 3r 2 + 3r + 1 = 0. We easily recognize this polynomial as (r + 1) 3 . Hence the only root is -1, with multiplicity 3, so the general solution is (by Theorem 4) an conditions: = a1 ( -1 r + a2n(- l r + a3n 2(-1 r. To find these coefficients, we plug in the initial 5 = ao = a1 -9 = al = -a1 - a2 - a3 15 = a2 = a1 + 2a2 + 4a3 Solving this system of equations, we get a 1 = 5, a2 = 3, and a 3 = 1. Therefore the answer is an = 5( -1)n+3n( -1 + n 2 ( -1 )n. We could also write this in factored form, of course, as an = (n 2 + 3n+ 5)( - l)n. As a check of our answer, we can calculate a3 both from the recurrence and from our formula, and we find that it comes out to be - 23 in both cases. r 21. This is similar to Example 6. We can immediately write down the general solution using Theorem 4. In this case there are four distinct roots, so t = 4. The multiplicities are 4, 3, 2, and 1. So the general solution is an= (a1,o + al,ln + a1,2n 2 + a1,3n 3) + (a2,o + 0:2,1n + a2,2n 2)(-2)n + (a3,o + a3,1n)3n + a4,o(-4)n. 23. Theorem 5 tells us that the general solution to the inhomogeneous linear recurrence relation can be found by finding one particular solution of this recurrence relation and adding it to the general solution of the corresponding homogeneous recurrence relation If we let f n be the particular solution to the inhomogeneous recurrence relation and gn be the general solution to the homogeneous recurrence relation (which will have some unspecified parameters a 1 , a 2 , ... , ak ), then the general solution to the inhomogeneous recurrence relation is f n + gn (so it, too, will have some unspecified parameters a1, a2, ... , ak ). a) To show that an= -2n+i is a solution to an = 3an-l +2n, we simply substitute it in and see if we get a true statement. Upon substituting into the right-hand side we get 3an-l +2n = 3(-2n)+2n = 2n(-3+1) = -2n+l, which is precisely the left-hand side. b) By Theorem 5 and the comments above, we need to find the general solution to the corresponding homogeneous recurrence relation an = 3an-l. This is easily seen to be an = a3n (either by the iterative method or by the method of this section with a linear characteristic equation). Putting these together as discussed above, we find the general solution to the given recurrence relation: an = a3n - 2n+l. c) To find the solution with a 0 = 1, we need to plug this initial condition (where n = 0) into our answer to part (b). Doing so gives the equation 1 = a - 2, whence a = 3. Therefore the solution to the given recurrence relation and initial condition is an = 3 · 3n - 2n+i = 3n+l - 2n+l. Section 8.2 Solving Linear Recurrence Relations 277 25. See the introductory remarks to Exercise 23, which apply here as well. a) We solve this problem by wishful thinking. Suppose that an = An + B, and substitute into the given recurrence relation. This gives us An+B = 2(A(n-l)+B)+n+5, which simplifies to (A+l)n+(-2A+B+5) = 0. Now if this is going to be true for all n, then both of the quantities in parentheses will have to be 0. In other words, we need to solve the simultaneous equations A+ 1 = 0 and -2A + B + 5 = 0. The solution is A = -1 and B = - 7. Therefore a solution to the recurrence relation is an = -n - 7. b) By Theorem 5 and the comments at the beginning of Exercise 23, we need to find the general solution to the corresponding homogeneous recurrence relation an = 2an- 1 . This is easily seen to be an = a2n (either by the iterative method or by the method of this section with a linear characteristic equation). Putting these together as discussed above, we find the general solution to the given recurrence relation: an = a2n - n - 7. c) To find the solution with a 0 = 4, we need to plug this initial condition (where n = 0) into our answer to part (b). Doing so gives the equation 4 = a - 7, whence a = 11. Therefore the solution to the given recurrence relation and initial condition is an = 11 · 2n - n - 7. 27. We need to use Theorem 6, and so we need to find the roots of the characteristic polynomial of the associated homogeneous recurrence relation. The characteristic equation is r 4 -8r 2 +16 = 0 , and as we saw in Exercise 20, r = ±2 are the only roots, each with multiplicity 2. a) Since 1 is not a root of the characteristic polynomial of the associated homogeneous recurrence relation, Theorem 6 tells us that the particular solution will be of the form p 3 n 3 here, in the notation of Theorem 6. + p 2 n 2 + p 1 n +Po. Note that s = 1 b) Since -2 is a root with multiplicity 2 of the characteristic polynomial of the associated homogeneous recurrence relation, Theorem 6 tells us that the particular solution will be of the form n 2 p 0 (-2r. c) Since 2 is a root with multiplicity 2 of the characteristic polynomial of the associated homogeneous recurrence relation, Theorem 6 tells us that the particular solution will be of the form n 2 (p 1 n + p0 )2n. d) Since 4 is not a root of the characteristic polynomial of the associated homogeneous recurrence relation, Theorem 6 tells us that the particular solution will be of the form (p2n 2 + p 1 n + p 0 )4n. e) Since -2 is a root with multiplicity 2 of the characteristic polynomial of the associated homogeneous recurrence relation, Theorem 6 tells us that the particular solution will be of the form n 2 (p 2 n 2 +p 1 n+p0 )(-2)n. Note that we needed a second degree polynomial inside the parenthetical expression because the polynomial in F(n) was second degree. f) Since 2 is a root with multiplicity 2 of the characteristic polynomial of the associated homogeneous recurrence relation, Theorem 6 tells us that the particular solution will be of the form n 2 (p 4 n 4 +p3 n 3 +p2 n 2 +p 1 n+p0 )2n. g) Since 1 is not a root of the characteristic polynomial of the associated homogeneous recurrence relation, Theorem 6 tells us that the particular solution will be of the form p0 . Note that s = 1 here, in the notation of Theorem 6. 29. a) The associated homogeneous recurrence relation is an = 2an-l. We easily solve it to obtain ath) = a2". Next we need a particular solution to the given recurrence relation. By Theorem 6 we want to look for a function of the form an = c · 3n. We plug this into our recurrence relation and obtain c · 3n = 2c · 3n-l + 3n. We divide through by 3n-l and simplify, to find easily that c = 3. Therefore the particular solution we seek is a~) = 3 · 3n = 3n+l. So the general solution is the sum of the homogeneous solution and this particular solution, namely an = a2n + 3n+l. b) We plug the initial condition into our solution from part (a) to obtain 5 = a 1 = 2a + 9. This tells us that a = -2. So the solution is an = - 2 · 2n + = -2n+l + 3n+l . At this point it would be very useful to check our answer. One method is to let a computer do the work; a computer algebra package such as Maple will solve equations of this type (see Exercise 49 for the syntax of the command). Alternatively, we can compute the next term of the sequence in two ways and verify that we obtain the same answer in each case. From the 3n+ 1 Chapter 8 278 recurrence relation, we expect that a 2 that a 2 = -2 2 +1 is correct. Advanced Counting Techniques = 2 · a 1 + 32 = 2 · 5 + 9 = 19. On the other hand, our solution tells us + 32 +1 = -8 + 27 = 19. Since the values agree, we can be fairly confident that our solution 31. The associated homogeneous recurrence relation is an = 5an-l - 6a,,_ 2 . To solve it we find the characteristic equation r 2 - 5r + 6 = 0, find that r = 2 and r = 3 are its solutions, and therefore obtain the homogeneous solution a~h) = o2n + µ3n. Next we need a particular solution to the given recurrence relation. By using the idea in Theorem 6 twice (or following the hint), we want to look for a function of the form a,, = en· 2n + dn + e. (The reason for the factor n in front of 2n is that 2" was already a solution of the homogeneous equation. The reason for the term dn + e is the first degree polynomial 3n.) We plug this into our recurrence relation and obtain cn·2n+dn+e = 5c(n-1)·2n-l +5d(n-1)+5e-6c(n-2) .2n- 2 -6d(n-2)-6e+2n+3n. In order for this equation to be true, the exponential parts must be equal, and the polynomial parts must be equal. Therefore we have c · 2n = 5c(n -1) · 2n-l - 6c(n - 2) · 2n- 2 + 2" and dn + e = 5d(n - 1) + 5e - 6d(n - 2) - 6e + 3n. To solve the first of these equations, we divide through by 2n- 1 , obtaining 2e = 5c(n-1) -3e(n - 2) + 2, whence a little algebra yields c = -2. To solve the second equation, we note that the coefficients of n as well as the constant terms must be equal on each side, so we know that d = 5d-6d+3 and e = -5d+5e+ 12d-6e. This tells us that d = 3/2 and e = 21/4. Therefore the particular solution we seek is a~)= -2n·2n+3n/2+21/4. So the general solution is the sum of the homogeneous solution and this particular solution, namely an = a2n + (33n - 2n · 2" + 3n/2 + 21/4 = a2n + (33n - n · 211 + 1 + 3n/2 + 21/4. 33. The associated homogeneous recurrence relation is a 11 = 4an-l - 4a,,_2. To solve it we find the characteristic equation r 2 - 4r + 4 = 0, find that r = 2 is a repeated root, and therefore obtain the homogeneous solution a~h) = a2n +(Jn· 2n. Next we need a particular solution to the given recurrence relation. By Theorem 6 we want to look for a function of the form a,, = n 2 (en+ d)2n. (The reason for the factor en+ d is that there is a linear polynomial factor in front of 2" in the nonhomogeneous term; the reason for the factor n 2 is that the root r = 2 already appears twice in the associated homogeneous relation.) We plug this into our recurrence relation and obtain n 2 (en+d)2n = 4(n-1)2(en-e+d)2n-l -4(n-2) 2 (en-2e+d)2 11 - 2 +(n+1)2". We divide through by 2n, obtaining n 2 (cn + d) = 2(n - 1) 2 (en - e + d) - (n - 2) 2 (en - 2e + d) + (n + 1). Some algebra transforms this into en 3 + dn 2 = en 3 + dn 2 + (-6e + 1 )n + (6e - 2d + 1) . Equating like powers of n tells us that e = 1/6 and d = l. Therefore the particular solution we seek is a~)= n 2 (n/6+ 1)2". So the general solution is the sum of the homogeneous solution and this particular solution, namely an= (o + f3n + n 2 + n 3 /6)2n. 35. The associated homogeneous recurrence relation is a,, = 4a,,_ 1 - 3an_ 2 . To solve it we find the characteristic equation r 2 - 4r + 3 = 0, find that r = 1 and r = 3 are its solutions, and therefore obtain the homogeneous solution a~h) = a+ (33". Next we need a particular solution to the given recurrence relation. By using the idea in Theorem 6 twice, we want to look for a function of the form an = e · 2" + n( dn + e) = c · 2n + dn 2 +en. (The factor n in front of (dn + e) is needed since 1 is already a root of the characteristic polynomial.) We plug this into our recurrence relation and obtain e · 2n + dn 2 +en= 4c · 2n-l + 4d(n - 1) 2 + 4e(n - 1) - 3e · 2n- 2 - 3d( n - 2) 2 - 3e( n - 2) + 2n + n + 3. A lot of messy algebra transforms this into the following equation, where we group by function of n: 2"- 2 (-e - 4) + n 2 · 0 + n(-4d - 1) + (8d - 2e - 3) = 0. The coefficients must therefore all be 0, whence c = -4, d = -1/ 4, and e = -5/2. Therefore the particular solution we seek is a}f l = -4 · 2" - n 2 /4 - 5n/2. So the general solution is the sum of the homogeneous solution and this particular solution, namely a11 = -4 · 2" - n 2 /4 - 5n/2 +a+ (33". Next we plug in the initial conditions to obtain 1 = ao = -4 +a+ (3 and 4 = a 1 = -8 - 11/4 +a+ 3(3. We solve this system of equations to obtain a = 1/8 and f3 = 39 /8. So the final solution is an = -4 · 2n - n 2 / 4 - 5n/2 + 1/8 + (39 /8)3". As a check of our work (it would be too much to hope that we could always get this far without making an algebraic error), we can compute a 2 both from the recurrence and from the solution, and we find that a2 = 22 both ways. Section 8.2 279 Solving Linear Recurrence Relations 37. Obviously the nth term of the sequence comes from the (n - l)st term by adding the nth triangular number; in symbols, an-l + n(n + 1)/2 = (I:~:=i k(k + 1)/2) + n(n + 1)/2 = L~=l k(k + 1)/2 = an. Also, the sum of the first triangular number is clearly 1. To solve this recurrence relation, we easily see that the homogeneous solution is a~h) = a, so since the nonhomogeneous term is a second degree polynomial, we need a particular solution of the form an = cn 3 + dn 2 + en. Plugging this into the recurrence relation gives cn 3 + dn 2 +en = c(n - 1) 3 + d(n - 1) 2 + e(n - 1) + n(n + 1)/2. Expanding and collecting terms, we have (3c- ~)n 2 + (-3c+2d- ~)n+ (c-d+e) = 0, whence c = i, d =~,and e = i. Thus a~) = in 3 + ~n 2 +in. So the general solution is an = a+ in 3 + ~n 2 + in. It is now a simple matter to plug in the initial condition a 1 = 1 to see that a = 0. Note that we can find a common denominator and write our solution in the nice form an= n(n + l)(n + 2)/6, which is the binomial coefficient C(n + 2, 3). 39. Nothing in the discussion of solving recurrence relations by the methods of this section relies on the roots of the characteristic equation being real numbers. Sometimes the roots are complex numbers (involving i = J=T). The situation is analogous to the fact that we sometimes get irrational numbers when solving the characteristic equation (for example, for the Fibonacci numbers), even though the coefficients are all integers and the terms in the sequence are all integers. It is just that we need irrational numbers in order to write down an algebraic solution. Here we need complex numbers in order to write down an algebraic solution, even though all the terms in the sequence are real. a) The characteristic equation is r 4 - 1 = 0. This factors as (r - 1) (r + 1) (r 2 + 1) = 0 , so the roots are r = 1 and r = -1 (from the first two factors) and r = i and r = -i (from the third factor). b) By our work in part (a), the general solution to the recurrence relation is an = a 1 + a 2( -1 )n + a3in + a 4(-ir. In order to figure out the a's we plug in the initial conditions, yielding the following system of linear equations: 1 = ao = 0:1 + 0:2 + a3 + a4 0= -1 ai = a2 = 0:1 - 0:2 + ia3 - ia4 = a1 + a2 - a3 - a4 1 = a3 = a1 - a2 - ia3 + ia4 Remembering that i is just a constant, we solve this system by elimination or other means. For instance, we could begin by subtracting the third equation from the first, to give 2 = 20:3 + 2a 4 and subtracting the fourth from the second to give -1 = 2ia 3 - 2ia4 . This gives us two equation in two unknowns. Solving them yields a3 = (2i - 1) / (4i) which can be put into nicer form by multiplying by i / i, so a3 = (2 + i) / 4; and then a4 = 1- a3 = (2 - i)/4. We plug these values back into the first and fourth equations, obtaining a1 + a2 = 0 and a 1 - a 2 = 1/2. These tell us that a1 = 1/4 and a 2 = -1/4. Therefore the answer to the problem is an= 2-i( ')n 41 - 41( -1 )n + -2+i.n -z + - - - i . 4 4 41. a) To '"Y that fn ;, the integec elos"t to these two numbers is less than ~. ~ ( 1 +2,/5)" ;, to 'ay that the ab,olote difference between I~ But the difference is just ( vs) nl. 1 -2 Thus we are asked to show that this latter number is less than ~. The value within the parentheses is about -0.62. When raised to the nth power, for n 2". 0, we get a number of absolute value less than or equal to 1. When we then divide by VS (which is greater than 2), we get a number less than ~ , as desired. b) Clearly the second term in the formula for f n alternates sign as n increases: a positive number is being subtracted for n even, and a negative number is being subtracted for n odd. Therefore fn is less than J5) 1 ( -1+ J5 2 n for even n and greater than J5) 1 ( -1+ J5 2 n for odd n. Chapter 8 280 Advanced Counting Techniques 43. We follow the hint and let bn = an + 1, or, equivalently, an = bn - 1. Then the recurrence relation becomes bn -1 = bn-1 -1 +bn-2-1+1, or bn = bn-1 +bn-2; and the initial conditions become bo = ao + 1=o+1=1 and b1 = a 1 + 1 = 1 + 1 = 2. We now apply the result of Exercise 42, with b playing the role of a, and s = 1 and t = 2, to get bn = fn-1 + 2fn. Therefore an = fn-1 + 2fn - 1. We can check this with a few small values of n: for n = 2, our solution predicts that a2 = Ji + 2f2 - 1 = 1 + 2 · 1 - 1 = 2; similarly, a 3 = h + 2f3 - 1 = 1 + 2 · 2 - 1 = 4 and a 4 = 7. These are precisely the values we would get by applying directly the recurrence relation defining an in this problem. A reality check like this is a good way to increase the chances that we haven't made a mistake. An alternative answer is an = f n+2 - 1. We can prove this as follows: fn-1 + 2fn - 1 = fn-1 + fn + fn - 1 = fn+l + fn - 1 = fn+2 - 1 45. Let an be the desired quantity, the number of pairs of rabbits on the island after n months. So ao = 1, since one pair is there initially. We need to read the problem carefully and decide how we will interpret what it says. Since a pair produces two new pairs ''at the age of one month" and six new pairs "at the age of two months" and every month thereafter, the original pair has already produced two new pairs at the end of one month, so a 1 = 3 (the original pair plus two new pairs), and a2 = 3 + 6 + 4 = 13 (the three pairs that were already there, six new pairs produced by the original inhabitants, and two new pairs produced by each of the two pairs born at the end of the first month). If you interpret the wording to imply that births do not occur until after the month has finished, then naturally you will get different answers from those we are about to find. a) We already have stated the initial conditions a0 = 1 and a 1 = 3. To obtain a recurrence relation for an, the number of pairs of rabbits present at the end of the nth month, we observe (as was the case in analyzing Fibonacci's example) that all the rabbit pairs who were present at the end of the (n - 2)nd month will give rise to six new ones, giving us 6an_ 2 new pairs; and all the rabbit pairs who were present at the end of the (n- l)st month but not at the end of the (n-2)nd month will give rise to two new ones, namely 2(an-1 -an-2) new pairs. Of course, the an-l pairs who were there stay around as well. Thus our recurrence relation is an = 6an-2 + 2(an-1 - an-2) + an-1, or, more simply, an = 3an-1 + 4an-2. As a check, we compute that a 2 = 3 · 3 + 4 · 1 = 13, which is the number we got above. b) We proceed by the method of this section, as we did in, say, Exercise 3. The characteristic equation is r 2 - 3r - 4 = 0, which factors as (r - 4)(r + 1) = 0, so we get roots 4 and -1. Thus the general solution is an = oo 1 4n + 00 2(-1) 11 • Plugging in the initial conditions ao = 1 and a 1 = 3, we find 1=00 1 +002 and 3 = 4oo 1 - 00 2 , which are easily solved to yield 00 1 = 4/ 5 and 00 2 = 1/5. Therefore the number of pairs of rabbits on the island after n months is an= 4 · 4n /5 + (-l)n /5 = (4n+l + (-l)n)/5. As a check, we see that a 2 =(4 3 +1)/5 = 65/5 = 13, the number we found above. 47. Let an be the employee's salary for the nth year of employment, in tens of thousands of dollars (this makes the numbers easier to work with). Thus we are told that a 1 = 5, and applying the given rule for raises, we have a 2 = 2 · 5 + 1 = 11 , a 3 = 2 · 11 + 2 = 24, and so on. a) For her nth year of employment, she has n - 1 years of experience, so the raise rule says that an = 2a 11 _ 1 + (n - 1). (Remember that we are using $10,000 as the unit of pay here.) b) The associated homogeneous recurrence relation is an = 2an-l, which clearly has the solution a~h) = oo2n. For the particular solution of the given relation, we note that the nonhomogeneous term is a linear function of n and try an = en+ d. Plugging into the relation yields en+ d = 2c(n - 1) + 2d + n - 1, which, upon grouping like terms, becomes (-c - l)n + (2c - d + 1) = 0. Therefore c = -1 and d = -1, so a};l = -n -1. Therefore the general solution is an = oo2n - n - 1. Plugging in the initial condition gives 5 = al = 200 - 2, Section 8.2 281 Solving Linear Recurrence Relations whence a = 7/2. Our solution is therefore an = 7 · 2n-l - n - 1. We can check that this gives the correct salary for the first few years, as computed above. 49. Using the notation of Exercise 48 we have f(n) = n + 1, g(n) = n + 3, h(n) = n, and C = 1. Therefore (2·3·4 .. ·n)·n Q(n) · n 6n -3 12 -9 = 4. 5 · 6 · · · (n + 3) = (n + l)(n + 2)(n + 3) = n + 1 + n + 2 + n + 3 · The last decomposition was by standard partial fractions techniques from calculus (write the fraction as A/ (n + 1) + B / (n + 2) + C / (n + 3) and solve for A, B, and C by multiplying it out and equating like powers of n with the original fraction). Now we can give a closed form for :Z::::~=l Q(i)i, since almost all the terms cancel out in a telescoping manner: n 12 -3 n -9 2= Q( i)i = 2= i + 1 + i + 2 + i + 3 i=l i=l 3 12 9 3 12 9 3 12 9 3 12 9 = -2 + 3 - 4 - 3 + 4 - 5- 4 + 5 - 6- 5 + 6 - 7 + ... = 3 12 9 3 12 9 3 12 9 - --+- - - - - -+-- - - - - - - +-- - - n-l n n+l n n+l n+2 n+l n+2 n+3 3 12 3 9 12 9 3 6n + 9 -- + - - - - - - + - - - - - = - - - - - - 2 3 3 n+2 n+2 n+3 2 (n+2)(n+3) This plus 1 gives us the numerator for an, according to the formula given in Exercise 48. For the denominator, we need (n+4)·2·3 .. ·(n+l) 6 g(n+l)Q(n+l) = 4-5 .. ·(n+4) = (n+2)(n+3) · Putting this all together algebraically, we obtain an = (5n 2 + l3n + 12) /12. We can (and should!) check that this conforms to the recurrence when we calculate a 1 , a 2 , and so on. Indeed, we get a 1 = 5/2 and a2 = 29/6 both ways. It is interesting to note that asking Maple to do this with the command rsolve({a(n) = ((n+3) *a(n-1) +n)/(n+ 1),a(O) = 1},a(n)); produces the correct answer. 51. A proof of this theorem can be found in textbooks such as Discrete Mathematics with Applications by H. E. Mattson, Jr. (Wiley, 1993), Chapter 11. 53. We follow the hint, letting n = 2k and ak = logT(n) = logT(2k). We take the log (base 2, of course) of both sides of the given recurrence relation and use the properties of logarithms to obtain logT(n) = logn + 2logT(n/2), so we have or The initial condition becomes a0 = log 6. Using the techniques in this section, we find that the general solution of the recurrence relation is ak = c · 2k - k - 2. Plugging in the initial condition leads to c = 2 +log 6. Now we have to translate this back into terms involving T. Since T( n) = 2ak and n = 2k we have T(n) = 2(2+1og6)·2k-k-2 = (iog6)2k ( 22.2k-2)(rk) 5n 4n-l = __· __ n Chapter 8 282 SECTION 8.3 Advanced Counting Techniques Divide-and-Conquer Algorithms and Recurrence Relations Many of these exercises are fairly straightforward applications of Theorem 2 (or its special case, Theorem 1). The messiness of the algebra and analysis in this section is indicative of what often happens when trying to get reasonably precise estimates for the efficiency of complicated or clever algorithms. 1. Let f (n) be the number of comparisons needed in a binary search of a list of n elements. From Example 1 we know that f satisfies the divide-and-conquer recurrence relation f(n) = f(n/2) +2. Also, 2 comparisons are needed for a list with one element, i.e., f(l) = 2 (see Example 3 in Section 3.3 for further discussion). Thus !(64) = !(32) + 2 = !(16) + 4 = f(8) + 6 = f(4) + 8 = f(2) + 10 = f(l) + 12 = 2 + 12 = 14. 3. In the notation of Example 4 (all numerals in base 2), we want to multiply a= 1110 by b = 1010. Note that n = 2. Therefore Ai= 11, Ao= 10, Bi= 10 and Bo= 10. We need to form Ai -Ao= 11-10 = 01 and Bo -Bi= 00. Then we need the following three products: AiBi = (11)(10), (Ai -Ao)(Bo -Bi)= (01)(00), and A 0 B 0 = (10)(10). In order to from these products, the algorithm would in fact recurse, but let us not worry about that, assuming instead that we have these answers, namely AiB 1 = 0110, (A 1 -Ao)(Bo -Bi)= 0000, and A 0 B 0 = 0100. Now we need to shift these products various numbers of places to the left. We shift AiBi 2n = 4 places and also n = 2 places, obtaining 01100000 and 011000; we shift (Ai - Ao)(Bo - Bi) n = 2 places, obtaining 000000, and we shift A 0 B 0 n = 2 places and also no places, obtaining 010000 and 0100. Finally we add all five of these binary numbers, obtaining 10001100. 5. This problem is asking us to estimate the number of bit operations needed to do the shifts, additions, and subtractions in multiplying two 2n-bit integers by the algorithm in Example 4. First recall from Example 9 in Section 4.2 that the number of bit operations needed for an addition of two k-bit numbers is at most 3k; the same bound holds for subtraction. Let us assume that to shift a number k bits also requires k bit operations. Thus we need to count the number of additions and shifts of various sizes that occur in the fast multiplication algorithm. First, we need to perform two subtractions of n-bit numbers to get Ai - Ao and Bo - Bi; these will take up to 6n bit operations altogether. We need to shift AiBi 2n places (requiring 2n bit operations), and also n places (requiring n bit operations); we need to shift (Ai - A 0 )(B0 - Bi) n places (requiring n bit operations); and we need to shift A 0 B 0 n places, also requiring n bit operations. This makes a total of 5n bit operations for the shifting. Finally we need to worry about the additions (which actually might include a subtraction if the middle term is negative). If we are clever, we can add the four terms that involve at most 3n bits first (that is, everything except the 22 n AiBi ). Three additions are required, each taking 9n bit operations, for a total of 27n bit operations. Finally we need to perform one addition involving a 4n-bit number, taking 12n operations. This makes a total of 39n bit operations for the additions. Putting all these operations together, we need perhaps a total of 6n + 5n + 39n = 50n bit operations to perform all the additions, subtractions, and shifts. Obviously this bound is not exact; it depends on the actual implementation of these binary operations. Using C = 50 as estimated above, the recurrence relation for fast multiplication is f(2n) = 3f(n) + 50n, with f(l) = 1 (one multiplication of bits is all that is needed if we have 1-bit numbers). Thus we can compute f(64) as follows: f(2) = 3 · 1 + 50 = 53; f(4) = 3 · 53 + 100 = 259; f(8) = 3 · 259 + 200 = 977; f (16) = 3 · 977 + 400 = 3331; f (32) = 3 · 3331 + 800 = 10793; and finally f (64) = 3 · 10793 + 1600 = 33979. Thus about 34,000 bit operations are needed. 7. We compute these from the bottom up. (In fact, it is easy to see by induction that computation is really needed at all.) a) f(3) = f(l) + 1=1+1 = 2 f (3k) = k + 1, so no b) f(9) = f(3) + 1=2+1 = 3; !(27) = f(9) + 1=3+1 = 4 c) f(81) = f(27) + 1=4+1=5; f(243) = f(81) + 1=5+1=6; f(729) = !(243) + 1=6+1 = 7 Section 8.3 283 Divide-and-Conquer Algorithms and Recurrence Relations 9. We compute these from the bottom up. a) f(5) = f(l) + 3 · 52 = 4 + 75 = 79 b) !(25) = f(5) + 3. 25 2 = 79 + 1875 = 1954; !(125) = !(25) + 3. 125 2 = 1954 + 46875 = 48,829 c) f(625) = !(125) + 3 · 625 2 = 48829 + 1171875 = 1220704; !(3125) = f(625) + 3 · 3125 2 = 1220704 + 29296875 = 30,517,579 bd, we have that f(n) is 1, b 2, c 1, and d 0. Since a 13. We apply Theorem 2, with a = 2, b O(nlogba) = O(nlog3 2) ~ O(n0.63). 3, c 4, and d 0. Since a > bd, we have that f(n) 11. We apply Theorem 2, with a O(ndlogn) = O(logn). IS 15. After 1 round, there are 16 teams left; after 2 rounds, 8 teams; after 3 rounds, 4 teams; after 4 rounds, 2 teams; and after 5 rounds, only 1 team remains, so the tournament is over. In general, k rounds are needed if there are 2k teams (easily proved by induction). 17. a) Our recursive algorithm will take a sequence of names and determine whether one name occurs as more than half of the elements of the sequence, and if so, which name that is. If the sequence has just one element, then the one person on the list is the winner. For the recursive step, divide the list into two parts-the first half and the second half-as equally as possible. As is pointed out in the hint, no one could have gotten a majority of the votes on this list without having a majority in one half or the other, since if a candidate got less than or equal to half the votes in each half, then he got less than or equal to half the votes in all (this is essentially just the distributive law). Apply the algorithm recursively to each half to come up with at most two names. Then run through the entire list to count the number of occurrences of each of those names to decide which, if either, is the winner. This requires at most 2n additional comparisons for a list of length n. b) We apply the master theorem with a = 2 , b = 2 , c = 2 , and d = 1 . Since a = bd , we know that the number of comparisons is O(nd logn) = O(nlogn). 19. a) We compute xn when n is even by first computing y = xn/ 2 recursively and then doing one multiplication, namely y · y. When n is odd, we first compute y = x(n-I)/ 2 recursively and then do two multiplications, namely y · y · x. So if f(n) is the number of multiplications required, assuming the worst, then we have essentially f(n) = f(n/2) + 2. b) By the master theorem, with a= 1, b = 2, c = 2, and d = 0, we see that f(n) is O(n° logn) = O(logn). 21. a) !(16) = 2f(4) + 1=2(2f(2)+1) + 1=2(2·1+1) + 1 = 7 b) Let m = logn, so that n = 2m. Also, let g(m) = f(2m). Then our recurrence becomes J(2m) = 2f(2m/ 2 ) + 1, since V'ffei = (2m) 112 = 2m/ 2 . Rewriting this in terms of g we have g(m) = 2g(m/2) + 1. Theorem 1 now tells us that g(m) is O(m10g2 2 ) = O(m). Since m = logn, this says that our function is O(logn). 23. a) The messiest part of this is just the bookkeeping. Note that we start with best set to 0, since the empty subsequence has a sum of 0, and this is the best we can do if all the terms are negative. Also note that it would be an easy improvement to keep track of where the subsequence is located, as well as what its sum is. Chapter 8 284 Advanced Counting Techniques procedure largest sum( a 1 , ... , an : real numbers) best := 0 {empty subsequence has sum 0} for i := 1 ton sum:= 0 for j := i to n sum := sum + aJ if sum > best then best := sum return best {the maximum possible sum of numbers in the list} b) One sum and one comparison are made inside the inner loop. This loop is executed C(n + 1, 2) times~ once for each choice of a pair (i, j) of endpoints of the sequence of consecutive terms being examined (this is a combination with repetition allowed, since i = j when we are examining one term by itself). Since C(n + 1, 2) = n(n + 1)/2 the computational complexity is O(n 2 ). c) We divide the list into a first half and a second half and apply the algorithm recursively to find the largest sum of consecutive terms for each half. The largest sum of consecutive terms in the entire sequence is either one of these two numbers or the sum of a sequence of consecutive terms that crosses the middle of the list. To find the largest possible sum of a sequence of consecutive terms that crosses the middle of the list, we start at the middle and move forward to find the largest possible sum in the second half of the list, and move backward to find the largest possible sum in the first half of the list; the desired sum is the sum of these two quantities. The final answer is then the largest of this sum and the two answers obtained recursively. The base case is that the largest sum of a sequence of one term is the larger of that number and 0 . d) (i) Split the list into the first half, -2, 4, -1, 3, and the second half, 5, -6, 1, 2. Apply the algorithm recursively to each half (we omit the details of this step) to find that the largest sum in the first half is 6 and the largest sum in the second half is 5. Now find the largest sum of a sequence of consecutive terms that crosses the middle of the list. Moving forward, the best we can do is 5; moving backward, the best we can do is 6. Therefore we can get a sum of 11 by adding the second through fifth terms. This is better than either recursive answer, so the desired answer is 11. (ii) Split the list into the first half, 4, 1, -3, 7, and the second half, -1, -5, 3, -2. Apply the algorithm recursively to each half (we omit the details of this step) to find that the largest sum in the first half is 9 and the largest sum in the second half is 3. Now find the largest sum of a sequence of consecutive terms that crosses the middle of the list. Moving forward, the best we can do is -1; moving backward, the best we can do is 9. Therefore we can get a sum of 8 by crossing the middle. The best of these three possibilities is 9, which we get from the first through fourth terms. (iii) Split the list into the first half, -1, 6, 3, -4, and the second half, -5, 8, -1, 7. Apply the algorithm recursively to each half (we omit the details of this step) to find that the largest sum in the first half is 9 and the largest sum in the second half is 14. Now find the largest sum of a sequence of consecutive terms that crosses the middle of the list. Moving forward, the best we can do is 9; moving backward, the best we can do is 5. Therefore we can get a sum of 14 by adding the second through eighth terms. The best of these three is actually a tie, between the second through eighth terms and the sixth through eighth terms, with a sum of 14 in each case. e) Let S(n) be the number of sums and C(n) the number of comparisons used. Since the "conquer" step requires n sums and n + 2 comparisons (two extra comparisons to determine the winner among the three possible largest sums), we have S(n) = 2S(n/2) +n and C(n) = 2C(n/2) +n+2. The basis step is C(l) = 1 and S(l) = 0. f) By the master theorem with a = b = 2 and d = 1, we see that we need only 0( n log n) of each type of operation. This is a significant improvement over the 0( n 2 ) complexity we found in part (b) for the algorithm in part (a). 25. To carry this down to its base level would require applying the algorithm seven times, so to keep things within reason, we will show only the outermost step. The points are already sorted for us, and so we divide them into two groups, using x coordinate. The left side will have the first eight points listed in it (they all have x coordinates less than 4.5), and the right side will have the rest, all of which have x coordinates greater Section 8.3 Divide-and-Conquer Algorithms and Recurrence Relations 285 than 4.5. Thus our vertical line will be taken to be x = 4.5. Now assume that we have already applied the algorithm recursively to find the minimum distance between two points on the left, and the minimum distance on the right. It turns out that d = dL = dR = 2. This is achieved, for example, by the points (1, 6) and (3, 6). Thus we want to concentrate on the strip from x = 2.5 to x = 6.5 of width 2d. The only points in this strip are (3, 1), (3, 6), (3, 10), (4, 3), (5, 1), (5, 5), (5, 9), and (6, 7), Working from the bottom up, we compute distances from these points to points as much as d = 2 vertical units above them. According to the discussion in the text, there can never be more than seven such computations for each point in the strip. The distances we need, then, are (3, 1)(5, 1), (3, 1)(4, 3), (5, 1)(4, 3), (4, 3)(5, 5), (5, 5)(3, 6), (5, 5)(6, 7), (3,6)(6, 7), (6, 7)(5, 9), and (5, 9)(3, 10). The smallest of these turns out to be 2, so the minimum distance d = 2 in fact is the smallest distance among all the points. (Actually we did not need to compute the distances between points that were already on the same side of the dividing line, since their distance had already been computed in the recursive step, but checking whether they are on opposite sides of the vertical line would entail additional computation anyway.) 27. The algorithm is essentially the same as the algorithm given in Example 12. The only difference is in constructing the boxes centered on the vertical line that divides the two halves of the set of points. In this variation, our strip still has width 2d (i.e., d units to the left and d units to the right of the vertical line), because it would be possible for two points within this box, one on each side of the line, to lie at a distance less than d from each other, but no point outside this strip has a chance to contribute to a small "across the line" distance. In this variation, however, we do not need to construct eight boxes of size (d/2) x (d/2), but rather just two boxes of size d x d. The reason for this is that there can be at most one point in each of those boxes using the distance formula given in this exercise-two points within such a box (which is on the same side of the dividing line) can be at most d units apart and so would already have been considered in the recursive step. Thus the recurrence relation is the same as the recurrence relation in Example 12, except that the coefficient 7 is replaced by 1. The analysis via the master theorem remains the same, and again we get a 0( n log n) algorithm. 29. Suppose n = bk, so that k = logb n. We will prove by induction on k that f(bk) = f(l)(bk)d + c(bk)dk, which is what we are asked to prove, translated into this notation. If k = 0, then the equation reduces to f(l) = f(l), which is certainly true. We assume the inductive hypothesis, that f(bk) = f(l)(bk)d + c(bk)dk, and we try to prove that f(bk+ 1) = f(l)(bk+ 1)d + c(bk+ 1)d(k + 1). By the recurrence relation for f(n) in terms of f (n/b), we have f (bk+l) = bd f (bk) + c(bk+ 1)d. Then we invoke the inductive hypothesis and work through the algebra: bd f (bk) + c(bk+1 )d = bd (f (l )(bk)d + c(bk)d k) + c(bk+1 )d = f(l)bkd+d + cbkd+dk + c(bk+l)d = = + c(bk+l)dk + c(bk+l)d f(l)(bk+l)d + c(bk+1)d(k + 1) f(l)(bk+l)d 31. The algebra is quite messy, but this is a straightforward proof by induction on k n = 1 , then we have the true statement = logb n. If k = 0, (since the fractions cancel each other out). Assume the inductive hypothesis, that for n =bk we have so that 286 Chapter 8 Then for n algebra: = Advanced Counting Techniques bk+l we apply first the recurrence relation, then the inductive hypothesis, and finally some f(n) = af (~)+end = a ( b:: a ( ~) d + ( f ( 1) + a~ cbd) ( ~ yagb a) + end = ___!!'!_!!__ . n d . _!:_ + ( f (1) + ___!!'!_!!__ ) bd-a = = n d bd a-bd n log ba + end (--5!:5:__ c(bd - a)) (!( 1)+a-bd ___!!'!_!!__) Jogb a bd-a+ bd-a + n ~. nd + (J(l) + ~) nlogba bd-a a-bd Thus we have verified that the equation holds for k + 1, and our induction proof is complete. 33. The equation given in Exercise 31 says that f(n) is the sum of a constant times nd and a constant times n 10 gb a. Therefore we need to determine which term dominates, i.e., whether d or logb a is larger. But we are given a> bd; hence logb a> logb bd = d. It therefore follows (we are also using the fact that that f(n) is O(n 10 gba). 35. We use the result of Exercise 33, since is increasing) a= 5 > 4 1 = bd. Therefore f(n) is O(n 10gb a)= O(n 10g4 5)::::::: O(nl. 1 6). 37. We use the result of Exercise 33, since a= 8 SECTION 8.4 f > 22 = bd. Therefore f(n) is O(n 10gb a)= O(n 10g2 8) = O(n3). Generating Functions Generating functions are an extremely powerful tool in mathematics (not just in discrete mathematics). This section, as well as some material introduced in these exercises, gives you an introduction to them. The algebra in many of these exercises gets very messy, and you probably want to check your answers, either by computing values when solving recurrence relation problems, or by using a computer algebra package. See the solution to Exercise 11, for example, to learn how to get Maple to produce the sequence for a given generating function. For more information on generating functions, consult reference {Wi2} given at the end of this Guide (in the List of References for the Writing Projects). 1. By definition we want the function f(x) = 2 + 2x + 2x 2 + 2x 3 + 2x 4 + 2x 5 = 2(1 + x + x 2 + x3 + x 4 + x5). From Example 2, we see that the expression in parentheses can also be written as (x 6 - 1)/(x - 1). Thus we can write the answer as f(x) = 2(x 6 - 1)/(x - 1). 3. We will use Table 1 in much of this solution. a) Apparently all the terms are 0 except for the six 2's shown. Thus f (x) = 2x + 2x 2+ 2x 3+ 2x 4+ 2x 5+ 2x 6. This is already in closed form, but we can also write it more compactly as f(x) = 2x(l - x 6 )/(1 - x) by factoring out 2x, or as f(x) = 2(1- x 7 )/(1- x) - 2 by subtracting away the missing term. In each case we use the identity from Example 2. b) Apparently all the terms beyond the first three are l's. Since 1/ (1 - x) = 1 + x + x 2 + x 3 + · · ·, we can write this generating function as 1/ (1- x )-1- x - x 2 , or we can write it as x 3/ (1- x), depending on whether we want to simplify by adding back the missing terms or by factoring out x 3 . c) This generating function is the sequence x + x 4 + x 7 + x 10 (x 3 ) + (x 3) 2 + (x 3)3 + · · ·) = x/(1- x 3), from Table 1. + · · ·. If we factor out an x, we have x(l + d) We factor out a 2 and then include the remaining factors of 2 along with the x terms. Thus our generating function is 2(1 + (2x) + (2x) 2 + (2x) 3 + · · ·) = 2/(1 - 2x), again using Table 1. Section 8.4 287 Generating Functions e) By the binomial theorem (see also Table 1), the generating function is (1 + x) 7 . f) From Table 1 we know that 1/(1 - ax) = 1 +ax+ a2 x 2 + a 3 x 3 + · · ·. That is what we have here, with a= -1 (and a factor of 2 in front of it all). Therefore the generating function is 2/(1 + x). g) This sequence is all l's except for a 0 where the x 2 coefficient should be. Therefore the generating function is (1/(1 - x)) - x 2 • h) If we factor out x 3 , then we can use a formula from Table 1: x 3 + 2x 4 + 3x 5 + · · · = x 3 ( 1 + 2x + 3x 2 + · · ·) x 3 /(1 - x) 2 . = 5. As in Exercise 3, we make extensive use of Table 1. a) Since the sequence with an = 1 for all n has generating function 1/(1 - x), this sequence has generating function 5/(1 - x). b) By Table 1 the answer is 1/(1 - 3x). c) We can either subtract the missing terms and write this generating function as (2/(1 - x)) - 2 - 2x - 2x 2 , or we can factor out x 3 and write it as 2x 3 /(1- x). Note that these two algebraic expressions are equivalent. d) We need to split this into two parts. Since we know that the generating function for the sequence {n + 1} is 1/(1 - x) 2 , we write 2n + 3 = 2(n + 1) + 1. Therefore the generating function is 2/(1 - x) 2 + 1/(1 - x). We can combine terms and write this function as (3 - x)/(1- x) 2 , but there is no particular reason to prefer that form in general. e) By Table 1 the answer is (1 + x ) 8 . Note that C(8, n) f) By Table 1 the generating function is 1/(1 - x) 5 . =0 by definition for all n > 8. 7. a) We can rewrite this as (-4(1 - ~x)) 3 = -64(1 - ~x) 3 and then apply the binomial theorem (the second line of Table 1) to get an = -64C(3, n)(-~r. Explicitly, this says that ao = -64, ai = 144, az = -108, a 3 = 27, and an = 0 for all n 2: 4. Alternatively, we could (by hand or with Maple) just multiply out this finite polynomial and note the coefficients. b) This is like part (a). By the binomial theorem (the third line of Table 1) we get a3 n = C(3, n), and the other coefficients are all 0. Alternatively, we could just multiply out this finite polynomial and note the nonzero coefficients: a0 = 1, a 3 = 3, a6 = 3, ag = 1. c) By Table 1, an = 5n. d) Note that x 3 /(1+3x) = x 3 L:~ 0 (-3)nxn = n 2: 3, and ao = a1 = az = 0. L::= 0 (-3)nxn+ 3 = I::= 3 (-3r- 3 xn. So an = (-3r- 3 for e) We know what the coefficients are for the power series of 1/(1- x 2 ), namely 0 for the odd ones and 1 for the even ones. The first three terms of this function force us to adjust the values of a0 , a 1 and a2 . So we have ao = 7 + 1 = 8, a 1 = 3 + 0 = 3, az = 1 + 1 = 2, an = 0 for odd n greater than 2, and an = 1 for even n greater than 2. f) Perhaps this is easiest to see if we write it out: x 4 (1 + x 4 + xs + x 12 +. · ·) - x 3 - x 2 - x - 1 = x 4 + xs + x 12 + · · · - x 3 - x 2 - x - 1. Therefore we have an = 1 if n is a positive multiple of 4; an = -1 if n < 4, and an = 0 otherwise. g) We know that x 2 /(1-x) 2 = x 2 L:~ 0 (n+l)xn = L::= 0 (n+l)xn+z = L:~ 2 (n-l)xn. Therefore an= n-1 for n 2: 2 and a 0 = a 1 = 0. h) We know that 2e 2 x = 2 L::= 0 (2x)n /n! = L::= 0 (2n+I /n!)xn. Therefore an= 2n+i /n!. 9. Different approaches are possible for obtaining these answers. One can use brute force algebra and just multiply everything out, either by hand or with computer algebra software such as Maple. One can view the problem as asking for the solution to a particular combinatorial problem and solve the problem by other means (e.g., listing all the possibilities). Or one can get a closed form expression for the coefficients, using the generating function theory developed in this section. Chapter 8 288 Advanced Counting Techniques a) First we view this combinatorially. To obtain a term x 10 when multiplying out these three factors, we could either take two x 5 's and one x 0 , or we could take two x 0 's and one x 10 . In each case there are C(3, 1) = 3 choices for the factor from which to pick the single value. Therefore the answer is 3 + 3 = 6. Second, it is clear that we can view this problem as asking for the coefficient of x 2 in (1 + x + x 2 + x 3 + · · · ) 3 , since each x 5 in the original is playing the role of x here. Since (1 + x + x 2 + x 3 + · · ·) 3 = 1/(1- x) 3 = l::~=O C(n + 2, 2)xn, the answer is clearly C(2 + 2, 2) = C( 4, 2) = 6. A third way to get the answer is to ask Maple to compute (1 + x 5 + x 10 ) 3 and look at the coefficient of x 10 , which will turn out to be 6. Note that we don't have to go beyond x 10 in each factor, because the higher terms can't contribute to an x 10 term in the answer. b) If we factor out x 3 from each factor, we can write this as x 9 (1 + x + x 2 + · · ·) 3 • Thus we are seeking the coefficient of x in (1 + x + x 2 + · · · ) 3 = l::~=O C(n + 2, 2)xn, so the answer is C(l + 2, 2) = 3. The other two methods explained in part (a) work here as well. c) If we factor out as high a power of x from each factor as we can, then we can write this as x 7 (1 + x + x 2 )(1 + x + x 2 + x 3 + x 4)(1 + x + x 2 + x 3 + · · ·), and so we seek the coefficient of x 3 in (1 + x + x 2)(1 + x + x 2 + x 3 + x 4)(1 + x + x 2 + x 3 + · · ·). By brute force we can list the nine ways to obtain x 3 in this product (where "ijk" means choose an x' term from the first factor, an xi term from the second factor, and an xk term from the third factor): 003, 012, 021, 030, 102, 111, 120, 201, 210. If we want to do this more analytically, let us write our expression in closed form as 1 - x3 l-x 1 - x5 l-x 1 l-x -- · -- · -- 1 - x 3 - x5 + x8 (l-x)3 1 1 - x3 · +irrelevant terms. (l-x)3 (l-x)3 Now the coefficient of xn in 1/(1 - x) 3 is C(n + 2, 2). Furthermore, the coefficient of x 3 in this power series comes either from the coefficient of x 3 in the first term in the final expression displayed above, or from the coefficient of x 0 in the second factor of the second term of that expression. Therefore our answer is C(3 + 2, 2) - C(O + 2, 2) = 10 - 1 = 9. d) Note that only even powers appear in the first and third factor, so to get x 10 when we multiply this out, we can only choose the x 6 term in the second factor. But this would require terms from the first and third factors with a total exponent of 4, and clearly that is not possible. Therefore the desired coefficient is 0. e) The easiest approach here might be brute force. Using the same notation as explained in part (c) above, the ways to get x 10 are 046, 280, 406, 640, and (10)00. Therefore the answer is 5. We can check this with Maple. An analytic approach would be rather messy for this problem. 11. a) By Table 1 the coefficient of xn in this power series is 2n. Therefore the answer is 210 = 1024. b) By Table 1 the coefficient of xn in this power series is (-l)nO(n + 1, 1). Therefore the answer is (-1) 10 0(10+1,1) = 11. c) By Table 1 the coefficient of xn in this power series is O(n+2, 2). Therefore the answer is 0(10+2, 2) = 66. d) By Table 1 the coefficient of xn in this power series is (-2)nO(n + 3, 3). Therefore the answer is (-2) 10 0(10 + 3, 3) = 292,864. Incidentally, Maple can do this kind of problem as well. Typing series(1/(1+2 * xr4, x = 0, 11); will cause Maple to give the terms of the power series for this function, including all terms less than x 11 . The output looks like 1 - 8 x + 40 x 2 - 160 x 3 + 560 x 4 - 1792 x 5 + 5376 x 6 - 15360 x 7 + 42240 x 8 x 11 , 12 - 112640 x 9 + 292864 x 10 + O(x 11 ) . 11 (You might wonder why Maple says that the terms involving x , and so on are big-0 of x . That seems backward! The reason is that one thinks of x as approaching 0 here, rather than infinity. Then, indeed, each term with a higher power of x (greater than 11) is smaller than x 11 , up to a constant multiple.) e) This is really asking for the coefficient of x 6 in 1/(1 - 3x) 3 . Following the same idea as in part (d), we see that the answer is 36 0(6 + 2, 2) = 20,412. Section 8.4 289 Generating Functions 13. Each child will correspond to a factor in our generating function. We can give any number of balloons to the child, as long as it is at least 2; therefore the generating function for each child is x 2 + x 3 + x 4 + · · ·. We want to find the coefficient of x 10 in the expansion of (x 2 + x 3 + x 4 + · · ·) 4 • This function is the same as x 8 (1 + x + x 2 + x 3 + · · ·) 4 = x 8 /(1 - x) 4 . Therefore we want the coefficient of x 2 in the generating function for 1/ (1 - x )4 , which we know from Table 1 is C (2 + 3, 3) = 10. Alternatively, to find the coefficient of x 2 in (1 + x + x 2 + x 3 + · · ·) 4 , we can multiply out (1 + x + x 2 ) 4 (perhaps with a computer algebra package such as Maple), and the coefficient of x 2 turns out to be 10. Note that we truncated the series to be multiplied out, since terms higher than x 2 can't contribute to the x 2 term. 15. Each child will correspond to a factor in our generating function. We can give 1, 2, or 3 animals to the child; therefore the generating function for each child is x + x 2 + x 3 . We want to find the coefficient of x 15 in the expansion of (x + x 2 + x 3 ) 6 . Factoring out an x from each term, we see that this is the same as the coefficient of x 9 in (1 + x + x 2 ) 6 . We can multiply this out (preferably with a computer algebra package such as Maple), and the coefficient of x 9 turns out to be 50. To solve it analytically, we write our generating function (1 + x + x2) 6 as ( ~)6 l-x 1 - 6x 3 + 15x6 - 20x 9 + higher order terms (1-x) 6 There are four contributions to the coefficient of x 9 , one for each listed term in the numerator, from the power series for 1/(1 - x) 6 • Since the coefficient of xn in 1/(1 - x) 6 is C(n + 5, 5), our answer is C(9 + 5, 5) 6C(6 + 5, 5) + 15C(3 + 5, 5) - 20C(O + 5, 5) = 2002 - 2772 + 840 - 20 = 50. 17. The factor in the generating function for choosing the donuts for each policeman is x 3 + x 4 + x 5 + x 6 + x 7 . Therefore the generating function for this problem is (x 3 +x 4 +x 5 +x 6 +x 7 ) 4 . We want to find the coefficient of x 25 , since we want 25 donuts in all. This is equivalent to finding the coefficient of x 13 in (l+x+x 2 +x 3 +x4 ) 4 , since we can factor out (x 3 ) 4 = x 12 . At this point, we could multiply it out (perhaps with Maple), and see that the desired coefficient is 20. Alternatively, we can write our generating function as ~)4 ( 1-x 1 - 4x 5 + 6x 10 +higher order terms (1 - x) 4 There are three contributions to the coefficient of x 13 , one for each term in the numerator, from the power series for 1/(1 - x) 4 . Since the coefficient of xn in 1/(1 - x) 4 is C(n + 3, 3), our answer is C(13 + 3, 3) 4C(8 + 3, 3) + 6C(3 + 3, 3) = 560 - 660 + 120 = 20. 19. We want the coefficient of xk to be the number of ways to make change for k dollars. One-dollar bills contribute 1 each to the exponent of x. Thus we can model the choice of the number of one-dollar bills by the choice of a term from 1 + x + x 2 + x 3 + · · ·. Two-dollar bills contribute 2 each to the exponent of x. Thus we can model the choice of the number of two-dollar bills by the choice of a term from 1 + x 2 + x 4 + x 6 + · · ·. Similarly, five-dollar bills contribute 5 each to the exponent of x, so we can model the choice of the number of five-dollar bills by the choice of a term from 1 + x 5 + x 10 + x 15 + · · ·. Similar reasoning applies to ten-dollar bills. Thus the generating function is f(x) = (1 +x+x2 +x 3 +· · ·)(1 +x 2 +x4 +x6 + · · ·)(1 +x5 +x 10 +x 15 + .. ·)(1 +x 10 +x 20 +x30 +·. ·), which can also be written (see Table 1) as 1 f(x) = (1 - x)(l - x2)(1 - x 5 )(1 - x 10 ) · 21. Let ei, for i = 1, 2, 3, be the exponent of x taken from the ith factor in forming a term x 4 in the expansion. Thus e 1 + e 2 + e3 = 4. The coefficient of x 4 is therefore the number of ways to solve this equation with nonnegative integers, which, from Section 6.5, is C(3 + 4 - 1, 4) = C(6, 4) = 15. 290 Chapter 8 Advanced Counting Techniques 23. a) The restriction on x 1 gives us the factor x 2 + x 3 + x 4 + · · ·. The restriction on x 2 gives us the factor 1 + x + x 2 + x 3 . The restriction on x 3 gives us the factor x 2 + x 3 + x 4 + x 5 . Thus the answer is the product of these: (x 2 + x 3 + x 4 + · · ·)(1 + x + x 2 + x 3 )(x 2 + x 3 + x 4 + x 5 ). We can use algebra and Table 1 to rewrite this in closed form as x 4 (1 + x + x 2 + x 3 ) 2 /(1 - x). b) We want the coefficient of x 6 in this series, which is the same as the coefficient of x 2 in the series for Since the coefficient of xn (1 + x + x 2 + x 3 ) 2 1 + 2x + 3x 2 + higher order terms l-x l-x in 1/ ( 1 - x) is 1, our answer is 1 + 2 + 3 = 6. 25. This problem reinforces the point that "and" corresponds to multiplication and "or" corresponds to addition. a) The only issue is how many stamps of each denomination we choose. The exponent on x will be the number of cents. So the generating function for choosing 3-cent stamps is 1 + x 3 + x 6 + x 9 + · · · , the generating function for 4-cent stamps is 1 + x 4 + x 8 + x 12 + · · ·, and the generating function for 20-cent stamps is 1 + x 20 + x 40 + x 60 + · · ·. In closed form this is 1/((1 - x 3 )(1 - x 4 )(1 - x 20 )). The coefficient of xr gives the answer~the number of ways to choose stamps totaling r cents of postage. b) Again the exponent on x will be the number of cents, but this time we paste one stamp at a time. For the first pasting, we can choose a 3-cent stamp, a 4-cent stamp, or a 20-cent stamp. Hence the generating function for the number of ways to paste one stamp is x 3 + x 4 + x 20 . For the second pasting, we can make these same choices, so the generating function for the number of ways to paste two stamps is (x 3 + x 4 + x 20 ) 2 . In general, if we use n stamps, the generating function is (x 3 + x 4 + x 20 )n. Since a pasting consists of a pasting of zero or more stamps, the entire generating function will be 00 '"'(x3 ~ + x4 + x20)n = n=O 1 1 - x3 - x4 - x20 . c) We seek the coefficient of x 46 in the power series for our answer to part (a), 1/((1-x3 )(1-x 4 )(1-x 20 )). Other than working this out by brute force (enumerating the combinations), the best way to get the answer is probably asking Maple or another computer algebra package to multiply out these series. If we do so, the answer turns out to be 7. (The choices are 2 · 20 + 2 · 3, 20 + 5 · 4 + 2 · 3, 20 + 2 · 4 + 6 · 3, 10 · 4 + 2 · 3, 7·4+6·3, 4·4+10·3, and 1·4+14·3.) d) We seek the coefficient of x 46 in the power series for our answer to part (b), 1/ ( 1 - x 3 - x 4 - x 20 ) . The best way to get the answer is probably asking Maple or another computer algebra package to find this power series using calculus. If we do so, the answer turns out to be 3224. Alternatively, for each of the seven combinations in our answer to part (c), we can find the number of ordered arrangements, as in Section 6.5. Thus the answer IS ~ 2!2! ~ ~ ~ 13 ' ~ ~ + 1!5!2! + 1!2!6! + 10!2! + 7!6! + 4!10! + 1!14! = 6 + 168 + 252 + 66 + 1716 + 1001 + 15 = 3224. 27. We will write down the generating function in each case and then use a computer algebra package to find the desired coefficients. As a check, one could carefully enumerate these by hand. In making change, one usually considers order irrelevant. a) The generating function for the dimes is 1 +x 10 +x 20 +x 30 + · · · = 1/(1-x10 ), and the generating function for the quarters is 1 + x 25 + x 50 + x 75 + · · · = 1/(1 - x 25 ), so the generating function for the whole problem is 1/((1 - x 10 )(1 - x 25 )). The coefficient of xk gives the number of ways to make change for k cents, so we seek the coefficient of x 100 . If we ask a computer algebra system to find this coefficient (it uses calculus to get the power series), we find that the answer is 3. In fact, this is correct, since we can use four quarters, two quarters, or no quarters (and the number of dimes is uniquely determined by this choice). Section 8.4 Generating Functions 291 b) This is identical to part (a) except for a factor for the nickels. Thus we seek the coefficient of x 100 in 1/((1 - x 5)(1 - x 10 )(1 - x 25 )), which turns out to be 29. (If we wanted to list these systematically, we could organize our work by the number of quarters, and within that by the number of dimes.) c) This is identical to part (a) except for a factor for the pennies. Thus we seek the coefficient of x 100 in 1/((1 - x)(l - x 10 )(1 - x 25 )), which turns out to be 29 again. (In retrospect, this is obvious. The only difference between parts (b) and ( c) is that five pennies are substituted for each nickel.) d) This is identical to part (a) except for factors for the pennies and nickels. Thus we seek the coefficient of x 100 in 1/((1 - x)(l - x 5)(1 - x 10 )(1 - x 25 )), which turns out to be 242. 29. We will write down the generating function in each case and then use a computer algebra package to find the desired coefficients. In making change, one usually considers order irrelevant. a) The generating function for the $10 bills is 1 + x 10 + x 20 + x 30 + · · · = 1/(1 - x 10 ), the generating function for the $20 bills is 1 + x 20 + x 40 + x 60 + · · · = 1/(1 - x 20 ), and the generating function for the $50 bills is 1 + x 50 + x 100 + x 150 + · · · = 1/(1 - x 50 ), so the generating function for the whole problem is 1/((1- x 10 )(1- x 20 )(1 - x 50 )). The coefficient of xk gives the number of ways to make change for k dollars, so we seek the coefficient of x 100 . If we ask a computer algebra system to find this coefficient (it uses calculus to get the power series), we find that the answer is 10. In fact, this is correct, since there is one way in which we can use two $50 bills, three ways in which we use one $50 bill (using either two, one, or no $20 bills), and six ways to use no $50 bills (using zero through five $20's). b) This is identical to part (a) except for a factor for the $5 bills. Thus we seek the coefficient of x 100 in 1/((1- x 5)(1-x 10 )(1-x 20 )(1- x 50 )), which turns out to be 49. c) In part (b) we saw that the generating function for this problem is 1/((1-x5)(1-x 10 )(1-x 20 )(1-x 50 )). If at least one of each bill must be used, let us assume that this $50 + $20 + $10 + $5 = $85 has already been dispersed. Then we seek the coefficient of x 15 . The computer algebra package tells us that the answer is 2, but it is trivial to see that there are only two ways to make $15 with these bills. d) This time the generating function is (x 5 + x 10 + x 15 + x 20 )(x 10 + x 20 + x 30 + x 40 )(x 20 + x 40 + x 60 + xBD). When the computer multiplies this out, it tells us that the coefficient of x 100 is 4, so that is the answer. (In retrospect, we see that the only solutions are 4·$20+ 1 ·$10+2· $5, 3 ·$20+3 · $10+2· $5, 3 · $20+2· $10+4· $5, and 2 · $20 + 4 · $10 + 4 · $5.) 31. a) The terms involving a0 , a 1 , and a 2 are missing; G(x) - a0 - a 1x - a 2x 2 = a3x 3 + a4x 4 + · · ·. That is the generating function for precisely the sequence we are given. Thus the answer is G(x) - a0 - a 1x - a 2x 2 . b) Every other term is missing, and the old coefficient of xn is now the coefficient of x 2n . This suggests that maybe x 2 should be used in place of x. Indeed, this works; the answer is G(x 2) = a + a x 2 + a x 4 + · · .. 0 1 2 c) If we want a 0 to be the coefficient of x 4 (and similarly for the other powers), we must throw in an extra factor. Thus the answer is x 4G(x). Note that x 4(a 0 + a 1x + a 2x 2 + · · ·) = a0x 4 + a 1 x 5 + a2x 6 + · · ·. d) Extra factors of 2 are applied to each term, with the power of 2 matching the subscript (which, of course, gives us the power of x). Thus the answer must be G(2x) = a0 + a 1 (2x) + a 2(2x) 2 + a 3 (2x) 3 · · · = ao + 2a1x + 4a2x 2 + 8a 3x 3 · · ·. e) Following the hint, we integrate G(t) = L:~o antn from 0 to x, to obtain fox G(t) dt = L::=o an f; tn dt = L::=o anxn+l / (n + 1). (If we had tried differentiating first, we'd see that that didn't work. It is a theorem of advanced calculus that it is legal to integrate inside the summation within the open interval of convergence.) This is the series ai a2 aox + -x 2 + -x 3 + · · · 2 3 ' precisely the sequence we are given (note that the constant term is 0). Thus fox G(t) dt is the generating function for this sequence. Chapter 8 292 Advanced Counting Techniques f) If we look at Theorem 1, it is not hard to see that the sequence shown here is precisely the coefficients of G(x) · (1 + x + x 2 + · · ·) = G(x)/(l - x). 33. This problem is like Example 16. First let G(x) = 'E%°=o akxk. Then xG(x) = 'E%°=o akxk+l = 2:%: 1 ak-1Xk (by changing the name of the variable from k to k + 1). Thus 00 00 00 00 G(x) - 3xG(x) = L akxk - L 3ak-1Xk = ao + L(ak - 3ak-1)xk = ao + L 2xk k=O k=l k=l k=l 2 l+x =1+---2=-1-x l-x' because of the given recurrence relation, the initial condition, and the fact from Table 1 that I:%°=o 2xk = 2/(1- x). Thus G(x)(l - 3x) = (1 + x)/(1- x), so G(x) = (1+x)/((1-3x)(l - x)). At this point we must use partial fractions to break up the denominator. Setting l+x A B (1 - 3x)(l - x) = 1 - 3x + 1- x' multiplying through by the common denominator, and equating coefficients, we find that A= 2 and B = -1. Thus 2 -1 ~ k k G(x) = 1 _ 3 x + 1 _ x = (the last equality came from using Table 1). Therefore ak L.)2 · 3 - l)x k=O 2 · 3k - 1. = 35. Let G(x) = 2::%: 0 akxk. Then xG(x) = L~o akxk+l = 2::~ 1 ak_ 1xk (by changing the name of the variable from k to k + 1 ), and similarly x 2G(x) = 2::%°=o akxk+ 2 = 2:%°= 2 ak-2Xk. Thus 00 00 00 00 G(x) - 5xG(x) + 6x 2G(x) = L akxk - L 5ak_ 1xk + L 6ak-2Xk = ao + a 1x - 5aox + L 0 · xk = 6, k=O k=l k=2 k=2 because of the given recurrence relation and the initial conditions. Thus G(x)(l - 5x + 6x 2) = 6, so G(x) = 6/((1 - 3x)(l - 2x)). At this point we must use partial fractions to break up the denominator. Setting 6 A 1 - 3x B 1 - 2x ------ = -- + -- ' (1 - 3x) ( 1 - 2x) multiplying through by the common denominator, and equating coefficients, we find that A -12. Thus 18 -12 ~ k k k G(x)= 1 = 18 and B = _ x + _ x = L.)18·3 -12·2 )x 1 2 3 k=O (the last equality came from using Table 1). Therefore ak = 18 · 3k - 12 · 2k. Incidentally, it would be wise to check our answers, either with a computer algebra package (see the solution to Exercise 37 for the syntax in Maple) or by computing the next term of the sequence from both the recurrence and the formula (here a2 = 114 both ways). 37. Let G(x) = 2::%°=o akxk. Then xG(x) = 2::%°= 0 akxk+l = 2::~ 1 ak_ 1xk (by changing the name of the variable from k to k + 1 ), and similarly x 2G(x) = 2::%°=o akxk+ 2 = 2::%°= 2 ak-2Xk. Thus 00 00 00 L 00 L G(x) - 4xG(x) + 4x 2G(x) = L akxk - L 4ak_ 1xk + 4ak-2Xk = ao + alx - 4aox + k 2 · xk k=O k=l k=2 k=2 2 3 1 = 2 - 3x + + -- - x (1-x) 3 (1-x) 2 l-x 2 3 1 -2-4x+ +-(1-x)3 (1-x)2 l-x' Section 8.4 Generating Functions 293 because of the given recurrence relation, the initial conditions, Table 1, and a calculation of the generating function for {k 2 } (the last "-x" comes from the fact that the k 2 sum starts at 2). (To find the generating function for {k 2}, start with the fact that 1/(1-x) 3 is the generating function for {C(k, 2) = (k+2)(k+ 1)/2}, that 1/ (1 - x) 2 is the generating function for { k + 1} , and that 1/ (1 - x) is the generating function for { 1} , and take an appropriate linear combination of these to get the generating function for {k 2 } .) Thus G(x)(l - 4x + 4x 2 ) = 2 - 4x + 2 (1-x ) 3 - ( 3 ) 1-x 2 + _l_, 1-x so 2 _ 3 1 (1 - 2x) 2 + (1 - 2x) 2(1- x) 3 (1 - 2x)2(1 - x) 2 + (1 - 2x)2(1 - x) · ( ) At this point we must use partial fractions to break up the denominators. Setting the previous expression equal to Gx=2-4x A B C D E -+ + +--+-----,1-x (1-x) 2 (1-x) 3 1-2x (1-2x) 2 ' multiplying through by the common denominator, and equating coefficients, we find (after a lot of algebra) that A= 13, B = 5, C = 2, D = -24, and E = 6. (Alternatively, one can ask Maple to produce the partial fraction decomposition, with the command convert( expression, parfrac, x); where the expression is G(x) .) Thus 13 5 2 -24 6 G( x ) =--+ + +--+---1-x (1-x) 2 (1-x)3 1-2x (1-2x)2 00 =I: (13 + s(k + 1) + 2(k + 2)(k + 1);2 - 24. 2k + 6(k + 1)2k) xk k=O (from Table 1). Therefore ak = k 2 + 8k + 20 + (6k - 18)2k. Incidentally, it would be most wise to check our answers, either with a computer algebra package, or by computing the next term of the sequence from both the recurrence and the formula (here a 2 = 16 both ways). The command in Maple for solving this recurrence is this: rsolve( { a(k) = 4 * a(k - 1) - 4 * a(k - 2) + kA2, a(O) = 2, a(1) = 5}, a(k)); 39. In principle this exercise is similar to the examples and previous exercises. In fact, the algebra is quite a bit messier. We want to solve the recurrence relation fk = fk-l + fk- 2 , with initial conditions fa = 0 and Ji = 1. 00 Let G be the generating function for fk, so that G(x) = 2.::: fkxk. We look at G(x) - xG(x) - x 2G(x) in k=O order to take advantage of the recurrence relation: 00 G(x)-xG(x)-x 2G(x) = 00 00 Lfkxk - Lfk-1xk - Lfk-2xk k=O k=l k=2 00 k=2 =0+x-0+0=x Thus G satisfies the equation G(x) = x 1-x-x2 . To write this more usefully, we need to use partial fractions. The roots of the denominator are r 1 = ( -1 +v'S) /2 and r2 = (-1 - v'S) /2. We want to find constants A and B such that x -x A B 1 - x - x 2 = x 2 + x - 1 = x - ri + x - r2 · Chapter 8 294 Advanced Counting Techniques This means that A and B have to satisfy the simultaneous equations A+ B = -1 and r 2 A + r 1B = 0 (multiply the last displayed equation through by the denominator and equate like powers of x ). Solving, we obtain A= (1 - v'5)/(2v'5) and B = (-1 - v'5)/(2v'5). Now we have A B G(x)=--+-x - r1 x - r2 -A 1 r1 1 - (x/r1) =- - -A - r1 Therefore fk =-A oo L k=O ClJ -B 1 +r2- 1-- -(x/r2) -- (__!_)k xk+ r1 -Boo r2 k=O L ClJ k+l - B (__!_)k xk r2 · k+l ~ (_1!y'5r- ~ (_1~y'5)k = We can check our answer by computing the first few terms with a calculator, and indeed we find that h = 2, f 4 = 3, f 5 = 5, f2 = 1, and so on. 41. a) Let G(x) = I:::::"=o Cnxn be the generating function for the sequence of Catalan numbers. Then by Theorem 1 a change of variable in the middle, and the recurrence relation for the Catalan numbers, 2 G(x) = ~ (~ CkCn-k)xn = ~ (~ CkCn-1-k )xn-l = ~ CnXn-l. So xG(x) 2 = I:::::"=l Cnxn. Therefore, 2 xG(x) - G(x) + 1 = (&i (~ Cnxn) + 1=-Co+1=0. Cnxn) - We now apply the quadratic formula to solve for G(x): G(x) = 1 ± J1=4X 2x We must decide whether to use the plus sign or the minus sign. If we use the plus sign, then trying to calculate G(O), which, after all, is supposed to be C0 , gives us the undefined value 2/0. Therefore we must use the minus sign, and indeed one can find using calculus that the indeterminate form 0/0 equals 1 here, since limx__,oG(x) = 1. b) By Exercise 40 we know that 1 2 (1- 4x)- ! = ~ (2:)xn, so by integrating term by term (which is valid) we have r (1- 4t)-l/2 dt = 1- J1=4X = x. 1- J1=4X = f-1-(2n)xn+l = x f-l-(2n)xn. 2 }0 2x n=O n + 1 n n=O n + 1 n Since G(x) = (1 - Jl - 4x)/(2x), equating coefficients of the power series tells us that Cn = n~l (2,:'). c) It is natural to try a proof by strong induction, because the sequence is defined recursively. We need to check the base cases: C 1 = 1 ;::: 21- 1 , C 2 = 2 ;::: 22- 1 , C3 = 5 2 23- 1 , C4 = 14 2 24 - 1 , C5 = 42 ;::: 25 - 1 . For the inductive step assume that CJ;::: 2J-l for 1::; j < n, where n;::: 6. Then Cn = n-1 n-2 k=O k=l L CkCn-k-1 2 L CkCn-k-1 2 (n - n_ 2 2)2k-l2n-k- 2 = - - · 2n-l 2 2n-l. 4 Section 8.4 Generating Functions 295 43. Following the hint, we note that (1 have + xr+n = (1 + xr(l + xr. Then applying the binomial theorem, we ~ C(m + n,r)xr = ~C(m,r)xr · ~C(n,r)xr = ~ (~C(m,r - k)C(n,k))xr by Theorem 1. Comparing coefficients gives us the desired identity. 00 45. We will make heavy use of the identity ex= 00 a) 2 b} c) 2ex n=O ~ (-l)n Xn = oo 3n L n=O -;xn. n=O n. 1 00 "'L"°"' -xn = 2 "'"°"' -xn = n! L n! n=O L n! oo ~ _!__(-x)n Ln! n=O = e-x 1 "'Ln! "°"' -xn = "'Ln! "°"' -(3xr = e 3 x n=O n=O d) This generating function can be obtained either with calculus or without. To do it without calculus, write 00 00 00 00 "'L"°"' -n +-x 1 n n n "'L"°"' -,x 1 n = "'L"°"' -,x + n=O = "'L"°"' n=O n.1 n=O n. n. n=l 00 1 n ( - l)'x n . "'L"°"' + ex = x n=l 1 n-1 ( - l)'x n . + ex 1 00 = x L -,xn +ex = xex +ex . n=O n. L ~ to obtain xex + ex = n=O L (n + 1); . n=O n. n. 00 To do it with calculus, differentiate both sides of xex = 00 n+l n e) This generating function can be obtained either with calculus or without. To do it without calculus, write oo 1 n 1 n oo oo 1 n+l n oo 1 "'"°"' x "'"°"' x "'"°"' x "'"°"'x x ~ n + 1 . n! = ~ (n + 1) ! = ; ~ (n + 1) ! = ; ~ n! = ; (e tn I from 0 to x to obtain oo To do it with calculus, integrate et =L n. n=O oo n+l 1 "'"""""x 1 e - = L n + 1 · n! n=O x oo Therefore 1 1 )· 1 oo "'""""" =xL n=O (n n + 1) x n! · n L ( )x =(ex n=O n + 1 n.1 1)/x. 47. In many of these cases, it's a matter of plugging the exponent of e into the generating function for ex. We let an denote the nth term of the sequence whose generating function is given. a) The generating function is e-x = )n n L--=:;= L(-1r;, so the sequence is an= (-lr. n=O n. n=O n. oo ( oo b) The generating function is 3e 2 x = 3 L n=O c) The generating function is e3 x - 3e 2 x an = 3n - 3 . 2n . = oo + (2 )n n. oo L n=O n oo = L(3 · 2n);, so the sequence is an= 3 · 2n. n. n=O +- + (3 )n n. oo 3L n=O (2 )n n. = oo n L(3n - 3 · 2n);, so the sequence is n. n=O d) The sequence whose exponential generating function is e- 2 x is clearly { (-2r}, as in the previous parts of this exercise. Since 1 0 -1 1 Loo 0 n 1 - x = -x + - x + -x O! 1! n=Z n! ' 296 Chapter 8 Advanced Counting Techniques we know that an= (-2r for n 2: 2, with a 1 = (-2) 1 -1 = -3 and a 0 =(-2) 0 +1=2. e) We know that oo oo I - 1 = '"""xn = '""" n. xn 1- x L..J L..J n! ' n=O n=O so the sequence for which 1/(1- x) is the exponential generating function is {n!}. Combining this with the rest of the function (similar to previous parts of this exercise), we have an= (-2)n + n!. t) This is similar to part ( e). The three functions being added here are the exponential generating functions for {(-3)n}, (-1, -1, 0, 0, 0, ... ) , and {n! · 2n}. Therefore an = (-3)n + n! · 2n for n 2: 2, with ao = (-3) 0 - 1 + O! · 2° = 1 and a 1 = (-3) 1 - 1+1! · 21 = -2. g) First we note that x2 e oo (x2)n x2 x4 x6 =I:-;:!=l+lf+2f+3f+··· n=O x 0 O! x 2 2! x 4 4! = OT . Ol + 2f . ll + 4! . 2! x6 6! + 6T . 3! + .... Therefore we see that an = 0 if n is odd, and an= n!/(n/2)! if n is even. 49. a) Let an be the number of codewords of length n. There are sn strings of length n in all, and only those that contain an even number of Ts are code words. The initial condition is clearly ao = 1 (the empty string has an even number of Ts); if that seems too obscure, one can take a 1 = 7, since one of the eight strings of length 1 (namely the string 7) is disallowed. To write down a recurrence, we observe that a valid string of length n consists either of a valid string of length n - l followed by a digit other