Myriad of applications

Similar documents
Design and Analysis of Algorithms

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Single Source Shortest Paths

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

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

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

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

Single Source Shortest Paths

Analysis of Algorithms I: All-Pairs Shortest Paths

Introduction to Algorithms

Introduction to Algorithms

Introduction to Algorithms

Introduction to Algorithms

Design and Analysis of Algorithms

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

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

Lecture Notes for Chapter 25: All-Pairs Shortest Paths

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

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Greedy algorithms. Shortest paths in weighted graphs. Tyler Moore. Shortest-paths problem. Shortest path applications.

CS4800: Algorithms & Data Jonathan Ullman

Shortest Path Algorithms

Today. Flow review. Augmenting paths. Ford-Fulkerson Algorithm. Intro to cuts (reason: prove correctness)

Data Structures and and Algorithm Xiaoqing Zheng

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

Sparse Fault-Tolerant BFS Trees. Merav Parter and David Peleg Weizmann Institute Of Science BIU-CS Colloquium

Ecient Parallel Algorithms for Computing All Pair. University of Kentucky. Duke University

Algorithm Design and Analysis

arxiv: v1 [math.mg] 25 Aug 2011

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

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

Primitive Digraphs with the Largest Scrambling Index

Clustering Methods without Given Number of Clusters

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Introduction to Algorithms

Problem Set 8 Solutions

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Lecture 21. The Lovasz splitting-off lemma Topics in Combinatorial Optimization April 29th, 2004

Chapter 5 Consistency, Zero Stability, and the Dahlquist Equivalence Theorem

All-Pairs Shortest Paths

Codes Correcting Two Deletions

MA015: Graph Algorithms

Chapter 4. The Laplace Transform Method

LINEAR ALGEBRA METHOD IN COMBINATORICS. Theorem 1.1 (Oddtown theorem). In a town of n citizens, no more than n clubs can be formed under the rules

Reinforcement Learning

RELIABILITY OF REPAIRABLE k out of n: F SYSTEM HAVING DISCRETE REPAIR AND FAILURE TIMES DISTRIBUTIONS

Chapter Landscape of an Optimization Problem. Local Search. Coping With NP-Hardness. Gradient Descent: Vertex Cover

3.1 The Revised Simplex Algorithm. 3 Computational considerations. Thus, we work with the following tableau. Basic observations = CARRY. ... m.

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

New bounds for Morse clusters

Chapter 7. Network Flow. CS 350: Winter 2018

Discrete Optimization 2010 Lecture 3 Maximum Flows

Department of Mechanical Engineering Massachusetts Institute of Technology Modeling, Dynamics and Control III Spring 2002

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

The machines in the exercise work as follows:

c n b n 0. c k 0 x b n < 1 b k b n = 0. } of integers between 0 and b 1 such that x = b k. b k c k c k

Z a>2 s 1n = X L - m. X L = m + Z a>2 s 1n X L = The decision rule for this one-tail test is

Lecture 7: Testing Distributions

Partha Sarathi Mandal

Chip-firing game and a partial Tutte polynomial for Eulerian digraphs

Preemptive scheduling on a small number of hierarchical machines

CS 170: Midterm Exam II University of California at Berkeley Department of Electrical Engineering and Computer Sciences Computer Science Division

List coloring hypergraphs

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

Algorithms Booklet. 1 Graph Searching. 1.1 Breadth First Search

Laplace Transformation

A Constraint Propagation Algorithm for Determining the Stability Margin. The paper addresses the stability margin assessment for linear systems

Math 273 Solutions to Review Problems for Exam 1

March 18, 2014 Academic Year 2013/14

A Study on Simulating Convolutional Codes and Turbo Codes

Optimizing Cost-sensitive Trust-negotiation Protocols

Linear Motion, Speed & Velocity

Advanced methods for ODEs and DAEs

Symmetric Determinantal Representation of Formulas and Weakly Skew Circuits

CHAPTER 6. Estimation

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

Convex Hulls of Curves Sam Burton

Moment of Inertia of an Equilateral Triangle with Pivot at one Vertex

