1 7-MST Minimal Spanning Trees Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Chapter 23 Minimum Spanning Tree
Advanced Algorithm Design and Analysis Jiaheng Lu Renmin University of China
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Greedy Algorithms Greed is good. (Some of the time)
Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Chapter 23 Minimum Spanning Trees
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Minimum Spanning Tree Algorithms
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Analysis of Algorithms CS 477/677
Dynamic Sets and Data Structures Over the course of an algorithm’s execution, an algorithm may maintain a dynamic set of objects The algorithm will perform.
CSE Algorithms Minimum Spanning Trees Union-Find Algorithm
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
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.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Definition: Given an undirected graph G = (V, E), a spanning tree of G is any subgraph of G that is a tree Minimum Spanning Trees (Ch. 23) abc d f e gh.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Introduction to Algorithms L ECTURE 14 (Chap. 22 & 23) Greedy Algorithms I 22.1 Graph representation 23.1 Minimum spanning trees 23.1 Optimal substructure.
Spring 2015 Lecture 11: Minimum Spanning Trees
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
November 13, Algorithms and Data Structures Lecture XII Simonas Šaltenis Aalborg University
Chapter 23: Minimum Spanning Trees: A graph optimization problem Given undirected graph G(V,E) and a weight function w(u,v) defined on all edges (u,v)
 2004 SDU Lecture 6- Minimum Spanning Tree 1.The Minimum Spanning Tree Problem 2.Greedy algorithms 3.A Generic Algorithm 4.Kruskal’s Algorithm.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Minimum- Spanning Trees
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
1 Week 3: Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
MST Lemma Let G = (V, E) be a connected, undirected graph with real-value weights on the edges. Let A be a viable subset of E (i.e. a subset of some MST),
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Introduction to Algorithms
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Tree.
Minimum Spanning Trees
Algorithms and Data Structures Lecture XII
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
Outline This topic covers Prim’s algorithm:
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Advanced Algorithms Analysis and Design
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Presentation transcript:

1 7-MST Minimal Spanning Trees Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:

2 7-MST Introduction Start with a connected, undirected graph, and add real-valued weights to each edge. The weights could indicate time, distance, cost, capacity, etc

3 7-MST Definitions A spanning tree of a graph G is a tree that contains every vertex of G. The weight of a tree is the sum of its edges’ weights. A minimal spanning tree is a spanning tree with lowest weight. (The left tree is not minimal. The right one is, as we will see.) weight = 21weight =

4 7-MST An Application of MSTs Wire up a network among several computers so that every computer can reach (directly or indirectly) every other. Use the minimum amount of cable. Vertices = computers Weights = distance between computers Another example: think about inter-connecting a set of n pins, using n–1 wires, using the minimal amount of wire.

5 7-MST The MST Property: Intro Divide the vertices of a graph into two sets (this is a cut of the graph). Consider an edge of lowest weight on the cut (e.g. 4, above). This edge is in some MST of the graph

6 7-MST Proving the MST Property: 1 Recall: A tree is an acyclic, connected, undirected graph Lemma 1: Adding an edge to a tree results in a cycle. Proof: Say the edge is from u to v. There was already a path from v to u (since the tree is connected); now there is an edge from u to v, forming a cycle. u v

7 7-MST Proving the MST Property: 2 Lemma 2: Adding an edge to a tree, then removing a different edge along the resulting cycle, still results in a tree. Proof: Omitted.

8 7-MST The MST Property Theorem: Given a cut of a graph, a lowest- weight edge crossing the cut will be in some MST for the graph. Proof: By contradiction. Assume an MST on the graph containing no lowest-weight edge crossing the cut. Then some other, higher- weight edge on the cut is in the MST (since it is a spanning tree). ( continued ) higher-weight edge lowest-weight edge

9 7-MST MST Property Proof, Cont. If we now add the lowest-weight edge to the supposed MST, we have a cycle. Removing the higher-weight one still results in a spanning tree, and it has a lower total weight than the alleged MST. Thus the assumption is false: some lowest-weight edge is in the MST. cut higher-weight edge lowest-weight edge

