1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.

Slides:



Advertisements
Similar presentations
Lecture 7. Network Flows We consider a network with directed edges. Every edge has a capacity. If there is an edge from i to j, there is an edge from.
Advertisements

Single Source Shortest Paths
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CS138A Single Source Shortest Paths Peter Schröder.
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
Data Structures and Algorithms Graphs Single-Source Shortest Paths (Dijkstra’s Algorithm) PLSD210(ii)
1 Theory I Algorithm Design and Analysis (10 - Shortest paths in graphs) T. Lauer.
Theory of Computing Lecture 8 MAS 714 Hartmut Klauck.
CSE 101- Winter ‘15 Discussion Section January 26th 2015.
Introduction to Algorithms 6.046J/18.401J/SMA5503
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Shortest Path Problems
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping.
Shortest Path Algorithms
Shortest Paths Definitions Single Source Algorithms
1 TCOM 799: Algorithms in Networking Instructor: Saswati Sarkar Contact Info: (Phone) Office Hours: 2-4 p.m. 360 MB Course.
DAST 2005 Tirgul 12 (and more) sample questions. DAST 2005 Q.We’ve seen that solving the shortest paths problem requires O(VE) time using the Belman-Ford.
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
All-Pairs Shortest Paths
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Copyright © Cengage Learning. All rights reserved.
1 Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch]
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
Introduction to Algorithms Jiafen Liu Sept
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
1 Introduction to Algorithms L ECTURE 17 (Chap. 24) Shortest paths I 24.2 Single-source shortest paths 24.3 Dijkstra’s algorithm Edsger Wybe Dijkstra
Lecture 13 Algorithm Analysis
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
Shortest paths Given: A single source vertex (given s) in a weighted, directed graph. Want to compute a shortest path for each possible destination. (Single.
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
Lecture 13 Shortest Path.
Algorithms and Data Structures Lecture XIII
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Basic Graph Algorithms
Advanced Algorithms Analysis and Design
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Slide Courtesy: Uwash, UT
Lecture 13 Algorithm Analysis
Fundamental Data Structures and Algorithms
Chapter 24: Single-Source Shortest Paths
Advanced Algorithms Analysis and Design
Shortest Paths.
Slide Courtesy: Uwash, UT
Graph Algorithms: Shortest Path
Chapter 24: Single-Source Shortest Paths
Lecture 12 Shortest Path.
Chapter 24: Single-Source Shortest-Path
Advanced Algorithms Analysis and Design
Data Structures and Algorithm Analysis Lecture 8
Presentation transcript:

1 Shortest Path Algorithms

2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a weight associated with each link –Weight can be a measure of congestion in the link, propagation delay etc. Weight of a path is the sum of weight of all links Shortest path is the minimum weight path

Source Destination Path 1 Path 2 Weight of path 1 = 2.5 Weight of path 2 = 3.0

4 Computation of shortest paths Enumerate all paths? –Exponential complexity Several polynomial complexity algorithms exist –Dijkstras algorithm (greedy algorithm) –Bellman-ford algorithm (distributed algorithm) –Flloyd-Warshall algorithm (dynamic programming) –Johnsons algorithm

5 Dijkstras algorithm Assumes a directed graph Source Destination Given any node, finds the shortest path to every other node in the graph O(V log V + E)

6 Let source node be s Maintains shortest path ``estimate’’ for every vertex v, (d(v)) –``estimate’’ is what it believes to be the shortest path from s and the list of vertices for whom the shortest path is known Initially the list of vertices for whom the shortest path is known is empty and the estimates are infinity for all vertices except the source vertex itself.

7 It holds that whenever the estimate d(v) is finite for a vertex v, there exists a path from the source s to v with weight d(v) It turns out that the estimate is accurate for the vertex with the minimum value of this estimate –Shortest path is known for this vertex (v) This vertex (v) is added to the list of vertices for whom shortest path is known Shortest path estimates are upgraded for every vertex which has an edge from v, and is not in this ``known list’’.

8 Estimate Upgrade Procedure Suppose vertex v is added to the list newly, and we are upgrading the estimate for vertex u –d(v) is the shortest path estimate for v, d(u) is the estimate for u –w(v, u) is the weight of the edge from v to u d(u) -> min(d(u), d(v) + w(v, u))

9 Intuition behind the upgrade procedure Assume that d(u) and d(v) are finite So there exists a path to v from s of weight d(v), (s, v 1, v 2,…..v) Hence there exists a path from s to u (s, v 1, v 2,…..v, u) of weight d(v) + w(v, u) Also, there exists a path to u of weight d(u). So the shortest path to u can not have weight more than either d(u) or d(v) + w(v, u). So we upgrade the estimate by the minimum of the two.

10 Notation Source vertex: s Shortest path estimate of vertex v: d(v) Weight of edge (u, v): w(u, v) Set of vertices whose shortest paths are known: S Q = V \ S

11 Algorithm 1. For every vertex v in V, d(v) =  2. d(s) = 0 3. Q = V S =  4. While Q is non-empty { (a) v=Extract-min(Q);

12 (b) Add v to S; (c ) Remove v from Q; (d) For each vertex u in Adj(v) d(u) -> min(d(u), d(v)) + w(v, u)) }

