EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008

Slides:



Advertisements
Similar presentations
and 6.855J Dijkstras Algorithm with simple buckets (also known as Dials algorithm)
Advertisements

Single Source Shortest Paths
Lecture 6 Shortest Path Problem. s t Dynamic Programming.
Chapter 5 Shortest Paths: Label-Correcting Algorithms
Chapter 6 Maximum Flow Problems Flows and Cuts Augmenting Path Algorithm.
15.082J, 6.855J, and ESD.78J Sept 16, 2010 Lecture 3. Graph Search Breadth First Search Depth First Search Intro to program verification Topological Sort.
Chapter 7 Maximum Flows: Polynomial Algorithms
Chapter 5 Routing Algorithm in Networks. How are message routed from origin to destination? 1) Circuit-Switching → telephone net. Dedicated bandwidth.
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 Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 15 Shortest paths algorithms Properties of shortest paths Bellman-Ford algorithm.
1 Routing Algorithms. 2 Outline zBellaman-Ford Algorithm zDijkstra Algorithm.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Computational Methods for Management and Economics Carla Gomes
Chapter 4 Shortest Path Label-Setting Algorithms Introduction & Assumptions Applications Dijkstra’s Algorithm.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
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.
Lecture 10 The Label Correcting Algorithm.
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.
15.082J & 6.855J & ESD.78J September 23, 2010 Dijkstra’s Algorithm for the Shortest Path Problem.
and 6.855J March 6, 2003 Maximum Flows 2. 2 Network Reliability u Communication Network u What is the maximum number of arc disjoint paths from.
15.082J & 6.855J & ESD.78J September 30, 2010 The Label Correcting Algorithm.
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.
EMIS 8374 Shortest Path Trees Updated 11 February 2008 Slide 1.
EMIS 8374 The Ford-Fulkerson Algorithm (aka the labeling algorithm) Updated 4 March 2008.
CS38 Introduction to Algorithms Lecture 3 April 8, 2014.
Trees.
1 1 Slide © 2005 Thomson/South-Western Chapter 9 Network Models n Shortest-Route Problem n Minimal Spanning Tree Problem n Maximal Flow Problem.
Cycle Canceling Algorithm
All-pairs Shortest paths Transitive Closure
Shortest Paths CONTENTS Introduction to Shortest Paths (Section 4.1)
Lecture 13 Shortest Path.
Network Simplex Animations
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Algorithms and Data Structures Lecture XIII
Dijkstra’s Algorithm with two levels of buckets
James B. Orlin Presented by Tal Kaminker
Party-by-Night Problem
15.082J & 6.855J & ESD.78J Visualizations
Dijkstra’s Algorithm for the Shortest Path Problem
15.082J & 6.855J & ESD.78J Visualizations
Lecture 6 Shortest Path Problem.
Dijkstra’s Algorithm for the Shortest Path Problem
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
4.4 Shortest Paths in a Graph
Advanced Algorithms Analysis and Design
Algorithms and Data Structures Lecture XIII
EMIS 8374 Shortest Path Problems: Introduction Updated 9 February 2008
Shortest-Path Property 4.1
Shortest Path Problems
Chapter 24: Single-Source Shortest Paths
15.082J & 6.855J & ESD.78J Radix Heap Animation
Dijkstra’s Algorithm for Shortest Paths
EMIS 8374 Search Algorithms Updated 9 February 2004
The Ford-Fulkerson Algorithm
and 6.855J Dijkstra’s Algorithm
Visualizations Dijkstra’s Algorithm
Network Simplex Animations
Chapter 24: Single-Source Shortest Paths
CSE 417: Algorithms and Computational Complexity
15.082J & 6.855J & ESD.78J Visualizations
Implementation of Dijkstra’s Algorithm
Lecture 12 Shortest Path.
Single-Source Shortest Path & Minimum Spanning Trees
EMIS 8374 Search Algorithms Updated 12 February 2008
Directed Graphs (Part II)
15.082J & 6.855J & ESD.78J Visualizations
Data Structures and Algorithm Analysis Lecture 8
Presentation transcript:

EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008

Dijkstra’s Algorithm Network may have cycles, but all arc lengths must be nonnegative. Maintains a partition of N into two subsets: Set P: permanently labeled nodes Set T: temporarily labeled nodes Moves nodes from T into P one at a time in non-decreasing order by shortest-path distance from the source node

Dijkstra’s Algorithm (pg 109) begin P := {}; T := N; d(i) :=  for each node i in N; d(s) := 0 and pred(s) := 0; while |P| < n do pick i in T with minimum d(i) value; move i from T to P; for each (i, j) in A(i) do if d(j) > d(i) + cij then d(j) := d(i) + cij; pred(j) := i; end;

Dijkstra’s Algorithm Example    2 4 5 4 3 1 1 6  2 1 6 7 2 3 2   P = {}, T = {1, 2, 3, 4, 5, 6}

Dijkstra’s Algorithm Example  4    2 4 5 4 3 1 1 6  2 1 6 7 2 3 2   7  P = {1}, T = {2, 3, 4, 5, 6}

