2_rec_graphstr

2_rec_graphstr - Minimum Spanning Tree Kruskals Algorithm...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Introduction to Computers and Programming Prof. I. K. Lundqvist Recitation 2 April 6 2004 2 Minimum Spanning Tree • Kruskal’s Algorithm – Finds a minimum spanning tree for a connected weighted graph • Create a set of trees, where each vertex in the graph is a separate tree • Create set S containing all edges in the graph • While S not empty – Remove edge with minimum weight from S – if that edge connects two different trees, then add it to the forest, combining two trees into a single tree – Otherwise discard that edge 3 A E C F D G H B 1 1 2 2 3 4 33 2 16 5 1 A E C F D G H B Set of trees 0 3 3 H 0 6 5 1 G 0 1 2 3 F 0 2 4 E 0 2 2 D 0 3 C 0 1 B 0 A H G F E D C B A S 3 Kruskal’s Algorithm 4 Step 1 A E C F D G H B 1 A E C F D G H B 1 2 2 3 4 2 5 1 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5 Step 2 A E C F D G H B 1 1 A E C F D G H B 1 2 2 3 4 33 2 6 5 1 3 6 Step 3 A E C F D G H B 1 1 1 A E C F D G H B 2 2 3 4 2 6 5 1 3 7 Step 4 A E C F D G H B 1 1 1 1 A E C F D G H B 2 2 3 4 2 6 5 3 8 Step 5 A E C F D G H B 1 1 2 1 1 A E C F D G H B 2 3 4 2 6 5 3
Background image of page 2
9 Slide 6 A E C F D G H B 1 1 2 2 1 1 A E C F D G H B 3 4 33 2 6 5 3 10 Slide 7 A E C F D G H B 1 1 2 2 3 1 1 A E C F D G H B 3 4 3 2 6 5 3 11 Minimum Spanning Tree • Prim’s Algorithm – Finds a subset of the edges (that form a tree) including every vertex and the total weight of all the edges in tree is minimized • Choose starting vertex • Create the Fringe Set • Loop until the MST contains all the vertices in the graph – Remove edge with minimum weight from Fringe Set – Add the edge to MST – Update the Fringe Set Initialization Body 12 Prim – Initialization • Pick any vertex x as the starting vertex •P lace x in the Minimum Spanning Tree (MST)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

2_rec_graphstr - Minimum Spanning Tree Kruskals Algorithm...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online