Handbook of Data Structures and Applications Second Edition Handbook of Data Structures and Applications Second Edition Edited by Dinesh P. Mehta Sartaj Sahni MATLAB(cid:2)RisatrademarkofTheMathWorks,Inc.andisusedwithpermission.TheMathWorksdoesnotwarranttheaccuracyofthetextor exercisesinthisbook.Thisbook’suseordiscussionofMATLAB(cid:2)Rsoftwareorrelatedproductsdoesnotconstituteendorsementorsponsorship byTheMathWorksofaparticularpedagogicalapproachorparticularuseoftheMATLAB(cid:2)Rsoftware. CRCPress Taylor&FrancisGroup 6000BrokenSoundParkwayNW,Suite300 BocaRaton,FL33487-2742 (cid:2)c 2018byTaylor&FrancisGroup,LLC CRCPressisanimprintofTaylor&FrancisGroup,anInformabusiness NoclaimtooriginalU.S.Governmentworks Printedonacid-freepaper InternationalStandardBookNumber-13:978-1-4987-0185-3(Hardback) Thisbookcontainsinformationobtainedfromauthenticandhighlyregardedsources.Reasonableeffortshavebeenmadetopublishreliabledata andinformation,buttheauthorandpublishercannotassumeresponsibilityforthevalidityofallmaterialsortheconsequencesoftheiruse.The authorsandpublishershaveattemptedtotracethecopyrightholdersofallmaterialreproducedinthispublicationandapologizetocopyright holdersifpermissiontopublishinthisformhasnotbeenobtained.Ifanycopyrightmaterialhasnotbeenacknowledgedpleasewriteandletus knowsowemayrectifyinanyfuturereprint. ExceptaspermittedunderU.S.CopyrightLaw, nopart ofthisbookmaybereprinted, reproduced,transmitted,orutilizedinanyformby anyelectronic,mechanical,orothermeans,nowknownorhereafterinvented,includingphotocopying,microfilming,andrecording,orinany informationstorageorretrievalsystem,withoutwrittenpermissionfromthepublishers. Forpermissiontophotocopyorusematerialelectronicallyfromthiswork,pleaseaccesswww.copyright.com(http://www.copyright.com/)or contacttheCopyrightClearanceCenter,Inc.(CCC),222RosewoodDrive,Danvers,MA01923,978-750-8400.CCCisanot-for-profitorgani- zationthatprovideslicensesandregistrationforavarietyofusers.FororganizationsthathavebeengrantedaphotocopylicensebytheCCC,a separatesystemofpaymenthasbeenarranged. TrademarkNotice:Productorcorporatenamesmaybetrademarksorregisteredtrademarks,andareusedonlyforidentificationandexplanation withoutintenttoinfringe. LibraryofCongressCataloging-in-PublicationData Names:Mehta,DineshP.,editor.|Sahni,Sartaj,editor. Title:Handbookofdatastructuresandapplications/editedbyDineshP.MehtaandSartajSahni. Othertitles:Datastructuresandapplications Description:Secondedition.|BocaRaton,Florida:CRCPress,[2018]|Includesbibliographicalreferencesandindex. Identifiers:LCCN2017041375|ISBN9781498701853(hardback)|ISBN9781315119335(e-book) Subjects:LCSH:Systemdesign--Handbooks,manuals,etc.|Datastructures(Computerscience)--Handbooks,manuals,etc. Classification:LCCQA76.9.S88H3632005|DDC005.7/3--dc23LCrecordavailableathttps://lccn.loc.gov/2017041375 VisittheTaylor&FrancisWebsiteat http://www.taylorandfrancis.com andtheCRCPressWebsiteat http://www.crcpress.com Toourwives, UshaMehtaandNeetaSahni Contents PrefacetotheSecondEdition.....................................................................................................................................xi PrefacetotheFirstEdition........................................................................................................................................xiii Editors..........................................................................................................................................................................xv Contributors..............................................................................................................................................................xvii PART I Fundamentals 1 AnalysisofAlgorithms.......................................................................................................................................3 SartajSahni 2 BasicStructures.................................................................................................................................................23 DineshP.Mehta 3 Trees...................................................................................................................................................................35 DineshP.Mehta 4 Graphs................................................................................................................................................................49 NarsinghDeo PART II Priority Queues 5 LeftistTrees........................................................................................................................................................69 SartajSahni 6 SkewHeaps........................................................................................................................................................77 C.PanduRangan 7 Binomial,Fibonacci,andPairingHeaps.........................................................................................................85 MichaelL.Fredman 8 Double-EndedPriorityQueues.......................................................................................................................97 SartajSahni PART III Dictionary Structures 9 HashTables......................................................................................................................................................117 PatMorin 10 BloomFilterandItsVariants.........................................................................................................................131 ShigangChen 11 BalancedBinarySearchTrees........................................................................................................................151 ArneAndersson,RolfFagerberg,andKimS.Larsen 12 FingerSearchTrees.........................................................................................................................................171 GerthStøltingBrodal vii viii Contents 13 Splaytrees........................................................................................................................................................179 SanjeevSaxena 14 RandomizedDictionaryStructures...............................................................................................................197 C.PanduRangan 15 TreeswithMinWeightedPathLength..........................................................................................................215 WojciechRytter 16 BTrees..............................................................................................................................................................233 DonghuiZhang PART IV Multidimensional/Spatial Structures 17 MultidimensionalSpatialDataStructures....................................................................................................251 HananSamet 18 PlanarStraightLineGraphs...........................................................................................................................277 Siu-WingCheng 19 Interval,Segment,Range,PrioritySearchTrees..........................................................................................291 D.T.LeeandHung-IYu 20 QuadtreesandOcttrees..................................................................................................................................309 SrinivasAluru 21 BSPTrees..........................................................................................................................................................329 BruceF.Naylor 22 R-Trees.............................................................................................................................................................343 ScottLeuteneggerandMarioA.Lopez 23 ManagingSpatio-TemporalData..................................................................................................................359 SumeetDuaandS.S.Iyengar 24 KineticDataStructures..................................................................................................................................377 LeonidasGuibas 25 OnlineDictionaryStructures.........................................................................................................................389 TeofiloF.Gonzalez 26 Cuttings............................................................................................................................................................397 BernardChazelle 27 ApproximateGeomQueryStructures..........................................................................................................405 ChristianA.DuncanandMichaelT.Goodrich 28 GeometricandSpatialDataStructuresinExternalMemory.....................................................................419 JeffreyScottVitter PART V Miscellaneous 29 Tries..................................................................................................................................................................445 SartajSahni 30 SuffixTreesandSuffixArrays........................................................................................................................461 SrinivasAluru 31 StringSearching..............................................................................................................................................477 AndrzejEhrenfeuchtandRossM.McConnell Contents ix 32 BinaryDecisionDiagrams.............................................................................................................................495 Shin-ichiMinato 33 PersistentDataStructures..............................................................................................................................511 HaimKaplan 34 DataStructuresforSets..................................................................................................................................529 RajeevRaman 35 CacheObliviousDataStructures...................................................................................................................545 LarsArge,GerthStøltingBrodal,andRolfFagerberg 36 DynamicTrees.................................................................................................................................................567 CamilDemetrescu,IreneFinocchi,andGiuseppeF.Italiano 37 DynamicGraphs.............................................................................................................................................581 CamilDemetrescu,IreneFinocchi,andGiuseppeF.Italiano 38 SuccinctRepresentationofDataStructures.................................................................................................595 J.IanMunroandS.SrinivasaRao 39 RandomizedGraphDataStructures.............................................................................................................611 SurenderBaswanaandSandeepSen 40 SearchingandPriorityQueuesino(logn)Time.........................................................................................627 ArneAndersson PART VI Data Structures in Langs and Libraries 41 FunctionalDataStructures............................................................................................................................639 ChrisOkasaki 42 LEDA,aPlatformforCombinatorialandGeometricComputing.............................................................653 StefanNaeher 43 DataStructuresinC++...................................................................................................................................667 MarkAllenWeiss 44 DataStructuresinJDSL..................................................................................................................................679 MichaelT.Goodrich,RobertoTamassia,andLucaVismara 45 DataStructureVisualization..........................................................................................................................697 JohnStasko 46 DrawingTrees..................................................................................................................................................707 SebastianLeipert 47 DrawingGraphs..............................................................................................................................................723 PeterEadesandSeok-HeeHong 48 ConcurrentDataStructures...........................................................................................................................741 MarkMoirandNirShavit PART VII Applications 49 IPRouterTables..............................................................................................................................................765 SartajSahni,KunSukKim,andHaibinLu 50 MultidimensionalPacketClassification........................................................................................................783 PankajGupta