Upload
hortense-morris
View
215
Download
0
Embed Size (px)
Citation preview
Growing an MST: general idea
GENERIC-MST(G,w)
1. A{}2. while A does not form a spanning tree3. do find an edge (u,v) that is safe
for A4. A A U {(u,v)}5. return A
Algorithms for MST
Prim’s Grow a MST by adding a single edge at a
time
Kruskal’s Choose a smallest edge and add it to the
forest If an edge is formed a cycle, it is
rejected
Prim’s greedy algorithm Start from some (any) vertex.
Build up spanning tree T, one vertex at a time.
At each step, add to T the lowest-weight edge in G that does not create a cycle.
Stop when all vertices in G are touched
Kruskal’s Algorithm
Choose the smallest edge and add it to a forest
Keep connecting components until all vertices connected
If an edge would form a cycle, it is rejected.