22 Elementary Graph Algorithms. There are two standard ways to represent a

Size: px
Start display at page:

Download "22 Elementary Graph Algorithms. There are two standard ways to represent a"

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 Let us 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 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 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. MAT AADS, Fall Nov

19 Proof: If we decompose path into then we have that = + +. Now, assume that there is a path weight <. Then, from to with is a path from to whose weight + + <, which contradicts the assumption that is a shortest path from to. MAT AADS, Fall Nov 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

20 If there is a negative-weight cycle on some path from to, we de ne, MAT AADS, Fall Nov 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

21 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 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

22 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 MAT AADS, Fall Nov

23 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 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

24 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 The Bellman-Ford algorithm Solves the single-source shortest-paths problem in the case in which weights may be negative Given a graph =, with source and weight function, it returns a boolean value indicating whether or not there is a negativeweight cycle that is reachable from the source If there is such a cycle, the algorithm indicates that no solution exists If there is no such cycle, the algorithm produces the shortest paths and their weights MAT AADS, Fall Nov

25 Relax edges, progressively decreasing. until we achieve the actual shortest-path weight (, ) BELLMAN-FORD(,, ) 1. INITIALIZE-SINGLE-SOURCE(, ) 2. for =1to for each edge,. 4. RELAX,, 5. for each edge,. 6. if. >. + (, ) 7. return FALSE 8. return TRUE MAT AADS, Fall Nov MAT AADS, Fall Nov

26 The algorithm makes 1 passes over the edges of the graph Each pass is one iteration of the for loop of lines 2 4 and consists of relaxing each edge of the graph once After making 1passes, lines 5 8 check for a negative-weight cycle and return the appropriate boolean value The Bellman-Ford algorithm runs in time ( ), the initialization in line 1 takes ( ) time, each of the 1passes over the edges in lines 2 4 takes ( ) time, and the for loop of lines 5 7 takes ( ) time MAT AADS, Fall Nov Lemma 24.2: Let =, be a weighted, directed graph with source and weight function :, and assume that contains no negative-weight cycles that are reachable from. Then, after the 1iterations of the for loop of lines 2 4 of BELLMAN-FORD, we have. = (, ) for all vertices that are reachable from. Proof: We prove the lemma by appealing to the path-relaxation property. MAT AADS, Fall Nov

27 Consider any vertex that is reachable from, and let =,,,, where = and =, be any shortest path from to. Because shortest paths are simple, has at most 1edges, and so 1. Each of the 1iterations of the for loop of lines 2 4 relaxes all edges. Among the edges relaxed in the th iteration, for =1,2,,, is (, ). By the path-relaxation property, therefore,. =. =, = (, ). MAT AADS, Fall Nov Corollary 24.3: Let =, be a weighted, directed graph with source and weight function :, and assume that contains no negative-weight cycles that are reachable from. Then, for each vertex, there is a path from to if and only if BELLMAN-FORD terminates with. when it is run on. MAT AADS, Fall Nov

