您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 硕士算法2010_第5章_图的算法001
1算法设计与分析李洪伟博士电子科技大学计算机科学与工程学院hongweili@uestc.edu.cn=2982第5章图的算法图的概念图的搜索问题拓扑排序强连通分支最小生成树算法最短路径算法欧拉回路与中国邮递员问题网络流及其应用3GraphsDefinitionsGraphTraversalsDepthFirstSearch(DFS)BreadthFirstSearch(BFS)TopologicalSortShortestPathsProblemsMinimumSpanningTree(MST)4图4.-1哥尼斯堡七桥问题哥尼斯堡七桥问题从任一地出发,是否能在每座桥只通过一次的前提下,游历全城最后又返回到原出发地?CDAB图4.-2哥尼斯堡七桥问题所对应的图CABD5Definition:DirectedgraphDirectedGraphAdirectedgraph,ordigraph,isapairG=(V,E)whereVisasetwhoseelementsarecalledvertices,andEisasetoforderedpairsofelementsofV.Verticesareoftenalsocallednodes.ElementsofEarecallededges,ordirectededges,orarcs.Fordirectededge(v,w)inE,visitstailandwitshead;(v,w)isrepresentedinthediagramsasthearrow,v-w.Intextwesimplewritevw.Definition:UndirectedgraphUndirectedGraphAundirectedgraphisapairG=(V,E)whereVisasetwhoseelementsarecalledvertices,andEisasetofunorderedpairsofdistinctelementsofV.Verticesareoftenalsocallednodes.ElementsofEarecallededges,orundirectededges.EachedgemaybeconsideredasasubsetofVcontainingtwoelements,{v,w}denotesanundirectededgeIndiagramsthisedgeisthelinev---w.Intextwesimplewritevw,orwvvwissaidtobeincidentupontheverticesvandwDefinitions:WeightedGraphAweightedgraphisatriple(V,E,W)where(V,E)isagraph(directedorundirected)andWisafunctionfromEintoR,thereals.Foranedgee,W(e)iscalledtheweightofe.GraphRepresentationsAdjacencyMatrixRepresentationLetG=(V,E),n=|V|,m=|E|,V={v1,v2,…,vn)Gcanberepresentedbyannnmatrix9AdjacencyMatrixforweightdigraphArrayofAdjacencyListsRepresentationFromtoArrayofAdjacencyListsRepresentationfrom-to,weightMoreDefinitionsSubgraphSymmetricdigraphcompletegraphAdjacencyrelationPath,simplepath,reachableConnected,StronglyConnectedCycle,simplecycleacyclicundirectedforestfreetree,undirectedtreerootedtreeConnectedcomponent13MoreDefinitionsAsubgraphG'=(V',E')ofagraphG=(V,E)consistsofasubsetofV'V,andE'E,suchthateachedgeinE'isaconnectionbetweenapairofverticesinV'.Thenumberofverticesisdenotedby|V|,andthenumberofedgesisdenotedby|E|.Asequenceofvertices,v1,v2,...,vnformsapathoflengthn–1ifthereexistedgesfromvitovi+1for1≤in.14MoreDefinitionsAcycleisapathoflength3ormorethatconnectsvitoitself.Acycleissimpleifthepathissimple,exceptforthefirstandlastverticesbeingthesame.Anundirectedgraphisconnectedifthereisatleastonepathfromanyvertextoanyother.Themaximalconnectedsubgraphsofanundirectedgrapharecalledconnectedcomponents.34121702413(a)(b)(c)MoreDefinitionsAgraphwithoutcyclesisacyclic.AdirectedgraphwithoutcyclesisadirectedacyclicgraphorDAG.Afreetreeisaconnected,undirectedgraphwithnosimplecycles.Equivalently,afreetreeisconnectedandhas|V–1|edges.16Bi-connectedComponentsofanUndirectedGraphProblem:Ifanyonevertex(andtheedgesincidentuponit)areremovedfromaconnectedgraph,Istheremainingsubgraphstillconnected?Biconnectedgraph:AconnectedundirectedgraphGissaidtobebiconnectedifitremainsconnectedafterremovalofanyonevertexandtheedgesthatareincidentuponthatvertex.17Bi-connectedComponentsofanUndirectedGraphBiconnectedcomponent:Abiconnectedcomponentofaundirectedgraphisamaximalbiconnectedsubgraph,thatis,abiconnectedsubgraphnotcontainedinanylargerbinconnectedsubgraph.Articulationpoint:AvertexvisanarticulationpointforanundirectedgraphGiftherearedistinctverticeswandx(distinctfromvalso)suchthatvisineverypathfromwtox.Bi-connectedcomponents,e.g.Someverticesareinmorethanonecomponent(whichverticesarethese?)StronglyConnectedComponentsofaDigraphStronglyconnected:Adirectedgraphisstronglyconnectedifandonlyif,foreachpairofverticesvandw,thereisapathfromvtow.Stronglyconnectedcomponent:AstronglyconnectedcomponentofadigraphGisamaximalstronglyconnectedsubgraphofG.20StronglyConnectedComponentsandEquivalenceRelationsStronglyconnectedcomponentsmaybedefinedintermsofanequivalencerelation,S,ontheverticesvSwiffthereisapathfromvtowandapathfromwtovThen,astronglyconnectedcomponentconsistsofoneequivalenceclass,C,alongwithalledgesvwsuchthatvandwareinC.21CondensationgraphThestronglyconnectedcomponentsofadigraphcaneachbecollapsedtoasinglevertexyieldinganewdigraphthathasnocycles.Condensationgraph:LetS1,S2,...SpbethestronglyconnectedcomponentsofG.ThecondensationgraphofGdenotedasG=(V',E'),whereV'haspelementss1,s2,...spandsisjisinE'ifandonlyifijandthereisanedgeinEfromsomevertexinSitosomevertexinSj.22CondensationgraphanditsstronglyconnectedcomponentsCondensationGraphisacyclic.234.3图的搜索搜索是解决许多有关图的问题的一种基本技术,同时也是许多图论算法的基础。简单地讲,图的搜索是指从图的某个节点出发,依某种次序访问图的各个节点。典型的搜索算法有宽度优先搜索(BreadthFirstSearch,BFS)和深度优先搜索(DepthFirstSearch,DFS)两种。24Breath-firstsearchBreadth-firstsearch:Strategy(fordigraph)chooseastartingvertex,distanced=0verticesarevisitedinorderofincreasingdistancefromthestartingvertex,examinealledgesleadingfromvertices(atdistanced)toadjacentvertices(atdistanced+1)then,examinealledgesleadingfromverticesatdistanced+1todistanced+2,andsoon,untilnonewvertexisdiscoveredBreath-firstsearch,e.g.e.g.StartfromvertexA,atd=0visitB,C,F;atd=1visitD;atd=2e.g.StartfromvertexE
本文标题:硕士算法2010_第5章_图的算法001
链接地址:https://www.777doc.com/doc-2180335 .html