Math 334 Fall 2011 Homework 10 Solutions

SOME RESULTS ON INFINITE POWER TOWERS

NCAAPMT Calculus Challenge Challenge #3 Due: October 26, 2011

4. Connectivity Connectivity Connectivity. Whitney's s connectivity theorem: (G) (G) (G) for special

Efficient Computation of Shortest Paths in Time-Dependent Multi-Modal Networks 1

Competitive Analysis of Task Scheduling Algorithms on a Fault-Prone Machine and the Impact of Resource Augmentation

A Full-Newton Step Primal-Dual Interior Point Algorithm for Linear Complementarity Problems *

Theoretical Computer Science. Optimal algorithms for online scheduling with bounded rearrangement at the end

A SIMPLE NASH-MOSER IMPLICIT FUNCTION THEOREM IN WEIGHTED BANACH SPACES. Sanghyun Cho

Jul 4, 2005 turbo_code_primer Revision 0.0. Turbo Code Primer

CS367 Lecture 3 (old lectures 5-6) APSP variants: Node Weights, Earliest Arrivals, Bottlenecks Scribe: Vaggos Chatziafratis Date: October 09, 2015

Layering as Optimization Decomposition

Root Locus Diagram. Root loci: The portion of root locus when k assume positive values: that is 0

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

Matching. Slides designed by Kevin Wayne.

Chapter 8 Dynamic Programming

Algorithm Design and Analysis

Cumulative Review of Calculus

Social Studies 201 Notes for March 18, 2005

IEOR 3106: Fall 2013, Professor Whitt Topics for Discussion: Tuesday, November 19 Alternating Renewal Processes and The Renewal Equation

MINITAB Stat Lab 3

Transcription:

Shortet Path

Myriad of application Finding hortet ditance between location (Google map, etc.) Internet router protocol: OSPF (Open Shortet Path Firt) i ued to find the hortet path to interchange package between erver (IP) Traffic information ytem Routing in VSLI etc...

Shortet ditance between two point not alway follow human intuition It may depend on many more contrain than the pure geometric one.

Shortet path problem in direct weighted graph Given a digraph G = (V, E) with edge weight w : E R, a path p = {v 0,..., v k } i a equence of conecutive edge, where (v i, v i+ ) E define w(p) = k i=0 w(v i, v i+ ). The hortet path between u and v a δ(u, v) = min p {w(p) u p v} v v v v 4 v 5 - -5 δ(v, v 5 ) = If G i undirected, we can conider every edge a doubly directed. Unweighted, every edge of weight =.

Optimal ubtructure of hortet path Given G = (V, E), w : E R, for any hortet path p : u v and any i, j vertice in p, the ub-path p = i j in p ha the hortet ditance δ(i, j). i j u v Negative cycle u 4 5 v δ(u, v) =

Taxonomy of hortet path problem Single ource hortet path (SSSP): Given G = (V, E), w : E R and V, compute δ(, v), v V {v}. In the graph below we want to compute (, a), (, b), (, c), (, d) All path hortet path (APSP): Given = (V, E), w : E R compute δ(u, v) for every pair (u, v) V V. In the graph below we want to compute (, a), (a, ),... (d, b), (b, d), (d, c), (c, d) a b d c

Single ource hortet path Let u conider the particular cae of having a ource and a ink t Aume that w : e R + Brute-force(G, W,, t) for all imple p : t do compute w(p) end for Compare all p return the p with mallet w(p) The number of path could be O( n ) a d 4 n b t t

Shortet Path Tree SSSP algorithm have the property that at termination the reulting path form a hortet path tree. Given G = (V, E) with edge weight w e and a ditinguihed V, a hortet path tree i a directed ub-tree T = (V, E ) of G,.t. T i rooted at, V i the et of vertice in G reachable from, v V the path v in T i the hortet path δ(, v). a d b c f a d b c f

Triangle Inequality Given G = (V, E), W, if u, v, z V, notice the hortet path u v i any other path between u and v. Therefore. Theorem For all u, v, z V δ(u, v) δ(u, z) + δ(z, v). u v u v δ(u, z) Want minimum z δ(z, y) δ(u, v) - - z Notice, in thi cae δ(u, v) =

