Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: 7 2 1 5 Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,

Slides:



Advertisements
Similar presentations
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
Advertisements

© DEEDS 2008Graph Algorithms1 Remarks on Dijkstra  Determining the minimum marginal element (code line: v = the vertex in M 2 with minimum v.L; ) accounts.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
November 14, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Aalborg University
Introduction To Algorithms CS 445 Discussion Session 6 Instructor: Dr Alon Efrat TA : Pooja Vaswani 03/21/2005.
CS138A Single Source Shortest Paths Peter Schröder.
Shortest-paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
Single-Source Shortest- paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.
Shortest Paths Algorithm Design and Analysis Week 7 Bibliography: [CLRS] – chap 24 [CLRS] – chap 25.
chapter Single-Source Shortest Paths Problem Definition Shortest paths and Relaxation Dijkstra’s algorithm (can be viewed as a greedy algorithm)
Chapter 20: Graphs CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Introduction to Algorithms 6.046J/18.401J/SMA5503
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
Shortest Paths1 C B A E D F
CSE 780 Algorithms Advanced Algorithms Shortest path Shortest path tree Relaxation Bellman-Ford Alg.
Lecture 20: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
Lecture 19: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
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
1 8a-ShortestPathsMore Shortest Paths in a Graph (cont’d) Fundamental Algorithms.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
1 Graph Algorithms Single source shortest paths problem Dana Shapira.
Lecture 8 Shortest Path Shortest-path problems
CS 253: Algorithms Chapter 24 Shortest Paths Credit: Dr. George Bebis.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Shortest Paths1 C B A E D F
SINGLE-SOURCE SHORTEST PATHS. Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
David Luebke 1 9/13/2015 CS 332: Algorithms S-S Shortest Path: Dijkstra’s Algorithm Disjoint-Set Union Amortized Analysis.
COSC 3101NJ. Elder Assignment 2 Remarking Assignment 2 Marks y = 0.995x R 2 = Old Mark New Mark.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
CS223 Advanced Data Structures and Algorithms 1 The Bellman-Ford Shortest Path Algorithm Neil Tang 03/11/2010.
1 Shortest Path Problem Topic 11 ITS033 – Programming & Algorithms C B A E D F Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program,
1 Shortest Path Problems How can we find the shortest route between two points on a road map? Model the problem as a graph problem: –Road map is a weighted.
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.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Lecture 13 Algorithm Analysis
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
1 Weighted Graphs. 2 Outline (single-source) shortest path –Dijkstra (Section 4.4) –Bellman-Ford (Section 4.6) (all-pairs) shortest path –Floyd-Warshall.
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,
CSE Graph Search Algorithms. CSE Graph a c b Node ~ city or computer Edge ~ road or data cable Undirected or Directed A surprisingly large.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
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.
Single-Source Shortest Paths (25/24) HW: 25-2 and 25-3 p. 546/24-2 and 24-3 p.615 Given a graph G=(V,E) and w: E   weight of is w(p) =  w(v[i],v[i+1])
Single-Source Shortest Path
Algorithms and Data Structures Lecture XIII
Minimum Spanning Trees
Page 620 Single-Source Shortest Paths
Advanced Algorithms Analysis and Design
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Shortest Path Problems
The Bellman-Ford Shortest Path Algorithm Neil Tang 03/27/2008
Advanced Algorithms Analysis and Design
Single-Source Shortest Path & Minimum Spanning Trees
Presentation transcript:

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, d) = 1, w(d, e) = 5 Path weight w(p) = = 15 A shortest path from vertex u to vertex v has the minimum weight among all paths connecting u to v.

Single-Source Shortest Paths path s s-a s-a-b s-a-b-c s-a-d s-a-b-e s-a-b-e-f weight s a b c d e f Problem Given a graph G = (V, E), where every edge e has a weight w(e), and a source vertex s in V, find the shortest path from s to every other vertex. a s b e f d c source

Applications Transportation (shortest route from Ames to Phoenix?) Network routing (how to direct packets to a destination across a network?) Telecommunications Speech interpretation (best interpretation of a spoken sentence) Robot path planning Medical imaging Building block for network algorithms...

Shortest-Paths Tree a s b e f d c The unique simple path from s to any vertex v in the tree is a shortest path from s to v. The vertices in the tree are exactly those reachable from s in G. Similar to the breadth-first tree (where all edges have weight 1).

Negative Weights  --   s a c e b d f g h j i unreachable from s negative-weight cycle source The shortest path may have length either  or – .

No Cycle in a Shortest Path A shortest path cannot contain a negative-weight cycle. A shortest path cannot contain a positive-weight cycle because otherwise the removal of such a cycle would reduce the path weight. Any zero-weight cycle in a shortest path can be removed. We only consider shortest path of at most |V| – 1 edges.

Optimal Substructure Any subpath of a shortest path is the shortest of all paths between the two intermediate vertices. u y x v shortest path from u to v: shortest path from x to y Greedy algorithm or dynamic programming? (Both are used in solving different versions of the shortest path problem.)

Representing Shortest Paths d(v) = length of the shortest path from s to v found so far (an upper bound on the weight of the eventual shortest path).  (v) = the predecessor of v in the above path (used for backtracking the shortest path from s to v in the end). During the execution of a shortest-path algorithm, maintain two arrays: Initialization for each vertex v in G do d[v]    [v]  NIL d[s]  0

Relaxation Test if the shortest path to v found so far can be improved by going through u. s w v u (v)(v) s w v u (v)(v) d[v] > d[u] + w(u, v) Relax(u, v) if d[v] > d[u] + w(u, v) then d[v]  d[u] + w(u, v)  [v]  u Shortest path algorithms differ in the number of times the edges are relaxed and the order in which they are relaxed.

The Bellman-Ford Algorithm Edge weights may be negative. It detects any negative-weight cycle reachable from the source. Each edge is relaxed |V| – 1 times. Bellman-Ford(G, s) Initialize(G, s) for i  1 to |V| – 1 do for each edge (u, v)  E do Relax(u, v) for each edge (u, v)  E do if d[v] > d[u] + w(u, v) then return false // negative-weight cycle found! return true // no negative-weight cycle Running time  (VE)

An Example 0     s t yz x Source: s Order of edge relaxation: (t, x), (t, y), (t, z), (x, t), (y, x), (y, z), (z, x), (z, s), (s, t), (s, y)

Round 1 0  7  s t yz x d[y] = 7  [y] = s d[t] = 6  [t] = s

Round s t yz x Relax (t, x), (t, y), (t, z), (x, t). d[x] = 11  [x] = t d[z] = 2  [z] = t

Round 2 (cont’d) s t yz x Relax (y, x), (y, z), (z, x), (z, s), (z, s), (s, t), (s, y). d[x] = 4  [x] = y

Round s t yz x d[t] = 2  [t] = x

Round s t yz x d[z] = -2  [z] = t (unchanged)

Detecting Negative-Weight Cycle 0    s a b c Order of edge relaxation: (s, a), (b, c), (b, a), (a, b), (s, c) s a b c s a b c s a b c s a b c d[a] > d[b] + w(b, a): a negative cycle exists!

Correctness Assume G has no negative-weight cycles reachable from s. After |V| – 1 rounds of relaxation, d[v] is the length of a shortest path from s to v for every vertex v. For any vertex v, a path from s to v exists if and only if Bellman-Ford terminates with d[v] < . If G has no negative-weight cycles reachable from s, then Bellman-Ford returns true, d[v] records the shortest path length for every vertex v, and all  [v] induce a shortest-paths tree. Otherwise, the algorithm returns false.