CS 253: Algorithms. Chapter 24. Shortest Paths. Credit: Dr. George Bebis

Similar documents
CS 4407 Algorithms Lecture: Shortest Path Algorithms

Design and Analysis of Algorithms

Lecture 11. Single-Source Shortest Paths All-Pairs Shortest Paths

Introduction to Algorithms

Introduction to Algorithms

Introduction to Algorithms

Introduction to Algorithms

Shortest Paths. CS 320, Fall Dr. Geri Georg, Instructor 320 ShortestPaths 3

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

Shortest Path Algorithms

Single Source Shortest Paths

Single Source Shortest Paths

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

BFS Dijkstra. Oct abhi shelat

Data Structures and and Algorithm Xiaoqing Zheng

Slides credited from Hsueh-I Lu & Hsu-Chun Hsiao

Algorithm Design and Analysis

Myriad of applications

A faster algorithm for the single source shortest path problem with few distinct positive lengths

Query Processing in Spatial Network Databases

Introduction to Algorithms

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

Lecture Notes for Chapter 25: All-Pairs Shortest Paths

COMP251: Bipartite graphs

L feb abhi shelat

Algorithms Booklet. 1 Graph Searching. 1.1 Breadth First Search

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

Greedy Alg: Huffman abhi shelat

Examination paper for TDT4120 Algorithms and Data Structures

Design and Analysis of Algorithms

COMP251: Bipartite graphs

Algorithm Design and Analysis

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Contents Lecture 4. Greedy graph algorithms Dijkstra s algorithm Prim s algorithm Kruskal s algorithm Union-find data structure with path compression

Algorithms: Lecture 12. Chalmers University of Technology

CS 161: Design and Analysis of Algorithms

Dynamic Programming: Shortest Paths and DFA to Reg Exps

CS781 Lecture 3 January 27, 2011

6.889 Lecture 4: Single-Source Shortest Paths

CS 6301 PROGRAMMING AND DATA STRUCTURE II Dept of CSE/IT UNIT V GRAPHS

Discrete Optimization 2010 Lecture 3 Maximum Flows

A Simple Implementation Technique for Priority Search Queues

NP-completeness. Chapter 34. Sergey Bereg

from notes written mostly by Dr. Matt Stallmann: All Rights Reserved

Analysis of Algorithms I: All-Pairs Shortest Paths

Partha Sarathi Mandal

Minimum Spanning Trees

Routing Algorithms. CS60002: Distributed Systems. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

CS 410/584, Algorithm Design & Analysis, Lecture Notes 4

Breadth-First Search of Graphs

25. Minimum Spanning Trees

25. Minimum Spanning Trees

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CS Data Structures and Algorithm Analysis

CS 580: Algorithm Design and Analysis

Mon Tue Wed Thurs Fri

ICS 252 Introduction to Computer Design

8 Priority Queues. 8 Priority Queues. Prim s Minimum Spanning Tree Algorithm. Dijkstra s Shortest Path Algorithm

ne a priority queue for the nodes of G; ile (! PQ.is empty( )) select u PQ with d(u) minimal and remove it; I Informatik 1 Kurt Mehlhorn

Part IA Algorithms Notes

Decision Mathematics D1 Advanced/Advanced Subsidiary. Tuesday 9 June 2015 Morning Time: 1 hour 30 minutes

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

2 GRAPH AND NETWORK OPTIMIZATION. E. Amaldi Introduction to Operations Research Politecnico Milano 1

Scribes: Po-Hsuan Wei, William Kuzmaul Editor: Kevin Wu Date: October 18, 2016

CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms

All-Pairs Shortest Paths

Matching Residents to Hospitals

Multi-Approximate-Keyword Routing Query

On the Complexity of Partitioning Graphs for Arc-Flags

Solutions to Exercises

MA015: Graph Algorithms

Minimum Spanning Trees

cs/ee/ids 143 Communication Networks

An 1.75 approximation algorithm for the leaf-to-leaf tree augmentation problem

Incremental Path Planning

arxiv: v1 [cs.cg] 29 Jun 2012

CSE 4502/5717 Big Data Analytics Spring 2018; Homework 1 Solutions

