CS420/520 Algorithm Analysis Spring 2009 Lecture 14

Size: px
Start display at page:

Download "CS420/520 Algorithm Analysis Spring 2009 Lecture 14"

Transcription

1 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 Volume 9 (1979) pages Decomposition Algorithm for Shortest Paths in a Network. Journal ORSA, Vol 16, No 1, 1968, pp notes from Integer, Network, and Combinatorial Algorithms class, Dr. Richard Soland, professor, GWU I. Chapter 24 Single-Source Shortest Paths A. introductory comments and overview i. Professor Patrick s routing problem Indianapolis to Pheonix. ii. in shortest-paths problem we are given a weighted, directed graph G=(V,E), with weight function w:e Real Numbers mapping edges to real-valued weights iii. the weight of path p = <v 0, v 1,..., v k > is the sum of the weights of its constituent edges k w(p)= w( vi-1, vi ) i=1 p min { w(p) : u v } path from u to v iv. shortest-path weight from u to v by (u,v)= otherwise v. a path is simple if all its vertices are distinct vi. this is a generalization of breadth-first-search to handle weighted graphs (i.e., when all edge weights = 1 for BFS) vii. Variants (1) single-destination shortest-paths problem: from every vertex v to specific t destination [n paths]; reversing direction of each edge in the path can reduce to a single-source problem (2) single-pair shortest-path problem: [n 1 paths] find a shortest path from u to v for given vertices u and v; all known alg for this problem have same worst-case asymptotic running time as the best single-source alg (3) all-pairs shortest-paths problem: [n(n 1) paths] (also called multiterminal shortest path); focus of chapter 25 viii. Optimal Substructure - proof by cut and paste method (1) A shortest path between two vertices contains other shortest paths within it (2) Triangle Inequality (a) Theorem: (u,v) (u,x)+ (x,v) (this is a generalization of Lemma 24.1) page 645. ix. Negative-weight edges (Well-definedness of solution) (1) Example: edge weights represented energy absorption (negative weight) and energy release (positive weight) (2) Tarjan Theorem 7.1: Let s and t be vertices such that t is reachable from s. There is a shortest path from s to t if and only if no path from s to t contains a cycle of negative length. If there is any shortest path from s to t, there is one that is simple. Spring

2 (3) if graph G contains no negative-weight cycles reachable from the source s, then for all v V, the shortest path (s,v) remains well-defined even if it has a negative value (otherwise you could always go around the negative cycle again and get a shorter path) (4) Dijkstra's assumes all non-negative weights (5) Bellman-Ford allows negative edges with no negative weight cycles are reachable from the source node. x. foundations (1) assume (a) all d ij > 0 (d ij > if there is no arc e ij in the network (nonnegativity) (b) d ij + d jk < d ik for some i,j,k (nontrivial) (c) d ij d ji for some i,j (nonsymmetric) (2) renumber the n nodes V 0, V 1,...,V n-1. We want the shortest paths from V 0 to all V i for i=1,2,...n-1 and their lengths (3) observations (a) the length of a path is always longer that the length of any of its subpaths (true because assumption (1) all costs > 0) (b) any subpaths of a shortest path must also be a shortest path (true even if some d ij < 0) (c) any shortest path contains at most (n-1) arcs (because there are no cycles and n nodes in the network) (d) the shortest path P k contains at most k arcs (i) now let P i be the shortest path from V 0 to V i (i = 1,...,n-1) and let l(p i ) be its length. Renumber the nodes so that l(p 1 ) l(p 2 )... l(p n-1 ) (ii) P 1 contains only 1 arc or there would be a subpath of P 1 that was shorter (iii) P 2 contains at most 2 arcs;... (4) to find P 1 we look at only 1 arc paths (5) to find P 2 we look at 2 or fewer arc paths (a) l(p 2 ) = d 02 one arc (b) l(p 2 ) = d 01 + d 12 two arcs (6) to find P 3 we look at (a) l(p 3 ) = d 03 (1 arc) (b) l(p 3 ) = l(p 1 ) + d 13 (2 arcs) (c) l(p 3 ) = l(p 2 ) + d 23 (3 arcs) (7) in general to find P k we see that either (a) l(p k ) = d 0k (1 arc) (b) l(p k ) = l(p j ) + d jk ( > 1 arc) with j < k in which case note that V k must be a successor to V j (8) definitions (a) V s is a successor to V r if there is an arc e rs (b) V r is a predecessor of V s if there is an arc e rs (9) thus V k must be a successor to V 0 or V 1, or... V k-1. When we find P k (and hence V k ), we can note the predecessor V j such that l(p k ) = l(p j ) + d jk xi. Cycles (1) Can a shortest path contain a cycle (a) Cannot contain a negative-weight cycle (b) Cannot contain a positive-weight cycle (c) What about 0-weight cycles (i) There must be a path between the two vertices that does not contain the 0- weight cycle Spring