13 Example 0 s s s s s s

14 Algorithm Complexity Statement 1 is executed |V| times Statements 2 and 3 are executed once Loop at statement 4 is executed |V| times Every extract-min operation can be done in at most |V| operations Statement 4(a) is executed total |V| 2 times Statements 4(b) and 4(c ) are executed |V| times each (total) Observe that statement 4(d) is executed |E| times

15 So overall complexity is O(|V| 2 + |E|) and this is same as O(|V| 2 ) Using improved data structures complexity can be reduced –O((|V| + |E|)log |V|) using binary heaps – O(|V| log |V| + |E|) using fibonacci heaps

16 Proof of Correctness Exercise: –Verify that whenever d(v) is finite, there is a path from source s to vertex v of weight d(v)

17 Assumptions Assume that source s is connected to every vertex in the graph, and all edge weights are finite Also, assume that edge weights are positive. Let p(s, v) be the weight of the shortest path from s to v. Will show that the graph terminates with d(v)=shortest path weights for every vertex

18 Will first show that once a vertex v enters S, d(v) equals the shortest path weight from source s, at all subsequent times. –Clearly this holds in step 1, as source enters S in step 1, and d(s) = 0 –Let this not hold for the first time in step k > 1 Thus the vertex u added has d(u) > p(s, u) Consider the situation just before insertion of u. Consider the true shortest path, p, from s to u.

19 Since s is in S, and u is in Q, path p must jump from S to Q at some point. Let the jump have end point x in S, and y in Q (possibly s = x, and u = y) We will argue that y and u are different vertices SQ s u y x Path p Since path p is the shortest path from s to u, the segment of path p between s and x, is the shortest path from s to x, and that between s and y is the shortest from s to y

20 Weight of the segment between s and x is d(x) since x is in S, d(x) is the weight of the shortest path to x SQ s u y x Path p Weight of the segment between s and y is d(x) + w(x, y) Also, d(y) <= d(x) + w(x, y) = p(s, y) Thus, p(s, y) = d(x) + w(x, y) Follows that d(y) = p(s, y) However, d(u) > p(s, u). So, u and y are different w(x,y)

21 Since, y appears somewhere along the shortest path between s and u, but y and u are different, p(s, y) < p(s, u) Using the fact that all edges have positive weight ysu Hence, d(y) = p(s, y) < p(s, u) < d(u) Both y and u are in Q. So, u should not be chosen in this step So, whenever a vertex u is inducted in S, d(y) = p(s, y). Once d(u) equals p(s, u) for any vertex it can not change any further (d(u) can only decrease or remain same, and d(u) can not fall below p(s, u). Since the algorithm terminates only when S= V, we are done!

22 We have proved only for edges with positive weight –One can prove for edges with nonnegative weight Shortcoming –Does not hold for edges with nonnegative weight –Centralized algorithm

23 Exercise: This computation gives shortest path weights only. Modify this algorithm to generate shortest paths as well!

24 Bellman-ford Algorithm Applies as long as there are no nonpositive weight cycles –If there are circles of weight 0 or less, then the shortest paths are not well defined Capable of full distributed operation O(|V||E|) complexity –slower than Dijkstra

25 Algorithm description Every node v maintains a shortest path weight estimate, d(v) These estimates are initialized to infinity, for all vertices except source, s, d(s)=0 Every node repeatedly updates its shortest path estimate as follows v d(v) = 2.6

26 1. For every vertex v in V, d(v) =  2. d(s) = 0 3. For t=1 to V-1,

27 Example 0 s s s s s

28 Complexity Analysis Initialization step takes |V| + 1 steps The loop in statement 3 is executed |V| times Each execution takes |E| steps Overall, there are |V| |V||E| steps –O(|V||E|)

29 Proof that it works Assume that all vertices are reachable from source, s. –Thus there is a shortest path to any vertex v from s. Assume that the graph has no cycles of weight 0 or less –So the shortest paths can not have more than |V|-1 edges. We will prove that at the termination of Bellman- Ford algorithm, d(v)=p(s,v) for every vertex v. We will show that if there is one shortest path to a vertex of k hops, then after the kth execution of the loop in statement 3, d(v) freezes at p(s, v)

30 We know the above holds for k = 0, as d(s) = p(s, s) = 0 at all times. Let the above hold for 1,….,k. We will show that this holds for k + 1 So, by induction hypothesis, d(y) = p(s, y) after the kth iteration and at all subsequent times. Consider a vertex u with a shortest path p of k + 1 hops. ysu p Let vertex y be its predecessor. Clearly p1 is a shortest path to y and it has k hops. So weight of path p1 is p(s, y) p1 So by the estimate update procedure, d(u) <= d(y) + w(y, u) = p(s, y) + w(y, u) = weight of path p = p(s, u) after the k+1 th iteration and all subsequent times.

31 Again verify that as long as d(v) is finite, d(v) is length of some path to vertex v. Hence d(u) >= p(s, u) always Thus, d(u) = p(s, u), always after the k+1th iteration. We have just shown that d(u) <= p(s, u) after the k+1 th iteration

32 Features of this algorithm Note that a node needs information about its neighbors only! So we do not need a global processor.