Baic technique for SSSP: Relaxation Given G = (V, E), W. v V we maintain a SP-etimate d[v], which i an UB on δ(, v). Initially, tart with d[v] = +, v V {} and d[] = 0. Repeatedly improve etimate toward the goal d[v] = δ(, v). For (u, v) E, Relax(u, v, w(u, v)) if d[v] > d[u] + w(u, v) then d[v] = d[u] + w(u, v) end if d[u] d[v] u w(u,v) v

Generic Relaxation algorithm Relaxation(G, W, ) for all v V {} do d[v] = + end for d[] = 0 while (u, v) with d[v] > d[u] + w(u, v) do Relax(u, v, w(u, v)) end while Lemma For all v V, Relaxation(G, W, ) maintain the invariant that d[v] δ(, v). Proof (Induction) I.H. when applying Relax(u, v, w(u, v)) we get d[u] δ(, u) By the triangle ineq. δ(, v) δ(, u) + δ(u, v) d[u] + w(u, v). Therefore, letting δ(u, v) = d[u] + w(u, v) i not a problem.

Generic Relaxation algorithm a b a b d c d c a b d c a d a b b c d c

Relaxation algorithm Note: If a negative-weight cycle i reachable from, then Relaxation(G, W, ) doe not top. If we apply Relaxation(G, W, ) to the graph in the graph below, we get that the number of tep follow T (n) = T (n ) +, T (n) = Θ( n/ ) 4 5 6 n 0 8 8 8 4 4 4 Prove that indeed the complexity of Relaxation on the above graph i T (n) = Θ( n/ )

Recall: Dktra SSSP E.W.Dktra, A note on two problem in connexion with graph. Num. Mathematik, (959) Greedy algorithm. Relax edge in an increaing ball around. Ue a priority queue Q Dtra doe not work with negative weight Complexity: Fatet SSSP algorithm. Dktra(G, W, ) Initialize SP-etimate on V S =, Q = {V } while Q do u =EXT-MIN(Q) S = S {u} for all v Adj[u] do Relax(u, v, w(u, v)) end for end while Q implementation Wort-time complexity Array O(n ) Heap O(m lg n) Fibonacci heap O(m + n lg n)

