D IJKSTRA ’ S S INGLE S OURCE S HORTEST P ATH Informatics Department Parahyangan Catholic University.

Slides:



Advertisements
Similar presentations
Bellman-Ford algorithm
Advertisements

Single Source Shortest Paths
Minimum Spanning Trees (MSTs) Prim's Algorithm For each vertex not in the tree, keep track of the lowest cost edge that would connect it to the tree This.
Graphs: MSTs and Shortest Paths David Kauchak cs161 Summer 2009.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
1 Paths in Graphs Oscar Miguel Alonso M. 2 Outline The problem to be solved Breadth first search Dijkstra's Algorithm Bellman-Ford Algorithm Shortest.
D IJKSTRA ' S ALGORITHM By Laksman Veeravagu and Luis Barrera Edited by: Manuela Caicedo, Francisco Morales, Rafael Feliciano, and Carlos Jimenez.
CSC 331: Algorithm Analysis Paths in Graphs. The DFS algorithm we gave is recursive. DFS generates a search tree showing paths from one vertex to all.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
Chapter 23 Minimum Spanning Trees
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
Lecture 19: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
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.
Shortest Path Algorithms
Shortest Path Algorithm By Weston Vu CS 146. What is Shortest Paths? Shortest Paths is a part of the graph algorithm. It is used to calculate the shortest.
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Prim’s Algorithm and an MST Speed-Up
D IJKSTRA ' S ALGORITHM By Laksman Veeravagu and Luis Barrera.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
CS112A1 Spring 2008 Practice Final. ASYMPTOTIC NOTATION: a)Show that log(n) and ln(n) are the same in terms of Big-Theta notation b)Show that log(n+1)
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
1 Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch]
COSC 2007 Data Structures II Chapter 14 Graphs III.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
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.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Shortest Path in Weighted Graph : Dijkstra’s Algorithm.
D IJKSTRA ' S ALGORITHM. S INGLE -S OURCE S HORTEST P ATH P ROBLEM Single-Source Shortest Path Problem - The problem of finding shortest paths from a.
Shortest Path Graph Theory Basics Anil Kishore.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
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.
Nattee Niparnan. Dijkstra’s Algorithm Graph with Length.
Shortest Paths CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Data Structures & Algorithms Shortest Paths Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Runtime O(VE), for +/- edges, Detects existence of neg. loops
Weighted Graphs Computing 2 COMP s1 Sedgewick Part 5: Chapter
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
F d a b c e g Prim’s Algorithm – an Example edge candidates choosen.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs Upon completion you will be able to:
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,
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Shortest Path -Prim’s -Djikstra’s. PRIM’s - Minimum Spanning Tree -A spanning tree of a graph is a tree that has all the vertices of the graph connected.
Minimum Spanning Trees
Short paths and spanning trees
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Chapter 11 Graphs.
Weighted Graphs & Shortest Paths
CSE 417: Algorithms and Computational Complexity
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

D IJKSTRA ’ S S INGLE S OURCE S HORTEST P ATH Informatics Department Parahyangan Catholic University

S HORTEST P ATH Given a graph G, a source vertex s, and a destination vertex d. Find a shortest path between s and d. Unweighted Graph Can be solved using simple BFS from s Weighted Graph Bellman-Ford Algorithm (single source) Dijkstra’s Algorithm (no negative cycle) Floyd-Warshall Algorithm (all-pairs shortest path) etc.

S INGLE S OURCE S HORTEST P ATH Given a graph G and a source vertex s. Find the shortest path from s to all other vertices. Can solve one-pair shortest path problem. Very similar to Prim’s MST Algorithm

R ECALL, P RIM ’ S MST At each step, a light edge is added to the tree A that connects A to an isolated vertex A b d a c Light edge ≡ edge with smallest weight that connects A to an isolated vertex

D IJKSTRA ’ S A LGORITHM Maintain a set A of vertices whose shortest path (from source vertex s ) is already known a b d c s

D IJKSTRA ’ S A LGORITHM On each iteration, pick a vertex u  S with the smallest shortest path estimate b’ d’ a’ c’ a b d c s sse = 2+22 = 24 sse = 3+8 = 11 sse = 8+5 = 13 sse = 4+14 = 18

S HORTEST PATH ESTIMATE d’ 8 5 a b c s sse is calculated as minimum of 2+4 = = = 13 = 6 sse is calculated as minimum of 2+4 = = = 13 = 6

E XAMPLE a0a0 bc i hgf d e A

E XAMPLE a0a0 b4b4 c i h8h8 gf d e A

E XAMPLE a0a0 b4b4 c 12 i h8h8 gf d e A distance(a,h)via b is 4+11, which is worse than directly a-h (8)

E XAMPLE a0a0 b4b4 c 12 i 15 h8h8 g9g9 f d e A

E XAMPLE a0a0 b4b4 c 12 i 15 h8h8 g9g9 f 11 d e A distance(a,i) via g is 9+6, which is equally good as via h (8+7)

E XAMPLE a0a0 b4b4 c 12 i 15 h8h8 g9g9 f 11 d 25 e A distance(a,c)via f is 11+4, which is worse than via c (12)

E XAMPLE a0a0 b4b4 c 12 i 14 h8h8 g9g9 f 11 d 19 e A distance(a,i) via c is 12+2, which is better than via h (15) distance(a,d) via c is 12+7, which is better than via f (25)

E XAMPLE a0a0 b4b4 c 12 i 14 h8h8 g9g9 f 11 d 19 e A

E XAMPLE a0a0 b4b4 c 12 i 14 h8h8 g9g9 f 11 d 19 e A distance(a,e) via d is 19+9, which is worse than via f (21)

E XAMPLE a0a0 b4b4 c 12 i 14 h8h8 g9g9 f 11 d 19 e A

P SEUDOCODE 1. Dijkstra-SSSP(G, w, s) 2. for each u  V do 3. dist[u] =  4. parent[u] = NIL 5. dist[s] = 0 6. Q = all vertices of G 7. While Q ≠  do 8. u = EXTRACT-MIN(Q) 9. for each v adjacent to u do 10. if v  Q and dist[u]+w(u,v)<dist[v] then 11. parent[v] = u 12. dist[v] = dist[u]+w(u,v) Initialization : Set all vertices’ dist to  except the source, so that it will be the first vertex processed. Parent of each vertex is set to NIL. Min-priority queue Q contains all vertices.

I MPLEMENTATION The performance of Dijkstra’s Algorithm depends on how we implement the min-priority queue Q (very similar analysis to Prim’s MST) Suppose we implement Q using a min-heap: Store vertices’ id on the heap’s array Store vertices’ dist on a separate array Store vertices’ location on a separate array Additionally, we need an array parent to store the resulting tree