3 (2) For any acyclic path in a graph G=(V,E) contains at most V distinct vertices and it contains at most V -1 edges (3) We can restrict our attention to shortest paths of at most V -1 edges. xii. Representing Shortest-paths tree (1) Representation: given a graph G = (V,E), represented by an adjacency list format as in section 22.1, maintain for each vertex in V a predecessor [v] that is either another vertex or NIL (a) use PRINT-PATH algorithm page 601 to print the shortest path from s to v once the [v] have been set (2) Interested in the predecessor subgraph (a) G = (V, E ) (b) V ={v V: v. NIL} {s} (c) E = { v., v) E: v V - {s}}. (3) Definition: (page 647) let G = (V,E) be a weighted, directed graph with weight function w:e Real Numbers, and assume that G contains no negative-weight cycles reachable from the source vertex s V, so that the shortest paths are well defined. A shortest-paths tree rooted at s is a directed subgraph of G = (V,E ), where V V and E E, such that (a) V is the set of vertices reachable from s in G, (b) G forms a rooted tree with root s, and (c) For all v V, the unique simple path from s to v in G is a shortest path from s to v in G. (4) note not unique, as shown in figure 24.2 (5) Tarjan Theorem 7.2 G contains shortest paths from a source to all other vertices if and only if G contains a shortest-path tree rooted at s. (6) Tarjan Theorem 7.3 T is a shortest-path tree if and only if, for every edge [v, w], distance(v) + length(v,w) distance(w) (a) Can be used to test in O(m) time whether a given spanning tree is a shortestpath tree: We compute distance(v) for every vertex v by processing the edges in preorder, and then we test the distance inequality for each edge (b) Also suggests a way to construct shortest-path trees by iterative improvement. For each vertex v, we maintain a tentative distance dist(v) from s to v and a tentative parent p(v). We initialize dist(s) = 0, dist(v) = for v s, p(v) = null for all v, and repeat the following step until distance(v) + length(v,w) distance(w) for every edge [v, w]: (i) Labeling Step (Ford) Select an edge [v, w] such that distance(v) + length(v,w) < distance(w). Replace dist(w) by distance(v) + length(v,w) and p(w) by v. (ii) Tarjan Lemma 7.5 If at some time during the labeling method p k (v) = v for some vertex v and integer k, then the corresponding cycle in G is negative (iii) Tarjan Theorem 7.5 When the labeling method halts, the parent pointers define a shortest-path tree for the subgraph of G induced by the vertices reachable from s (iv) Algorithm can run in 2 m 1 steps, so need refinements for efficiency 1. Labeling and scanning method: partition the vertices into three states (unlabeled, labeled, and scanned). Initially s is labeled and every other vertex is unlabeled. Repeat the following step until there are no unlabeled vertices: 2. Scanning Step. Select a labeled vertex v and scan it, thereby Spring

4 converting it to the scanned state, by applying the labeling step to each edge [v, w] such that distance(v) + length(v,w) < distance(w), thereby converting w to the labeled state a. Needs an efficient scanning order i. Topological used for acyclic graphs (e.g., PERT); running time O(m) including time for topological ordering. Order the vertices reachable from s so that if [v, w] is an edge, v appears before w in the order, and we apply the scanning step once to each vertex in order ii. Shortest first if there are no negative length edges; among labeled vertices, always scan one whose tentative distance in minimum; uses a d-heap of labeled vertices iii. Breadth-first among labeled vertices, scan the one least recently labeled. Needs a queue of labeled vertices. If there is no negative cycle reachable from s, then breadth-first scanning runs in O(nm) time, stopping at the end of pass n 1. Otherwise the method never halts (algorithm can be augmented to detect negative length cycles). iv. Breadth-first/depth-first hybrid xiii. labeling algorithm approach (Tarjan 87-89) (1) label the nodes with distances (a) temporary labels l k (b) permanent labels l k * (2) a permanent node is one with a permanent label (3) a temporary node is one with a temporary label (4) the permanent label on V k is the true shortest path distance from V 0 to V k (5) the temporary label on V k is the minimum of (a) d 0k (b) minimum over V j with permanent labels {l(p j ) + d jk } (6) to find P k we find the minimum temporary label of all successors of V 0, V 1,..., V k-1 and make that label (and the node) permanent. Record the predecessor node V j such that l(p k ) = l(p j ) + d jk. Update the temporary labels of all successors of the node V k that are temporary nodes (a) if l i * + d ij is less than the current temporary label of V j replace the current temporary label by the smaller value xiv. Relaxation (1) For each vertex v V, maintain an attribute d[v] which is the upper bound on the shortest path from s to v. d[v] is the shortest path estimate (2) initialize-single-source and relax pseudo code pages xv. Properties of shortest paths and relaxation page 650 (1) relaxation either updates triangle inequality or changes nothing and in either case triangle inequality is satisfied after the relaxation step (2) relaxation initialize single source sets shortest path estimates at either their lowest value or a value that will be reduced by the relaxation step, and in either case once the shortest path estimate is at its minimum for a vertex it never changes (3) the shortest path estimate for vertex u plus the edge weight from u to v results in the shortest path estimate for vertex v B The Bellman-Ford Algorithm i. most basic single-source shortest-paths algorithm (1) edge weights may be negative Spring

