ECE 242 Data Structures Lecture 32 Minimum Spanning Trees December 2, 2009 ECE242 L32: Minimum Spanning Trees Overview ° Problem: What is the minimum cost edges to connect all vertices in a graph? ° Spanning Tree • Connects all vertices ° Minimum Spanning Tree • Minimum connection for all vertices ° Use minimum spanning tree algorithm to generate MST from a graph December 2, 2009 ECE242 L32: Minimum Spanning Trees
Spanning Tree ° Connected subgraph that includes all vertices of the original connected graph ° Subgraph is a tree • If original graph has n vertices, the spanning tree has n vertices and n-1 edges. • No cycle in the subgraph December 2, 2009 ECE242 L32: Minimum Spanning Trees Minimum Spanning Trees ° Connect a set of vertices while minimizing expenses. ° Spanning tree • Given a connected, undirected graph G, a spanning tree is another graph which has all of G's vertices and a subset of G's edges Spanning tree has only v – 1 edges. • - Minimum number of edges required to connect all of the vertices. - Never contains a cycle. - May be more than one spanning tree for a given graph. December 2, 2009 ECE242 L32: Minimum Spanning Trees
Spanning Tree ° Minimum number of edges to keep it connected ° If N vertices, spanning tree has N-1 edges December 2, 2009 ECE242 L32: Minimum Spanning Trees Minimum Spanning Tree (MST) Spanning tree with minimum weight 6 6 10 10 1 1 7 20 5 5 December 2, 2009 ECE242 L32: Minimum Spanning Trees
Algorithm For Finding MST 1. All nodes are unselected 2. Mark node v selected 3. For each node in graph { Find the edge with minimum weight that connects one - unselected node with one selected node Mark this unselected node as selected - } December 2, 2009 ECE242 L32: Minimum Spanning Trees Demos For Finding MST ° Step 1: mark vertex A as selected A 1 2 10 D B 6 5 C December 2, 2009 ECE242 L32: Minimum Spanning Trees
Demos For Finding MST ° Step 2: find the minimum weighted edge connected to vertex A, and mark the other A vertex on this edge as selected. 1 2 10 D B 6 5 C December 2, 2009 ECE242 L32: Minimum Spanning Trees Demos For Finding MST ° Step 3: find the minimum weighted edge connected A to vertices set { A, D } , and mark the other vertex on 1 this edge as selected. 2 10 D B 6 5 C December 2, 2009 ECE242 L32: Minimum Spanning Trees
Demos For Finding MST ° Step 4: find the minimum weighted edge connected to vertices set { A, D, B} , A and mark the other vertex on this edge as selected. 1 2 10 D B 6 5 C December 2, 2009 ECE242 L32: Minimum Spanning Trees Demos For Finding MST ° Step 5: All vertex are marked as selected, So we find the minimum spanning tree A 1 2 10 D B 6 5 C December 2, 2009 ECE242 L32: Minimum Spanning Trees
Finding Spanning Trees ° Every spanning tree in an unweighted graph has edges. ° If the graph is unweighted, then any tree is a “minimum” spanning tree. ° Both breadth- and depth-first search construct a tree, all nodes are visited (in time). ° Total running time December 2, 2009 ECE242 L32: Minimum Spanning Trees
Recommend
More recommend