Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Chapter 23 Minimum Spanning Tree
O(N 1.5 ) divide-and-conquer technique for Minimum Spanning Tree problem Step 1: Divide the graph into  N sub-graph by clustering. Step 2: Solve each.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
Minimum Spanning Trees
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Minimum Spanning Trees CIS 606 Spring Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
ASC Program Example Part 3 of Associative Computing Examining the MST code in ASC Primer.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Minimum Spanning Tree in Graph - Week Problem: Laying Telephone Wire Central office.
An Illustration of Prim's Algorithm
Minimum Spanning Trees and Clustering By Swee-Ling Tang April 20, /20/20101.
Analysis of Algorithms
Chapter 2 Graph Algorithms.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Prim's Algorithm This algorithm starts with one node. It then, one by one, adds a node that is unconnected to the new graph to the new graph, each time.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
Minimal Spanning Tree Problems in What is a minimal spanning tree An MST is a tree (set of edges) that connects all nodes in a graph, using.
Minimum- Spanning Trees
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
Prims Algorithm for finding a minimum spanning tree
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graph Algorithms Mathematical Structures for Computer Science Chapter 6 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraph Algorithms.
Kruskal’s Algorithm for Computing MSTs Section 9.2.
Minimum Spanning Trees
COMP108 Algorithmic Foundations Greedy methods
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Greedy Technique.
May 12th – Minimum Spanning Trees
MA/CSSE 473 Day 36 Student Questions More on Minimal Spanning Trees
Chapter 5. Greedy Algorithms
Minimum Spanning Tree Chapter 13.6.
Spanning Trees.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Minimum Spanning Trees and Shortest Paths
Lecture 12 Algorithm Analysis
Short paths and spanning trees
Data Structures & Algorithms Graphs
Spanning Trees.
Minimum Spanning Tree.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Tree.
CSE 373 Data Structures and Algorithms
Spanning Trees.
Kruskal’s Minimum Spanning Tree Algorithm
MA/CSSE 473 Day 33 Student Questions Change to HW 13
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
Networks Kruskal’s Algorithm
Minimum Spanning Tree.
Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
CS 584 Project Write up Poster session for final Due on day of final
Minimum spanning trees
Minimum Spanning Trees (MSTs)
Lecture 12 Algorithm Analysis
CSE 373: Data Structures and Algorithms
Spanning Tree.
Topological Sorting Minimum Spanning Trees Shortest Path
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class There are Slight Changes From the Code These Slides are not Complete

Example – MST (Prim’s Algorithm) Assume a connected graph has nodes labeled by some identifying letter or number, arcs which are non-directional and have positive weights associated with them. The MST problem is to find a minimum spanning tree.

Representing a Non-directed Graph - 2 PEs Needed for Each Edge Yellow is memory for PE10. TAIL HEAD WEIGHT STATE XX NXTNODE GRAPH 1 a b 2 3 c 4 5 e f 6 7 8 9 10

We will maintain three sets of nodes whose membership will change during the run. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 V1 will be nodes selected to be in the tree. V2 will be candidates at the current step to be added to V1. V3 will be nodes not considered yet.

Colors Used in Graphic Visualization V1 nodes and their selected edges will be in red. V2 nodes with their candidate edges will be in blue. V3 nodes and all other edges will remain white.

Select an arbitrary node to place in V1, say A Select an arbitrary node to place in V1, say A. Put into V2, all nodes adjacent to A. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Look at the code presented. Is the first node picked this way? Is there any problem?

Choose the blue edge with the smallest weight, AB, and put its other node, B, into V1. Mark that edge with red also. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 If an edge is selected, throw out its reverse edge, i.e. put B  A in V0.

Add all the edges incident to B to the candidate list. . 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Note that AG has weight 3 and BG has weight 6. So, there is no sense of including BG in V2. But, in associative computing, there is no harm in doing so.

Add the node, G, whose edge has the smallest weight that is colored blue and add it to V1.Color A  G red. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Throw out blue edges that could form a cycle – i.e. edges whose head or tail is G and blue ( as well as their reverse edges).

Add the node, G, whose edge has the smallest weight that is colored blue and add it to V1.Color A  G red. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 Throw out blue edges that could form a cycle – i.e. edges whose head or tail is G and blue ( as well as their reverse edges). 

Throw out BG and GB 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 After creating more slides interacting with the class, we have the final solution.

The final solution after 8 iterations total. 2 D E H I F C G B A 7 4 3 6 5 1 2 3 2 6 4 8 2 1 The subgraph is clearly a tree – no cycles and connected. The tree spans – i.e. all nodes are included. While not obvious, it can be shown that this algorithm always produces a minimal spanning tree. The algorithm is known as Prim’s Algorithm for MST.