CS146
Chris Pollett
May 7, 2014
Prior to each iteration, A is a subset of some minimum spanning tree.
GENERIC-MST(G,w) 1 A = 0 2 while A does not form a spanning tree 3 find an edge (u,v) that is safe for A 4 A = A union {(u,v)} 5 return A
MST-KRUSHKAL(G, w) 1 A = 0 2 for each vertex v in G.V 3 MAKE-SET(v) 4 sort the edges of G.E into nondecreasing order by weight w 5 for each edge (u,v) in G.E with respect to this order 6 if FIND-SET(u) != FIND-SET(v) 7 A = A union {(u,v)} 8 UNION(u,v) 9 return A
MST-PRIM(G, w, r) // r is a starting node to grow the tree from 01 for each u in G.V 02 u.key = infty 03 u.pi = NIL 04 r.key = 0 05 Q = MAKE-QUEUE(G.V) 06 while Q != 0 07 u = EXTRACT-MIN(Q) 08 for each v in G.adj[u] 09 if v in Q and w(u, v) < v.key 10 v.pi = u 11 v.key = w(u,v) //call appropriate DECREASE-KEY