Minimum Spanning Trees

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

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.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
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.
CSE 421 Algorithms Richard Anderson Lecture 10 Minimum Spanning Trees.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
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.
Dijkstra’s Algorithm. Announcements Assignment #2 Due Tonight Exams Graded Assignment #3 Posted.
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.
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
MCA 202: Discrete Structures Instructor Neelima Gupta
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.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Kruskal’s Algorithm for Computing MSTs Section 9.2.
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.
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Data Structures & Algorithms Graphs
Graph Algorithm.
CSCE350 Algorithms and Data Structure
Connected Components Minimum Spanning Tree
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.
Spanning Trees.
Chapter 9: Graphs Basic Concepts
Graphs.
Chapter 11 Graphs.
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 Tree Algorithms
Minimum spanning trees
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Minimum Spanning Trees
Minimum spanning trees
Networks Kruskal’s Algorithm
Algorithms Searching in a Graph.
Minimum spanning tree Shortest path algorithms
CSE 373: Data Structures and Algorithms
Autumn 2016 Lecture 10 Minimum Spanning Trees
Kruskal’s Algorithm AQR.
Dijkstra Algorithm examples
Prim’s algorithm for minimum spanning trees
Winter 2019 Lecture 10 Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Chapter 9: Graphs Basic Concepts
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 .
Minimum Spanning Trees
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 dv records edge weights, not path lengths

Walk-Through F C A B D H G E Initialize array K dv pv A F   B C D E 2 Initialize array 3 F C K dv pv A F   B C D E G H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

F C A B D H G E Start with any node, say D K dv pv A B C D T  E F G H 2 Start with any node, say D 3 F C K dv pv A B C D T  E F G H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Update distances of adjacent, unselected nodes 2 3 F C K dv pv A B C 3 D T  E 25 F 18 G 2 H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Select node with minimum distance 2 3 F C K dv pv A B C 3 D T  E 25 F 18 G 2 H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Update distances of adjacent, unselected nodes 2 3 F C K dv pv A B C 3 D T  E 7 G F 18 2 H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Select node with minimum distance 2 3 F C K dv pv A B C T 3 D  E 7 G F 18 2 H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Update distances of adjacent, unselected nodes 2 3 F C K dv pv A B 4 C T 3 D  E 7 G F 2 H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Select node with minimum distance 2 3 F C K dv pv A B 4 C T 3 D  E 7 G F 2 H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Update distances of adjacent, unselected nodes 2 3 F C K dv pv A 10 F B 4 C T 3 D  E 2 G H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Select node with minimum distance 2 3 F C K dv pv A 10 F B 4 C T 3 D  E 2 G H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

F C A B D H G E Update distances of adjacent, unselected nodes 2 3 F C K dv pv A 10 F B 4 C T 3 D  E 2 G H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7 Table entries unchanged

Select node with minimum distance 2 3 F C K dv pv A 10 F B 4 C T 3 D  E 2 G H 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Update distances of adjacent, unselected nodes 2 3 F C K dv pv A 4 H B C T 3 D  E 2 F G 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Select node with minimum distance 2 3 F C K dv pv A T 4 H B C 3 D  E 2 F G 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

F C A B D H G E Update distances of adjacent, unselected nodes 2 3 F C K dv pv A T 4 H B C 3 D  E 2 F G 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7 Table entries unchanged

Select node with minimum distance 2 3 F C K dv pv A T 4 H B C 3 D  E 2 F G 10 A 7 3 8 4 18 4 B D 9 H 10 25 2 3 G E 7

Cost of Minimum Spanning Tree =  dv = 21 3 F C K dv pv A T 4 H B C 3 D  E 2 F G A 3 4 4 B D H 2 3 G E 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 F C A B D H G E Consider an undirected, weight graph 3 10 4 3 8 4 6 5 B D 4 H 4 1 2 3 G E 3

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

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

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

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

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

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

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

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

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

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

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

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

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

Detecting Cycles Use Disjoint Sets (Chapter 8)