Minimum-Cost Spanning Tree

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

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 cost spanning tree and activity networks Data structure 2002/12/2.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Discussion #36 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:
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Chapter 9: Greedy Algorithms The Design and Analysis of 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)
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
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.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Minimum spanning tree Prof Amir Geva Eitan Netzer.
Minimum Spanning Tree Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
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 CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
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)
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Chapter 6 Graphs. 2 Outline Definitions, Terminologies and Applications Graph Representation Elementary graph operations Famous Graph Problems.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Minimum-Cost Spanning Tree weighted connected undirected graph cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Network.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Minimum Spanning Trees and Shortest Paths
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Shortest Path Problems
Short paths and spanning trees
Data Structures & Algorithms Graphs
Graph Algorithm.
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Tree.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Minimum-Cost Spanning Tree
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
Minimum-Cost Spanning Tree
Shortest Path Problems
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Kruskal’s Idea Adding one edge at a time Non-decreasing order No cycle
Lecture 12 Algorithm Analysis
Lecture 14 Minimum Spanning Tree (cont’d)
Minimum-Cost Spanning Tree
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
Presentation transcript:

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 cost

Example Network has 10 edges. Spanning tree has only n - 1 = 7 edges. 3 5 7 2 4 6 8 10 14 12 9 Network has 10 edges. Spanning tree has only n - 1 = 7 edges. Need to either select 7 edges or discard 3.

Edge Selection Greedy Strategies Start with an n-vertex 0-edge forest. Consider edges in ascending order of cost. Select edge if it does not form a cycle together with already selected edges. Kruskal’s method. Start with a 1-vertex tree and grow it into an n-vertex tree by repeatedly adding a vertex and an edge. When there is a choice, add a least cost edge. Prim’s method.

Edge Selection Greedy Strategies Start with an n-vertex forest. Each component/tree selects a least cost edge to connect to another component/tree. Eliminate duplicate selections and possible cycles. Repeat until only 1 component/tree is left. Sollin’s method.

Edge Rejection Greedy Strategies Start with the connected graph. Repeatedly find a cycle and eliminate the highest cost edge on this cycle. Stop when no cycles remain. Consider edges in descending order of cost. Eliminate an edge provided this leaves behind a connected graph.

Kruskal’s Method Start with a forest that has no edges. 8 10 14 1 3 5 7 2 4 6 8 1 3 5 7 7 12 6 3 2 4 2 4 6 8 9 Start with a forest that has no edges. Consider edges in ascending order of cost. Edge (1,2) is considered first and added to the forest.

Kruskal’s Method Edge (7,8) is considered next and added. 10 14 1 3 5 7 1 3 5 7 7 7 4 6 3 12 6 3 2 2 4 2 4 6 8 2 4 6 8 9 Edge (7,8) is considered next and added. Edge (3,4) is considered next and added. Edge (5,6) is considered next and added. Edge (2,3) is considered next and added. Edge (1,3) is considered next and rejected because it creates a cycle.

Kruskal’s Method 10 14 8 10 14 1 3 5 7 1 3 5 7 7 7 4 6 3 12 6 3 2 2 4 2 4 6 8 2 4 6 8 9 Edge (2,4) is considered next and rejected because it creates a cycle. Edge (3,5) is considered next and added. Edge (3,6) is considered next and rejected. Edge (5,7) is considered next and added.

Kruskal’s Method n - 1 edges have been selected and no cycle formed. 10 14 8 10 14 1 3 5 7 1 3 5 7 7 7 4 6 3 4 12 6 3 2 2 2 4 6 8 2 4 6 8 9 n - 1 edges have been selected and no cycle formed. So we must have a spanning tree. Cost is 46. Min-cost spanning tree is unique when all edge costs are different.

