正在加载图片...
algorithm 8.4 Prim Input: A weighted connected undirected graph G=(V,E), where Output: The set of edges T of minimum cost spanning tree for G 1.T←(}:X←{1}:y←V1(1 2.foy←2ton 3. if y is ad acent to l then 4.My+1 6. C(y)+c(1, yl 6.esec←∞ 7. end if 8. end 9.forj←1ton-1 10. Let y be such that Cly is mInimum 11.T←TU{(y,My 12.X←Xuy 13.Y←Y(y 14. for each edge(y, w)such that wEY 15. if cly, w< Cothen 6789 cw←cb,wl (n) end if end for Heap: 0(mlogn) 20. end for
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有