Description of The Algorithm

Similar documents
Lecture 18 Solving Shortest Path Problem: Dijkstra s Algorithm. October 23, 2009

DIJKSTRA'S ALGORITHM. By Laksman Veeravagu and Luis Barrera

Algorithms for Data Science

Algorithms for Data Science

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 8: Negative Edges

(Refer Slide Time: 00:18)

Single Source Shortest Path (SSSP) Problem

Graphs: Finding shortest paths. Tecniche di Programmazione A.A. 2016/2017

Dijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5

Solution. violating the triangle inequality. - Initialize U = {s} - Add vertex v to U whenever DIST[v] decreases.

Solving Difference Constraints Incrementally

CS350: Data Structures Dijkstra s Shortest Path Alg.

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

Single Source Shortest Path

Introduction to Information Science and Technology (IST) Part IV: Intelligent Machines and Robotics Planning

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CMSC351 - Fall 2014, Homework #6

Dr. Alexander Souza. Winter term 11/12

Module 27: Chained Matrix Multiplication and Bellman-Ford Shortest Path Algorithm

Homework Assignment #3 Graph

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

Three Graph Algorithms

Three Graph Algorithms

MST & Shortest Path -Prim s -Djikstra s

Week 12: Minimum Spanning trees and Shortest Paths

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS

1 Dijkstra s Algorithm

Minimum Spanning Tree

Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University

Design and Analysis of Algorithms

Lecture I: Shortest Path Algorithms

Design and Analysis of Algorithms

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

The Shortest Path Problem

Quiz 2 CS 3510 October 22, 2004

Solutions to Assessment

CSC Intro to Intelligent Robotics, Spring Graphs

Outline. Computer Science 331. Definitions: Paths and Their Costs. Computation of Minimum Cost Paths

SHORTEST PATHS. Weighted Digraphs. Shortest paths. Shortest Paths BOS ORD JFK SFO LAX DFW MIA

Analysis of Algorithms, I

Dijkstra s Shortest Path Algorithm

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

CSE 502 Class 23. Jeremy Buhler Steve Cole. April BFS solves unweighted shortest path problem. Every edge traversed adds one to path length

Algorithms and Data Structures 2014 Exercises and Solutions Week 9

Parallel Graph Algorithms

Shortest path problems

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s

Routing Protocols and the IP Layer

5.4 Shortest Paths. Jacobs University Visualization and Computer Graphics Lab. CH : Algorithms and Data Structures 456

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Lecture 2: Routing algorithms

Introduction to Optimization

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Comparison of the moore s method and dijkstra s algorithm in determing the shortest path between two points on a map

Lecture 11: Analysis of Algorithms (CS ) 1

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 7 Lecturer: David Wagner February 13, Notes 7 for CS 170

Dijkstra s Algorithm. Single source shortest paths for a directed acyclic graph

CS 310 Advanced Data Structures and Algorithms

CSE 100 Minimum Spanning Trees Prim s and Kruskal

LEC13: SHORTEST PATH. CSE 373 Analysis of Algorithms Fall 2016 Instructor: Prof. Sael Lee. Lecture slide courtesy of Prof.

CHAPTER 13 GRAPH ALGORITHMS

Week 11: Minimum Spanning trees

Lecture 14: Shortest Paths Steven Skiena

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

Algorithm Design and Analysis

Parallel Graph Algorithms

Dijkstra s Algorithm

Graphs. The ultimate data structure. graphs 1

Shortest Path Algorithms

09 B: Graph Algorithms II

Pred 8 1. Dist. Pred

Eulerian Cycle (2A) Walk : vertices may repeat, edges may repeat (closed or open) Trail: vertices may repeat, edges cannot repeat (open)

Addis Ababa University, Amist Kilo July 20, 2011 Algorithms and Programming for High Schoolers. Lecture 12

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

from notes written mostly by Dr. Carla Savage: All Rights Reserved

COL 702 : Assignment 1 solutions

Math 381 Discrete Mathematical Modeling

Classical Shortest-Path Algorithms

Introduction to Algorithms. Lecture 11

CSE 4/531 Solution 3

Section authors: Hamilton Clower, David Scott, Ian Dundore.

CS 4349 Lecture October 23rd, 2017

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Algorithms on Graphs: Part III. Shortest Path Problems. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

CS 561, Lecture 10. Jared Saia University of New Mexico

Directed Graphs. DSA - lecture 5 - T.U.Cluj-Napoca - M. Joldos 1

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Lecture 28: Graphs: Shortest Paths (Part 1)

Java II Graph Algorithms II

1 i n (p i + r n i ) (Note that by allowing i to be n, we handle the case where the rod is not cut at all.)

Homework 2 Solutions

Termination Conditions. Distributed Termination Detection Algorithms. Using Acknowledgment Messages

Artificial Intelligence