5 (2) indicates with a Boolean value if there is a negative weight cycle reachable from the source (in which case no solution exists); otherwise algorithm produces the shortest paths and their weights (3) finds shortest path weights from source s to all v V (4) actual paths can be reconstructed ii. pseudo code page 651 (1) initialize d, which will converge to the shortest path value (2) relaxation: V - 1 times, do relaxation step for each edge (3) test whether got a solution (gets a solution iff no negative-weight cycles) (4) Time = O(VE) (5) iii. Correctness (1) Pages (2) Reliance on optimal substructure property C Single-source shortest paths in directed acyclic graphs i. common problem: finding shortest paths in directed acyclic graph (project management functions) ii. Algorithm page 655 DAG-SHORTEST-PATHS (1) Topological sort algorithm Section 22.4 pages , (V + E) iii. How fast can it be done? (1) Bellman-Ford takes O(VE) (2) If this is a topological sort problem, and we are lucky and process vertices on each shortest path from left to right it would be done in 1 pass (3) every path in a DAG is a subsequence of the topologically sorted vertex order, so if you do topological sort and process vertices in that order, the algorithm will do each path in forward order (it will never relax edges out of a vertex until it has done all edges into a vertex) So only 1 pass is needed (4) runs in linear O(V+E) time iv. quick comments on the longest distance V 0 to V i denoted by L i in an acyclic network (1) L 0 = 0 (2) L 1 = d 01 (3) L 2 = max[(l 0 + d 02 ), (L 1 + d 12 )] (4) L k = max over j (L j + d jk ) for (j < k) (5) d ij = - if no directed arc V i to V j (6) O(n 2 ) algorithm (7) can use for shortest path problem with negative arcs Spring

6 (a) replace max by min (b) l i = shortest distance (c) d ij = implies no directed arc V i to V j D Dijkstra's algorithm (a greedy algorithm) i. non-negative edge weights (if no edge weights are negative, can beat Bellman-Ford) ii. solves the single-source shortest paths problem iii. like BFS; if all weights = 1 you should use BFS iv. use Q = priority queue keyed by d[v] (BFS used FIFO queue) v. pseudo code page 658 vi. notice that it is similar to Prim's MST algorithm vii. viii. Correctness using loop invariant page (a) Note that for all v, d[v] (s,v) (b) Let u be the first vertex chosen such that there exists a shorter path than d[u] which implies that d[u] > (s,u) (c) Let y be the first vertex V S on the actual shortest path from s to u which implies that d[y] > (s,y) (d) d[u] > (s,u) = (s,y) + (y,u) by optimal substructure = d[y] + (y,u) d[y] by no negative weights but d[u] > d[y] implies that the algorithm would have chosen y to process next, not u (CONTRADICTION) ix. Analysis page 598 (1) EXTRACT-MIN executed V times (2) DECREASE-KEY executed E times (3) Time = V * T EXTRACT-MIN + E * T DECREASE-KEY Q T EXTRACT-MIN T DECREASE-KEY Total Array O(V) O(1) O(V 2 ) Binary Heap O(lgV) O(lgV) O(ElgV) Fibonacci Heap O(lgV) O(1) O(VlgV + E) Amortized amortized worst case Spring

