Dijkstra’s algorithm N: set of nodes for which shortest path already found Initialization: (Start with source node s) n N = {s}, D s = 0, “s is distance.

Slides:



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

DIJKSTRA’s Algorithm. Definition fwd search Find the shortest paths from a given SOURCE node to ALL other nodes, by developing the paths in order of increasing.
The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
Lecture 6 Shortest Path Problem. s t Dynamic Programming.
Data Structures and Algorithms Graphs Single-Source Shortest Paths (Dijkstra’s Algorithm) PLSD210(ii)
Quiz 4-26-’07 Search.
Management Science 461 Lecture 2b – Shortest Paths September 16, 2008.
The Out of Kilter Algorithm in Introduction The out of kilter algorithm is an example of a primal-dual algorithm. It works on both the primal.
1 Dijkstra's Shortest Path Algorithm Find shortest path from s to t. s 3 t
1 Dijkstra's Shortest Path Algorithm Find shortest path from s to t. s 3 t
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Fibonacci Heaps. Single Source All Destinations Shortest Paths
Routing algorithms, all distinct routes, ksp, max-flow, and network flow LPs W. D. Grover TRLabs & University of Alberta © Wayne D. Grover 2002, 2003 E.
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.
Shortest Path Problem For weighted graphs it is often useful to find the shortest path between two vertices Here, the “shortest path” is the path that.
1 Heaps Chapter 6 in CLRS. 2 Motivation Router: Dijkstra’s algorithm for single source shortest path Prim’s algorithm for minimum spanning trees.
The Shortest Path Problem
Lecture20: Graph IV Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Weighted Graphs In a weighted graph, each edge has an associated numerical value, called the weight of the edge Edge weights may represent, distances,
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
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.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Packet-Switching Networks Routing in Packet Networks.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
Dijkstra’s Algorithm. This algorithm finds the shortest path from a source vertex to all other vertices in a weighted directed graph without negative.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
Diverse Routing Algorithms
A* Path Finding Ref: A-star tutorial.
E E Module 5 © Wayne D. Grover 2002, (for non-negative edge weights only) Key concepts: “labelling”, “scanning” Label = {distance, predecessor}.
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.
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali :
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Chapter 7 Packet-Switching Networks Shortest Path Routing.
Graphs - II CS 2110, Spring Where did David leave that book? 2.
ליאור שפירא, חיים קפלן וחברים
Shortest Path from G to C Using Dijkstra’s Algorithm
Graph Algorithms BFS, DFS, Dijkstra’s.
Chapter 7: Greedy Algorithms
EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008
Disjoint Path Routing Algorithms
Party-by-Night Problem
Dijkstra’s Algorithm We are given a directed weighted graph
The Shortest Augmenting Path Algorithm for the Maximum Flow Problem
15.082J & 6.855J & ESD.78J Visualizations
4.4 Shortest Paths in a Graph
A* Path Finding Ref: A-star tutorial.
Lecture 24 CSE 331 Oct 29, 2012.
Dynamic Sets (III, Introduction)
Advanced Computer Networks
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
Assignment Problem Example
Weighted Graphs & Shortest Paths
Autumn 2016 Lecture 10 Minimum Spanning Trees
Sorting and Divide-and-Conquer
Dijkstra’s Algorithm for Shortest Paths
The Shortest Augmenting Path Algorithm for the Maximum Flow Problem
The Shortest Augmenting Path Algorithm for the Maximum Flow Problem
and 6.855J Dijkstra’s Algorithm
Visualizations Dijkstra’s Algorithm
Lecture 23 CSE 331 Oct 24, 2011.
CSE 417: Algorithms and Computational Complexity
Dijkstra's Shortest Path Algorithm
Implementation of Dijkstra’s Algorithm
Dijkstra Algorithm examples
Prim’s algorithm for minimum spanning trees
15.082J & 6.855J & ESD.78J Visualizations
Presentation transcript:

Dijkstra’s algorithm N: set of nodes for which shortest path already found Initialization: (Start with source node s) n N = {s}, D s = 0, “s is distance zero from itself” n D j =C sj for all j  s, distances of directly-connected neighbors Step A: (Find next closest node i) n Find i  N such that n D i = min Dj for j  N n Add i to N n If N contains all the nodes, stop Step B: (update minimum costs) n For each node j  N n D j = min (D j, D i +C ij ) n Go to Step A Minimum distance from s to j through node i in N

2 Dijkstra's Shortest Path Algorithm Find shortest path from s to t. s 3 t

3 Dijkstra's Shortest Path Algorithm s 3 t        0 distance label S = { } PQ = { s, 2, 3, 4, 5, 6, 7, t }

4 Dijkstra's Shortest Path Algorithm s 3 t        0 distance label S = { } PQ = { s, 2, 3, 4, 5, 6, 7, t } delmin

5 Dijkstra's Shortest Path Algorithm s 3 t    14  0 distance label S = { s } PQ = { 2, 3, 4, 5, 6, 7, t } decrease key  X   X X

