This preview shows page 1. Sign up to view the full content.
Unformatted text preview: has the lowest weight of edges that… have one vertex in the tree and one not in the tree. Thus buildsup one tree by adding a new edge to it Can this lead
(Tell me why not.) Is it optimal? (Yes. Need a proof.) 29 to an infeasible solution? Tracking Edges for Prim’s MST Candidates edges: edge from a treenode to a
nontree node Since we’ll choose smallest, keep only one candidate
edge for each nontree node But, may need to make sure we always have the
smallest edge for each nontree node Fringenodes: nontrees nodes adjacent to the
tree Need data structure to hold fringenodes Priority queue, ordered by minedge weight May need to update priorities! 30 Prim’s Algorithm
MSTPrim(G, wt)
init PQ to be empty;
PQ.Insert(s, wt=0);
parent[s] = NULL;
while (PQ not empty)
v = PQ.ExtractMin();
for each w adj to v
if (w is unseen) {
PQ.Insert(w, wt(v,w));
parent[w] = v;
}
31 else if (w is fringe && wt[v,w] < fringeWt(w)){ Cost of Prim’s Algorithm (Assume connected graph) Clearly it loo...
View
Full
Document
This note was uploaded on 02/25/2014 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.
 Spring '10
 HORTON
 Algorithms

Click to edit the document details