Minimum Spanning Trees Text Read Weiss, §9.5 Prim’s Algorithm Weiss §9.5.1 Similar to Dijkstra’s Algorithm Kruskal’s Algorithm Weiss §9.5.2 Focuses on.

Slides:



Advertisements
Similar presentations
Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Advertisements

Lecture 15. Graph Algorithms
Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Chapter 4 The Greedy Approach. Minimum Spanning Tree A tree is an acyclic, connected, undirected graph. A spanning tree for a given graph G=, where E.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Greedy methods Prudence Wong
CS 146: Data Structures and Algorithms July 21 Class Meeting
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstra's algorithm CS3240. The author: Edsger Wybe Dijkstra "Computer Science is no more about computers than astronomy is about telescopes."
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Chapter 4 sections 1 and 2.  Fig. 1  Not connected  All vertices are even.  Fig. 2  Connected  All vertices are even.
Minimum Spanning Trees Prof. Sin-Min Lee Dept. of Computer Science, San Jose State University.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Spanning Trees. A spanning tree for a connected, undirected graph G is a graph S consisting of the nodes of G together with enough edges of G such that:
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
MCA 202: Discrete Structures Instructor Neelima Gupta
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Minimum Spanning Tree A Minimum Spanning Tree (MST) is a subgraph of an undirected graph such that the subgraph spans (includes) all nodes, is connected,
UNIT-4 Graphs and Graph Terminology
Minimum Spanning Tree A Minimum Spanning Tree (MST) is a subgraph of an undirected graph such that the subgraph spans (includes) all nodes, is connected,
Instructor: Lilian de Greef Quarter: Summer 2017
COMP108 Algorithmic Foundations Greedy methods
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
May 12th – Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Spanning Trees.
Minimal Spanning Trees
Kruskal’s Algorithm Elaicca Ronna Ordoña. A cable company want to connect five villages to their network which currently extends to the market town of.
Minimum Spanning Trees and Shortest Paths
CISC 235: Topic 10 Graph Algorithms.
Jan 2007.
Data Structures & Algorithms Graphs
Graph Algorithm.
CSCE350 Algorithms and Data Structure
Connected Components Minimum Spanning Tree
Graphs & Graph Algorithms 2
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
CSE373: Data Structures & Algorithms Lecture 20: Minimum Spanning Trees Linda Shapiro Spring 2016.
Minimum Spanning Trees
Spanning Trees.
Graphs.
Chapter 11 Graphs.
Lecture 8 Greedy Approach
Example A cable company want to connect five villages to their network which currently extends to the market town of Avonford. What is the minimum.
Minimum spanning trees
Minimum Spanning Trees
AB AC AD AE AF 5 ways If you used AB, then, there would be 4 remaining ODD vertices (C, D, E and F) CD CE CF 3 ways If you used CD, then, there.
Minimum spanning trees
Networks Kruskal’s Algorithm
CSE 373: Data Structures and Algorithms
Kruskal’s Algorithm AQR.
Prim’s algorithm for minimum spanning trees
CSE 373: Data Structures and Algorithms
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Minimum Spanning Trees Text Read Weiss, §9.5 Prim’s Algorithm Weiss §9.5.1 Similar to Dijkstra’s Algorithm Kruskal’s Algorithm Weiss §9.5.2 Focuses on edges, rather than nodes

Definition A Minimum Spanning Tree (MST) is a subgraph of an undirected graph such that the subgraph spans (includes) all nodes, is connected, is acyclic, and has minimum total edge weight

Algorithm Characteristics Both Prim’s and Kruskal’s Algorithms work with undirected graphs Both work with weighted and unweighted graphs but are more interesting when edges are weighted Both are greedy algorithms that produce optimal solutions

Prim’s Algorithm Similar to Dijkstra’s Algorithm except that d v records edge weights, not path lengths

Walk-Through Initialize array Kdvdv pvpv AF  BF  CF  DF  EF  FF  GF  HF  4 25 A H B F E D C G

4 25 A H B F E D C G Start with any node, say D Kdvdv pvpv A B C DT0  E F G H 2

4 25 A H B F E D C G Update distances of adjacent, unselected nodes Kdvdv pvpv A B C 3D DT0  E25D F18D G2D H 2