10 7-MST MST Algorithms Both of the MST algorithms we will study exploit the MST property. –Kruskal’s: repeatedly add the lowest- weight legal edge to a growing MST. –Prim’s (really Prim-Jarvik): keep track of a cut, and add the lowest-weight edge across the cut to the growing MST.

11 7-MST Kruskal’s Algorithm Choose the lowest-weight edge in the graph. This is certainly the lowest weight edge for some cut, so it must be in an MST. Continue taking the lowest-weight edge and adding it to the MST, unless it would result in a cycle.

12 7-MST Kruskal’s Example a b c d ef ca 1 fd 2 eb 3 fc 4 cb 5 dc 5 x

KRUSKAL CODE

14 7-MST Aside: The Union-Find Problem (This relates to the running time of Kruskal...) Given several items, in disjoint sets, support three operations: – Make-Set(x): create a set containing x –Find-Set(x): return the set to which x belongs –Union(x, y): take the union of sets of x and y The “disjoint-set forests” implementation of union-find, with certain heuristics, yields outstanding performance. The running time of these operations is (for all practical purposes) linear in m ( the total number of operations). See section 21.3 for more details...

15 7-MST Fast Union-Find Choose an item as the representative of its set. –Find-Set(x): return x’s representative –Union(x, y): make x’s representative point to y With path compression: –Union(x, y): make x and everything on the path to its representative point to y Time for n Union-finds:  (nlg*n). lg*n is the iterated logarithm function: the number of times you must take lgn in order to get  1. For all practical purposes, lg*n < 4.

16 7-MST Running Time of Kruskal’s Total:  (ElgE) time.  (ElgE) Done E times.  (Elg*E)

17 7-MST Prim’s Algorithm Begin with any vertex. Choose the lowest weight edge connected to that vertex. Add the vertex on the other side of that edge to the “active set.” Again, choose the lowest-weight edge of any vertex in the active set that connects to a vertex outside the set, and repeat. start here

18 7-MST Prim’s Example a b c d ef a b c d ef a b c d ef a b c d ef a b c d ef

19 7-MST Why Prim’s Works It comes right out of the MST property. There are always two sets, the active set and everything else, making a cut. The MST property says that the lowest- weight edge crossing the cut is in an MST. This is just the edge Prim’s chooses.

20 7-MST High-level Code for Prim’s

21 7-MST High-Level Prim (Cont.) How can we choose an edge without looking through every edge in the graph? Use a priority queue. But make it a queue of vertices, not edges.

22 7-MST A Sophisticated Implementation of Prim’s 1. Build a minimizing priority queue from the graph’s vertices, where the key of a vertex (the value minimized) is the weight of the lowest-weight edge from that vertex to a vertex in the MST. 2. Repeatedly do the following, until the queue is empty: a. Extract the minimum vertex from the queue. Call it u. b. For each vertex v adjacent to u that is still in the queue, if the weight of the edge between u and v is smaller than key[v], then update key[v] to that weight, and set the parent of v to be u.

23 7-MST Prim’s à la CLRS key[v] is the weight of the lowest-weight edge from vertex v to a vertex in the MST. Q contains all the vertices that are not in the MST.

24 7-MST

25 7-MST CLRS Prim

26 7-MST Running Time of Prim

27 7-MST Running Time of Prim (Cont.)

28 7-MST Fibonacci Heaps It is possible to do better. A Fibonacci Heap is a priority queue implementation that can do –EXTRACT-MIN in  (lgn) –DECREASE-KEY in  (1) amortized time. (See CLRS, Chapter 20). Improves the time from  (ElgV) to  (VlgV+E). (We had  (VlgV+ElgV), but the second lgV becomes 1.) This is better for dense graphs (E  V 2 ). Theoretical interest only —Fibonacci heaps have a large constant.