CSE 373: Data Structures and Algorithms

Slides:



Advertisements
Similar presentations
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Advertisements

The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
CS171 Introduction to Computer Science II Graphs Strike Back.
Management Science 461 Lecture 2b – Shortest Paths September 16, 2008.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
Shortest Paths and Dijkstra's Algorithm CS 110: Data Structures and Algorithms First Semester,
Directed Graph Algorithms CSE 373 Data Structures Lecture 14.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
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.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
The Shortest Path Problem
Dijkstra's algorithm.
More Graph Algorithms 15 April Applications of Graphs Graph theory is used in dealing with problems which have a fairly natural graph/network.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
SPANNING TREES Lecture 21 CS2110 – Spring
CSC 213 – Large Scale Programming. Today’s Goals  Discuss what is meant by weighted graphs  Where weights placed within Graph  How to use Graph ’s.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
CSE 326: Data Structures Lecture #20 Graphs I.5 Alon Halevy Spring Quarter 2001.
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
1 Weighted Graphs. 2 Outline (single-source) shortest path –Dijkstra (Section 4.4) –Bellman-Ford (Section 4.6) (all-pairs) shortest path –Floyd-Warshall.
A Introduction to Computing II Lecture 16: Dijkstra’s Algorithm Fall Session 2000.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
CSE 326: Data Structures Lecture #23 Dijkstra and Kruskal (sittin’ in a graph) Steve Wolfman Winter Quarter 2000.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Shortest Path -Prim’s -Djikstra’s. PRIM’s - Minimum Spanning Tree -A spanning tree of a graph is a tree that has all the vertices of the graph connected.
Graphs – Part III CS 367 – Introduction to Data Structures.
Shortest Paths.
Cinda Heeren / Geoffrey Tien
Shortest Path Problems
Shortest Path Problems
Graphs & Graph Algorithms 2
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Shortest Paths.
CSE373: Data Structures & Algorithms Lecture 18: Dijkstra’s Algorithm
A* Path Finding Ref: A-star tutorial.
4-4 Graph Theory Trees.
Hannah Tang and Brian Tjaden Summer Quarter 2002
Shortest Path Problems
Shortest Path Problems
Shortest Path Algorithms
Slide Courtesy: Uwash, UT
CSE 373: Data Structures and Algorithms
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
CSE 373: Data Structures and Algorithms
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
Weighted Graphs & Shortest Paths
Shortest Path Problems
CSE332: Data Abstractions Lecture 17: Shortest Paths
CSE 373 Data Structures and Algorithms
Slide Courtesy: Uwash, UT
Shortest Path Problems
Shortest Paths.
CSE 417: Algorithms and Computational Complexity
Dijkstra's Shortest Path Algorithm
CSE 373: Data Structures and Algorithms
Lecture 12 Shortest Path.
Richard Anderson Spring 2016
CSE 373: Data Structures and Algorithms
Graphs: Shortest path and mst
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Directed Graphs (Part II)
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

CSE 373: Data Structures and Algorithms Lecture 22: Graphs IV

Dijkstra's algorithm Dijkstra's algorithm: finds shortest (minimum weight) path between a particular pair of vertices in a weighted directed graph with nonnegative edge weights solves the "one vertex, shortest path" problem basic algorithm concept: create a table of information about the currently known best way to reach each vertex (distance, previous vertex) and improve it until it reaches the best solution in a graph where: vertices represent cities, edge weights represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and any other

Dijkstra pseudocode Dijkstra(v1, v2): for each vertex v: // Initialization v's distance := infinity. v's previous := none. v1's distance := 0. List := {all vertices}. while List is not empty: v := remove List vertex with minimum distance. mark v as known. for each unknown neighbor n of v: dist := v's distance + edge (v, n)'s weight. if dist is smaller than n's distance: n's distance := dist. n's previous := v. reconstruct path from v2 back to v1, following previous pointers.

Example: Initialization  Distance(source) = 0 Distance (all vertices but source) = A 2 B  4 1 3 10 C 2 D 2 E    5 8 4 6 F 1 G   Pick vertex in List with minimum distance.

Example: Update neighbors' distance 2 A 2 B 4 1 3 10 C 2 D 2 E   1 5 8 4 6 Distance(B) = 2 F 1 G Distance(D) = 1  

Example: Remove vertex with minimum distance G F B E C D 4 1 2 10 3 6 8 5  Pick vertex in List with minimum distance, i.e., D

Example: Update neighbors 2 A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 Distance(C) = 1 + 2 = 3 Distance(E) = 1 + 2 = 3 Distance(F) = 1 + 8 = 9 Distance(G) = 1 + 4 = 5 F 1 G 9 5

Example: Continued... Pick vertex in List with minimum distance (B) and update neighbors 2 A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 Note : distance(D) not updated since D is already known and distance(E) not updated since it is larger than previously computed F 1 G 9 5

Example: Continued... Pick vertex List with minimum distance (E) and update neighbors 2 A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 F 1 G No updating 9 5

Example: Continued... Pick vertex List with minimum distance (C) and update neighbors 2 A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 Distance(F) = 3 + 5 = 8 F 1 G 8 5

Example: Continued... Pick vertex List with minimum distance (G) and update neighbors 2 A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 F 1 G Previous distance 6 5 Distance(F) = min (8, 5+1) = 6

Example (end) 2 A 2 B 4 1 3 10 C 2 D 2 E 3 3 1 5 8 4 6 F 1 G 6 5 Pick vertex not in S with lowest cost (F) and update neighbors

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

“Cloudy” Proof: The Idea Next shortest path from inside the known cloud Least cost node v THE KNOWN CLOUD competitor v' Source If the path to v is the next shortest path, the path to v' must be at least as long. Therefore, any path through v' to v cannot be shorter!