4 25 A H B F E D C G Select node with minimum distance Kdvdv pvpv A B C 3D DT0  E25D F18D GT2D H 2

4 25 A H B F E D C G Update distances of adjacent, unselected nodes Kdvdv pvpv A B C 3D DT0  E7G F18D GT2D H3G 2

4 25 A H B F E D C G Select node with minimum distance Kdvdv pvpv A B CT 3D DT0  E7G F18D GT2D H3G 2

4 25 A H B F E D C G Update distances of adjacent, unselected nodes Kdvdv pvpv A B4C CT 3D DT0  E7G F3C GT2D H3G 2

4 25 A H B F E D C G Select node with minimum distance Kdvdv pvpv A B4C CT 3D DT0  E7G FT3C GT2D H3G 2

4 25 A H B F E D C G Update distances of adjacent, unselected nodes Kdvdv pvpv A10F B4C CT 3D DT0  E2F FT3C GT2D H3G 2

4 25 A H B F E D C G Select node with minimum distance Kdvdv pvpv A10F B4C CT 3D DT0  ET2F FT3C GT2D H3G 2

4 25 A H B F E D C G Update distances of adjacent, unselected nodes Kdvdv pvpv A10F B4C CT 3D DT0  ET2F FT3C GT2D H3G 2 Table entries unchanged

4 25 A H B F E D C G Select node with minimum distance Kdvdv pvpv A10F B4C CT 3D DT0  ET2F FT3C GT2D HT3G 2

4 25 A H B F E D C G Update distances of adjacent, unselected nodes Kdvdv pvpv A4H B4C CT 3D DT0  ET2F FT3C GT2D HT3G 2

4 25 A H B F E D C G Select node with minimum distance Kdvdv pvpv AT4H B4C CT 3D DT0  ET2F FT3C GT2D HT3G 2

4 25 A H B F E D C G Update distances of adjacent, unselected nodes Kdvdv pvpv AT4H B4C CT 3D DT0  ET2F FT3C GT2D HT3G 2 Table entries unchanged

4 25 A H B F E D C G Select node with minimum distance Kdvdv pvpv AT4H BT4C CT 3D DT0  ET2F FT3C GT2D HT3G 2

4 A H B F E D C G Cost of Minimum Spanning Tree =  d v = 21 Kdvdv pvpv AT4H BT4C CT 3D DT0  ET2F FT3C GT2D HT3G 2 Done

Kruskal’s Algorithm Work with edges, rather than nodes Two steps: –Sort edges by increasing edge weight –Select the first |V| – 1 edges that do not generate a cycle

Walk-Through Consider an undirected, weight graph 5 1 A H B F E D C G

Sort the edges by increasing edge weight edgedvdv (D,E)1 (D,G)2 (E,G)3 (C,D)3 (G,H)3 (C,F)3 (B,C)4 5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2 (E,G)3 (C,D)3 (G,H)3 (C,F)3 (B,C)4 5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3 (C,D)3 (G,H)3 (C,F)3 (B,C)4 5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3 (G,H)3 (C,F)3 (B,C)4 5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10 Accepting edge (E,G) would create a cycle

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3 (C,F)3 (B,C)4 5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3 (B,C)4 5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3  (B,C)4 5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3  (B,C)4  5 1 A H B F E D C G edgedvdv (B,E)4 (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3  (B,C)4  5 1 A H B F E D C G edgedvdv (B,E)4  (B,F)4 (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3  (B,C)4  5 1 A H B F E D C G edgedvdv (B,E)4  (B,F)4  (B,H)4 (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3  (B,C)4  5 1 A H B F E D C G edgedvdv (B,E)4  (B,F)4  (B,H)4  (A,H)5 (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3  (B,C)4  5 1 A H B F E D C G edgedvdv (B,E)4  (B,F)4  (B,H)4  (A,H)5  (D,F)6 (A,B)8 (A,F)10

Select first |V|–1 edges which do not generate a cycle edgedvdv (D,E)1  (D,G)2  (E,G)3  (C,D)3  (G,H)3  (C,F)3  (B,C)4  5 1 A H B F E D C G edgedvdv (B,E)4  (B,F)4  (B,H)4  (A,H)5  (D,F)6 (A,B)8 (A,F)10 Done Total Cost =  d v = 21 4 } not considered

Detecting Cycles Use Disjoint Sets (Chapter 8)