Dijkstra’s Algorithm We are given a directed weighted graph

Slides:



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

Every edge is in a red ellipse (the bags). The bags are connected in a tree. The bags an original vertex is part of are connected.
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.
Lecture 6 Shortest Path Problem. s t Dynamic Programming.
Quiz 4-26-’07 Search.
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.
Management Science 461 Lecture 2b – Shortest Paths September 16, 2008.
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
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.
Fibonacci Heaps. Single Source All Destinations Shortest Paths
1 Routing Algorithms. 2 Outline zBellaman-Ford Algorithm zDijkstra Algorithm.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Dijkstra’s Algorithm. 2 Shortest-path Suppose we want to find the shortest path from node X to node Y It turns out that, in order to do this, we need.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
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.
Dijkstra’s Algorithm: single source shortest paths David Kauchak cs62 Spring 2010.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Optical Network Security Daniel Stewart. Preliminary work Dijkstra's Algorithm Dijkstra's algorithm, is a graph search algorithm that solves the single-
Fibonacci Heaps. Analysis FibonacciAnalysis.ppt Video  iew/cop5536sahni
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali :
Prims Algorithm for finding a minimum spanning tree
Honors Track: Competitive Programming & Problem Solving Finding your way with A*-algorithm Patrick Shaw.
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Po-Lung Chen (Dont block me) d091: Urban Transport System 2010/03/26 (1) d091: Urban Transport System Po-Lung Chen Team Dont Block Me, National Taiwan.
Homework 6 Shortest Paths!. The Basic Idea You have seen BFS and DFS tree searches. These are nice, but if we add the concept of “distance”, we can get.
Programming Abstractions
Shortest Path from G to C Using Dijkstra’s Algorithm
CSC317 Shortest path algorithms
Single-Source Shortest Paths
Minimum Spanning Trees
Spanning Trees Lecture 21 CS2110 – Fall 2016.
Cinda Heeren / Geoffrey Tien
Shortest Path Problems
Dijkstra’s Algorithm with two levels of buckets
Chapter 15 Lists Objectives
Lecture 6 Shortest Path Problem.
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
CSE373: Data Structures & Algorithms Lecture 18: Dijkstra’s Algorithm
A* Path Finding Ref: A-star tutorial.
Shortest-Paths Trees Kun-Mao Chao (趙坤茂)
CSE 373: Data Structures and Algorithms
Outline This topic covers Prim’s algorithm:
Lecture 22 CSE 331 Oct 23, 2017.
Lecture 24 CSE 331 Oct 29, 2012.
Making Change Coins: 2 and
Dynamic Sets (III, Introduction)
Dijkstra’s Shortest Path Algorithm Neil Tang 03/25/2008
Shortest Path Problems
Shortest Path Algorithms
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
Algorithms Lecture # 29 Dr. Sohail Aslam.
Algorithms Searching in a Graph.
Minimum spanning tree Shortest path algorithms
Weighted Graphs & Shortest Paths
Autumn 2016 Lecture 10 Minimum Spanning Trees
Dijkstra’s Shortest Path Algorithm Neil Tang 3/2/2010
Sorting and Divide-and-Conquer
Shortest Paths.
Dijkstra’s Algorithm for Shortest Paths
and 6.855J Dijkstra’s Algorithm
Graph Algorithms: Shortest Path
CSE 417: Algorithms and Computational Complexity
Implementation of Dijkstra’s Algorithm
Shortest Path Solutions
Dijkstra Algorithm examples
The Shortest Path Algorithm
Prim’s algorithm for minimum spanning trees
Winter 2019 Lecture 10 Minimum Spanning Trees
Presentation transcript:

Dijkstra’s Algorithm We are given a directed weighted graph There are no negative weights. We need to solve the single source shortest path problem. The source is given to be 1.

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 Processed nodes will be shown in red. Partially processed nodes will be shown in green. The partially processed nodes will be kept in a heap, where the key is value. Unprocessed nodes will be shown in black. Search tree pointers will be shown in red. The back pointers are the reverse of the search tree pointers.

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 value back *

The value of a node is the weight of the shortest path found so far. 29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 11:1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 9:2 20:27 value 0 2 1 34 27 back * 1 1 1 1 17:34 The value of a node is the weight of the shortest path found so far.

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 9:2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 14:4 20:27 value 0 32 2 1 4 34 27 back * 11 1 1 11 1 1 17:34 6:32

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 14:4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 10:4 20:27 value 0 32 2 4 1 4 34 27 back * 11 1 9 1 11 1 1 17:34 6:32

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 10:4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 12:6 20:27 value 0 32 2 4 1 6 4 34 27 back * 11 1 9 1 14 11 1 1 17:34 6:32