Graph Algorithms Introduction to Data Structures. Ananda Gunawardena 7/31/2011 1

Introduction Single-source shortest paths All-pairs shortest paths. Shortest paths in graphs

CS 561, Lecture 10. Jared Saia University of New Mexico

Transcription:

Description of The Algorithm Dijkstra s algorithm works by solving the sub-problem k, which computes the shortest path from the source to vertices among the k closest vertices to the source. For the dijkstra s algorithm to work it should be directed- weighted graph and the edges should be non-negative. If the edges are negative then the actual shortest path cannot be obtained. General Description Suppose we want to find a shortest path from a given node s to other nodes in a network (one-toall shortest path problem) Dijkstra s algorithm solves such a problem It finds the shortest path from a given node s to all other nodes in the network Node s is called a starting node or an initial node How is the algorithm achieving this? Dijkstra s algorithm starts by assigning some initial values for the distances from node s and to every other node in the network It operates in steps, where at each step the algorithm improves the distance values. At each step, the shortest distance from node s to another node is determined Formal Description The algorithm characterizes each node by its state.the state of a node consists of two features: Distance value and status label Distance value of a node is a scalar representing an estimate of the its distance from node s. Status label is an attribute specifying whether the distance value of a node is equal to the shortest distance to node s or not. The status label of a node is Permanent if its distance value is equal to the shortest distance from node s Otherwise, the status label of a node is Temporary The algorithm maintains and step-by-step updates the states of the nodes. At each step one node is designated as current Algorithm Steps Step 1. Initialization Assign the zero distance value to node s, and label it as Permanent. [The state of node s is (0, p)] Assign to every node a distance value of and label them as Temporary. [The state of every other node is (, t)] Designate the node s as the current node Step 2. Distance Value Update and Current Node Designation Update Let i be the index of the current node. (1) Find the set J of nodes with temporary labels that can be reached from the current node i by a link (i, j). Update the distance values of these nodes.

For each j J, the distance value d j of node j is updated as follows new d j = min{d j, d i +c ij } where c ij is the cost of link (i, j), as given in the network problem. (2) Determine a node j that has the smallest distance value d j among all nodes j J, find j* such that (3) Change the label of node j* to permanent and designate this node as the current node. Step 3. Termination Criterion If all nodes that can be reached from node s have been permanently labeled, then stop - we are done. If we cannot reach any temporary labeled node from the current node, then all the temporary labels become permanent - we are done. Otherwise, go to Step 2. Dijkstra's Algorithm - Pseudocode dist[s] 0 (distance to source vertex is zero) for all v V {s} do dist[v] (set all other distances to infinity) S Q V (S, the set of visited vertices is initially empty) (Q, the queue initially contains all vertices) while Q (while the queue is not empty) do u mindistance(q,dist) (select the element of Q with the min. distance) S S {u} (add u to list of visited vertices) for all v neighbors[u] do if dist[v] > dist[u] + w(u, v) (if new shortest path found) then d[v] d[u] + w(u, v) (set new value of shortest path) (if desired, add traceback code) return dist Example: We want to find the shortest path from node 1 to the all the other nodes in the network using Dijkstra s algorithm

Step 1- Initialization Node 1 is designated as the current node The state of node 1 is (0, p) Every other node has state (, t) Step 2 Nodes 2, 3,and 6 can be reached from the current node 1 Update distance values for these nodes d2 = min{, 0+7} = 7 d3 = min{, 0+9} = 9 d6 = min{, 0+} =

Now, among the nodes 2, 3, and 6, node 2 has the smallest distance value The status label of node 2 changes to permanent, so its state is (7, p), while the status of 3 and 6 remains temporary Node 2 becomes the current node Step 3 Another Implementation of Step 2 Nodes 3 and 4 can be reached from the current node 2 Update distance values for these nodes d3 = min{9, 7+10} = 9 d4 = min{, 7+15} = 22 Now, between the nodes 3 and 4 node 3 has the smallest distance value The status label of node 3 changes to permanent, while the status of 4 remains temporary 11

Node 3 becomes the current node We are not done (Step 3 fails), so we perform another Step 2 Another Step 2 Nodes 6 and 4 can be reached from the current node 3 Update distance values for them d4 = min{22, 9+11} = 20 d6 = min{, 9+2} = 11 Now, between the nodes 6 and 4 node 6 has the smallest distance value The status label of node 6 changes to permanent, while the status of 4 remains temporary Node 6 becomes the current node we are not done (Step 3 fails), so we perform another Step 2 Another Step 2 Node 5 can be reached from the current node 6 Update distance value for node 5

d5 = min{, 11+9} = 20 Now, node 5 is the only candidate, so its status changes to permanent Node 5 becomes the current node From node 5 we cannot reach any other node. Hence, node 4 gets permanently labeled and we are done.