28 primsmstalgorithm greedy strategy choose some start

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: has the lowest weight of edges that… have one vertex in the tree and one not in the tree. Thus builds-up 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 tree-node to a non-tree node Since we’ll choose smallest, keep only one candidate edge for each non-tree node But, may need to make sure we always have the smallest edge for each non-tree node Fringe-nodes: non-trees nodes adjacent to the tree Need data structure to hold fringe-nodes Priority queue, ordered by min-edge weight May need to update priorities! 30 Prim’s Algorithm MST-Prim(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.

Ask a homework question - tutors are online