7 x. Dijkstra's algorithm (shortest path distance to all other nodes) (1) implemented using d-heaps in Tarjan page 91 Step 0 Set l i = d 0i (i = 1,2,, n-1) V 0 gets a perm label l i = if there does not exist e 0i STOP All labels Perm? Step 1 Pick l k = min over i{l i } successors of perm labeled nodes Change l k to l k *. Suppose this is node V k. Label V k perm. Step 2 successors V i of V k that have temp labels, replace l i by the min of {l i, l k * + d kj } Record the predecessor node, V k, if the temp label is updated (2) (3) do the example in the class worksheet (4) note Dijkstra's algorithm always produces a (spanning) tree (ignoring direction) (a) each iteration labels a new node (b) no cycles (c) all nodes are connected ( shortest path from node 0 to every other node) (5) amount of work done in Dijkstra's algorithm (# of adds and # of comparisons (a) in step 1 there are n-2 comparisons the first time; n-3 the second time; n-4 the third time;...; 1 the last time n-2 (n -1)(n - 2) (i) i= i=1 2 (b) in step 2 there are n-2 additions and n-2 comparisons the first time; n-3 adds and n-3 comparisons the second time;... (n -1)(n - 2) (i) additions and comparisons 2 (c) the total amount of work is on the order of (3n 2 /2) so Dijkstra's algorithm is O(n 2 ) (i) hence Dijkstra's algorithm is time-optimal (ii) Dijkstra's algorithm is Ω(n 2 ) (iii) therefor Dijkstra's algorithm is Θ(n 2 ) (6) no shortest path algorithm in general needs O(nlogn) steps because there are O(n 2 ) arcs in a network of n nodes E Difference constraints and shortest paths i. relationship to linear programming ii. skip this semester Spring

8 F Proof of Shortest-Paths Properties i. The triangle inequality ii. Effects of relaxation on shortest-path estimates iii. Relaxation and shortest-path trees. II. Chapter 25 All-Pairs Shortest Paths A. Multiterminal Shortest Path Intro i. we allow some d ij 0 as long as there are no negative cycles ii. recall that any subpath of a shortest path is itself a shortest path (1) let (e ij, e jk,...,e pq ) be a shortest path from V i to V q. then the shortest path from V i to V j must be the single arc e ij,... (2) An arc e ij is a basic arc if it is the shortest path from V i to V j (3) thus a shortest path can consist only of basic arcs iii. the algorithm focuses on basic arcs and "creates" an arc between every ordered pair of nodes not connected by a basic arc. The length of the arc created (call it d*) is the length of the shortest path between the two nodes iv. the triple operation: for a given V j find minimum(d ik *, d ij * + d jk *). Replace d ik * with this minimum. We'll do this for all distinct ordered paris (i,k) such that i j and k j. We can do this successively for j=1,2,...,n. It can be shown that after we have done it for j=n, the d ij * are the lengths of the time shortest path v. we can keep track of the actual paths by using a matrix P, where at the end, p ik is the index j of V j such that the shortest path from V i to V k first goes from V i to V j. We start with all p ik = k. The rule is then (1) p ik = p ij if d ik * > d ij * + d jk * (2) p ik = p ik if d ik * d ij * + d jk * (3) set all p ii = i vi. we also keep all entries d ij * in an n x n matrix D*, where d ii = 0 and initially we have d ij * = d ij B. Text Introduction Section i. directed graph G=(V,E), weight function w:e Real Number, V = n ii. Goal: create an n x n matrix of shortest path distances (u,v) (1) u form rows and v form columns, intersection in matrix is shortest path from u to v iii. could solve by running Bellman-Ford once for each vertex. What would be the runtime? (1) O(V 2 E) or on a dense graph O(V 4 ) (2) Dijsktra's with priority queue O(V 3 ); binary heap O(V E lgv) for a sparse graph; with Fibonacci heap O(V 2 lgv + V E). iv. Adjacency-matrix representation of a graph: (1) n x n adjacency matrix W=(w ij ) of edge weights (2) assume w ii = 0 i because the shortest path to self has no edges, in absence of negative-weight cycles) v. must also keep a predecessor matrix (1) For each vertex i V define the predecessor subgraph (a) G,i = (V,i, E,i ) (b) V,i ={j V: ij NIL} {i} (c) E,i = { ( ij, j) : j = V,i - {i}}. (2) = ( ij ) where ij is NIL if i = j or there is no path from I to j, otherwise ij is the predecessor of j on some shortest path from i. (3) The subgraph induced by the ith row of should be a shortest-paths tree with root I Spring

