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
Single Source Shortest Paths
Advertisements

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.
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,
Introduction to Algorithms 6.046J/18.401J/SMA5503
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
CPSC 411, Fall 2008: Set 9 1 CPSC 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Fall 2008.
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
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1.1 Data Structure and Algorithm Lecture 11 Application of BFS  Shortest Path Topics Reference: Introduction to Algorithm by Cormen Chapter 25: Single-Source.
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.
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
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
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.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Dijkstra's algorithm.
Topological Sorting and Least-cost Path Algorithms.
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.
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
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.
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.
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
Shortest Path in Weighted Graph : Dijkstra’s Algorithm.
Kruskal’s and Dijkstra’s Algorithm.  Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted.
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
F d a b c e g Prim’s Algorithm – an Example edge candidates choosen.
Lecture 13 Algorithm Analysis
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
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.
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])
David Luebke 1 11/21/2016 CS 332: Algorithms Minimum Spanning Tree Shortest Paths.
Lecture 13 Shortest Path.
Algorithms and Data Structures Lecture XIII
Minimum Spanning Tree Shortest Paths
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Advanced Algorithms Analysis and Design
Lecture 11 Topics Application of BFS Shortest Path
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
Advanced Algorithms Analysis and Design
Graph Algorithms: Shortest Path
Lecture 12 Shortest Path.
CS 3013: DS & Algorithms Shortest Paths.
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

Single-Source Shortest Paths A shortest path from vertex u to vertex v has the minimum weight among all paths connecting u to v. Problem Given a graph G = (V, E), where every edge e has a nonnegative weight w(e), and a source vertex s in V, find the shortest path from s to every other vertex.

An Example a s be f d c 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 5

Applications Routing Telecommunications Robot path planning Building block for network algorithms...

Dijkstra’s Algorithm Idea: Successively compute u, u, …, u, where u = the kth closest vertex to s 1 2 n k u = s u is the closest vertex to s;i.e., w(s, u ) = min{ w(s,v) | (s, v) in E } u is the closest vertex to u or the second closest to s

How to Find u ? k+1 Let V = {u, u,…, u } 1 2 k Lemma The shortest path to u goes only through vertices in V. k k+1 Proof Suppose there exists a vertex x not in V but on the path to u. Then x is closer to s than u, a contradiction. k k +1 k+1k+1 s x u k+1k+1 V k

Implementation Maintain arrays d and pred. At beginning of kth iteration: d(v) = length of the shortest path from s to v that only contains vertices in V. k pred(v) = the predecessor of v in the above path. u is the vertex with minimum d-value in V(G) - V. k+1k+1 k

Relaxation After finding u, update d(v) for every neighbor v of u. k+1 s v w u s w v u d(v) = min{ d(v), d(u ) + w(u, v) } k+1 If d(v) decreases, set pred(v) = u. k+1

Dijkstra(G, w, s) for each vertex v in V(G) // initialization do d(v) = infinity pred(v) = NIL d(s) = 0 S = {} Q = V(G) // initializing priority queue while Q {} do u = Extract-Min(Q) // minimum d value in V-S S = S + {u} for each vertex v in Adj(u) do // adjacency lists if d(v) > d(u) + w(u, v) // relaxation then d(v) = d(u) + w(u, v) pred(v) = u

An Example a f e c b d s inf 2

a f e c b d s

a f e c b d s

a f e c b d s

a f e c b d s

a f e c b d s

a f e c b d s

a f e c b d s

a f e c b d s Shortest Path Tree The unique simple path from s to v in the tree is a shortest path from s to v.

Analysis Q build-queue extract-min decrease-key total Array O(n) O(n) O(1) O(n ) Heap O(n) O(lg n) O(lg n) O(m lg n) 2 n times m times