Chapter 23 Minimum Spanning Trees

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Advertisements

Greedy Algorithms Greed is good. (Some of the time)
Greed is good. (Some of the time)
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Graph Algorithms. Jaruloj Chongstitvatana Chapter 3: Greedy Algorithms 2 Outline Graph Representation Shortest path Minimum spanning trees.
Minimum Spanning Tree (MST) form a tree that connects all the vertices (spanning tree). minimize the total edge weight of the spanning tree. Problem Select.
Applications Data Structures and Algorithms (60-254)
Introduction to Algorithms 6.046J/18.401J/SMA5503
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Chapter 23: Graph Algorithms Chapter 24: 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.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lectures 3 Tuesday, 9/25/01 Graph Algorithms: Part 1 Shortest.
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.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2008 Lecture 4 Tuesday, 9/30/08 Graph Algorithms: Part 1 Shortest.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Graph Algorithms: Part 1
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Analysis of Algorithms CS 477/677
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Dijkstra's algorithm.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
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.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
COSC 3101NJ. Elder Assignment 2 Remarking Assignment 2 Marks y = 0.995x R 2 = Old Mark New Mark.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
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.
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.
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.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
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)
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
Lecture 13 Algorithm Analysis
 2004 SDU Lecture 6- Minimum Spanning Tree 1.The Minimum Spanning Tree Problem 2.Greedy algorithms 3.A Generic Algorithm 4.Kruskal’s Algorithm.
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
© 2007 Seth James Nielson Minimum Spanning Trees … or how to bring the world together on a budget.
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.
Minimum Spanning Tree. p2. Minimum Spanning Tree G=(V,E): connected and undirected w: E  R, weight function a b g h i c f d e
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
Greedy Algorithms General principle of greedy algorithm
Lecture ? The Algorithms of Kruskal and Prim
Introduction to Algorithms
Minimum Spanning Trees
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
CS 583 Analysis of Algorithms
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Greedy Algorithms Comp 122, Spring 2004.
Lecture 12 Algorithm Analysis
Advanced Algorithms Analysis and Design
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

Chapter 23 Minimum Spanning Trees Kruskal Prim [Source: Cormen et al. textbook except where noted] I joined the UMass Lowell Computer Science faculty this summer. This collection of slides is intended to familiarize the reader/viewer with my field of research (Computational Geometry), summarize my previous research results in this field and outline my plan for Computational Geometry research at UMass Lowell.

Minimum Spanning Trees This refers to a number of problems (many of practical importance) that can be reduced to the following abstraction: let G = (V, E) be a connected, undirected graph. You are also given a function w : E  R (usually non-negative, but not always so required). You are then asked to find an acyclic subset T Í E that connects all the vertices and whose total weight is minimized. The acyclicity of T implies that T is a tree; the requirement that it connect all the vertices implies that it is a spanning tree; the minimization implies that it is a minimum such object.

Minimum Spanning Trees MST Example

Minimum Spanning Trees Algorithms We will construct two algorithms as variants of a “generic” one. Both will be greedy algorithms (requiring that we show all necessary greedy properties are satisfied). We start with a loop invariant: let A be a set of edges; prior to each iteration, A is a subset of some minimum spanning tree. At each step we determine an edge (u, v) (a safe edge) that we can add to A without violating the invariant.

Minimum Spanning Trees The Generic Algorithm

Minimum Spanning Trees The Generic Algorithm How do we find a safe edge? It exists, because of the assumption on A (part of a minimum spanning tree)… Def.: a cut (S, V – S) of an undirected graph G = (V, E) is a partition of V. Def.: an edge (u, v) crosses the cut (S, V – S) if one of its endpoints is in S and the other in V. Def.: a cut respects a set A of edges if no edge in A crosses the cut. Def.: An edge is a light edge crossing a cut if its weight is minimum among all edges crossing the cut. Uniqueness is not required. This can be generalized to properties other than crossing.

Minimum Spanning Trees The Generic Algorithm

Minimum Spanning Trees The Generic Algorithm Theorem 23.1. Let G = (V, E) be a connected undirected graph with a real-valued weight function w defined on E. Let A be a subset of E that is included in some minimum spanning tree for G, let (S, V – S) be any cut of G that respects A, and let (u, v) be a light edge crossing (S, V – S). Then edge (u, v) is safe for A. Proof: let T be an MST, A Í T, A ≠ T. Assume T does not contain the light edge (u, v). If it does, we are done. If not, we construct another MST T’ that contains both A and (u, v). T {(u, v)} must contain a cycle, with edges on a simple path p from u to v in T. u and v are on opposite sides of the cut (S, V – S), and at least one edge in T lies on p and crosses the cut.

Minimum Spanning Trees The Generic Algorithm Proof (cont.) Let (x, y) be any such edge – it cannot be in A, because the cut respects A. Since (x, y) is on the unique simple path from u to v in T, removing (x, y) breaks T into two components. Adding (u, v) reconnects them to form a new spanning tree T’ = (T – {(x, y)}) {(u, v)}. But T’ is also an MST: since (u, v) is a light edge crossing (S, V – S) and (x, y) also crosses the cut, w(u, v) ≤ w(x, y) and w(T’) = w(T) – w(x, y) + w(u, v) ≤ w(T). The minimality of T implies w(T) ≤ w(T’), so T’ must be minimal, also. Is (u, v) safe? Since A Í T and (x, y) Ï A, we have A Í T’. Thus A {(u, v)} Í T’. Since T’ is an MST, (u, v) is safe for A.

Minimum Spanning Trees The Generic Algorithm Corollary 23.2. Let G = (V, E) be a connected undirected graph with a real-valued weight function w defined on E. Let A be a subset of E that is included in some minimum spanning tree for G, let C = (VC, EC) be a connected component (tree) in the forest GA = (V, A). If (u, v) is a light edge connecting C to some other component in GA, then (u, v) is safe for A. Proof: the cut (VC, V – VC) respects A, and (u, v) is a light edge for this cut. Therefore (u, v) is safe for A.

Minimum Spanning Trees The Generic Algorithm We now move to realizations of the generic algorithm. We choose two distinct ones, one based on a sorted (non-decreasing) list of edges and the set operations Make-Set, Find-Set and Union; the other based on priority queues of edges and the operation Extract-Min.

Minimum Spanning Trees Kruskal’s Algorithm

Minimum Spanning Trees Kruskal’s Algorithm This algorithm uses the disjoint-set datatype introduced in Ch. 21. The user-accessible operations are Make-Set(x), Union(x, y) and Find-Set(x), where x and y stand for either singletons or sets of which they are representative elements. We can show (easily) that a sequence of m Make-Set, Union and Find-Set operations (with an easy implementation), n of which are Make-Set takes O(m lg n) time. A more complex implementation (with union-by-rank and path compression) and analysis gives a bound O(m•a(n)), where a(n) ≤ 4 for any value of n relevant to our universe.

Minimum Spanning Trees Kruskal’s Algorithm Line 1 takes O(1); lines 2 and 3 take O(n), but we will account for it later; line 4 takes O(|E| lg |E|); the for loop (ll. 5-8) performs O(|E|) Find-Set and Union operations, which, with the |V| Make-Set operations take a total of O((|V| + |E|)a(|V|)) time. The assumption that G is connected implies |E| ≥ |V| - 1, so that the disjoint-set operations take O(|E|a(|V|)). Since a(|V|) = O(lg |V|) = O(lg |E|), the total time of Kruskal’s algorithm is O(|E| lg |E|) and |E| < |V|2 reduces this to O(|E| lg |V|).

Minimum Spanning Trees Kruskal’s Algorithm We observe that the set A is a forest, whose vertices are all those of the given graph. A safe edge is added to A: it is always a least-weight edge that connects two distinct components.

Minimum Spanning Trees Prim’s Algorithm

Minimum Spanning Trees Prim’s Algorithm The edges in the set A always make up a single tree. The tree starts from an arbitrary root vertex r and grows until it spans all vertices in V. Each step adds to the tree A a light edge that connects A to an isolated vertex (one on which no edge of A is incident) By Cor. 23.2, this process this adds only edges that are safe for A, so that, at the end, A forms an MST. The strategy is greedy, since at each step it adds to the tree an edge of minimum weight.

Minimum Spanning Trees Prim’s Algorithm: Invariant Prior to each iteration of the while loop (ll. 6-11): A = {(v, v.p) : v Î V – {r} – Q} The vertices already placed into the minimum spanning tree are those in V – Q For all vertices v Î Q, if v.p ≠ NIL, then v.key < ¥ and v.key is the weight of a light edge (v, v.p) connecting v to some vertex already placed into the MST.

Minimum Spanning Trees Prim’s Algorithm: Maintenance L. 7 extracts a vertex u in Q incident on a light edge that crosses the cut (V – Q, Q) (except for the first iteration, which extracts r). Removing u from Q adds it to V – Q of vertices in the tree, adding (u, u.p) to A. The for loop updates the key and p attributes of each vertex adjacent to u, but not in the tree, thus maintaining the third part of the loop invariant.

Minimum Spanning Trees Prim’s Algorithm: Time This will depend on the implementation of the priority queue. But; Creating a priority queue is O(|V|). Extracting elements is O(lg |V|) for each extraction. Decrease-Key operations, necessary because the keys of elements in the queue can change, will also take time O(lg |V|). Since this can happen for each edge we examine, total time can be O(|E| lg |V|).

Minimum Spanning Tree: Greedy Algorithms Invariant: Minimum weight spanning forest Becomes single tree at end Time: O(|E|lg|E|) given fast FIND-SET, UNION Produces minimum weight tree of edges that includes every vertex. A B C D E F G 2 1 3 4 5 6 8 7 Time: O(|E|lg|V|) = O(|E|lg|E|) slightly faster with fast priority queue Invariant: Minimum weight tree Spans all vertices at end for Undirected, Connected, Weighted Graph G=(V,E) source: 91.503 textbook Cormen et al.

Minimum Spanning Trees Review problem: For the undirected, weighted graph below, show 2 different Minimum Spanning Trees. Draw each using one of the 2 graph copies below. Thicken an edge to make it part of a spanning tree. What is the sum of the edge weights for each of your Minimum Spanning Trees? A B C D E F G 2 1 3 4 5 6 8 7

Chapter 24 Shortest Paths Dijkstra [Source: Cormen et al. textbook except where noted] I joined the UMass Lowell Computer Science faculty this summer. This collection of slides is intended to familiarize the reader/viewer with my field of research (Computational Geometry), summarize my previous research results in this field and outline my plan for Computational Geometry research at UMass Lowell.

BFS as a Basis for Shortest Path Algorithms for unweighted, undirected graph G=(V,E) Time: O(|V| + |E|) adj list O(|V|2) adj matrix Source/Sink Shortest Path Problem: Given 2 vertices u, v, find the shortest path in G from u to v. Solution: BFS starting at u. Stop at v. Single-Source Shortest Paths Problem: Given a vertex u, find the shortest path in G from u to each vertex. Solution: BFS starting at u. Full BFS tree. All-Pairs Shortest Paths Problem: Find the shortest path in G from each vertex u to each vertex v. Solution: For each u: BFS starting at u; full BFS tree. Time: O(|V|(|V| + |E|)) adj list O(|V|3) adj matrix source: based on Sedgewick, Graph Algorithms

Shortest Path Applications for weighted, directed graph G=(V,E) Weight ~ Cost ~ Distance Road maps Airline routes Telecommunications network routing VLSI design routing source: based on Sedgewick, Graph Algorithms

Shortest Path Trees Shortest Path Tree gives shortest path from root to each other vertex source: Sedgewick, Graph Algorithms

Shortest Path Principles: Relaxation Graph Initialization We start with a weighted, directed graph with a weight function w defined on its edges. We will generally consider a distinguished vertex, called the source, and usually denoted by s.

Shortest Path Principles: Relaxation “Relax” a constraint to try to improve solution “Rubber band” analogy [Sedgewick] Relaxation of an Edge (u,v): test if shortest path to v [found so far] can be improved by going through u A B C D E F G 2 1 3 4 5 6 8 7

Shortest Path Principles: Relaxation

Shortest Path Principles: Bellman-Ford

Dag-Shortest-Paths

Single Source Shortest Paths Dijkstra’s Algorithm for (nonnegative) weighted, directed graph G=(V,E) source: 91.503 textbook Cormen et al.

Single Source Shortest Paths Dijkstra’s Algorithm for (nonnegative) weighted, directed graph G=(V,E) source: 91.503 textbook Cormen et al.

Single Source Shortest Paths Dijkstra’s Algorithm for (nonnegative) weighted, directed graph G=(V,E) See separate ShortestPath 91.404 slide show A B C D E F G 2 1 3 4 5 6 8 7 source: 91.503 textbook Cormen et al.

Single Source Shortest Paths Dijkstra’s Algorithm Review problem: For the directed, weighted graph below, find the shortest path that begins at vertex A and ends at vertex F. List the vertices in the order that they appear on that path. What is the sum of the edge weights of that path? A B C D E F G 2 1 3 4 5 6 8 7 Why can’t Dijkstra’s algorithm handle negative-weight edges?

Single Source Shortest Paths Dijkstra’s Algorithm for (nonnegative) weighted, directed graph G=(V,E) source: Sedgewick, Graph Algorithms

Shortest Path Algorithms source: Sedgewick, Graph Algorithms