9 (4) Algorithm page 685 PRINT-ALL-PAIRS-SHORTEST-PATH C Shortest paths and matrix multiplication i. Steps for developing a dynamic-programming algorithm (1) characterize the structure of an optimal solution (2) recursively define the value of an optimal solution (3) compute the value of an optimal solution in a bottom-up fashion (4) construct an optimal solution from computed information ii. The structure of the shortest path (1) weight of shortest path from i to j that uses at most m edges (2) (i,j) = (i,k) + w kj iii. A recursive solution to the all-pairs shortest-paths problem (1) Recursive definition 25.2 page 687 (2) Uses solution of (m-1) edges and smallest weight connecting an (m-1) edge solution and the new node iv. Computing the shortest-path weights bottom up (1) EXTEND-SHORTEST-PATHS is the relaxation step for this problem (2) relationship to matrix multiplication (a) O(n 3 ) time for straightforward matrix multiplication (3) SLOW-ALL-PAIRS-SHORTEST-PATHS algorithm page 689 runs in (n 4 ) time v. Improving the running time (1) Recognize that the above algorithm does repeated squarings W 2n = W n x W n (2) Sequence computed is W, W 2, W 4, W 8, W lg(n-1) (3) (lgn) squarings (4) FASTER-ALL-PAIRS-SHORTEST-PATHS algorithm page 691 D The Floyd-Warshall algorithm (a dynamic programming algorithm) i. allows negative edge weights if no negative weight cycles exist ii. structure of the shortest path (1) use of intermediate vertices (2) we don't have to check all intermediate vertices, we just need to know if the shortest path does or does not include a particular vertex iii. A recursive solution to the all pairs shortest-paths problem (eq 25.5 page 694) iv. Computing the shortest-path weights bottom up (1) FLOYD-WARSHALL algorithm page 630 (2) runs in O(n 3 ); best time is O(V 2 lgv + VE) (3) for a dense graph ( E V 2 ) can get all pairs shortest paths with Floyd-Warshall from the same cost as getting the single source shortest path with Bellman-Ford! ( (VE) = (n 3 )) v. Constructing a shortest path (1) Requires augmenting the algorithm to update the matrix vi. Transitive Closure: is there a path in G from i to j for all ij V? (1) Substitute logical OR for minimum (2) Substitute logical AND for addition (3) Use weights of 1 E. Alternative algorithm statement Spring

10 STOP Initialization yes i, j (i j) p ij = j, d ij * = d ij p ii = 1, d ii * = 0 j = 1 no j > n i, j and j i, k j, i k p ik p ij d ik * d ij * + d jk * no d ik d ij * + d jk * yes j j + 1 i. ii. do the handout example iii. amount of work done (1) there are n(n-1)(n-2) = (n 3-3n 2 + 2n) possible triple operations. Hence the algorithm is O(n 3 ) and it is a good algorithm. It is O(n 2 ) in terms of space F Johnson s algorithm for sparse graphs i. skip this semester Spring

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

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

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

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

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

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming and data-structures CS/ENGRD 20 SUMMER 208 Lecture 3: Shortest Path http://courses.cs.cornell.edu/cs20/208su Graph Algorithms Search Depth-first search Breadth-first search

More information

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

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4.

