Design and Analysis of Algorithms Thetextintroducesreaderstodifferentparadigmsofcomputinginadditiontothetraditional approach of discussing fundamental computational problems and design techniques in the random access machine model. Alternate models of computation including parallel, cache-sensitive design and streaming algorithms are dealt in separate chapters to underline thesignificantroleoftheunderlyingcomputationalenvironmentinthealgorithmdesign. The treatment is made rigorous by demonstrating new measures of performances along with matchinglowerboundarguments. The importance of greedy algorithms, divide-and-conquer technique and dynamic programming is highlighted by additional applications to approximate algorithms that come withguarantees.Inadditiontoseveralclassicaltechniques,thebookencouragesliberaluseof probabilistic analysis and randomized techniques that have been pivotal for many recent advancesinthisarea. Thereisalsoachapterintroducingtechniquesfordimensionreduction which is at the heart of many interesting applications in data analytics as well as statistical machinelearning. Whilethesetechniqueshavebeenknownforawhileinothercommunities, theiradoptionintomainstreamcomputersciencehasbeenrelativelyrecent. Concepts are discussed with the help of rigorous mathematical proofs, theoretical explanations and their limitations. Problems have been chosen from a diverse landscape including graphs, geometry, strings, algebra and optimization. Some exposition of approximation algorithms has also been included, which has been a very active area of research in algorithms. Real life applications and numerical problems are spread throughout the text. The reader is expected to test her understanding by trying out a large number of exerciseproblemsaccompanyingeverychapter. Thebookassumesfamiliaritywithbasicdatastructures,tofocusonmorealgorithmicaspects andtopicsofcontemporaryimportance. Sandeep Sen has been a faculty member in the Department of Computer Science and Engineering, Indian Institute of Technology Delhi, India, since 1991 where he is currently a professor. His research spans randomized algorithms, computational geometry, dynamic graph algorithms and models of computation. He is a Fellow of the Indian National Science AcademyandtheIndianAcademyofSciences. Amit Kumar is a faculty member in the Department of Computer Science and Engineering, Indian Institute of Technology Delhi, India. His research lies in the area of combinatorial optimization, with emphasis on problems arising in scheduling, graph theory and clustering.HeisaFellowofIndianAcademyofSciences,andisarecentrecipientoftheShanti SwarupBhatnagarAwardforMathematicalSciences. Design and Analysis of Algorithms Sandeep Sen Amit Kumar UniversityPrintingHouse,CambridgeCB28BS,UnitedKingdom OneLibertyPlaza,20thFloor,NewYork,NY10006,USA 477WilliamstownRoad,PortMelbourne,VIC3207,Australia 314to321,3rdFloor,PlotNo.3,SplendorForum,JasolaDistrictCentre,NewDelhi110025,India 79AnsonRoad,#06–04/06,Singapore079906 CambridgeUniversityPressispartoftheUniversityofCambridge. ItfurtherstheUniversity’smissionbydisseminatingknowledgeinthepursuitof education,learningandresearchatthehighestinternationallevelsofexcellence. www.cambridge.org Informationonthistitle: www.cambridge.org/9781108496827 (cid:13)c SandeepSenandAmitKumar2019 Thispublicationisincopyright. Subjecttostatutoryexception andtotheprovisionsofrelevantcollectivelicensingagreements, noreproductionofanypartmaytakeplacewithoutthewritten permissionofCambridgeUniversityPress. Firstpublished2019 PrintedinIndia AcataloguerecordforthispublicationisavailablefromtheBritishLibrary LibraryofCongressCataloging-in-PublicationData Names: Sen,Sandeep,author. |Kumar,Amit,1976-author. Title: Designandanalysisofalgorithms/SandeepSen,AmitKumar. Description: NewYork,NY,USA:UniversityPrintingHouse,2019. |Includes bibliographicalreferencesandindex. Identifiers: LCCN2019002080|ISBN9781108496827(hardback: alk. paper)| ISBN9781108721998(paperback: alk. paper) Subjects: LCSH:Algorithms. Classification: LCCQA9.58.S4542019|DDC005.1–dc23 LCrecordavailableathttps://lccn.loc.gov/2019002080 ISBN978-1-108-49682-7Hardback ISBN978-1-108-72199-8Paperback CambridgeUniversityPresshasnoresponsibilityforthepersistenceoraccuracy ofURLsforexternalorthird-partyinternetwebsitesreferredtointhispublication, anddoesnotguaranteethatanycontentonsuchwebsitesis,orwillremain, accurateorappropriate. To the loving memory of my parents, Sisir Sen and Krishna Sen who nourished and inspired my academic pursuits and all my teachers who helped me imbibe the beauty andintricaciesofvarioussubjects –SandeepSen Tomyparents –AmitKumar Content ListofFigures xv ListofTables xix Preface xxi Acknowledgments xxv 1 ModelandAnalysis 1 1.1 ComputingFibonacciNumbers 1 1.2 FastMultiplication 3 1.3 ModelofComputation 4 1.4 RandomizedAlgorithms: AShortIntroduction 6 1.4.1 Adifferentflavorofrandomizedalgorithms 8 1.5 OtherComputationalModels 10 1.5.1 Externalmemorymodel 10 1.5.2 Parallelmodel 11 FurtherReading 12 ExerciseProblems 13 2 BasicsofProbabilityandTailInequalities 16 2.1 BasicsofProbabilityTheory 16 2.2 TailInequalities 21 2.3 GeneratingRandomNumbers 26 2.3.1 Generatingarandomvariateforanarbitrarydistribution 26 viii Contents 2.3.2 Generatingrandomvariablesfromasequentialfile 27 2.3.3 Generatingarandompermutation 29 FurtherReading 31 ExerciseProblems 31 3 Warm-upProblems 34 3.1 Euclid’sAlgorithmfortheGreatestCommonDivisor(GCD) 34 3.1.1 ExtendedEuclid’salgorithm 35 3.1.2 Applicationtocryptography 36 3.2 FindingthekthSmallestElement 37 3.2.1 Choosingarandomsplitter 38 3.2.2 Medianofmedians 39 3.3 SortingWords 41 3.4 MergeableHeaps 43 3.4.1 Mergingbinomialheaps 44 3.5 ASimpleSemi-dynamicDictionary 45 3.5.1 Potentialmethodandamortizedanalysis 46 3.6 LowerBounds 47 FurtherReading 50 ExerciseProblems 50 4 OptimizationI:BruteForceandGreedyStrategy 54 4.1 HeuristicSearchApproaches 55 4.1.1 Gametrees* 57 4.2 AFrameworkforGreedyAlgorithms 60 4.2.1 Maximumspanningtree 64 4.2.2 Findingminimumweightsubset 64 4.2.3 Aschedulingproblem 65 4.3 EfficientDataStructuresforMinimumSpanningTreeAlgorithms 66 4.3.1 AsimpledatastructureforUnion–Find 68 4.3.2 Afasterscheme 69 4.3.3 Theslowestgrowingfunction? 71 4.3.4 Puttingthingstogether 72 4.3.5 Pathcompressiononly* 73 4.4 GreedyinDifferentWays 74 4.5 CompromisingwithGreedy 76