Study Guides (248,215)
Canada (121,406)
COMP 251 (7)
Final

FINAL Crib Sheet

11 Pages
302 Views
Unlock Document

Department
Computer Science (Sci)
Course
COMP 251
Professor
Michel Lapointe
Semester
Winter

Description
COMP251FinalCribSheetLecture2BalancedSearchTreesheight1BSTbestcasenodes2depthOlognworstcasenodesheightAVLbalanceconditionheightofleftandrightsubtreemustdifferbyatmost1noderotateRightrootnewRootrootleftrootleftnewRootrightnewRootrightrootreturnnewRootOutsidebalancesfixedbysimplerotationsInsideinsidetreerotationmaintreerotationLecture3HashingAmapisasetofkeyvaluepairsEachkeymaxonevalueHashmaphashfuncthashtablebadhashfunctsamevaluesfordifferentkeysgoodlessvaluecollisionsfordifferentkeyshUhashcodingintegerscompressionhashvalues01m1CompositionofmapshkeycompressionhashCodekeyLinearProbingEntryhkeyclosedhashingIfhkeyisfullLinearProbingEntryhkey1mhkeyhkeyii02QuadraticprobinghkeyhkeyiWeavoidclusteringbutitstillhappensi0Thenthereisdoublehashinghkeyhkeyigkeyi00Lecture4HeapsQueueFILOPriorityQueueremoveobjectwithhighestprioritydefinedbyakeyArraybasedimplementationRootisatA1AileftchildA2iAirightchildA2i1buildHeapfori1tonupHeapiOnlognFasterBuildHeapforin2downto1downHeapiHeightlogn11nodes2h11LevelL2LnodesTilllevelL2L11nodesWorstcaseifeachelementbubblesuptotherootTotalofswapssumofdepthsMaxnumberofswapsforanodeatlevelllWorstcasetotalnumberofswapssumofallhL2Lnlogn1Lecture5DisjointSetsThesetofverticesVinagraphGisportionedconnectedcomponentsthatarepathconnectedForanyundirectedgraphpathconnecteduvdefinesanequivalencerelationonverticesthereisapathoflength0fromutovthereisapathfromutovifandonlyifthereisapathfromvtouifthereisapathfromutovvtowthenthereisapathfromutowDisjointSetsADTAssumeeachsetinthepartitionhasauniquerepresentativeelementfindireturnstherepresentativesamesetijreturnsBooleanunionijmergesCOMP251FinalCribSheetquickfindireturnrepiunionijwithquickfindiOnperuniontooslowifrepirepjoldreprepiforkin01n1ifrepkrepioldreprepkrepjRedundantcallsQuickunionrepresentthedisjointsetsasrootedtreesTherootbeingtherepresentativeiefindifindrepifindrootiEachnodepointstotheirparentsuseparentnonrootelementsholdrootvaluerootnodeshavevalue1Findiifpi1returnielsereturnfindpiUnionijiffindifindjthenpfindifindjUnisizelinkssmalltreetorootofbigtreemxtreesize2ndepthofanynodeislognUniheightlinksshorttreetorootoftalltreemxheightlognnodesaddedproofbyinductionn2hPathCompressionFindiifpi1returnielsepiPathCompressionFindpireturnpiQuickfindisO1forfindandOnforunionQuickunionbyhorsisOlognforbothLecture6DirectedGraphsstronglyconnectedcomponentsofdirectedgraphssetofmutuallyreachableverticesTofindtheSCCcontainingvyouhavetofindtheintersectionofRvandRvsetsofvertsfromtoRGvDFSBFSvvisitedtrueforeachwvadjlistifwvisitedBFSDFSGwfromWefollowtheedgesbackwardsforRtoorwerunRfromGTvonthetransversegraphRunforallverticesinagraphtofindallSCCsDIRECTEDACYCLICGRAPHSaredirectedgraphsthathavenocyclesIfDAGthenitmusthaveatleastonevertexwithnoincomingedgesandonewithnooutgoingTopologicalOrderingiswhenagraphlabeltheverticesv1v2v3visuchthatifvivjEthenijGhasTOifandonlyifGisaDAGLecture7DijkstrasAlgorithmTofindtheshortestpathtoreachavertexnonweightedonemustuseBFSBFSvvvisitedtruewhilequeueemptyAddneighboursutoqueifvisiteduvisitedtrueDijktra2setsSVertsweknowtheshortpathVVertswedontDijkstraGVEsuseapriorityqueueInitializeemptypqForeachuinVparentunullpqadduinfinitypqadds0WhilepqisemptyupqgetMinVertexdistupqremoveMinDistanceSadduForeachvinuadjifvinVStempDistToVdistucostuvIftmpDistpqgetvpqsetvtmpDistparentvuSpaceofthepqisVTimeisOlogVOElogVLikeBFSDijkstragrowsarootedtreeUnlikeBFSitdoesntincrementitspathsby1Lecture8MinimalSpanningTreesPrimandKruskalaregreedyTreeconnectedundirgraphwithnosimplecyclesSimpcycacyclenorepeaedgesandverticesSpanningtreeofconnectedundirgraphisasubgraphthatisatreeandhasallverticesofgraphIfagraphhasVverticesthenaspanningtreehasV1edgesMSTisaspanningtreewhosetotalweightsareassmallaspossibleAcutinagraphisapartitionoftheverticesintoSandVSThecrossingedgesofacutarethesetofverticesuvsuchthatuSandvVSLetebethecrossingedgewithstrictlythesmallestweightthenebelongstoeveryMSTCutPropertyAlgDefineacutChooseamincrossedgeAddedgetoT
More Less

Related notes for COMP 251

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit