Chapter 9: Graphs Shortest Paths

Slides:



Advertisements
Similar presentations
Chapter 9: Graphs Topological Sort
Advertisements

Chapter 9: Graphs Shortest Paths
Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Chapter 9: Graphs Scheduling Networks Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Breadth-First and Depth-First Search
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
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 Shortest Path Algorithms Given a graph G = (V, E) and a distinguished vertex s, find the shortest weighted path from s to every other vertex in G. weighted.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Chapter 9: Graphs Summary Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Graphs. Graphs Many interesting situations can be modeled by a graph. Many interesting situations can be modeled by a graph. Ex. Mass transportation system,
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.
Shortest path algorithm. Introduction 4 The graphs we have seen so far have edges that are unweighted. 4 Many graph situations involve weighted edges.
Applications of Depth-First Search
Chapter 4: Trees AVL Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Shortest Path Problem For weighted graphs it is often useful to find the shortest path between two vertices Here, the “shortest path” is the path that.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Chapter 6: Priority Queues
Chapter 9: Graphs Basic Concepts
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
1 Shortest Path Calculations in Graphs Prof. S. M. Lee Department of Computer Science.
Dijkstra's algorithm.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
CS 146: Data Structures and Algorithms July 21 Class Meeting
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
1 WEEK 9-10 Graphs II Unweighted Shortest Paths Dijkstra’s Algorithm Graphs with negative costs Acyclic Graphs Izmir University of Economics.
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.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs and Paths Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss Chapter 14 © 2002 Addison Wesley.
CSE 373 Topological Sort Graph Traversals
Data Structures, Algorithms & Complexity
Cinda Heeren / Geoffrey Tien
Shortest Path Problems
Unweighted Shortest Path Neil Tang 3/11/2010
Short paths and spanning trees
CSC 172 DATA STRUCTURES.
Graphs Representation, BFS, DFS
Minimum Spanning Tree Neil Tang 3/25/2010
Chapter 22: Elementary Graph Algorithms I
Chapter 9: Graphs Basic Concepts
Dijkstra’s Shortest Path Algorithm Neil Tang 03/25/2008
Shortest Path Problems
Yan Shi CS/SE 2630 Lecture Notes
Shortest Path Algorithms
Minimum Spanning Tree Neil Tang 4/3/2008
Slide Courtesy: Uwash, UT
CSE 373: Data Structures and Algorithms
Algorithms: Design and Analysis
Dijkstra’s Shortest Path Algorithm Neil Tang 3/2/2010
CSE 373 Data Structures and Algorithms
A vertex u is reachable from vertex v iff there is a path from v to u.
Slide Courtesy: Uwash, UT
Graph Algorithms: Shortest Path
Data structure for graph algorithms: Adjacent list, Adjacent matrix
Chapter 9: Graphs Basic Concepts
Chapter 9: Graphs Spanning Trees
Presentation transcript:

Chapter 9: Graphs Shortest Paths Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Chapter 9: Graphs Shortest Paths Lydia Sinapova, Simpson College

Shortest Paths Shortest Paths in Unweighted Graphs Shortest Paths in Weighted Graphs - Dijkstra’s Algorithm Animation

Unweighted Directed Graphs V1 V2 V3 V4 V5 V6 V7 What is the shortest path from V3 to V5?

Problem Data The problem: Given a source vertex s, find the shortest path to all other vertices. Data structures needed: Graph representation: Adjacency lists / adjacency matrix Distance table: distances from source vertex paths from source vertex

Example Let s = V3, stored in a queue Initialized distance table: distance parent V1 -1 -1 V2 -1 -1 V3 0 0 V4 -1 -1 V5 -1 -1 V6 -1 -1 V7 -1 -1 Adjacency lists : V1: V2, V4 V2: V4, V5 V3: V1, V6 V4: V3, V5, V6, V7 V5: V7 V6: - V7: V6

Breadth-first search in graphs Take a vertex and examine all adjacent vertices. Do the same with each of the adjacent vertices .

Algorithm Store s in a queue, and initialize distance = 0 in the Distance Table 2. While there are vertices in the queue: Read a vertex v from the queue     For all adjacent vertices w : If distance = -1 (not computed) Distance = (distance to v) + 1 Parent = v Append w to the queue

Complexity Matrix representation: O(|V|2)   Adjacency lists - O(|E| + |V|) We examine all edges (O(|E|)), and we store in the queue each vertex only once (O(|V|)).

Weighted Directed Graphs V1 V2 V3 V4 V5 V6 V7 What is the shortest distance from V3 to V7?

Comparison Differences: Similar to the algorithm for unweighted graphs Differences: weights are included in the graph representation priority queue : the node with the smallest distance is chosen for processing distance is not any more the number of edges, instead it is the sum of weights Distance table is updated if newly computed distance is smaller.

Algorithm 1. Store s in a priority queue with distance = 0 2. While there are vertices in the queue DeleteMin a vertex v from the queue For all adjacent vertices w: Compute new distance Store in / update Distance table Insert/update in priority queue

Processing Adjacent Nodes For all adjacent vertices w: Compute new distance = (distance to v) + (d(v,w)) If distance = -1 (not computed) store new distance in table path = v Insert w in priority queue If old distance > new distance Update old_distance = new_distance Update path = v Update priority in priority queue

Complexity O(E logV + V logV) = O((E + V) log(V))   Each vertex is stored only once in the queue – O(V) DeleteMin operation is : O( V logV ) Updating the priority queue – search and inseart: O(log V) performed at most for each edge: O(E logV)

Historical Notes Invented by Edsger Dijkstra in 1955   http://www.cs.utexas.edu/users/EWD/