Lecture XIV MINIMUM COST PATHS

Combinatorial optimization problems

Centrality measures in graphs or social networks

A Note on the Connection between the Primal-Dual and the A* Algorithm

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

IS 709/809: Computational Methods in IS Research Fall Exam Review

CS213d Data Structures and Algorithms

An example of LP problem: Political Elections

Unit 1A: Computational Complexity

CMU Lecture 4: Informed Search. Teacher: Gianni A. Di Caro

Algorithms for Picture Analysis. Lecture 07: Metrics. Axioms of a Metric

2-INF-237 Vybrané partie z dátových štruktúr 2-INF-237 Selected Topics in Data Structures

Graph Search Howie Choset

Lecture 7: Shortest Paths in Graphs with Negative Arc Lengths. Reading: AM&O Chapter 5

Observation 4.1 G has a proper separation of order 0 if and only if G is disconnected.

Transcription:

CS : Algorithms Chapter 4 Shortest Paths Credit: Dr. George Bebis

Shortest Path Problems How can we find the shortest route between two points on a road map? Model the problem as a graph problem: Road map is a weighted graph: vertices = cities edges = road segments between cities edge weights = road distances Goal: find a shortest path between two vertices (cities)

Shortest Path Problem Input: Directed graph G = (V, E) Weight function w : E R s 0 Weight of path p = v 0, v,..., v k w( p) k i w( v i, v i ) Shortest-path weight from u to v: p 9 δ(u, v) = min w(p) : u v if there exists a path from u to v t y 6 4 7 6 x z otherwise Note: there might be multiple shortest paths from u to v

Negative-Weight Edges Negative-weight edges may form negative-weight cycles If such cycles are reachable from the source, then δ(s, v) is not properly defined! Keep going around the cycle, and get w(s, v) = - for all v on the cycle s 0 a -4 c d g y 6 b 8 4-7 e -6 f Therefore, negative-weight edges will not be considred here 4

Cycles Can shortest paths contain cycles? No! Negative-weight cycles Shortest path is not well defined (we will not consider this case) If there is a positive-weight cycle, we can get a shorter path by removing the cycle. Zero-weight cycles? No reason to use them Can remove them and obtain a path with the same weight

Shortest-Paths Notation For each vertex v V: δ(s, v): shortest-path weight d[v]: shortest-path weight estimate Initially, d[v]= d[v] δ(s,v) as algorithm progresses [v] = predecessor of v on a shortest path from s If no predecessor, [v] = NIL induces a tree shortest-path tree s 0 t 6 9 y 4 6 x z 7

Initialization Alg.: INITIALIZE-SINGLE-SOURCE(V, s). for each v V. do d[v]. [v] NIL 4. d[s] 0 All the shortest-paths algorithms start with INITIALIZE-SINGLE-SOURCE 7

Relaxation Step Relaxing an edge (u, v) = testing whether we can improve the shortest path to v found so far by going through u If d[v] > d[u] + w(u, v) we can improve the shortest path to v d[v]=d[u]+w(u,v) [v] u s u v 9 s u 6 After relaxation: d[v] d[u] + w(u, v) v RELAX(u, v, w) RELAX(u, v, w) u v 7 u v 6 no change

Dijkstra s Algorithm Single-source shortest path problem: No negative-weight edges: w(u, v) > 0, (u, v) E Each edge is relaxed only once! Maintains two sets of vertices: d[v]=δ (s, v) d[v]>δ (s, v) 9

Dijkstra s Algorithm (cont.) Vertices in (V S) reside in a min-priority queue Keys in Q are estimates of shortest-path weights d[u] Repeatedly select a vertex u (V S), with the minimum shortestpath estimate d[u] Relax all edges leaving u STEPS ) Extract a vertex u from Q (i.e., u has the highest priority) ) Insert u to S ) Relax all edges leaving u 4) Update Q

Dijkstra (G, w, s) s 0 S=<> Q=<s,t,x,z,y> S=<s> Q=<y,t,x,z> 0 t y 9 7 x 4 6 z s 0 0 t 0 y 9 7 x 4 6 z

