Implementation of Dijkstra’s Algorithm

Slides:



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

Single Source Shortest Paths
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.
15.082J & 6.855J & ESD.78J Shortest Paths 2: Bucket implementations of Dijkstra’s Algorithm R-Heaps.
and 6.855J February 25, 2003 Radix Heap Animation.
Lecture 6 Shortest Path Problem. s t Dynamic Programming.
Chapter 5 Shortest Paths: Label-Correcting Algorithms
By Amber McKenzie and Laura Boccanfuso. Dijkstra’s Algorithm Question: How do you know that Dijkstra’s algorithm finds the shortest path and is optimal.
Management Science 461 Lecture 2b – Shortest Paths September 16, 2008.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
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
1 Routing Algorithms. 2 Outline zBellaman-Ford Algorithm zDijkstra Algorithm.
Prim’s Algorithm and an MST Speed-Up
Quickest Route B St Li C La time matrix (minutes) Liskeard Launceston Callington St Austell Bodmin 32 What is the quickest route from.
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”
Shortest Path. Dijkstra’s Algorithm finds the shortest path from the start vertex to every other vertex in the network. We will find the shortest path.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
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.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
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,
E E Module 5 © Wayne D. Grover 2002, (for non-negative edge weights only) Key concepts: “labelling”, “scanning” Label = {distance, predecessor}.
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali :
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Lecture: Priority Queue. Questions Is array a data structure? What is a data structure? What data structures are implemented by array? Priority queue.
Fibonacci Heaps. Fibonacci Binary insert O(1) O(log(n)) find O(1) N/A union O(1) N/A minimum O(1) O(1) decrease key O(1) O(log(n)) delete O(log(n) O(log(n))
Shortest Paths.
Lecture: Priority Queue
Shortest Path from G to C Using Dijkstra’s Algorithm
Network Flow Problems – Shortest Path Problem
Single-Source Shortest Paths
EMIS 8374 Dijkstra’s Algorithm Updated 18 February 2008
Dijkstra’s Algorithm with two levels of buckets
Party-by-Night Problem
Dijkstra’s Algorithm We are given a directed weighted graph
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Shortest Path Consider the following weighted undirected graph: 20 10
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.
Shortest Path.
Shortest Path.
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Advanced Algorithms Analysis and Design
Lecture 11 Topics Application of BFS Shortest Path
Dynamic Sets (III, Introduction)
Dijkstra’s Shortest Path Algorithm Neil Tang 03/25/2008
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Spanning Tree Algorithms
Algorithms Lecture #37 Dr. Sohail Aslam.
Shortest Path.
15.082J & 6.855J & ESD.78J Radix Heap Animation
Autumn 2016 Lecture 10 Minimum Spanning Trees
Dijkstra’s Shortest Path Algorithm Neil Tang 3/2/2010
Dijkstra’s Algorithm for Shortest Paths
and 6.855J Dijkstra’s Algorithm
Lecture 6 Shortest Path Problem.
Visualizations Dijkstra’s Algorithm
CSE 417: Algorithms and Computational Complexity
The Minimum Cost Spanning Tree Problem
Priority Queues Supports the following operations. Insert element x.
Dijkstra Algorithm examples
Lecture 12 Shortest Path.
Prim’s algorithm for minimum spanning trees
Winter 2019 Lecture 10 Minimum Spanning Trees
15.082J & 6.855J & ESD.78J Visualizations
Data Structures and Algorithm Analysis Lecture 8
Presentation transcript:

Implementation of Dijkstra’s Algorithm

Dijkstra’s Algorithm

Implementations With min-priority queue, Dijkstra algorithm can be implemented in time With Fibonacci heap, Dijkstra algorithm can be implemented in time With Radix heap, Dijkstra algorithm can be implemented

An Example      Initialize 4 2 4 2 2 1 2 3 1  1 6 4 2 3 3 5   1 Initialize 2 ∞ 3 ∞ Select the node with the minimum temporary distance label. 4 5 6 ∞ ∞ ∞

Update Step 2   4 2 4 2 2 1 2 3  1 6 4 2 3 3 5   1 2 ∞ 3 ∞ 4 5 6 ∞ ∞ ∞

Update Step 2     Decrease-Key(S,2,2) 4 2 4 2 2 1 2 3 1 6 4 2 3 3 1 2 3  1 6 4 2 3 3 5   1 2 2 3 ∞ Decrease-Key(S,2,2) 4 5 6 ∞ ∞ ∞

Update Step 2     4 Decrease-Key(S,2,2) Decrease-Key(S,3,4) 4 2 4 1 2 3  1 6 4 2 3 3 5   1 4 2 2 3 4 Decrease-Key(S,2,2) Decrease-Key(S,3,4) 4 5 6 ∞ ∞ ∞

Update Step 2    4 Extract-Min(S) 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 ∞ 6 1 2 3  1 6 4 2 3 3 5 4  ∞ 6 2 2 3 4 Extract-Min(S) 4 5 ∞ ∞

Choose Minimum Temporary Label 2  4 2 4 2 2 1 2 3  1 6 4 2 3 3 5  4 2 2 6 ∞ 3 4 4 5 ∞ ∞

Update Step 6 The predecessor of node 3 is now node 2 2    4 4 3 1 2 3  1 6 4 2 3 3 5  4 2 2 4 3 5 4 3 3 Decrease-Key(S,3,3) Decrease-Key(S,4,6) Decrease-Key(S,5,4) 6 4 ∞ 6

Choose Minimum Temporary Label 2 6 4 2 4 2 2 1 2 3  1 6 4 2 3 3 5 3 4 6 4 5 4 3 3 Extract-Min(S) 6 ∞

Choose Minimum Temporary Label 2 6 4 2 4 2 2 1 2 3  1 6 4 2 3 3 5 3 4 3 3 5 4 4 6 Extract-Min(S) 6 ∞

Update 2 6  3 4 d(5) is not changed. 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 3 1 2 3  1 6 4 2 3 3 5 3 4 3 3 5 4 4 6 d(5) is not changed. 6 ∞

Choose Minimum Temporary Label 2 6 4 2 4 2 2 1 2 3  1 6 4 2 3 3 5 3 4 6 ∞ 5 4 4 6 Extract-Min(S)

Choose Minimum Temporary Label 2 6 4 2 4 2 2 1 2 3  1 6 4 2 3 3 5 3 4 5 4 6 4 6 Extract-Min(S) ∞

Update d(4) is not changed 2 6 6  3 4 Decrease-Key(S,6,6) 4 2 4 2 2 1 6 1 2 3  1 6 4 2 3 3 5 3 4 5 4 6 4 6 Decrease-Key(S,6,6) 6

Choose Minimum Temporary Label 2 6 4 2 4 2 2 1 2 3 6 1 6 4 2 3 3 5 3 4 4 6 6 6

Update 2 6 6 3 4 d(6) is not updated 4 2 4 2 2 1 2 3 1 6 4 2 3 3 5 4 6 1 2 3 6 1 6 4 2 3 3 5 3 4 4 6 6 6 d(6) is not updated

Choose Minimum Temporary Label 2 6 4 2 4 2 2 1 2 3 6 1 6 4 2 3 3 5 3 4 6 6 There is nothing to update

End of Algorithm 2 6 6 3 4 All nodes are now permanent 1 2 3 6 1 6 4 2 3 3 5 3 4 All nodes are now permanent The predecessors form a tree The shortest path from node 1 to node 6 can be found by tracing back predecessors

Implementations Decrease-Key(S,x,key): Call at most m times. Extract-Min(S): Call n times. With min-priority queue, Dijkstra algorithm can be implemented in time