Bellman-Ford-Moore SSSP R. Bellman (958) L. Ford (956) E. Moore (957) The algorithm BFM i ued for G with negative weight, but without negative cycle. Given G, w, V (G),with n vertice and m edge, the BFM algorithm doe n iteration: Each iteration i doe a relaxation on all edge than can be reached from in at mot i-tep, the remaining one are et to (e, e,..., e n ), (e }{{}, e,..., e n ), (e }{{}, e,..., e n ) }{{} i= i= i=n

BFM Algorithm Recall that given a graph G, V = n, E = n, and a et of edge weight w with a ource vertex v V, BFM (G, w, ) Initialize v, d[v] =, π[v] = u Initialize d[] = 0 for i = to n do for every (u, v) E do Relax(u, v, w(u, v)) end for end for for every (u, v) E do if d[v] > d[u] + w(u, v) then return Negative-weight cycle end if end for Relax(u, v, w(u, v)) if d[v] > d[u] + w(u, v) then d[v] = d[u] + w(u, v) π[v] = u end if

BFM Algorithm: Example 0 0 8 a 4 g b f e c d Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a b c d e f g

BFM Algorithm: Example 0 0 8 0 a 4 g 8 b f e c d Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a 0 0 0 0 0 0 0 b c d e f g 8 8 8 8 8 8 8

BFM Algorithm: Example 0 0 8 0 a 4 g 8 b f 9 c e d Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a 0 0 0 0 0 0 0 b c d e f 9 9 9 9 9 9 g 8 8 8 8 8 8 8

BFM Algorithm: Example 0 0 8 5 0 a b 4 g f 8 9 c e 8 d Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a 0 0 5 5 5 5 5 b 0 0 0 0 0 c d e 8 8 8 8 8 f 9 9 9 9 9 9 g 8 8 8 8 8 8 8

BFM Algorithm: Example 0 0 8 5 6 a b 4 g f 8 9 c e 7 d Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a 0 0 5 5 5 5 5 b 0 6 0 0 0 c d e 8 7 7 7 7 f 9 9 9 9 9 9 g 8 8 8 8 8 8 8

BFM Algorithm: Example 0 0 8 5 5 7 a b c 4 g f e 8 9 7 d 4 Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a 0 0 5 5 5 5 5 b 0 6 5 5 5 c 7 7 7 d 4 4 4 e 8 7 7 7 7 f 9 9 9 9 9 9 g 8 8 8 8 8 8 8

BFM Algorithm: Example 0 0 8 5 5 6 a b c 4 g f e 8 9 7 d 0 Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a 0 0 5 5 5 5 5 b 0 6 5 5 5 c 7 6 6 d 4 0 4 e 8 7 7 7 7 f 9 9 9 9 9 9 g 8 8 8 8 8 8 8

BFM Algorithm: Example 0 0 8 5 5 6 a b c 4 g f e 8 9 7 d 9 Node i 0 4 5 6 7 0 0 0 0 0 0 0 0 a 0 0 5 5 5 5 5 b 0 6 5 5 5 c 7 6 6 d 4 0 9 e 8 7 7 7 7 f 9 9 9 9 9 9 g 8 8 8 8 8 8 8

Complexity BFM O(n) O() O(m) O(nm) O(m) Complexity T(n)=O(nm)

Correctne of BFM Lemma In the BFM-algorithm, after the ith. iteration we have that d[v] the weight of every path v uing at mot i edge, v V. Proof (Induction on i) Before the ith iteration, d[v] min{w(p)} over all path p with at mot i edge. The relaxation only decreae d[v] The ith iteration conider all path with i edge when relaxing the edge to v. at mot i edge v

Correctne of BFM Theorem If G, w ha no negative weight cycle, then at the end of the BFM-algorithm d[v] = δ(, v). Proof Without negative-weight cycle, hortet path are alway imple. Every imple path ha at mot n vertice and n edge. By the previou lemma, the n iteration yield d[v] δ(, v). By the invariance of the relaxation algorithm d[v] δ(, v).

Correctne of BFM Theorem BFM will report negative-weight cycle if there exit in G. Proof Without negative-weight cycle in G, the previou theorem implie d[v] = δ(, v), and by triangle inequality d[v] δ(, u) + w(u, v), o BFM won t report a negative cycle if it doen t exit. If there i a negative-weight cycle, then one of it edge can be relaxed, o BFM will report correctly.

Shortet path in a direct acyclic graph (dag). Min-cot path in DAG INPUT: Edge weighted dag G = (V, E, w), V = n, w : E R together with given, t V. QUESTION: Find a path P : t of minimum total weight. Notice given a dag G = (V, E), W we wih to find a path P from to t.t. min P () P w. a c 6 b e g

Arranging dag into a line Arrange the dag in topological order, o that all edge go from left to right. Thi can be done in O(n) uing DFS. a c 6 b e f c a 6 b f e DFS

We want to find horter ditance from to v. Let d(v) = ditance v d(f ) = min{d(b)+, d(c)+} The chema i baed on the topological linearity of G. c a b f e 6 Shortet ditance in dag G Initialize d() := 0 and v V {}, d(v) := for all v V {} in linearized order do d(v) := min (u,v) E {d(u) + w uv } end for Complexity? T (n) = O(n)

All pair hortet path: APSP Given G = (V, E), V = n, E = m and a weight w : E R we want to determine u, v V, δ(u, v). We aume we can have w < 0 but G doe not contain negative cycle. Naive idea: We apply O(n) time BFM or Dktra (if there are not negative weight) Repetition of BFM: O(n m) Repetition of Dktra: O(nm lg n) (if Q i implemented by a heap)

All pair hortet path: APSP Unlike in the SSSP algorithm that aumed adjacency-lit repreentation of G, for the APSP algorithm we conider the adjacency matrix repreentation of G. For convenience V = {,,... n}. The n n adjacency matrix W = (w(i, j)) of G, w: 0 if i = j w = w if (i, j) E if i j and (i, j) E

All pair hortet path: APSP The input i a n n adjacency matrix W = (w ) 4 0 4 0 W = 0 4 0 0 0 The output i a n n matrix D = (d ), where d = δ(i, j) For the implementation we alo need to compute the et of predeceor matrix Π k

Bernard-Floyd-Warhall Algorithm R. Bernard: Tranitivité et connexité C.R.Aca. Sci. 959 R. Floyd: Algorithm 97: Shortet Path. CACM 96 S. Warhall: A theorem on Boolean matrice. JACM, 96 The BFW Algorithm ued dynamic programming to compare all poible path between each pair of vertice in G. The algorithm work in O(n ) and the number of edge could be O(n ).

Optimal ubtructure of APSP Recall: Triangle inequality δ(u, v) δ(u, z) + δ(z, v). u δ(u, v) δ(u, z) δ(z, y) z Let p = p, p,..., p }{{ r, p } r and intermediate v. Let d (k) be the hortet i j.t. the intermediate vertice are in {,..., k}. So if k = 0, then d (0) = w. v

The recurrence Let p a hortet path i j with value d (k) If k i not an intermediate vertex of p, then d (k) If k i an intermediate vertex of p, then p = (i,..., k) (k,..., j) }{{}}{{} p p = d (k ) By triangle inequality p i a hortet path i k and p i a hortet path k j. { Therefore d (k) w if k = 0 = min{d (k ), d (k ) ik + d (k ) kj } if k

Bottom-up BFW-algorithm Given G = (V, E), w : E Z without negative cycle, the following DP algo. compute d (n), i, j V : BFW W = (w ) for k = to n do for i = to n do for j = to n do d (k) end for end for end for return d (n) = min{d (k ), d (k ) ik + d (k ) kj } Time complexity: T (n) = O(n ), S(n) = O(n ) but S(n) can be lowered to O(n ) How? Correctne follow from the recurrence argument.

Example 4 0 4 0 0 D (0) = 0 4 0 0 D() = 0 0 0 0 0 0 0 0 0 D () = 0 0 0 D() = 0 0 0 D(4) = 0 0 0 0 0 0 0 0 0 0 0 For intance, d, = (uing vertex ) = 4 (uing all vertice) d 4,

Example 0 NIL NIL NIL D (0) = 0 4 0 0 Π (0) = NIL NIL NIL NIL 0 4 NIL NIL NIL 0 NIL NIL NIL D () = 0 0 0 Π () = NIL NIL NIL NIL 0 0 4 NIL NIL 4 0 4 0 NIL NIL NIL D () = 0 0 0 Π () = NIL NIL NIL NIL 0 0 4 NIL NIL 0 D () = 0 0 0 Π () = 0 0 NIL NIL NIL 4 NIL

Contructing the hortet path We want to contruct the matrix Π = (π ), where π = predeceor of j in hortet i j, we define a equence of matrice Π (0),..., Π (n).t. Π (k) = (π (k) ), i.e. the matrix of lat predeceor in the hortet path i j, which ue only vertice in {,..., k}. { If k = 0: π (k) NIL if i = j or w =, = i if i j and w. For k we get the recurrence: π (k) = { π (k ) π (k ) kj if d (k ) d (k ) ik otherwie. + d (k ) kj,

BFW with path BFW W d (0) = W for k = to n do for i = to n do for j = to n do if d (k) d (k) Π (k) d (k ) = d (k ) = Π (k ), d (k ) ik ele d (k) = d (k ) ik + d (k ) kj Π (k) end if end for end for end for return d (n) = Π (k ) kj Complexity: T (n) = O(n ) + d (k ) kj then

Concluion Dktra BFM BFW w 0 O(m lg n) O(nm) O(n ) w R NO O(nm) O(n ) There exit an algorithm by D. Johnon (978) that work in O(n lg n) for pare graph with negative edge. It ue Dktra a a function. For further reading on hortet path, ee chapter 4 and 5 of Cormen, Leieron, Rivet, Stein: Introduction to Algorithm.