Example (cont.) 0 t 0 8 4 9 x 0 t 8 4 9 x s 0 4 6 s 0 4 6 7 y 7 z 7 y 7 z S=<s,y> Q=<z,t,x> S=<s,y,z> Q=<t,x>

Example (cont.) s 0 0 t 8 9 4 6 7 7 y S=<s,y,z,t> Q=<x> 9 x z s 0 0 t 8 9 4 6 7 7 y S=<s,y,z,t,x> Q=<> 9 x z

Dijkstra (G, w, s). INITIALIZE-SINGLE-SOURCE(V, s) (V). S s. Q V[G] 4. while Q O(V) build min-heap Executed O(V) times. do u EXTRACT-MIN(Q) O(lgV) O(VlgV) 6. S S {u} 7. for each vertex v Adj[u] O(E) times (max) 8. do RELAX(u, v, w) O(ElgV) 9. Update Q (DECREASE_KEY) O(lgV) Running time: O(VlgV + ElgV) = O(ElgV)

Dijkstra s SSSP Algorithm (adjacency matrix) a f L [.] = 0 S b c 4 d new L[i] = Min{ L[i], L[k] + W[k, i] } e a 0 b 0 c 0 d 0 4 e 4 0 f 0 where k is the newly-selected intermediate node and W[.] is the distance between k and i

SSSP cont. b a d c new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i 4 f e L [.] = 0 new L [.] = 0 a 0 b 0 c 0 d 0 4 e 4 0 f 0

b a d c new L[i] = Min{ L[i], L[k] + W[k, i] } where k is the newly-selected intermediate node and W[.] is the distance between k and i 4 f e L [.] = 0 new L [.] = 0 a 0 b 0 c 0 d 0 4 e 4 0 f 0

a f L [.] = 0 new L [.] = 0 4 b c 4 e a 0 b 0 d c 0 d 0 4 e 4 0 f 0

a f L [.] = 0 4 new L [.] = 0 4 b c 4 e a 0 b 0 d c 0 d 0 4 e 4 0 f 0

a f L [.] = 0 4 new L [.] = 0 4 b c 4 e a 0 b 0 d c 0 d 0 4 e 4 0 f 0 Running time: O(V ) (adjacency matrix) Which one is better? O(ElgV) (adjacency list)

All-Pairs Shortest Paths Given: Directed graph G = (V, E) Weight function w : E R Compute: The shortest paths between all pairs of vertices in a graph Result: an n n matrix of shortest-path distances δ(u, v) 4 8 7 4 6 9 We can run Dijkstra s algorithm once from each vertex: O(VElgV) with binary heap and adjacency-list representation if the graph is dense O(V lgv) We can achieve O(V ) by using an adjacency-matrix.

Problem We are given a directed graph G=(V, E) on which each edge (u,v) has an associated value r(u,v), which is a real number in the range 0 r(u,v) that represents the reliability of a communication channel from vertex u to vertex v. We interpret r(u,v) as the probability that the channel from u to v will not fail, and we assume that these probabilities are independent. Give an efficient algorithm to find the most reliable path between two given vertices.

Problem (cont.) r(u,v) = Pr(channel from u to v will not fail) Assuming that the probabilities are independent, the reliability of a path p=<v,v,,v k > is: r(v,v ) r(v,v ) r(v k-,v k ) Solution : modify Dijkstra s algorithm Perform relaxation as follows: if d[v] < d[u] w(u,v) then d[v] = d[u] w(u,v) Use EXTRACT_MAX instead of EXTRACT_MIN

Problem (cont.) Solution : use Dijkstra s algorithm without any modifications! We want to find the channel with the highest reliability, i.e., max r( u, v) p ( u, v) p But Dijkstra s algorithm computes Take the log p ( u, v) p min w( u, v) lg(max r( u, v)) max lg( r( u, v)) p ( u, v) p p ( u, v) p

Problem (cont.) Turn this into a minimization problem by taking the negative: p p ( u, v) p ( u, v) p min lg( r( u, v)) min lg( r( u, v)) Run Dijkstra s algorithm using w( u, v) lg( r( u, v))