MST-Kruskal( G, w ).ppt


文档分类:研究报告 | 页数:约14页 举报非法文档有奖
1/14
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/14
文档列表 文档介绍
UNC Chapel Hill Lin/Foskey/Manocha MST- Kruskal( G, w ) 1. A??// initially A is empty 2. for each vertex v ? V[G ] // line 2-3 takes O(V ) time 3. do Create-Set( v) // create set for each vertex 4. sort the edges of E by nondecreasing weight w 5. for each edge ( u,v)? E, in order by nondecreasing weight 6. do if Find-Set( u ) ? Find-Set( v ) // u&v on different trees 7. then A? A ?{(u,v)} 8. Union( u,v) 9. return A Total running time is O( E lg E ). UNC Chapel Hill Lin/Foskey/Manocha Analysis of Kruskal ? Lines 1-3 (initialization): O(V) ? Line 4 (sorting): O(E lgE) ? Lines 6-8 (set operations): O(E log E) ? Total: O(E log E) UNC Chapel Hill Lin/Foskey/Manocha Correctness of Kruskal ? Idea: Show that every edge added is a safe edge for A ? Assume ( u, v ) is next edge to be added to A. – Will not create a cycle ? Let A’ denote the tree of the forest A that contains vertex u . Consider the cut ( A’, V-A ’). – This cut respects A (why?) – and ( u, v ) is the light edge across the cut (why?) ? Thus, by the MST Lemma, ( u,v ) is safe. UNC Chapel Hill Lin/Foskey/Manocha Intuition behind Prim ’s Algorithm ? Consider the set of vertices S currently part of the tree, and plement ( V-S ). We have a cut of the graph and the current set of tree edges A is respected by this cut. ? Which edge should we add next? Light edge! UNC Chapel Hill Lin/Foskey/Manocha Basics of Prim ’ s Algorithm ? It works by adding leaves on at a time to the current tree. – Start with the root vertex r (it can be any vertex). At any time, the subset of edges A forms a single tree. S = vertices of A.– At each step, a light edge connecting a vertex in S to a vertex in V- S is added to the tree. – The tree grows until it spans all the vertices in V. ? Implementation Issues: – How to update the cut efficiently? – How to determine the light edge quickly? UNC

MST-Kruskal( G, w ) 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数14
  • 收藏数0 收藏
  • 顶次数0
  • 上传人gyzhluyin
  • 文件大小0 KB
  • 时间2016-07-14