Prim’s Method Start with any single vertex tree. 3 10 7 14 8 10 14 1 2 5 1 3 5 7 2 7 7 4 6 8 3 4 12 6 3 2 2 4 6 8 9 Start with any single vertex tree. Get a 2-vertex tree by adding a cheapest edge. Get a 3-vertex tree by adding a cheapest edge. Grow the tree one edge at a time until the tree has n - 1 edges (and hence has all n vertices).

Sollin’s Method Start with a forest that has no edges. 8 10 14 1 3 5 7 2 4 6 8 1 3 5 7 7 2 4 6 3 12 6 3 2 4 2 4 6 8 9 Start with a forest that has no edges. Each component selects a least cost edge with which to connect to another component. Duplicate selections are eliminated. Cycles are possible when the graph has some edges that have the same cost.

Sollin’s Method 10 14 8 10 14 1 3 5 7 2 4 6 8 1 3 5 7 2 7 7 4 6 3 4 12 6 3 2 2 4 6 8 9 Each component that remains selects a least cost edge with which to connect to another component. Beware of duplicate selections and cycles.

Greedy Minimum-Cost Spanning Tree Methods Can prove that all result in a minimum-cost spanning tree. Prim’s method is fastest. O(n2) using an implementation similar to that of Dijkstra’s shortest-path algorithm. O(e + n log n) using a Fibonacci heap. Kruskal’s uses union-find trees to run in O(n + e log e) time.

Pseudocode For Kruskal’s Method Start with an empty set T of edges. while (E is not empty && |T| != n-1) { Let (u,v) be a least-cost edge in E. E = E - {(u,v)}. // delete edge from E if ((u,v) does not create a cycle in T) Add edge (u,v) to T. } if (| T | == n-1) T is a min-cost spanning tree. else Network has no spanning tree.

Data Structures For Kruskal’s Method Edge set E. Operations are: Is E empty? Select and remove a least-cost edge. Use a min heap of edges. Initialize. O(e) time. Remove and return least-cost edge. O(log e) time.

Data Structures For Kruskal’s Method Set of selected edges T. Operations are: Does T have n - 1 edges? Does the addition of an edge (u, v) to T result in a cycle? Add an edge to T.

Data Structures For Kruskal’s Method Use an array linear list for the edges of T. Does T have n - 1 edges? Check size of linear list. O(1) time. Does the addition of an edge (u, v) to T result in a cycle? Not easy. Add an edge to T. Add at right end of linear list. O(1) time. Just use an array rather than ArrayLinearList.

Data Structures For Kruskal’s Method Does the addition of an edge (u, v) to T result in a cycle? 1 3 5 7 2 4 6 8 Each component of T is a tree. When u and v are in the same component, the addition of the edge (u,v) creates a cycle. When u and v are in the different components, the addition of the edge (u,v) does not create a cycle.

Data Structures For Kruskal’s Method 1 3 5 7 2 4 6 8 Each component of T is defined by the vertices in the component. Represent each component as a set of vertices. {1, 2, 3, 4}, {5, 6}, {7, 8} Two vertices are in the same component iff they are in the same set of vertices.

Data Structures For Kruskal’s Method 1 3 5 7 2 4 6 8 When an edge (u, v) is added to T, the two components that have vertices u and v combine to become a single component. In our set representation of components, the set that has vertex u and the set that has vertex v are united. {1, 2, 3, 4} + {5, 6} => {1, 2, 3, 4, 5, 6}

Data Structures For Kruskal’s Method Initially, T is empty. 1 3 5 7 2 4 6 8 Initial sets are: {1} {2} {3} {4} {5} {6} {7} {8} Does the addition of an edge (u, v) to T result in a cycle? If not, add edge to T. s1 = find(u); s2 = find(v); if (s1 != s2) union(s1, s2);

Data Structures For Kruskal’s Method Use FastUnionFind. Initialize. O(n) time. At most 2e finds and n-1 unions. Very close to O(n + e). Min heap operations to get edges in increasing order of cost take O(e log e). Overall complexity of Kruskal’s method is O(n + e log e).