6 Dijkstra's Shortest Path Algorithm s 3 t    14  0 distance label S = { s } PQ = { 2, 3, 4, 5, 6, 7, t }  X   X X delmin

7 Dijkstra's Shortest Path Algorithm s 3 t    14  0 S = { s, 2 } PQ = { 3, 4, 5, 6, 7, t }  X   X X

8 Dijkstra's Shortest Path Algorithm s 3 t    14  0 S = { s, 2 } PQ = { 3, 4, 5, 6, 7, t }  X   X X decrease key X 33

9 Dijkstra's Shortest Path Algorithm s 3 t    14  0 S = { s, 2 } PQ = { 3, 4, 5, 6, 7, t }  X   X X X 33 delmin

10 Dijkstra's Shortest Path Algorithm s 3 t    14  0 S = { s, 2, 6 } PQ = { 3, 4, 5, 7, t }  X   X X X X X 32

11 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 6 } PQ = { 3, 4, 5, 7, t }  X   X X 44 X delmin  X 33 X 32

12 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 6, 7 } PQ = { 3, 4, 5, t }  X   X X 44 X 35 X 59 X 24  X 33 X 32

13 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 6, 7 } PQ = { 3, 4, 5, t }  X   X X 44 X 35 X 59 X delmin  X 33 X 32

14 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 6, 7 } PQ = { 4, 5, t }  X   X X 44 X 35 X 59 XX 51 X 34  X 33 X 32

15 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 6, 7 } PQ = { 4, 5, t }  X   X X 44 X 35 X 59 XX 51 X 34 delmin  X 33 X 32 24

16 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 5, 6, 7 } PQ = { 4, t }  X   X X 44 X 35 X 59 XX 51 X X 50 X 45  X 33 X 32

17 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 5, 6, 7 } PQ = { 4, t }  X   X X 44 X 35 X 59 XX 51 X X 50 X 45 delmin  X 33 X 32

18 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 4, 5, 6, 7 } PQ = { t }  X   X X 44 X 35 X 59 XX 51 X X 50 X 45  X 33 X 32

19 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 4, 5, 6, 7 } PQ = { t }  X   X X 44 X 35 X 59 XX 51 X 34 X 50 X 45 delmin  X 33 X 32 24

20 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { }  X   X X 44 X 35 X 59 XX 51 X 34 X 50 X 45  X 33 X 32

21 Dijkstra's Shortest Path Algorithm s 3 t   14  0 S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { }  X   X X 44 X 35 X 59 XX 51 X 34 X 50 X 45  X 33 X 32

Modified Dijkstra’s algorithm Dijkstra-aux (G, target-node,sub-path) N: set of nodes for which shortest path already found Initialization: Start with node s= (pop sub-path)//last node on sub-path n V’ = V – {sub-path} //search over nodes not already in sub-path n N = {s}, D s = 0 for s  sub-path, “s is distance zero from itself” n D j =C sj for all j  V’, j  s, distances of directly-connected neighbors Step A: (Find next closest node i) n Find i  N such that n D i = min Dj for j  N n Add i to N n If N contains j=target-node, – return N, C sj – Else return  //no path to target-node Step B: (update minimum costs) n For each node j  N n D j = min (D j, D i +C ij ) n Go to Step A

Modified Dijkstra’s k-Path algorithm Dijkstra-recurse (G, target-node, Path, count) n Do while count< k and Path   – New-Path = Dijkstra-aux (G, target-node, Path)// min-cost path to target- node  If New-Path   //another min-cost path –count=count+1; Path-set=Path-set  New-Path –E’ = E – {(pop-Path, target-node)//remove edge from graph –New-Path=Dijkstra-aux (G(V,E’), target-node, pop-Path, count) // graph with edge deleted to prevent finding same path  Else New-Path=Dijkstra-aux (G(V,E), target-node, pop-Path, count) n End while n Return Path-set

Modified Dijkstra’s k-Path algorithm Dijkstra (G, target-node) Initialization: Start with node s= source node n V’ = V – {s} //search over all nodes n Path-set =  //set of min-cost paths n count=0 //path counter n Path = {s} n Do while count< k and Path   – New-Path = Dijkstra-aux (G, target-node, Path)// min-cost path to target-node  If New-Path   //another min-cost path –count=count+1; Path-set=Path-set  New-Path –E’ = E – {(pop-Path, target-node)//remove edge from graph –New-Path=Dijkstra-aux (G(V,E’), target-node, pop-Path )// min-cost path to target-node  Else New-Path=Dijkstra-aux (G(V,E), target-node, pop-Path ) n End while n Return Path-set

25

Modified Dijkstra’s k-Path algorithm Dijkstra-recurse (G, target-node, Path, count) n Do while count< k and Path   – New-Path = Dijkstra-aux (G, target-node, Path)// min-cost path to target- node  If New-Path   //another min-cost path –count=count+1; Path-set=Path-set  New-Path  Else New-Path=Dijkstra-aux (G(V,E), target-node, pop-Path, count) n End while n Return Path-set