Dijkstra’s Algorithm Example 4 4  6   2 4 5 4 3 1 1 6  2 1 6 7 2 3 2   7 5   P = {1,4}, T = {2, 3, 5, 6}

Dijkstra’s Algorithm Example 4 6 2 4 4 5 3 1 1 6 11   2 1 6 7 2 3 2  7  5 5 P = {1,4,3}, T = {2, 5, 6}

Dijkstra’s Algorithm Example 4 6 6 2 4 4 5 3 1 1 6 11 9 2 1 6 7 2 3 2  7  5 P = {1,4,3,5}, T = {2, 6}

Dijkstra’s Algorithm Example 4  6 6 2 4 5 4 3 1 6  1 11 9 2 1 6 7 2 3 2  7  7 5 P = {1,4,3,5,2}, T = {6}

Dijkstra’s Algorithm Example 4  6 6 2 4 5 4 3 1 1 6 9 9 2 1 6 7 2 3 2   7 5 P = {1,4,3,5,2,6}, T = {}

Shortest Path Tree 4  6 6 2 4 5 4 3 1 1 6 9 2 1 6 7 2 3 2   7 5

Shortest Path Tree 4  6 6 2 4 5 4 3 1  1 6  11 9 9 2 1 6 7 2 3 2   11 9 9 2 1 6 7 2 3 2   7 5

Correctness of Dijkstra’s Algorithm At the end of any iteration the following statements hold: The distance label d(i) is optimal for any node i in the set P. That is, d(i) = d*(i) for all i in P. The distance label d(i) for any node i in T is the length of a shortest path from the source to i such that all internal nodes are in P.

Statement 2 Example: d(6) after scanning node 3 4 6 2 4 4 5 3 1 1 6 11 2 1 6 7 2 3 2 7 5 Shortest path in Statement 2 uses internal nodes 1, 4, and 3

Statement 2 Example: d(6) after scanning node 5 4 6 2 4 4 5 3 1 1 6 9 2 1 6 7 2 3 2 7 5 Shortest path in Statement 2 uses internal nodes 1, 4, and 5

Proof Statements 1 and 2 are clearly true after the first iteration. Assume they are true after iteration k and prove that they hold after iteration k+1

Base Cases for Proof by Induction After the first iteration the only node in P is the source with d(s) = 0. After the first iteration there are two cases for a node j in T: If j is in A(s), then d(j) = csj If j is not in A(s), then d(j) = .

Illustration of Base Cases 14  2 4 5 14 3 1 1 6  2 1 6 7 2 3 2  7 P = {1}, T = {2, 3, 4, 5, 6}

Proof that Statement 1 Holds after Iteration k+1 Let i be the node moved from T to P in iteration k+1 Need to show d(i) = d*(i) Idea Let B be a path from s to i Let L(B) be the length of B Show that d(i) ≤ L(B)

Proof that Statement 1 Holds after Iteration k+1 There are two cases to consider for B All internal nodes of B are in P At least one internal node of B is in T Case 1: Statement 2 implies that d(i) ≤ L(B)

Proof that Statement 1 Holds after Iteration k+1 Case 2: Let j be first internal node of B that is in T By Statement 2, the length of the subpath of B from s to j is at least d(j) Since all arc lengths are non-negative, the length of the subpath of B from j to i is at least zero Thus, L(B) ≥ d(j) Since node i was picked to move to P, d(i) ≤ d(j) Therefore, d(i) ≤ L(B)

Diagram for Case 2 P i s j Since Statement 2 holds for the first k iterations, d(j) ≤ length of the subpath of B from s to j.

Diagram for Case 2 P i s j Since the arc lengths are non-negative, the length of the subpath of B from j to i is at least zero.

Diagram for Case 2 P i s j The length of path B from s to i is at least d(j).

Diagram for Case 2 P i s j Since d(i) ≤ d(j), the length of path B from s to i is at least d(i).

Diagram for Case 2 P i s j Since d(i) ≤ L(B) for any path B from s to i , d(i) = d*(i).

Proof of Statement 2 When node i moves from T to P, the algorithm changes pred(j) to i and sets d(j) = d(i) + cij for all j in T such that d(j) > d(i) + cij . Thus, the path defined by the predecessor indices from j to s satisfies Property 4.2. Therefore, d(j) is the length of a shortest path from s to j subject to the restriction that each internal node in the path is in P.

Diagram for Statement 2 j s i T P pred(j) Move node i from T to P If d(j)  d(i) + cij then Statement 2 still holds for node j.

Diagram for Statement 2 j s i T P old pred(j) new pred(j) Move node i from T to P If d(j) > d(i) + cij then d(j) gets reset to d(i) + cij

Complexity of Dijkstra’s Algorithm Node selections Must compare the distance labels of all nodes in T: O(n + (n-1) + (n-2) + … + 1) = O(n2) Total work for scanning nodes is O(m) Overall complexity is O(n2 + m) = O(n2) Can be improved to O(m + n log n) with Fibonacci heaps