Outline. (single-source) shortest path. (all-pairs) shortest path. minimum spanning tree. Dijkstra (Section 4.4) Bellman-Ford (Section 4. Weighted Graphs 1 Outline (single-source) shortest path Dijkstra (Section 4.4) Bellman-Ford (Section 4.6) (all-pairs) shortest path Floyd-Warshall (Section 6.6) minimum spanning tree Kruskal (Section 5.1.3)

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

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

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University Algorithms All-Pairs Shortest Paths Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr Contents Using single source shortest path algorithms Presents O(V 4 )-time algorithm, O(V 3 log V)-time algorithm,

More information

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest Paths. Nishant Mehta Lectures 10 and 11 Shortest Paths Nishant Mehta Lectures 0 and Finding the Fastest Way to Travel between Two Intersections in Vancouver Granville St and W Hastings St Homer St and W Hastings St 6 Granville St and W Pender

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

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest Paths. Nishant Mehta Lectures 10 and 11 Shortest Paths Nishant Mehta Lectures 0 and Communication Speeds in a Computer Network Find fastest way to route a data packet between two computers 6 Kbps 4 0 Mbps 6 6 Kbps 6 Kbps Gbps 00 Mbps 8 6 Kbps

More information

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1 Directed Graphs Definitions. Representations. ADT s. Single Source Shortest Path Problem (Dijkstra, Bellman-Ford, Floyd-Warshall). Traversals for DGs. Parenthesis Lemma. DAGs. Strong Components. Topological

More information

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456 5.4 Shortest Paths CH08-320201: Algorithms and Data Structures 456 Definitions: Path Consider a directed graph G=(V,E), where each edge e є E is assigned a non-negative weight w: E -> R +. A path is a

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

from notes written mostly by Dr. Carla Savage: All Rights Reserved

from notes written mostly by Dr. Carla Savage: All Rights Reserved CSC 505, Fall 2000: Week 9 Objectives: learn about various issues related to finding shortest paths in graphs learn algorithms for the single-source shortest-path problem observe the relationship among

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

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20. Title Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis Nesrine Damak Fakultät für Informatik TU München 20. September 2010 Nesrine Damak: Classical Shortest-Path Algorithms 1/ 35

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

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 20. Example. Shortest Paths Definitions

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 20. Example. Shortest Paths Definitions Taking Stock IE170: Algorithms in Systems Engineering: Lecture 20 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 19, 2007 Last Time Minimum Spanning Trees Strongly

More information

Chapter 25: All-Pairs Shortest-Paths

Chapter 25: All-Pairs Shortest-Paths Chapter : All-Pairs Shortest-Paths When no negative edges Some Algorithms Using Dijkstra s algorithm: O(V ) Using Binary heap implementation: O(VE lg V) Using Fibonacci heap: O(VE + V log V) When no negative

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

Classical Shortest-Path Algorithms

Classical Shortest-Path Algorithms DISTANCE PROBLEMS IN NETWORKS - THEORY AND PRACTICE Classical Shortest-Path Algorithms Nesrine Damak October 10, 2010 Abstract In this work, we present four algorithms for the shortest path problem. The

More information

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24

4/8/11. Single-Source Shortest Path. Shortest Paths. Shortest Paths. Chapter 24 /8/11 Single-Source Shortest Path Chapter 1 Shortest Paths Finding the shortest path between two nodes comes up in many applications o Transportation problems o Motion planning o Communication problems

More information

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation The Shortest Path Problem jla,jc@imm.dtu.dk Department of Management Engineering Technical University of Denmark The Shortest Path Problem Given a directed network G = (V,E,w) for which the underlying

More information

Design and Analysis of Algorithms 演算法設計與分析. Lecture 13 December 18, 2013 洪國寶

Design and Analysis of Algorithms 演算法設計與分析. Lecture 13 December 18, 2013 洪國寶 Design and Analysis of Algorithms 演算法設計與分析 Lecture 13 December 18, 2013 洪國寶 1 Homework #10 1. 24.1-1 (p. 591 / p. 654) 2. 24.1-6 (p. 592 / p. 655) 3. 24.3-2 (p. 600 / p. 663) 4. 24.3-8 (p. 601) / 24.3-10

More information

Single Source Shortest Path (SSSP) Problem

Single Source Shortest Path (SSSP) Problem Single Source Shortest Path (SSSP) Problem Single Source Shortest Path Problem Input: A directed graph G = (V, E); an edge weight function w : E R, and a start vertex s V. Find: for each vertex u V, δ(s,

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

Parallel Graph Algorithms

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

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati MA 252: Data Structures and Algorithms Lecture 36 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati The All-Pairs Shortest Paths Problem

More information

Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis

Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis 3.2.12 simas@cs.aau.dk All-pairs shortest paths Main goals of the lecture: to go through one more example of dynamic programming

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

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Single-Source Shortest Paths CSE Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Terminology A network is a directed graph. We will use both terms interchangeably. The

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

Artificial Intelligence

Artificial Intelligence Artificial Intelligence Shortest Path Problem G. Guérard Department of Nouvelles Energies Ecole Supérieur d Ingénieurs Léonard de Vinci Lecture 3 GG A.I. 1/42 Outline 1 The Shortest Path Problem Introduction

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

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

Parallel Graph Algorithms

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

All Shortest Paths. Questions from exercises and exams

All Shortest Paths. Questions from exercises and exams All Shortest Paths Questions from exercises and exams The Problem: G = (V, E, w) is a weighted directed graph. We want to find the shortest path between any pair of vertices in G. Example: find the distance

More information

Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the

Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the Floyd-Warshall algorithm in O(n 3 ) time. Neither of

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

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College Laura Toma Algorithms (csci2200), Bowdoin College Topics Weighted graphs each edge (u, v) has a weight denoted w(u, v) or w uv stored in the adjacency list or adjacency matrix The weight of a path p =

More information

Single Source Shortest Paths

Single Source Shortest Paths Single Source Shortest Paths Given a connected weighted directed graph G(V, E), associated with each edge u, v E, there is a weight w(u, v). The single source shortest paths (SSSP) problem is to find a

More information

Algorithm Design (8) Graph Algorithms 1/2

Algorithm Design (8) Graph Algorithms 1/2 Graph Algorithm Design (8) Graph Algorithms / Graph:, : A finite set of vertices (or nodes) : A finite set of edges (or arcs or branches) each of which connect two vertices Takashi Chikayama School of

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

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2 Breadth-First Search, Slides for CIS DPV Chapter Jim Royer EECS October, 00 Definition In an undirected graph, the distance between two vertices is the length of the shortest path between them. (If there

More information

Algorithms for Data Science

Algorithms for Data Science Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Shortest paths in weighted graphs (Bellman-Ford, Floyd-Warshall) Outline 1 Shortest paths in graphs with

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

COT 6405 Introduction to Theory of Algorithms

COT 6405 Introduction to Theory of Algorithms COT 6405 Introduction to Theory of Algorithms Topic 16. Single source shortest path 11/18/2015 1 Problem definition Problem: given a weighted directed graph G, find the minimum-weight path from a given

More information

Lecture 6 Basic Graph Algorithms

Lecture 6 Basic Graph Algorithms CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 6 Basic Graph Algorithms Uttam Thakore University of Illinois at Urbana-Champaign September 30, 2015 Updates ICPC Regionals teams will be

More information

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms Introduction to Parallel & Distributed Computing Parallel Graph Algorithms Lecture 16, Spring 2014 Instructor: 罗国杰 gluo@pku.edu.cn In This Lecture Parallel formulations of some important and fundamental

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

Lecture 5: Graph algorithms 1

Lecture 5: Graph algorithms 1 DD2458, Problem Solving and Programming Under Pressure Lecture 5: Graph algorithms 1 Date: 2008-10-01 Scribe(s): Mikael Auno and Magnus Andermo Lecturer: Douglas Wikström This lecture presents some common

More information

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

CS 561, Lecture 10. Jared Saia University of New Mexico CS 561, Lecture 10 Jared Saia University of New Mexico Today s Outline The path that can be trodden is not the enduring and unchanging Path. The name that can be named is not the enduring and unchanging

More information

Basic Graph Definitions

Basic Graph Definitions CMSC 341 Graphs Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges, E. Each edge is a pair (v,w) where v, w V. V and E are sets, so each vertex

More information

Shortest Paths. March 21, CTU in Prague. Z. Hanzálek (CTU) Shortest Paths March 21, / 44

Shortest Paths. March 21, CTU in Prague. Z. Hanzálek (CTU) Shortest Paths March 21, / 44 Shortest Paths Zdeněk Hanzálek hanzalek@fel.cvut.cz CTU in Prague March 21, 2017 Z. Hanzálek (CTU) Shortest Paths March 21, 2017 1 / 44 Table of contents 1 Introduction Problem Statement Negative Weights

More information

Konigsberg Bridge Problem

Konigsberg Bridge Problem Graphs Konigsberg Bridge Problem c C d g A Kneiphof e D a B b f c A C d e g D a b f B Euler s Graph Degree of a vertex: the number of edges incident to it Euler showed that there is a walk starting at

More information

Detecting negative cycles with Tarjan s breadth-first scanning algorithm

Detecting negative cycles with Tarjan s breadth-first scanning algorithm Detecting negative cycles with Tarjan s breadth-first scanning algorithm Tibor Ásványi asvanyi@inf.elte.hu ELTE Eötvös Loránd University Faculty of Informatics Budapest, Hungary Abstract The Bellman-Ford

More information

Unit 2: Algorithmic Graph Theory

Unit 2: Algorithmic Graph Theory Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw

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

CS6301 Programming and Data Structures II Unit -5 REPRESENTATION OF GRAPHS Graph and its representations Graph is a data structure that consists of following two components: 1. A finite set of vertices

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

Practical Session No. 12 Graphs, BFS, DFS, Topological sort

Practical Session No. 12 Graphs, BFS, DFS, Topological sort Practical Session No. 12 Graphs, BFS, DFS, Topological sort Graphs and BFS Graph G = (V, E) Graph Representations (V G ) v1 v n V(G) = V - Set of all vertices in G E(G) = E - Set of all edges (u,v) in

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

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II Anna University 2 & 16 Mark Questions & Answers Year / Semester: II / III

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

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

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15 600.363 Introduction to Algorithms / 600.463 Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15 14.1 Introduction Today we re going to talk about algorithms for computing shortest

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

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6

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

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS45-05S-7 Shortest Path Dijkstra s Algorithm David Galles Department of Computer Science University of San Francisco 7-0: Computing Shortest Path Given a directed weighted

More information

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck Theory of Computing Lecture 7 MAS 714 Hartmut Klauck Shortest paths in weighted graphs We are given a graph G (adjacency list with weights W(u,v)) No edge means W(u,v)=1 We look for shortest paths from

More information

CS261: Problem Set #1

CS261: Problem Set #1 CS261: Problem Set #1 Due by 11:59 PM on Tuesday, April 21, 2015 Instructions: (1) Form a group of 1-3 students. You should turn in only one write-up for your entire group. (2) Turn in your solutions by

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

Sample Solutions to Homework #4

Sample Solutions to Homework #4 National Taiwan University Handout #25 Department of Electrical Engineering January 02, 207 Algorithms, Fall 206 TA: Zhi-Wen Lin and Yen-Chun Liu Sample Solutions to Homework #4. (0) (a) Both of the answers

More information

COMP 251 Winter 2017 Online quizzes with answers

COMP 251 Winter 2017 Online quizzes with answers COMP 251 Winter 2017 Online quizzes with answers Open Addressing (2) Which of the following assertions are true about open address tables? A. You cannot store more records than the total number of slots

More information

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

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

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Graphs : Shortest Paths Marius Kloft Content of this Lecture Single-Source-Shortest-Paths: Dijkstra s Algorithm Single-Source-Single-Target All-Pairs Shortest Paths Transitive

More information

Graph Algorithms Using Depth First Search

Graph Algorithms Using Depth First Search Graph Algorithms Using Depth First Search Analysis of Algorithms Week 8, Lecture 1 Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Graph Algorithms Using Depth

More information

Theory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 4/5 MAS 714 Hartmut Klauck Theory of Computing Lecture 4/5 MAS 714 Hartmut Klauck How fast can we sort? There are deterministic algorithms that sort in worst case time O(n log n) Do better algorithms exist? Example [Andersson et

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

More Graph Algorithms: Topological Sort and Shortest Distance

More Graph Algorithms: Topological Sort and Shortest Distance More Graph Algorithms: Topological Sort and Shortest Distance Topological Sort The goal of a topological sort is given a list of items with dependencies, (ie. item 5 must be completed before item 3, etc.)

More information

Exam 1 Solutions. Jonathan Turner 10/4/01 9/27/01. CS 541 Algorithms and Programs. Be neat and concise, but complete.

Exam 1 Solutions. Jonathan Turner 10/4/01 9/27/01. CS 541 Algorithms and Programs. Be neat and concise, but complete. CS 541 Algorithms and rograms Exam 1 Solutions Jonathan Turner 10/4/01 9/27/01 Be neat and concise, but complete. 1. (15 points) State the general greedy method for finding minimum spanning trees. Show

More information

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

CSC 373 Lecture # 3 Instructor: Milad Eftekhar Huffman encoding: Assume a context is available (a document, a signal, etc.). These contexts are formed by some symbols (words in a document, discrete samples from a signal, etc). Each symbols s i is occurred

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle

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

n 2 ( ) ( ) + n is in Θ n logn

n 2 ( ) ( ) + n is in Θ n logn CSE Test Spring Name Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply an m n matrix and a n p matrix is in: A. Θ( n) B. Θ( max(

More information

Shortest Paths: Algorithms for standard variants. Algorithms and Networks 2017/2018 Johan M. M. van Rooij Hans L. Bodlaender

Shortest Paths: Algorithms for standard variants. Algorithms and Networks 2017/2018 Johan M. M. van Rooij Hans L. Bodlaender Shortest Paths: Algorithms for standard variants Algorithms and Networks 2017/2018 Johan M. M. van Rooij Hans L. Bodlaender 1 Shortest path problem(s) Undirected single-pair shortest path problem Given

More information

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity. 1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:

More information

Dijkstra s Shortest Path Algorithm

Dijkstra s Shortest Path Algorithm Dijkstra s Shortest Path Algorithm DPV 4.4, CLRS 24.3 Revised, October 23, 2014 Outline of this Lecture Recalling the BFS solution of the shortest path problem for unweighted (di)graphs. The shortest path

More information

Graph Algorithms shortest paths, minimum spanning trees, etc.

Graph Algorithms shortest paths, minimum spanning trees, etc. Graph Algorithms shortest paths, minimum spanning trees, etc. SFO ORD LAX DFW Graphs 1 Outline and Reading Graphs ( 1.1) Definition Applications Terminology Properties ADT Data structures for graphs (

More information

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution Taking Stock IE170: Algorithms in Systems Engineering: Lecture 26 Jeff Linderoth Last Time Department of Industrial and Systems Engineering Lehigh University April 2, 2007 This Time Review! Jeff Linderoth

More information

Graphs II - Shortest paths

Graphs II - Shortest paths Graphs II - Shortest paths Single Source Shortest Paths All Sources Shortest Paths some drawings and notes from prof. Tom Cormen Single Source SP Context: directed graph G=(V,E,w), weighted edges The shortest

More information

Lecture 10: Analysis of Algorithms (CS ) 1

Lecture 10: Analysis of Algorithms (CS ) 1 Lecture 10: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 05, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 Topological Sort Strongly Connected Components 2

More information

CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016

CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016 CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016 1 Depth first search 1.1 The Algorithm Besides breadth first search, which we saw in class in relation to Dijkstra s algorithm, there

More information