A better path to 20 is found; its value and backpointer are updated. 29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 12:6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 6:32 20:8 value 0 32 2 4 1 6 4 34 8 back * 11 1 9 1 14 11 1 10 17:34 A better path to 20 is found; its value and backpointer are updated.

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 20:8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 5:10 17:34 value 0 10 32 2 4 1 6 4 34 8 back * 12 11 1 9 1 14 11 1 10 6:32

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 5:10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 3:15 19:28 value 0 15 10 32 2 4 1 6 4 30 34 28 8 back * 20 12 11 1 9 1 14 11 20 1 20 10 6:32 15:30 17:34

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 3:14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 15:30 2:18 value 0 16 14 10 32 2 4 1 6 4 30 34 28 8 back * 5 5 12 11 1 9 1 14 11 20 1 20 10 6:32 17:34 19:28

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 2:18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 15:30 8:22 value 0 16 14 10 32 22 2 4 1 6 4 30 34 28 8 back * 5 5 12 11 3 1 9 1 14 11 20 1 20 10 6:32 17:34 19:28

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 8:18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 15:30 7:25 value 0 16 14 10 32 25 18 2 4 1 6 4 30 34 28 8 back * 5 5 12 11 2 2 1 9 1 14 11 20 1 20 10 6:32 17:34 19:28

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 7:25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 15:30 19:27 value 0 16 14 10 32 25 18 2 4 1 6 4 30 34 27 8 back * 5 5 12 11 2 2 1 9 1 14 11 20 1 8 10 6:32 17:34

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 19:26 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 6:28 17:34 value 0 16 14 10 28 25 18 2 4 1 6 4 30 34 26 8 back * 5 5 12 7 2 2 1 9 1 14 11 20 1 7 10 15:30

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 6:28 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 15:30 17:30 value 0 16 14 10 28 25 18 2 4 1 6 4 30 30 26 8 back * 5 5 12 7 2 2 1 9 1 14 11 20 19 7 10

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 17:30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 15:30 18:35 value 0 16 14 10 28 25 18 2 4 1 6 4 30 30 35 26 8 back * 5 5 12 7 2 2 1 9 1 14 11 20 19 6 7 10

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 15:30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 18:35 value 0 16 14 10 28 25 18 2 4 1 6 4 30 30 35 26 8 back * 5 5 12 7 2 2 1 9 1 14 11 20 19 6 7 10

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 18:35 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 4:37 16:35 value 0 16 14 37 10 28 25 18 2 4 1 6 4 30 35 30 35 26 8 back * 5 5 15 12 7 2 2 1 9 1 14 11 20 15 19 6 7 10

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 16:35 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 4:37 value 0 16 14 37 10 28 25 18 2 4 1 6 4 30 35 30 26 8 back * 5 5 15 12 7 2 2 1 9 1 14 11 20 15 19 7 10

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 4:37 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 13:40 value 0 16 14 37 10 28 25 18 2 4 1 6 40 4 30 35 30 35 26 8 back * 5 5 15 12 7 2 2 1 9 1 14 16 11 20 15 19 6 7 10

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap 13:40 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 value 0 16 14 37 10 28 25 18 2 4 1 6 40 4 30 35 30 35 26 8 back * 5 5 15 12 7 2 2 1 9 1 14 16 11 20 15 19 6 7 10

29 34 27 22 32 26 27 20 2 2 4 7 8 9 4 3 5 1 9 10 20 3 8 19 17 15 16 9 5 8 7 6 3 6 1 1 1 3 7 3 5 5 7 6 2 2 4 8 2 8 1 6 5 5 5 5 5 5 2 7 2 8 6 2 2 6 3 3 9 7 9 4 4 3 3 2 4 6 9 3 7 8 8 11 14 12 5 2 7 6 18 4 13 3 4 7 7 3 2 1 1 2 22 28 30 35 31 31 heap empty 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 value 0 16 14 37 10 28 25 18 2 4 1 6 40 4 30 35 30 35 26 8 back * 5 5 15 12 7 2 2 1 9 1 14 16 11 20 15 19 6 7 10 The heap is empty and we are done.