Dijkstra's algorithm.

Slides:



Advertisements
Similar presentations
The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
Advertisements

October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
November 14, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Aalborg University
Introduction To Algorithms CS 445 Discussion Session 6 Instructor: Dr Alon Efrat TA : Pooja Vaswani 03/21/2005.
Applications Data Structures and Algorithms (60-254)
CSE 101- Winter ‘15 Discussion Section January 26th 2015.
Introduction to Algorithms 6.046J/18.401J/SMA5503
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Chapter 23 Minimum Spanning Trees
Lecture 19: Shortest Paths Shang-Hua Teng. Weighted Directed Graphs Weight on edges for distance
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)
Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping.
Shortest Path Algorithms
Shortest Paths Definitions Single Source Algorithms
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
CS 253: Algorithms Chapter 24 Shortest Paths Credit: Dr. George Bebis.
CSC 2300 Data Structures & Algorithms April 3, 2007 Chapter 9. Graph Algorithms.
D IJKSTRA ' S ALGORITHM By Laksman Veeravagu and Luis Barrera.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
1 Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch]
COSC 3101NJ. Elder Assignment 2 Remarking Assignment 2 Marks y = 0.995x R 2 = Old Mark New Mark.
1 WEEK 9-10 Graphs II Unweighted Shortest Paths Dijkstra’s Algorithm Graphs with negative costs Acyclic Graphs Izmir University of Economics.
1 Shortest Path Problem Topic 11 ITS033 – Programming & Algorithms C B A E D F Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program,
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 CS3240. The author: Edsger Wybe Dijkstra "Computer Science is no more about computers than astronomy is about telescopes."
COSC 2007 Data Structures II Chapter 14 Graphs III.
Introduction to Algorithms Jiafen Liu Sept
D IJKSTRA ' S ALGORITHM. S INGLE -S OURCE S HORTEST P ATH P ROBLEM Single-Source Shortest Path Problem - The problem of finding shortest paths from a.
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
Shortest Paths CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
1 Introduction to Algorithms L ECTURE 17 (Chap. 24) Shortest paths I 24.2 Single-source shortest paths 24.3 Dijkstra’s algorithm Edsger Wybe Dijkstra
Lecture 13 Algorithm Analysis
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
CS38 Introduction to Algorithms Lecture 3 April 8, 2014.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Shortest Path Dr. Yasir. Weighted Graphs In many applications, each edge of a graph has an associated numerical value, called a weight. Usually, the edge.
By Laksman Veeravagu and Luis Barrera
Single-Source Shortest Paths
Algorithms and Data Structures Lecture XIII
Short paths and spanning trees
CSE 373: Data Structures and Algorithms
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Minimum Spanning Tree Algorithms
Lecture 13 Algorithm Analysis
Slide Courtesy: Uwash, UT
Lecture 13 Algorithm Analysis
CSE 373: Data Structures and Algorithms
Fundamental Structures of Computer Science II
CSE 373 Data Structures and Algorithms
Slide Courtesy: Uwash, UT
Graph Algorithms: Shortest Path
CSE 417: Algorithms and Computational Complexity
Presentation transcript:

Dijkstra's algorithm

The author: Edsger Wybe Dijkstra   "Computer Science is no more about computers than astronomy is about telescopes." http://www.cs.utexas.edu/~EWD/

Shortest Path Problem for Graphs Let G: (V,E) be a (di)graph. The shortest path between two vertices is a path with the shortest length (least number of edges). Call this the link-distance. Breadth-first-search is an algorithm for finding shortest (link-distance) paths from a single source vertex to all other vertices. BFS processes vertices in increasing order of their distance from the root vertex. BFS has running time O(│V│+│E│)

Shortest Path Problem for Weighted Graphs In a shortest-paths problem, we are given a weighted, directed graph G :(V,E), with weight function w: E → R mapping edges to real-valued weights. The weight w(p) of path p= < v0, v1,……, vk> is the sum of the weights of its constituent edges:

Single-source (single-destination) Single-source (single-destination). Find a shortest path from a given source (vertex s) to each of the vertices.

Single-Source Shortest-Paths Problem The Problem: Given a graph with non-negative edge weights G :(V,E) and a distinguished source vertex s Є V determine the distance and a shortest path from the source vertex to every vertex in the digraph. Question: How do you design an efficient algorithm for this problem?

Single-Source Shortest-Paths Problem Important Observation: Any subpath of a shortest path must also be a shortest path. Why?

Intuition behind Dijkstra’s Algorithm Report the vertices in increasing order of their distance from the source vertex. Construct the shortest path tree edge by edge; at each step adding one new edge, corresponding to construction of shortest path to the current new vertex.

The Rough Idea of Dijkstra’s Algorithm

relaxation

relaxation Relaxing an edge (u,v) means testing whether we can improve the shortest path to v found so far by going through u

Finding new paths

Selection

Review of Priority Queues

Dijkstra's algorithm Dijkstra's algorithm - is a solution to the single-source shortest path problem in graph theory.    Works on both directed and undirected graphs. However, all edges must have nonnegative edge weights. Approach: Greedy, similar to Prim's algorithm for MST Like breadth-first search (if all weights = 1, one can simply use BFS) Basic idea: maintain a set S of solved vertices at each step select "closest" vertex u, add it to S, and relax all edges from u Input: Weighted graph G={E,V} and source vertex v ∈ V, such that all edge weights are nonnegative Output: Lengths of shortest paths (or the shortest paths themselves) from a given source vertex v∈V to all other vertices

EXAMPLE

EXAMPLE

EXAMPLE

EXAMPLE

EXAMPLE

EXAMPLE

EXAMPLE

Dijkstra’s Algorithm

Dijkstra’s Analysis O(V) O(1) O(V) O(V) O((V+E)log V) O(logV) O(E) O(E log V) O(logV)

Time Complexity For sparse graphs, (i.e. graphs with much less than |V2| edges) Dijkstra's implemented more efficiently by priority queue (binary minheap) Initialization O(|V|) using O(|V|) buildHeap While loop O(|V|) Find and remove min distance vertices O(log |V|) using O(log |V|) deleteMin Potentially |E| updates Update costs O(log |V|) using decreaseKey Each EXTRACT-MIN operation then takes time O(lg V). There are │V│ such operations. Each DECREASE-KEY operation takes time O(lgV), and there are still at most│E│ such operations. The total running time is therefore O((V+E)lgV), which is O(E lgV) if all vertices are reachable from the source.

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Dijkstra Animated Example

Correctness Dijkstra’s algorithm is a greedy algorithm make choices that currently seem the best locally optimal does not always mean globally optimal Correct because maintains following two properties: for every known vertex, recorded distance is shortest distance to that vertex from source vertex for every unknown vertex v, its recorded distance is shortest path distance to v from source vertex, considering only currently known vertices and v

Applications of Dijkstra's Algorithm - Traffic Information Systems are most prominent use  - Mapping (Map Quest, Google Maps) Routing Systems robot motion planning