i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page i | #1 i i Foundations of Discrete Mathematics with Algorithms and Programming i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page ii | #2 i i i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page iii | #3 i i Foundations of Discrete Mathematics with Algorithms and Programming Sriraman Sridharan Laboratoire LAMPS Département de Mathématiques et d’Informatique Université de Perpignan Via Domitia Perpignan FRANCE R. Balakrishnan Bharathidasan University Tiruchirappalli Tamil Nadu INDIA i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page iv | #4 i i CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2019 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Printed on acid-free paper Version Date: 20180813 International Standard Book Number-13: 978-0-8153-7848-8 (Hardback) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging-in-Publication Data Names: Sridharan, Sriraman, author. | Balakrishnan, R. (Rangaswami), author. Title: Foundations of discrete mathematics with algorithms and programming / Sriraman Sridharan, R. Balakrishnan. Description: Boca Raton : Taylor & Francis, a CRC title, part of the Taylor & Francis imprint, a member of the Taylor & Francis Group, the academic division of T&F Informa, plc, 2019. | Includes bibliographical references and index. Identifiers: LCCN 2018018635| ISBN 9780815378488 (hardback : acid-free paper) | ISBN 9781351019149 (ebook) Subjects: LCSH: Computer science--Mathematics. Classification: LCC QA76.9.M35 S725 2019 | DDC 004.01/51--dc23 LC record available at https://lccn.loc.gov/2018018635 Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page v | #5 i i i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page vi | #6 i i The (cid:12)rst author S. S. affectionately dedicates this book in memory of his parents: Geeyar Sriraman Padmavathi Sundaravaradhan The second author R. B. dedicates this book in memory of the Late Professor Jacob K. Goldhaber, formerlyoftheUniversityofMaryland,USAforallthegoodthings in life the author learned from him, besides, of course, mathemat- ics. i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page vii | #7 i i Contents Preface xi 1 Sets, Relations and Functions 1 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Functions . . . . . . . . . . . . . . . . . . . . . . . 5 1.3 Equivalence Relations . . . . . . . . . . . . . . . . . 9 1.4 Finite and In(cid:12)nite Sets . . . . . . . . . . . . . . . 11 1.5 Cardinal Numbers of Sets . . . . . . . . . . . . . . 14 1.6 Power Set of a Set . . . . . . . . . . . . . . . . . . 17 1.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 19 1.8 Partially Ordered Sets . . . . . . . . . . . . . . . . 20 1.9 Lattices . . . . . . . . . . . . . . . . . . . . . . . . 25 1.10 Boolean Algebras . . . . . . . . . . . . . . . . . . . 34 1.10.1 Introduction . . . . . . . . . . . . . . . . . . 34 1.10.2 Examples of Boolean Algebras . . . . . . . . 34 1.11 Atoms in a Lattice . . . . . . . . . . . . . . . . . . 38 1.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 42 2 Combinatorics 47 2.1 What Is Combinatorics? . . . . . . . . . . . . . . . 48 2.2 Elementary Counting Principles . . . . . . . . . . . 51 2.3 Permutations and Combinations . . . . . . . . . . . 64 2.3.1 Sums and Products . . . . . . . . . . . . . . 79 2.4 Binomial Theorem . . . . . . . . . . . . . . . . . . 83 2.5 Multinomial Coefficients . . . . . . . . . . . . . . . 91 2.6 Stirling Numbers . . . . . . . . . . .{.}. . . . . . . 103 2.7 Stirling Number of the Second Kind n . . . . . . 113 k vii i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page viii | #8 i i viii CONTENTS 2.8 Bell Numbers . . . . . . . . . . . . . . . . . . . . . 125 2.9 The Principle of Inclusion . . . . . . . . . . . . . . 127 2.9.1 Applications of Inclusion and Exclusion Principle . . . . . . . . . . . . . . . . . . . . 132 2.9.2 Application of Inclusion and Exclusion Principle to Elementary Number Theory . . 137 2.9.3 Applications to Permanents . . . . . . . . . 143 2.10 Generating Functions . . . . . . . . . . . . . . . . . 152 2.10.1 Solving Recurrence Relations Using Generating Function Techniques . . . . . . . 157 2.10.2 Catalan Numbers . . . . . . . . . . . . . . . 160 2.11 Generating Subsets . . . . . . . . . . . . . . . . . . 166 2.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 175 3 Basics of Number Theory 183 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . 184 3.2 Divisibility . . . . . . . . . . . . . . . . . . . . . . . 184 3.3 gcd and lcm of Two Integers . . . . . . . . . . . . . 186 3.4 Primes . . . . . . . . . . . . . . . . . . . . . . . . . 189 3.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 193 3.6 Congruences . . . . . . . . . . . . . . . . . . . . . . 194 3.7 Complete System of Residues . . . . . . . . . . . . 197 3.8 Linear Congruences . . . . . . . . . . . . . . . . . . 202 3.9 Lattice Points Visible from the Origin . . . . . . . . 206 3.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 209 3.11 Some Arithmetical Functions . . . . . . . . . . . . 210 3.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 218 3.13 The Big O Notation . . . . . . . . . . . . . . . . . 218 4 Introduction to Graph Theory 225 4.1 The Idea of a Graph . . . . . . . . . . . . . . . . . 225 4.2 An Informal and Intuitive . . . . . . . . . . . . . . 234 4.3 Multigraph or Undirected Graph . . . . . . . . . . 239 4.4 Some Special Graphs . . . . . . . . . . . . . . . . . 244 4.5 Graphs and Subgraphs . . . . . . . . . . . . . . . . 264 4.6 Walks, Paths, Cycles . . . . . . . . . . . . . . . . . 271 4.7 Connectedness . . . . . . . . . . . . . . . . . . . . . 275 i i i i i i \rb_sri_book_vol_1" | 2018/10/4 | 10:13 | page ix | #9 i i CONTENTS ix 4.8 Graphs and Puzzles . . . . . . . . . . . . . . . . . . 283 4.8.1 An Application . . . . . . . . . . . . . . . . 288 4.8.2 Two Friendship Theorems . . . . . . . . . . 289 4.8.3 Pandava Princes Problem and 3 Houses, 3 Utilities Problem . . . . . . . . . . . . . . . 292 4.9 Ramsey Numbers . . . . . . . . . . . . . . . . . . . 293 4.10 Graph Algebra . . . . . . . . . . . . . . . . . . . . 308 4.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 314 5 Introduction to Algorithms 325 5.1 Algorithms . . . . . . . . . . . . . . . . . . . . . . . 326 5.2 Complexity of Algorithms . . . . . . . . . . . . . . 330 5.3 An Overview of a Classical Computer . . . . . . . . 353 5.4 Introduction to Programming . . . . . . . . . . . . 360 5.4.1 Parameter Passing . . . . . . . . . . . . . . 373 5.4.2 Recursion . . . . . . . . . . . . . . . . . . . 381 5.5 Introduction to Data Structures . . . . . . . . . . . 387 5.5.1 Access Restricted Lists . . . . . . . . . . . . 406 5.6 Examples of Algorithms . . . . . . . . . . . . . . . 416 5.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 439 6 Introduction to Logic 447 6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . 447 6.2 Algebra of Propositions . . . . . . . . . . . . . . . . 448 6.3 Proofs in Mathematics . . . . . . . . . . . . . . . . 454 6.3.1 Universal and Existential Quanti(cid:12)ers . . . . 457 6.4 Probability . . . . . . . . . . . . . . . . . . . . . . 458 Appendices Answers to Even-Numbered Exercises 477 A Answers to Chapter 1 479 B Answers to Chapter 2 483 C Answers to Chapter 3 487 D Answers to Chapter 4 491 i i i i
Description: