22 Elementary Graph Algorithms. There are two standard ways to represent a
|
|
- Octavia Baker
- 5 years ago
- Views:
Transcription
1 VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph =(, ): as a collection of adjacency lists or as an adjacency matrix Either way applies to both directed and undirected graphs The adjacency-list representation provides a compact way to represent sparse graphs those for which MAT AADS, Fall Nov
2 23 Minimum Spanning Trees Electronic circuit designs often need to make the pins of several components electrically equivalent by wiring them together To interconnect a set of pins, we can use an arrangement of 1wires, each connecting two pins Of all such arrangements, the one that uses the least amount of wire is usually the most desirable MAT AADS, Fall Nov Model this wiring problem with a connected, undirected graph =,, where is the set of pins, is the set of possible interconnections between pairs of pins, and for each edge (,, we have a weight (, ) specifying the cost (amount of wire) to connect and Find an acyclic subset that connects all of the vertices and whose total weight is minimized = (, ) (, MAT AADS, Fall Nov
3 Since is acyclic and connects all of the vertices, it must form a tree, which we call a spanning tree since it spans the graph We call the problem of determining the tree the minimum-spanning-tree problem (MST) MAT AADS, Fall Nov We examine two algorithms for solving the MST problem: Kruskal s and Prim s algorithms We can easily make each of them run in time ( lg ) using ordinary binary heaps By using Fibonacci heaps, Prim s algorithm runs in time ( + lg ), which improves over the binary-heap implementation if The two algorithms are greedy algorithms Greedy strategy does not generally guarantee nding globally optimal solutions to problems For the MST problem we can prove that greedy strategies do yield a tree with minimum weight MAT AADS, Fall Nov
4 23.1 Growing a minimum spanning tree Assume that we have a connected, undirected graph =, with a weight function :, and we wish to nd a MST for The following generic method grows the MST one edge at a time The generic method manages a set of edges, maintaining the following loop invariant: Prior to each iteration, is a subset of some minimum spanning tree MAT AADS, Fall Nov At each step, we determine an edge (, ) that we can add to without violating this invariant, in the sense that (, ) is also a subset of a MST We call such an edge a safe edge for GENERIC-MST(, ) 1. ; 2. while does not form a spanning tree 3. nd an edge (, ) that is safe for 4. (, ) 5. return MAT AADS, Fall Nov
5 Initialization: After line 1, the set trivially satis es the loop invariant Maintenance: The loop in lines 2 4 maintains the invariant by adding only safe edges Termination: All edges added to are in a MST, and so the set returned in line 5 must be a MST The tricky part is nding a safe edge in line 3 One must exist, since the invariant dictates that there is a spanning tree such that Within the while loop body, must be a proper subset of, and there must be an edge (, s.t. (, ) and (, ) is safe for MAT AADS, Fall Nov Acut (, ) of an undirected graph =, is a partition of An edge (, crosses the cut if one of its endpoints is in and the other is in We say that a cut respects a set of edges if no edge in crosses the cut Alight edge crossing a cut has the minimum weight of any edge crossing the cut Note that there can be ties More generally, an edge is a light edge satisfying a given property if its weight is the minimum of any edge satisfying the property MAT AADS, Fall Nov
6 MAT AADS, Fall Nov Theorem 23.1: Let =, be a connected, undirected graph with a real-valued weight function on. Let be a subset of that is included in some MST for, let (, ) be any cut of that respects, and let (, ) be a light edge crossing (, ). Then, edge (, ) is safe for. MAT AADS, Fall Nov
7 Theorem 23.1 gives us a better understanding of the workings of the GENERIC-MST method on a connected graph =, As the method proceeds, the set is always acyclic; otherwise, a MST including would contain a cycle, which is a contradiction At any point in the execution, the graph =, is a forest, and each of the connected components of is a tree Some of the trees may contain just one vertex, as is the case, e.g., when the method begins: is empty and the forest contains trees, one for each vertex MAT AADS, Fall Nov Moreover, any safe edge (, ) for connects distinct components of, since (, ) must be acyclic The while loop in lines 2 4 of GENERIC-MST executes 1times because it nds one of the 1edges of a minimum spanning tree in each iteration Initially, when, there are trees in, and each iteration reduces that number by 1 When the forest contains only a single tree, the method terminates MAT AADS, Fall Nov
8 Corollary 23.2: Let =, be a connected, undirected graph with a real-valued weight function defined on. Let be a subset of that is included in some MST for, and let =, be a connected component (tree) in the forest =,. If (, ) is a light edge connecting to some other component in, then (, ) is safe for. Proof: The cut (, ) respects, and (, ) is a light edge for this cut. Therefore, (, ) is safe for. MAT AADS, Fall Nov The algorithms of Kruskal and Prim These algorithms use a speci c rule to determine a safe edge in line 3 of GENERIC-MST In Kruskal s algorithm, the set is a forest whose vertices are all those of the given graph The safe edge added to is always a least-weight edge in the graph that connects two distinct components In Prim s algorithm, the set forms a single tree The safe edge added to is always a least-weight edge connecting the tree to a vertex not in the tree MAT AADS, Fall Nov
9 Kruskal s algorithm Find a safe edge to add to the growing forest by nding, of all the edges that connect any two trees in the forest, an edge (, ) of least weight Let and denote the two trees that are connected by (, ) Since (, ) must be a light edge connecting to some other tree, Corollary 23.2 implies that (, ) is a safe edge for This is a greedy algorithm because at each step it adds an edge of least possible weight MAT AADS, Fall Nov MST-KRUSKAL(, ) for each vertex. 3. MAKE-SET( ) 4. sort the edges of. into nondecreasing order by weight 5. for each edge (,., taken in nondecreasing order by weight 6. if FIND-SET( FIND-SET( ) 7. (, ) 8. UNION(, ) 9. return MAT AADS, Fall Nov
10 FIND-SET( ) returns a representative element from the set that contains Determine whether and belong to the same tree by testing FIND-SET = FIND-SET( ) UNION procedure combines trees Lines 1 3 initialize the set to the empty set and create trees, one containing each vertex The for loop in lines 5 8 examines edges in order of weight, from lowest to highest MAT AADS, Fall Nov The loop checks, for each edge (, ), whether the endpoints and belong to the same tree If they do, then the edge (, ) cannot be added to the forest without creating a cycle, and the edge is discarded Otherwise, the two vertices belong to different trees In this case, line 7 adds the edge (, ) to, and line 8 merges the vertices in the two trees MAT AADS, Fall Nov
11 MAT AADS, Fall Nov MAT AADS, Fall Nov
12 The running time depends on how we implement the disjoint-set data structure Initializing the set (line 1) takes (1) time, and the time to sort the edges (line 4) is ( lg ) The for loop (lines 5 8) performs ( ) FIND-SET and UNION operations on the disjoint-set forest With the MAKE-SET operations, these take a total of ( + )time is the very slowly growing funct We assume that is connected, so have 1, and so the disjoint-set operations take ( ) time Moreover, since = (lg ) = (lg ), the total running time of Kruskal s algorithm is ( lg ) Observing that <, we have lg = (lg ), and the running time of Kruskal s algorithm is ( lg ) MAT AADS, Fall Nov Prim s algorithm Prim s algorithm has the property that the edges in the set always form a single tree We start from an arbitrary root vertex and grow until the tree spans all the vertices in Each step adds to a light edge that connects to an isolated vertex (no edge of is incident) By Corollary 23.2, this rule adds only edges that are safe for and eventually forms a MST Greedy: each step adds to the tree an edge that contributes the min amount to the tree s weight MAT AADS, Fall Nov
13 MAT AADS, Fall Nov MAT AADS, Fall Nov
14 In order to implement Prim s algorithm ef ciently, we need a fast way to select a new edge to add to the tree formed by the edges in In the pseudocode below, the connected graph and the root of the MST to be grown are inputs to the algorithm During execution of the algorithm, all vertices that are not in the tree reside in a min-priority queue based on a key attribute For each vertex, the attribute. is the minimum weight of any edge connecting to a vertex in the tree; by convention. if there is no such edge MAT AADS, Fall Nov Attribute. names the parent of in the tree The algorithm implicitly maintains the set from GENERIC-MST as =,. When the algorithm terminates, the min-priority queue is empty; the minimum spanning tree for is thus =,. MAT AADS, Fall Nov
15 MST-PRIM(,, ) 1. for each NIL while 7. EXTRACT-MIN( ) 8. for each. [ ] 9. if and, < (, ) MAT AADS, Fall Nov The algorithm maintains the following three-part loop invariant: Prior to each iteration of the while loop of lines 6 11, 1. =,. 2. The vertices already placed into the minimum spanning tree are those in 3. For all vertices, if. NIL, then. and. is the weight of a light edge,. connecting to some vertex already placed into the MST MAT AADS, Fall Nov
16 Line 7 identi es a vertex incident on a light edge that crosses the cut (, ) Removing from the set adds it to the set of vertices in the tree, thus adding (,. ) to The for loop of lines 8 11 updates the and attributes of every vertex adjacent to but not in the tree, thereby maintaining the third part of the loop invariant MAT AADS, Fall Nov The total time for Prim s algorithm is ( lg + lg ) = ( lg ), which is asympt. the same as for Kruskal s algorithm We can improve the asymptotic running time of Prim s algorithm by using Fibonacci heaps If a Fibonacci heap holds elements, an EXTRACT-MIN operation takes (lg ) amortized time and a DECREASE-KEY operation (to implement line 11) takes (1) amortized time Therefore, by using a Fibonacci heap for the min-priority queue, the running time of Prim s algorithm improves to ( + lg ) MAT AADS, Fall Nov
17 24 Single-Source Shortest Paths In a shortest-paths problem, we are given a weighted, directed graph =,, with weight function : mapping edges to real-valued weights The weight ( ) of path =,,, is the sum of the weights of its constituent edges: = (, ) MAT AADS, Fall Nov We de ne the shortest-path weight (, ) from to by, = min if there is a path from to otherwise A shortest path from vertex to vertex is then de ned as any path with weight (, ) MAT AADS, Fall Nov
18 Optimal substructure of a shortest path Shortest-paths algorithms typically rely on the property that a shortest path between two vertices contains other shortest paths within it Recall that optimal substructure is one of the key indicators that dynamic programming and the greedy method might apply The following lemma states the optimalsubstructure property of shortest paths more precisely MAT AADS, Fall Nov Lemma 24.1 (Subpaths of shortest paths are shortest paths) Given a weighted, directed graph =,, with weight function :, let =,,, be a shortest path from vertex to vertex and, for any and such that, let =,,, be the subpath from vertex to. Then, is a shortest path from to. Proof: If we decompose path into, then we have that = + +. Now, assume that there is a path from to with weight <. Then, is a path from to whose weight + + is less than, which contradicts the assumption that is a shortest path from to. MAT AADS, Fall Nov
19 Negative-weight edges If the graph =, contains no negativeweight cycles reachable from the source, then for all, the shortest-path weight, is well de ned, even if it has a negative value If contains a negative-weight cycle reachable from, shortest-path weights aren t well de ned No path from to a vertex on the cycle can be a shortest path we always nd a path with lower weight by following the proposed shortest path and then traversing the negative-weight cycle MAT AADS, Fall Nov If there is a negative-weight cycle on some path from to, we de ne, MAT AADS, Fall Nov
20 Cycles A shortest path cannot either contain a positiveweight cycle, since removing the cycle from the path produces a path with the same source and destination vertices and a lower path weight If =,,, is a path and =,,, is a positive-weight cycle on this path ( = and ( ) >0), then the path =,,,,,, has weight = < ( ), and so cannot be a shortest path from to MAT AADS, Fall Nov If there is a shortest path from a source vertex to a destination vertex that contains a 0-weight cycle, then there is another shortest path from to without this cycle We can repeatedly remove 0-weight cycles from the path until the shortest path is cycle-free Therefore, we can assume that when we are nding shortest paths, they have no cycles, i.e., they are simple paths Any acyclic path in =, contains at most distinct vertices, and at most 1edges Thus, we can restrict our attention to shortest paths of at most 1 edges MAT AADS, Fall Nov
21 Relaxation The attribute. is an upper bound on the weight of a shortest path from source to We call. a shortest-path estimate The following ( )-time procedure initializes the shortest-path estimates and predecessors ( ): INITIALIZE-SINGLE-SOURCE(, ) 1. for each vertex NIL MAT AADS, Fall Nov The process of relaxing an edge (, ) consists of testing whether we can improve the shortest path to found so far by going through and, if so, updating. and. A relaxation step may decrease the value of the shortest-path estimate. and update s predecessor attribute. The following code performs a relaxation step on edge (, ) in (1) time: RELAX(,, ) 1. if. >. + (, ) (, ) 3.. MAT AADS, Fall Nov
22 MAT AADS, Fall Nov Properties of shortest paths and relaxation To prove the following algorithms correct, we appeal to several properties of shortest paths and relaxation: Triangle inequality (Lemma 24.10) For any edge (,, we have,, +, Upper-bound property (Lemma 24.11) We always have., for all vertices, and once. achieves the value,, it never changes MAT AADS, Fall Nov
23 No-path property (Corollary 24.12) If there is no path from to, then we always have. =, Convergence property (Lemma 24.14) If is a shortest path in for some,, and if. = (, ) at any time prior to relaxing edge (, ), then. = (, ) at all times afterward MAT AADS, Fall Nov Path-relaxation property (Lemma 24.15) If =,,, is a shortest path from = to, and we relax the edges of in the order (, ),(, ),,(, ), then. = (, ). This property holds regardless of any other relaxation steps that occur, even if they are intermixed with relaxations of the edges of Predecessor-subgraph property (Lemma 24.17) Once. = (, ) for all, the predecessor subgraph is a shortest-paths tree rooted at MAT AADS, Fall Nov
22 Elementary Graph Algorithms. There are two standard ways to represent a
VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph
More informationDecreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )
Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 1. if >. 2. error new key is greater than current key 3.. 4.. 5. if NIL and.
More informationMinimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem
Minimum Spanning Trees (Forests) Given an undirected graph G=(V,E) with each edge e having a weight w(e) : Find a subgraph T of G of minimum total weight s.t. every pair of vertices connected in G are
More informationMinimum Spanning Trees
Minimum Spanning Trees Overview Problem A town has a set of houses and a set of roads. A road connects and only houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and
More informationCHAPTER 23. Minimum Spanning Trees
CHAPTER 23 Minimum Spanning Trees In the design of electronic circuitry, it is often necessary to make the pins of several components electrically equivalent by wiring them together. To interconnect a
More informationMinimum Spanning Trees My T. UF
Introduction to Algorithms Minimum Spanning Trees @ UF Problem Find a low cost network connecting a set of locations Any pair of locations are connected There is no cycle Some applications: Communication
More informationGreedy Algorithms. At each step in the algorithm, one of several choices can be made.
Greedy Algorithms At each step in the algorithm, one of several choices can be made. Greedy Strategy: make the choice that is the best at the moment. After making a choice, we are left with one subproblem
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 05 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction
More informationLecture Notes for Chapter 23: Minimum Spanning Trees
Lecture Notes for Chapter 23: Minimum Spanning Trees Chapter 23 overview Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has
More informationShortest Path Problem
Shortest Path Problem CLRS Chapters 24.1 3, 24.5, 25.2 Shortest path problem Shortest path problem (and variants) Properties of shortest paths Algorithmic framework Bellman-Ford algorithm Shortest paths
More informationCOP 4531 Complexity & Analysis of Data Structures & Algorithms
COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 9 Minimum Spanning Trees Thanks to the text authors who contributed to these slides Why Minimum Spanning Trees (MST)? Example 1 A
More informationCIS 121 Data Structures and Algorithms Minimum Spanning Trees
CIS 121 Data Structures and Algorithms Minimum Spanning Trees March 19, 2019 Introduction and Background Consider a very natural problem: we are given a set of locations V = {v 1, v 2,..., v n }. We want
More informationMinimum Spanning Trees
Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no
More informationMinimum spanning trees
Minimum spanning trees [We re following the book very closely.] One of the most famous greedy algorithms (actually rather family of greedy algorithms). Given undirected graph G = (V, E), connected Weight
More informationV Advanced Data Structures
V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,
More informationMinimum Spanning Trees
Minimum Spanning Trees 1 Minimum- Spanning Trees 1. Concrete example: computer connection. Definition of a Minimum- Spanning Tree Concrete example Imagine: You wish to connect all the computers in an office
More informationDijkstra s algorithm for shortest paths when no edges have negative weight.
Lecture 14 Graph Algorithms II 14.1 Overview In this lecture we begin with one more algorithm for the shortest path problem, Dijkstra s algorithm. We then will see how the basic approach of this algorithm
More informationV Advanced Data Structures
V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,
More informationAnnouncements Problem Set 5 is out (today)!
CSC263 Week 10 Announcements Problem Set is out (today)! Due Tuesday (Dec 1) Minimum Spanning Trees The Graph of interest today A connected undirected weighted graph G = (V, E) with weights w(e) for each
More informationRepresentations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs
Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects
More information2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23)
2pt 0em Computer Science & Engineering 423/823 Design and of s Lecture 04 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 18 Given a connected, undirected
More informationWeek 11: Minimum Spanning trees
Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,
More information2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016
CS125 Lecture 2 Fall 2016 2.1 Greedy Algorithms We will start talking about methods high-level plans for constructing algorithms. One of the simplest is just to have your algorithm be greedy. Being greedy,
More informationWeek 12: Minimum Spanning trees and Shortest Paths
Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601
More informationShortest path problems
Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths
More informationUC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170
UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, 2003 Notes 8 for CS 170 1 Minimum Spanning Trees A tree is an undirected graph that is connected
More informationIntroduction to Algorithms. Lecture 11
Introduction to Algorithms Lecture 11 Last Time Optimization Problems Greedy Algorithms Graph Representation & Algorithms Minimum Spanning Tree Prim s Algorithm Kruskal s Algorithm 2 Today s Topics Shortest
More information6.1 Minimum Spanning Trees
CS124 Lecture 6 Fall 2018 6.1 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties
More information1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m
Minimum Spanning Trees (MST) 8 0 e 7 b 3 a 5 d 9 h i g c 8 7 6 3 f j 9 6 k l 5 m A graph H(U,F) is a subgraph of G(V,E) if U V and F E. A subgraph H(U,F) is called spanning if U = V. Let G be a graph with
More informationNotes on Minimum Spanning Trees. Red Rule: Given a cycle containing no red edges, select a maximum uncolored edge on the cycle, and color it red.
COS 521 Fall 2009 Notes on Minimum Spanning Trees 1. The Generic Greedy Algorithm The generic greedy algorithm finds a minimum spanning tree (MST) by an edge-coloring process. Initially all edges are uncolored.
More informationG205 Fundamentals of Computer Engineering. CLASS 21, Mon. Nov Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm
G205 Fundamentals of Computer Engineering CLASS 21, Mon. Nov. 22 2004 Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm Greedy Algorithms, 1 Algorithms for Optimization Problems Sequence of steps Choices at
More informationAlgorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree
Algorithms and Theory of Computation Lecture 5: Minimum Spanning Tree Xiaohui Bei MAS 714 August 31, 2017 Nanyang Technological University MAS 714 August 31, 2017 1 / 30 Minimum Spanning Trees (MST) A
More informationAlgorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree
Algorithms and Theory of Computation Lecture 5: Minimum Spanning Tree Xiaohui Bei MAS 714 August 31, 2017 Nanyang Technological University MAS 714 August 31, 2017 1 / 30 Minimum Spanning Trees (MST) A
More informationMinimum Spanning Trees Ch 23 Traversing graphs
Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs
More informationCS 561, Lecture 9. Jared Saia University of New Mexico
CS 561, Lecture 9 Jared Saia University of New Mexico Today s Outline Minimum Spanning Trees Safe Edge Theorem Kruskal and Prim s algorithms Graph Representation 1 Graph Definition A graph is a pair of
More informationChapter 23. Minimum Spanning Trees
Chapter 23. Minimum Spanning Trees We are given a connected, weighted, undirected graph G = (V,E;w), where each edge (u,v) E has a non-negative weight (often called length) w(u,v). The Minimum Spanning
More informationMinimum Spanning Trees
Chapter 23 Minimum Spanning Trees Let G(V, E, ω) be a weighted connected graph. Find out another weighted connected graph T(V, E, ω), E E, such that T has the minimum weight among all such T s. An important
More informationIntroduction to Algorithms
Introduction to Algorithms, Lecture 1 /1/200 Introduction to Algorithms.04J/1.401J LECTURE 11 Graphs, MST, Greedy, Prim Graph representation Minimum spanning trees Greedy algorithms hallmarks. Greedy choice
More informationChapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 9 Greedy Technique Copyright 2007 Pearson Addison-Wesley. All rights reserved. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that
More informationCS 6783 (Applied Algorithms) Lecture 5
CS 6783 (Applied Algorithms) Lecture 5 Antonina Kolokolova January 19, 2012 1 Minimum Spanning Trees An undirected graph G is a pair (V, E); V is a set (of vertices or nodes); E is a set of (undirected)
More informationGraphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs
Graphs and Network Flows ISE 411 Lecture 7 Dr. Ted Ralphs ISE 411 Lecture 7 1 References for Today s Lecture Required reading Chapter 20 References AMO Chapter 13 CLRS Chapter 23 ISE 411 Lecture 7 2 Minimum
More informationPart VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths
Part VI Graph algorithms Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths 1 Chapter 22 Elementary Graph Algorithms Representations of graphs
More informationCSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013
CSE373: Data Structures & Algorithms Lecture 7: Minimum Spanning Trees Dan Grossman Fall 03 Spanning Trees A simple problem: Given a connected undirected graph G=(V,E), find a minimal subset of edges such
More informationLet the dynamic table support the operations TABLE-INSERT and TABLE-DELETE It is convenient to use the load factor ( )
17.4 Dynamic tables Let us now study the problem of dynamically expanding and contracting a table We show that the amortized cost of insertion/ deletion is only (1) Though the actual cost of an operation
More informationCSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms
CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms Professor Henry Carter Fall 2016 Recap Greedy algorithms iterate locally optimal choices to construct a globally optimal solution
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401J LECTURE 13 Graph algorithms Graph representation Minimum spanning trees Greedy algorithms Optimal substructure Greedy choice Prim s greedy MST algorithm Prof.
More informationCHAPTER 13 GRAPH ALGORITHMS
CHAPTER 13 GRAPH ALGORITHMS SFO LAX ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 00) AND SLIDES FROM NANCY
More information18.3 Deleting a key from a B-tree
18.3 Deleting a key from a B-tree B-TREE-DELETE deletes the key from the subtree rooted at We design it to guarantee that whenever it calls itself recursively on a node, the number of keys in is at least
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401J LECTURE 16 Greedy Algorithms (and Graphs) Graph representation Minimum spanning trees Optimal substructure Greedy choice Prim s greedy MST algorithm Prof. Charles
More informationSingle Source Shortest Path
Single Source Shortest Path A directed graph G = (V, E) and a pair of nodes s, d is given. The edges have a real-valued weight W i. This time we are looking for the weight and the shortest path from s
More informationCSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li
CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast
More informationAlgorithms for Minimum Spanning Trees
Algorithms & Models of Computation CS/ECE, Fall Algorithms for Minimum Spanning Trees Lecture Thursday, November, Part I Algorithms for Minimum Spanning Tree Sariel Har-Peled (UIUC) CS Fall / 6 Sariel
More informationmanaging an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm
Spanning Trees 1 Spanning Trees the minimum spanning tree problem three greedy algorithms analysis of the algorithms 2 The Union-Find Data Structure managing an evolving set of connected components implementing
More informationAdvanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012
topological ordering, minimum spanning tree, Union-Find problem Jiří Vyskočil, Radek Mařík 2012 Subgraph subgraph A graph H is a subgraph of a graph G, if the following two inclusions are satisfied: 2
More informationMinimum Spanning Trees Outline: MST
Minimm Spanning Trees Otline: MST Minimm Spanning Tree Generic MST Algorithm Krskal s Algorithm (Edge Based) Prim s Algorithm (Vertex Based) Spanning Tree A spanning tree of G is a sbgraph which is tree
More information16 Greedy Algorithms
16 Greedy Algorithms Optimization algorithms typically go through a sequence of steps, with a set of choices at each For many optimization problems, using dynamic programming to determine the best choices
More informationLecture 10. Elementary Graph Algorithm Minimum Spanning Trees
Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo
More informationMinimum Spanning Trees
CS124 Lecture 5 Spring 2011 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties
More informationCS 5321: Advanced Algorithms Minimum Spanning Trees. Acknowledgement. Minimum Spanning Trees
CS : Advanced Algorithms Minimum Spanning Trees Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Minimum Spanning
More informationCOMP251: Single source shortest paths
COMP51: Single source shortest paths Jérôme Waldispühl School of Computer Science McGill University Based on (Cormen et al., 00) Problem What is the shortest road to go from one city to another? Eample:
More informationCSci 231 Final Review
CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.
More informationCSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo
CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 07 Single-Source Shortest Paths (Chapter 24) Stephen Scott and Vinodchandran N. Variyam sscott@cse.unl.edu 1/36 Introduction
More information23.2 Minimum Spanning Trees
23.2 Minimum Spanning Trees Kruskal s algorithm: Kruskal s algorithm solves the Minimum Spanning Tree problem in O( E log V ) time. It employs the disjoint-set data structure that is similarly used for
More informationCS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department
CS473-Algorithms I Lecture 3-A Graphs Graphs A directed graph (or digraph) G is a pair (V, E), where V is a finite set, and E is a binary relation on V The set V: Vertex set of G The set E: Edge set of
More informationAlgorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee
Algorithm Analysis Graph algorithm Chung-Ang University, Jaesung Lee Basic definitions Graph = (, ) where is a set of vertices and is a set of edges Directed graph = where consists of ordered pairs
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More information2 A Template for Minimum Spanning Tree Algorithms
CS, Lecture 5 Minimum Spanning Trees Scribe: Logan Short (05), William Chen (0), Mary Wootters (0) Date: May, 0 Introduction Today we will continue our discussion of greedy algorithms, specifically in
More informationCS521 \ Notes for the Final Exam
CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )
More informationAlgorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1
Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm ADS: lects 14 & 15 slide 1 Weighted Graphs Definition 1 A weighted (directed or undirected graph) is a pair (G, W ) consisting
More informationCSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees
CSE1 Introduction to Algorithms Lecture 1 Minimum Spanning Trees Antoine Vigneron antoine@unist.ac.kr Ulsan National Institute of Science and Technology July 11, 201 Antoine Vigneron (UNIST) CSE1 Lecture
More informationMinimum Spanning Trees
Minimum Spanning Trees Minimum Spanning Trees Representation of Weighted Graphs Properties of Minimum Spanning Trees Prim's Algorithm Kruskal's Algorithm Philip Bille Minimum Spanning Trees Minimum Spanning
More information7.3 Spanning trees Spanning trees [ ] 61
7.3. Spanning trees [161211-1348 ] 61 7.3 Spanning trees We know that trees are connected graphs with the minimal number of edges. Hence trees become very useful in applications where our goal is to connect
More informationKruskal s MST Algorithm
Kruskal s MST Algorithm CLRS Chapter 23, DPV Chapter 5 Version of November 5, 2014 Main Topics of This Lecture Kruskal s algorithm Another, but different, greedy MST algorithm Introduction to UNION-FIND
More informationAdvanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret
Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret Greedy Algorithms (continued) The best known application where the greedy algorithm is optimal is surely
More informationParallel Graph Algorithms
Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050/VT3 Part I Introduction Overview Graphs definitions & representations Minimal Spanning Tree (MST) Prim s algorithm Single Source
More informationCS420/520 Algorithm Analysis Spring 2009 Lecture 14
CS420/520 Algorithm Analysis Spring 2009 Lecture 14 "A Computational Analysis of Alternative Algorithms for Labeling Techniques for Finding Shortest Path Trees", Dial, Glover, Karney, and Klingman, Networks
More informationMinimum-Cost Spanning Tree. Example
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 2 4 12 6 3 Network has 10 edges.
More informationGreedy Algorithms Part Three
Greedy Algorithms Part Three Announcements Problem Set Four due right now. Due on Wednesday with a late day. Problem Set Five out, due Monday, August 5. Explore greedy algorithms, exchange arguments, greedy
More informationExample. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies
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 2 4 12 6 3 Network has 10 edges.
More informationUndirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1
Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching
More informationUNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD
UNIT 3 Greedy Method GENERAL METHOD Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset
More informationMinimum Spanning Trees and Prim s Algorithm
Minimum Spanning Trees and Prim s Algorithm Version of October 3, 014 Version of October 3, 014 Minimum Spanning Trees and Prim s Algorithm 1 / 3 Outline Spanning trees and minimum spanning trees (MST).
More informationAnalysis of Algorithms, I
Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, March 8, 2016 Outline 1 Recap Single-source shortest paths in graphs with real edge weights:
More information15.4 Longest common subsequence
15.4 Longest common subsequence Biological applications often need to compare the DNA of two (or more) different organisms A strand of DNA consists of a string of molecules called bases, where the possible
More informationGraphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs
Graphs and Network Flows IE411 Lecture 21 Dr. Ted Ralphs IE411 Lecture 21 1 Combinatorial Optimization and Network Flows In general, most combinatorial optimization and integer programming problems are
More informationSpanning Trees. CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Motivation. Observations. Spanning tree via DFS
Spanning Trees S: ata Structures & lgorithms Lecture : Minimum Spanning Trees simple problem: iven a connected undirected graph =(V,), find a minimal subset of edges such that is still connected graph
More informationCS 310 Advanced Data Structures and Algorithms
CS 0 Advanced Data Structures and Algorithms Weighted Graphs July 0, 07 Tong Wang UMass Boston CS 0 July 0, 07 / Weighted Graphs Each edge has a weight (cost) Edge-weighted graphs Mostly we consider only
More information1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1
Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 1. O(logn) 2. O(n) 3. O(nlogn) 4. O(n 2 ) 5. O(2 n ) 2. [1 pt] What is the solution
More informationOutline. Computer Science 331. Analysis of Prim's Algorithm
Outline Computer Science 331 Analysis of Prim's Algorithm Mike Jacobson Department of Computer Science University of Calgary Lecture #34 1 Introduction 2, Concluded 3 4 Additional Comments and References
More informationMinimum Spanning Tree
Minimum Spanning Tree 1 Minimum Spanning Tree G=(V,E) is an undirected graph, where V is a set of nodes and E is a set of possible interconnections between pairs of nodes. For each edge (u,v) in E, we
More informationCS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya
CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Graphs (review) Definition. A directed graph (digraph) G = (V, E) is an ordered pair consisting of a set V of vertices
More informationUndirected Graphs. Hwansoo Han
Undirected Graphs Hwansoo Han Definitions Undirected graph (simply graph) G = (V, E) V : set of vertexes (vertices, nodes, points) E : set of edges (lines) An edge is an unordered pair Edge (v, w) = (w,
More information11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions
Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is
More informationChapter 9 Graph Algorithms
Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)
More informationContext: Weighted, connected, undirected graph, G = (V, E), with w : E R.
Chapter 23: Minimal Spanning Trees. Context: Weighted, connected, undirected graph, G = (V, E), with w : E R. Definition: A selection of edges from T E such that (V, T ) is a tree is called a spanning
More informationParallel Graph Algorithms
Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050 Spring 202 Part I Introduction Overview Graphsdenitions, properties, representation Minimal spanning tree Prim's algorithm Shortest
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 10 Implementing MST Algorithms Adam Smith Minimum spanning tree (MST) Input: A connected undirected graph G = (V, E) with weight function w : E R. For now, assume
More information5 MST and Greedy Algorithms
5 MST and Greedy Algorithms One of the traditional and practically motivated problems of discrete optimization asks for a minimal interconnection of a given set of terminals (meaning that every pair will
More informationCSE 100 Minimum Spanning Trees Prim s and Kruskal
CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:
More information