28 Theorem 24.4 (Correctness of the B-F algorithm) Let BELLMAN-FORD be run on a weighted, directed graph =(, ) with source and weight function :. If contains no negative-weight cycles that are reachable from, then the algorithm returns TRUE, we have. = (, ) for all vertices, and the predecessor subgraph is a shortest-paths tree rooted at. If does contain a negative-weight cycle reachable from, then the algorithm returns FALSE. MAT AADS, Fall Nov Dijkstra s algorithm Dijkstra s algorithm solves the single-source shortest-paths problem on a weighted, directed graph =(, )for the case in which all edge weights are nonnegative Therefore, we assume that (, 0for each edge (, With a good implementation, the running time of Dijkstra s algorithm is lower than that of the Bellman-Ford algorithm MAT AADS, Fall Nov

29 Dijkstra s algorithm maintains a set of vertices whose nal shortest-path weights from the source have already been determined The algorithm repeatedly selects the vertex with the minimum shortest-path estimate, adds to, and relaxes all edges leaving The following implementation uses a minpriority queue of vertices, keyed by their values MAT AADS, Fall Nov DIJKSTRA(,, ) 1. INITIALIZE-SINGLE-SOURCE(, ) while 5. EXTRACT-MIN( ) for each vertex. [ ] 8. RELAX (,, ) MAT AADS, Fall Nov

30 Shaded edges indicate predecessor values Black vertices are in the set MAT AADS, Fall Nov Maintain the invariant that = at the start of each iteration of the while loop of lines 4 8 Line 3 initializes the min-priority queue to contain all the vertices in ; since ; at that time, the invariant is true after line 3 Each time through the while loop, line 5 extracts a vertex from = and line 6 adds it to set, thereby maintaining the invariant The rst time through this loop, = Vertex, therefore, has the smallest shortestpath estimate of any vertex in MAT AADS, Fall Nov

31 Then, lines 7 8 relax each edge (, ) leaving, thus updating the estimate. and the predecessor. if we can improve the shortest path to found so far by going through Observe that the algorithm never inserts vertices into after line 3 and that each vertex is extracted from and added to exactly once, so that the while loop iterates exactly times Because Dijkstra s algorithm always chooses the lightest or closest vertex in to add to set, we say that it uses a greedy strategy MAT AADS, Fall Nov Theorem 24.6 (Correctness of Dijkstra s algorithm) Dijkstra s algorithm, run on a weighted, directed graph =(, )with non-negative weight function and source, terminates with. = (, ) for all vertices. Proof: We use the following loop invariant: At the start of each iteration of the while loop of lines 4 8,. = (, ) for each vertex. It suf ces to show for each vertex, we have. = (, ) at the time when is added to set. Once. = (, ), we rely on the upper-bound property to show that it holds thereafter. MAT AADS, Fall Nov

32 Initialization: Initially, =, and so the invariant is trivially true. Maintenance: We wish to show that in each iteration,. = (, ) for the vertex added to set. For the purpose of contradiction, let be the rst vertex for which. (, ) when it is added to set. Focus on the situation at the beginning of the iteration of the while loop in which is added to and derive the contradiction that. = (, ) at that time by examining a shortest path from to. We must have because is the rst vertex added to set and. =, = 0 at that time. MAT AADS, Fall Nov Because, we also have that just before is added to. There must be some path from to, for otherwise. =, by the nopath property, which would violate our assumption that. (, ). Because there is at least one path, there is a shortest path from to. Prior to adding to, path connects a vertex in ( ) to a vertex in ( ). Consider the rst vertex along such that, and let be s predecessor along. Decompose path into. (Either path or may have no edges.) MAT AADS, Fall Nov

33 MAT AADS, Fall Nov We claim that. =, when is added to. To prove this claim, observe that. Then, because we chose as the rst vertex for which. (, ) when it is added to, we had. =, when was added to. Edge (, ) was relaxed at that time, and the claim follows from the convergence property. We can now obtain a contradiction to prove that. = (, ). Because appears before on a shortest path from to and all edge weights are non-negative (notably those on path ), we have,,, and thus. =,,.. MAT AADS, Fall Nov

34 But because both vertices and were in when was chosen in line 5, we have... Thus, the two inequalities above are in fact equalities, giving. =, =, =.. Consequently,. =,, which contradicts our choice of. We conclude that. =, when is added to, and that this equality is maintained at all times thereafter. Termination: At termination, which, along with our invariant that =, implies that =. Thus,. =, for all vertices. MAT AADS, Fall Nov

22 Elementary Graph Algorithms. There are two standard ways to represent a

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 information

Decreasing 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(,, ) 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 information

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Minimum-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 information

Minimum Spanning Trees

Minimum 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 information

CHAPTER 23. Minimum Spanning Trees

CHAPTER 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 information

Minimum Spanning Trees My T. UF

Minimum 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 information

Single Source Shortest Path

Single 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 information

Shortest Path Problem

Shortest 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 information

Greedy 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 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 information

Minimum Spanning Trees

Minimum 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 information

Shortest path problems

Shortest 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 information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer 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 information

Lecture Notes for Chapter 23: Minimum Spanning Trees

Lecture 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 information

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Dijkstra 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 information

Introduction to Algorithms. Lecture 11

Introduction 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 information

V Advanced Data Structures

V 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 information

V Advanced Data Structures

V 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 information

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

CIS 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 information

Announcements Problem Set 5 is out (today)!

Announcements 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 information

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 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 information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer 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 information

UC 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, 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 information

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

CSE373: 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 information

2pt 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 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 information

Part 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 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 information

Week 11: Minimum Spanning trees

Week 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 information

CHAPTER 13 GRAPH ALGORITHMS

CHAPTER 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 information

Minimum Spanning Trees Ch 23 Traversing graphs

Minimum 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 information

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Representations 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 information

CS 6783 (Applied Algorithms) Lecture 5

CS 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 information

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

2.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 information

6.1 Minimum Spanning Trees

6.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 information

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 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 information

Minimum spanning trees

Minimum 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 information

Let the dynamic table support the operations TABLE-INSERT and TABLE-DELETE It is convenient to use the load factor ( )

Let 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 information

Minimum Spanning Trees

Minimum 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 information

Minimum Spanning Tree

Minimum 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 information

COMP251: Single source shortest paths

COMP251: 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 information

16 Greedy Algorithms

16 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 information

CS521 \ Notes for the Final Exam

CS521 \ 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 information

Week 12: Minimum Spanning trees and Shortest Paths

Week 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 information

CS 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 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 information

Algorithms for Minimum Spanning Trees

Algorithms 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 information

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms

CSC 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 information

G205 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 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 information

Lecture 11: Analysis of Algorithms (CS ) 1

Lecture 11: Analysis of Algorithms (CS ) 1 Lecture 11: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 12, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 2 Dynamic Programming Approach Floyd-Warshall Shortest

More information

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

CS420/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 information

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

managing 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 information

Notes 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.

Notes 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 information

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m

1 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 information

Minimum Spanning Trees

Minimum 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 information

Minimum Spanning Trees

Minimum 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 information

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Introduction. I Given a weighted, directed graph G =(V, E) with weight function ntroduction Computer Science & Engineering 2/82 Design and Analysis of Algorithms Lecture 06 Single-Source Shortest Paths (Chapter 2) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu

More information

Outline. Computer Science 331. Analysis of Prim's Algorithm

Outline. 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 information

CSE 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 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 information

CS 561, Lecture 9. Jared Saia University of New Mexico

CS 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 information

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Graphs 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 information

CSE 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 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 information

Analysis of Algorithms, I

Analysis 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 information

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Algorithms 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 information

18.3 Deleting a key from a B-tree

18.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 information

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Algorithms 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 information

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review 1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,

More information

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Algorithm 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 information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

2 A Template for Minimum Spanning Tree Algorithms

2 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 information

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

CSE331 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 information

CSci 231 Final Review

CSci 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 information

CS 5321: Advanced Algorithms Minimum Spanning Trees. Acknowledgement. Minimum Spanning Trees

CS 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 information

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Lecture 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 information

Algorithms on Graphs: Part III. Shortest Path Problems. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

Algorithms on Graphs: Part III. Shortest Path Problems. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar.. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar.. Shortest Path Problems Algorithms on Graphs: Part III Path in a graph. Let G = V,E be a graph. A path p = e 1,...,e k, e i E,

More information

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

Advanced 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 information

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Undirected 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 information

1 Dijkstra s Algorithm

1 Dijkstra s Algorithm Lecture 11 Dijkstra s Algorithm Scribes: Himanshu Bhandoh (2015), Virginia Williams, and Date: November 1, 2017 Anthony Kim (2016), G. Valiant (2017), M. Wootters (2017) (Adapted from Virginia Williams

More information

Chapter 23. Minimum Spanning Trees

Chapter 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 information

Context: Weighted, connected, undirected graph, G = (V, E), with w : E R.

Context: 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 information

The Shortest Path Problem

The Shortest Path Problem The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring

More information

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G. 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G. A shortest s-t path is a path from vertex to vertex, whose sum of edge weights is minimized. (b) Give the pseudocode

More information

24 Single-Source Shortest Paths

24 Single-Source Shortest Paths 4 Single-Source Shortest Paths Professor Patrick wishes to find the shortest possible route from Phoenix to Indianapolis. Given a road map of the United States on which the distance between each pair of

More information

15.4 Longest common subsequence

15.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 information

Introduction to Algorithms

Introduction 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 information

Chapter 9 Graph Algorithms

Chapter 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 information

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

11/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 information

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems Chapter 24. Shortest path problems We are given a directed graph G = (V,E) with each directed edge (u,v) E having a weight, also called a length, w(u,v) that may or may not be negative. A shortest path

More information

Minimum Spanning Trees

Minimum 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 information

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CSE 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

Sources for this lecture 2. Shortest paths and minimum spanning trees

Sources for this lecture 2. Shortest paths and minimum spanning trees S-72.2420 / T-79.5203 Shortest paths and minimum spanning trees 1 S-72.2420 / T-79.5203 Shortest paths and minimum spanning trees 3 Sources for this lecture 2. Shortest paths and minimum spanning trees

More information

Theorem 2.9: nearest addition algorithm

Theorem 2.9: nearest addition algorithm There are severe limits on our ability to compute near-optimal tours It is NP-complete to decide whether a given undirected =(,)has a Hamiltonian cycle An approximation algorithm for the TSP can be used

More information

Advanced 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 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 information

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

UNIT 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 information

11.9 Connectivity Connected Components. mcs 2015/5/18 1:43 page 419 #427

11.9 Connectivity Connected Components. mcs 2015/5/18 1:43 page 419 #427 mcs 2015/5/18 1:43 page 419 #427 11.9 Connectivity Definition 11.9.1. Two vertices are connected in a graph when there is a path that begins at one and ends at the other. By convention, every vertex is

More information

Ensures that no such path is more than twice as long as any other, so that the tree is approximately balanced

Ensures that no such path is more than twice as long as any other, so that the tree is approximately balanced 13 Red-Black Trees A red-black tree (RBT) is a BST with one extra bit of storage per node: color, either RED or BLACK Constraining the node colors on any path from the root to a leaf Ensures that no such

More information

7.3 Spanning trees Spanning trees [ ] 61

7.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 information

Greedy Algorithms Part Three

Greedy 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 information

COMP 355 Advanced Algorithms

COMP 355 Advanced Algorithms COMP 355 Advanced Algorithms Algorithms for MSTs Sections 4.5 (KT) 1 Minimum Spanning Tree Minimum spanning tree. Given a connected graph G = (V, E) with realvalued edge weights c e, an MST is a subset

More information

Kruskal s MST Algorithm

Kruskal 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 information

Introduction. I Given a weighted, directed graph G =(V, E) with weight function

Introduction. I Given a weighted, directed graph G =(V, E) with weight function ntroduction Computer Science & Engineering 2/82 Design and Analysis of Algorithms Lecture 05 Single-Source Shortest Paths (Chapter 2) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu

More information

Minimum Spanning Trees Outline: MST

Minimum 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 information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS 4 Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

Minimum Spanning Trees and Prim s Algorithm

Minimum 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 information