2_rec_graphstr

# 2_rec_graphstr - Minimum Spanning Tree Kruskals Algorithm...

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

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

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

View Full Document
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
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)

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

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

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online