




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
Chapter12 Terms:vertex,edge,adjacent,incident,degree,cycle,path,connectedcomponent,spanningtree;Threetypesofgraphs:undirected,directed,Commongraphrepresentations:adjacencymatrix,adjacencylists.G=VisthevertexVerticesarealsocallednodesandEistheedgeEachedgeconnectstwodifferentEdgesarealsocalledarcsandDirectededgehasanorientation Undirectededgehasnoorientation Undirectedgraph=>noorientedDirectedgraph=>everyedgehasanUndirectedDirectedThereisadirectedpathfromanyvertextoanyothervertex.2231845967Vertex=city,edge=communicationDrivingDistance/Time442381862445543956677Vertex=city,edgeweight=drivingStreet2231845967SomestreetsareoneCompleteUndirectedHasallpossiblen= n= n= n=NumberOfEdges—UndirectedEachedgeisoftheform(u,v),u!=Numberofsuchpairsinannvertexgraphisn(n-1).Sinceedge(u,v)isthesameasedge(v,u),thenumberofedgesinacompleteundirectedgraphisn(n-1)/2.Numberofedgesinanundirectedgraph<=n(n-NumberOfEdges--DirectedEachedgeisoftheform(u,v),u!=NumberofsuchpairsinannvertexgraphSinceedge(u,v)isnotthesameasedge(v,u),thenumberofedgesinacompletedirectedgraphisn(n-1).NumberofedgesinadirectedgraphisVertex2231845967Numberofedgesincidenttovertex.degree(2)=2,degree(5)=3,degree(3)=1SumOfVertex889Sumofdegrees=2e(eisnumberofIn-DegreeOfA2231845967in-degreeisnumberofincomingedgesindegree(2)=1,indegree(8)=0Out-DegreeOfA2231845967out-degreeisnumberofoutboundedgesoutdegree(2)=1,outdegree(8)=2SumOfIn-AndOut-eachedgecontributes1tothein-degreeofsomevertexand1totheout-degreeofsomeothervertexsumofin-degrees=sumofout-=e,whereeisthenumberofedgesinthedigraphComputerAdjacencyTables(orAdjacencyLinkedAdjacencyArrayAdjacencyTheSetAdjacency0/1n×nmatrix,wheren=#ofA(i,j)=1iff(i,j)isan23231 512345 1010 0001 0001 0001 1110AdjacencyMatrix231 5 231 5 DiagonalentriesareAdjacencymatrixofanundirectedgraphisA(i,j)=A(j,i)foralliand AdjacencyMatrix23145 23145 DiagonalentriesareAdjacencymatrixofadigraphneednotbeAdjacencyn2bitsofForanundirectedgraph,maystoreonlyloweroruppertriangle(excludediagonal).(n-1)n/2O(n)timetofindvertexdegreeand/orverticesadjacenttoagivenvertex.Adjacency AdjacencyAdjacencylistforvertexiisalinearlistofverticesadjacentfromvertexi.AnarrayofnadjacencyaList[1]=231 231 5aList[3]=aList[4]=aList[5]=ArrayAdjacencyEachadjacencylistisanarray231231 524243ArrayLength=#oflistelements=2e(undirectedgraph)#oflistelements=e(digraph)LinkedAdjacencyEachadjacencylistisa231231 5ArrayLength=#ofchainnodes=2e(undirected#ofchainnodes=eGraphAvertexuisreachablefromvertexviffthereisapathfromvtou.2231845967 Asearchmethodstartsatagivenvertexvandvisits/labels/markseveryvertexthatisreachablefromv.22314577ManygraphproblemssolvedusingasearchPathfromonevertextoIsthegraphFindaspanningCommonlyusedsearchDepth-firstVisitstartvertexandputintoaFIFORepeatedlyremoveavertexfromthequeue,visititsunvisitedadjacentvertices,putnewlyvisitedverticesintothequeue.2231845967Startsearchatvertex231231845967FIFOQueueVisit/mark/labelstartvertexandputinaFIFO231231845967FIFOQueue231231845967FIFOQueue24231231845967FIFOQueue24231231845967FIFOQueue4536231231845967FIFOQueue4536231231845967FIFO53231231845967FIFO53231231845967FIFOQueue3697231231845967FIFOQueue3697231231845967FIFO69231231845967FIFO69231231845967FIFO9231231845967FIFO9231231845967FIFO7231231845967FIFO7231231845967FIFOQueue231231845967FIFOQueue231231845967FIFOQueueisempty.SearchBreadth-FirstSearchAllverticesreachablefromthestartvertex(includingthestartvertex)arevisited.TimeEachvisitedvertexisputon(andsoremovedfrom)thequeueexactlyonce.Whenavertexisremovedfromthequeue,weexamineitsadjacentvertices.O(n)ifadjacencymatrixO(vertexdegree)ifadjacencylistsTotalΘ(sn),wheresisnumberofverticesinthecomponentthatissearched(adjacencymatrix)
)(adjacencyDepth-First{Labelvertexvasreached.for(eachunreachedvertexuadjacenctfromv)}2231845967Startsearchatvertex2231845967223184596722318459672231845967Labelvertex8andreturntovertexFromvertex9doa2231845967Labelvertex6anddoadepthfirstsearchfromeither4or7.Supposethatvertex4is 2231845967Labelvertex4andreturntoFromvertex6doa 2231845967Labelvertex7andreturnto22318459672231845967Doa2231845967Label3andreturntoReturntoDepth-FirstSearch23814 67Returnto231845231845967ReturntoinvokingDepth-FirstSearchSamecomplexityasSamepropertieswithrespecttopathfinding,connectedcomponents,andspanningtrees.Edgesusedtoreachunlabeledverticesdefineadepth-firstspanningtreewhenthegraphisThereareproblemsforwhichBFSisbetterthanDFSandviceversa.12.412.4Topological12.4.3Breadth-First}}12.4.3Breadth-First該方法的每一步均是輸出當(dāng)前無后繼(即出度為0)的頂點(diǎn)。對(duì)于一個(gè)while(G中有出度為0的頂點(diǎn))do{}12.512.5AGreedyAlgorithm:ShortestDirectedweightedPathlengthissumofweightsofedgesonThevertexatwhichthepathbeginsisthesourcevertex.Thevertexatwhichthepathendsisthedestinationvertex.11365247Apathfrom1to11365247Anotherpathfrom1toShortestPathSinglesourcesingleSinglesourceallAllpairs(everyvertexisasourceanddestination).SingleSourceSinglePossiblegreedyLeavesourcevertexusingcheapest/shortestLeavenewvertexusingcheapestedgesubjecttotheconstraintthatanewvertexisreached.ContinueuntildestinationisGreedyShortest1To711365247PathlengthisNotshortestpath.Algorithmdoesn’tSingleSourceAllNeedtogenerateupton(nisnumberofvertices)paths(includingpathfromsourcetoitself).GreedyConstructtheseuptonpathsinorderofincreasingAssumeedgecosts(lengths)are>=So,nopathhaslength<Firstshortestpathisfromthesourcevertextoitself.Thelengthofthispathis0. 4 1 113 1321351351 10131313135121213135413136
Eachpath(otherthanfirst)isaoneedgeextensionofapreviousNextshortestpathistheshortestoneedgeextensionofanalreadygeneratedshortest131367GreedySingleSourceAllLetd(i)(distanceFromSource(i))bethelengthofashortestoneedgeextensionofanalreadygeneratedshortestpath,theoneedgeextensionendsatvertexi.Thenextshortestpathistoanasyetunreachedvertexforwhichthed()valueisleast.Letp(i)(predecessor(i))bethevertexjustbeforevertexiontheshortestoneedgeextensiontoi.d062--p-111--11 11136524713d062p-111311 11136524713 13135 6 135 1 11136524713 13135 9 13512 1211365113652471313512 6295p-11533411354 4 6295 1153361 101313131351212135135406295-11533613136131367DataStructuresForDijkstra’sThegreedysinglesourcealldestinationsalgorithmisknownasDijkstra’salgorithm.Implementd()andp()as1DKeepalinearlistLofreachableverticestowhichshortestpathisyettobegenerated.SelectandremovevertexvinLthathassmallestd()value.Updated()andp()valuesofverticesadjacentto O(n)toselectnextdestinationO(out-degree)toupdated()andp()valueswhenadjacencylistsareused.O(n)toupdated()andp()valueswhenadjacencymatrixisused.Selectionandupdatedoneonceforeachvertextowhichashortestpathisfound.TotaltimeisO(n2+e)=12.612.6Minimum-CostSpanningweightedconnectedundirectedspanningcostofspanningtreeissumofedgefindspanningtreethathasminimum 9Networkhas10Spanningtreehasonlyn-1=7Needtoeitherselect7edgesordiscardStartwithann-vertex0-edgeforest.Consideredgesinascendingorderofcost.Selectedgeifitdoesnotformacycletogetherwithalreadyselectededges.Kruskal’sStartwitha1-vertextreeandgrowitintoann-vertextreebyrepeatedlyaddingavertexandanedge.Whenthereisachoice,addaleastcostedge.Prim’sStartwithann-vertexforest.Eachcomponent/treeselectsaleastcostedgetoconnecttoanothercomponent/tree.Eliminateduplicateselectionsandpossiblecycles.Repeatuntilonly1component/treeisleft.Sollin’s 9
StartwithaforestthathasnoConsideredgesinascendingorderof Edge(1,2)isconsideredfirstandaddedtotheforest.1223744566738 1223744566738 9Edge(7,8)isconsiderednextandEdge(3,4)isconsiderednextandEdge(5,6)isconsiderednextandEdge(2,3)isconsiderednextandEdge(1,3)isconsiderednextandrejecteditcreatesa 9
Edge(2,4)isconsiderednextandrejectedbecauseitcreatesacycle.Edge(3,5)isconsiderednextandEdge(3,6)isconsiderednextandEdge(5,7)isconsiderednextand183575722794466836683n-1edgeshavebeenselectedandnocycleSowemusthaveaspanningCostisMin-costspanningtreeisuniquewhenedgecostsare Prim’s 9StartwithanysinglevertexGeta2-vertextreebyaddingache
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 超星爾雅學(xué)習(xí)通《藝術(shù)鑒賞(北京大學(xué))》2025章節(jié)測試附答案
- 2025年婦幼保健員考試所需的學(xué)習(xí)工具及試題及答案
- 建立自信2025健康管理師試題及答案
- 二零二五年度企業(yè)個(gè)人借款擔(dān)保合同
- 2025年度英語夏令營英語教師派遣與培訓(xùn)合同
- 二零二五歲以上員工勞動(dòng)權(quán)益保障與薪酬福利協(xié)議
- 2025年度餐飲管理公司入股合作協(xié)議
- 2025年度新能源汽車合資項(xiàng)目融資合作協(xié)議
- 二零二五年度汽車經(jīng)銷商返利合同模板
- 二零二五年度水利工程款代付與防洪安全協(xié)議
- 《卓越領(lǐng)導(dǎo)力》課件
- 《大數(shù)據(jù)時(shí)代對(duì)會(huì)計(jì)行業(yè)產(chǎn)生的影響探究》10000字【論文】
- 2025年中國中信集團(tuán)有限公司招聘筆試參考題庫含答案解析
- 阜陽PLC基礎(chǔ)知識(shí)培訓(xùn)課件
- 基金會(huì)專項(xiàng)信息審核業(yè)務(wù)約定書參考格式
- 個(gè)體戶信用修復(fù)申請(qǐng)書范本
- GB/T 44768-2024配電網(wǎng)線損理論計(jì)算導(dǎo)則
- Module 2 Unit 1 London is a big city.(說課稿)-2023-2024學(xué)年外研版(三起)英語四年級(jí)下冊(cè)
- 2023年遼寧省公務(wù)員錄用考試《行測》真題及答案解析
- GB/T 32124-2024磷石膏的處理處置規(guī)范
- 高考志愿填報(bào)師資格新版考試題及答案
評(píng)論
0/150
提交評(píng)論