Data Structures and Algorithms CMPSC 465

Similar documents
Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

6. DYNAMIC PROGRAMMING II. sequence alignment Hirschberg's algorithm Bellman-Ford distance vector protocols negative cycles in a digraph

6. DYNAMIC PROGRAMMING II

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

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

cs/ee/ids 143 Communication Networks

Algorithm Design and Analysis

Running Time. Assumption. All capacities are integers between 1 and C.

Mathematics for Decision Making: An Introduction. Lecture 8

Lecture 2: Divide and conquer and Dynamic programming

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

6. DYNAMIC PROGRAMMING II

Algorithm Design and Analysis

Dynamic Programming: Shortest Paths and DFA to Reg Exps

6. DYNAMIC PROGRAMMING II

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Algorithms: Lecture 12. Chalmers University of Technology

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Single Source Shortest Paths

Design and Analysis of Algorithms

Single Source Shortest Paths

Algorithm Design and Analysis

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

Algorithm Design and Analysis

Part V. Matchings. Matching. 19 Augmenting Paths for Matchings. 18 Bipartite Matching via Flows

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

Theoretical Computer Science. Partially dynamic efficient algorithms for distributed shortest paths

Algorithm Design and Analysis

Algorithm Design and Analysis

Asynchronous Models For Consensus

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

Routing. Topics: 6.976/ESD.937 1

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

Two Applications of Maximum Flow

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Algorithms and Theory of Computation. Lecture 11: Network Flow

Algorithm Design and Analysis

iretilp : An efficient incremental algorithm for min-period retiming under general delay model

1.1 First Problem: Stable Matching. Six medical students and four hospitals. Student Preferences. s6 h3 h1 h4 h2. Stable Matching Problem

6. DYNAMIC PROGRAMMING I

5. Solving the Bellman Equation

CS173 Lecture B, November 3, 2015

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

Section 6 Fault-Tolerant Consensus

Solutions to Exercises

Problem. Problem Given a dictionary and a word. Which page (if any) contains the given word? 3 / 26

Midterm Exam 2 Solutions

Linear Selection and Linear Sorting

Q520: Answers to the Homework on Hopfield Networks. 1. For each of the following, answer true or false with an explanation:

Dantzig s pivoting rule for shortest paths, deterministic MDPs, and minimum cost to time ratio cycles

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

CSE613: Parallel Programming, Spring 2012 Date: May 11. Final Exam. ( 11:15 AM 1:45 PM : 150 Minutes )

CMSC 858F: Algorithmic Game Theory Fall 2010 BGP and Interdomain Routing

Math 391: Midterm 1.0 Spring 2016

Algorithm Design CS 515 Fall 2015 Sample Final Exam Solutions

Models for representing sequential circuits

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

Dynamic Programming. Cormen et. al. IV 15

CSE 202 Dynamic Programming II

CS Algorithms and Complexity

Matching Residents to Hospitals

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

AGREEMENT PROBLEMS (1) Agreement problems arise in many practical applications:

CS505: Distributed Systems

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

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

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

Distributed Optimization. Song Chong EE, KAIST

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

Shortest Path Algorithms

1 Review for Lecture 2 MaxFlow

Distributed Consensus

Sorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort

1. REPRESENTATIVE PROBLEMS

Friday, September 21, Flows

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

6. DYNAMIC PROGRAMMING I

An algebraic framework for a unified view of route-vector protocols

Symmetric Rendezvous in Graphs: Deterministic Approaches

CSC 5170: Theory of Computational Complexity Lecture 4 The Chinese University of Hong Kong 1 February 2010

2.2 Asymptotic Order of Growth. definitions and notation (2.2) examples (2.4) properties (2.2)

Shortest paths: label setting

On Equilibria of Distributed Message-Passing Games

Chapter 8 The Disjoint Sets Class

Agenda. Soviet Rail Network, We ve done Greedy Method Divide and Conquer Dynamic Programming

arxiv: v1 [cs.dc] 10 Feb 2014

CS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs. Instructor: Shaddin Dughmi

CS781 Lecture 3 January 27, 2011

Algorithm Efficiency. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University

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

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

6.852: Distributed Algorithms Fall, Class 10

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Dynamic Programming 1

directed weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time

CS 6901 (Applied Algorithms) Lecture 2

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

6.852: Distributed Algorithms Fall, Class 24

Transcription:

ata Structures and Algorithms MPS LTUR ellman-ford Shortest Paths Algorithm etecting Negative ost ycles Adam Smith // A. Smith; based on slides by K. Wayne,. Leiserson,. emaine L.

Negative Weight dges S A - This graph causes ijkstra s algorithm to fail (incorrectly estimate the distance and shortest path to A) 0//0

Shortest Paths: Negative ost ycles Negative cost cycle. - - 7 Observation. If some path from s to t contains a negative cost cycle, there does not exist a shortest s-t path; otherwise, there exists one that is simple. s W t c(w) < 0

Shortest Paths: ynamic Programming ef. OPT(i, v) = length of shortest v-t path P using at most i edges ( if no such path exists) ase : P uses at most i- edges. OPT(i, v) = OPT(i-, v) ase : P uses exactly i edges. if (v, w) is first edge, then OPT uses (v, w), and then selects best w-t path using at most i- edges OPT(i, v) = 0 or if i = 0 min OPT(i, v), min { OPT(i, w)+ c vw } otherwise (v, w) Remark. y previous observation, if no negative cycles, then OPT(n-, v) = length of shortest v-t path.

Shortest Paths: Implementation Shortest-Path(G, t) { foreach node v V M[0, v] M[0, t] 0 } for i = to n- foreach node v V M[i, v] M[i-, v] foreach edge (v, w) M[i, v] min { M[i, v], M[i-, w] + c vw } Analysis. Θ(mn) time, Θ(n ) space. Finding the shortest paths. Maintain a "successor" for each table entry.

xample of ellman-ford A The demonstration is for a sligtly different version of the algorithm (see LRS) that computes distances from the sourse node rather than distances to the destination node. 0//0

xample of ellman-ford 0 A Initialization. 0//0

xample of ellman-ford 0 7 A Order of edge relaxation. 0//0

xample of ellman-ford 0 7 A 0//0

xample of ellman-ford 0 7 A 0//0

xample of ellman-ford 0 7 A 0//0

xample of ellman-ford - 0 7 A 0//0

xample of ellman-ford - 0 7 A 0//0

xample of ellman-ford - 0 7 A 0//0

xample of ellman-ford - 0 7 A 0//0

xample of ellman-ford - 0 7 A 0//0

xample of ellman-ford - 0 7 A nd of pass. 0//0

xample of ellman-ford - 0 A 7 0//0

xample of ellman-ford - 0 A 7 0//0

xample of ellman-ford - 0 A 7 0//0

xample of ellman-ford - 0 A 7 0//0

xample of ellman-ford - 0 A 7 0//0

xample of ellman-ford - 0 A 7 0//0

xample of ellman-ford - 0 A 7 0//0

xample of ellman-ford - 0 A 7-0//0

xample of ellman-ford - 0 A 7 - nd of pass (and and ). 0//0

Shortest Paths: Improvements Maintain only one array M[v] = length of shortest v-t path found so far. No need to check edges of the form (v, w) unless M[w] changed in previous iteration. Theorem. Throughout the algorithm, M[v] is length of some v-t path, and after i rounds of updates, the value M[v] is no larger than the length of shortest v-t path using i edges. Overall impact. Memory: O(m + n). Running time: O(mn) worst case, but substantially faster in practice.

ellman-ford: fficient Implementation ellman-ford-shortest-path(g, s, t) { foreach node v V { M[v] successor[v] φ } } M[t] = 0 for i = to n- { foreach node w V { if (M[w] has been updated in previous iteration) { foreach node v such that (v, w) { if (M[v] > M[w] + c vw ) { M[v] M[w] + c vw successor[v] w } } } If no M[w] value changed in iteration i, stop. }

istance Vector Protocol ommunication network. Nodes routers. dges direct communication links. ost of edge delay on link. naturally nonnegative, but ellman-ford used anyway! ijkstra's algorithm. Requires global information of network. ellman-ford. Uses only local knowledge of neighboring nodes. Synchronization. We don't expect routers to run in lockstep. The order in which each foreach loop executes in not important. Moreover, algorithm still converges even if updates are asynchronous.

istance Vector Protocol istance vector protocol. ach router maintains a vector of shortest path lengths to every other node (distances) and the first hop on each path (directions). Algorithm: each router performs n separate computations, one for each potential destination node. "Routing by rumor." x. RIP, Xerox XNS RIP, Novell's IPX RIP, isco's IGRP, 's NA Phase IV, AppleTalk's RTMP. aveat. dge costs may change during algorithm (or fail completely). s v t "counting to infinity" deleted

Path Vector Protocols Link state routing. ach router also stores the entire path. not just the distance and first hop ased on ijkstra's algorithm. Avoids "counting-to-infinity" problem and related difficulties. Requires significantly more storage. x. order Gateway Protocol (GP), Open Shortest Path First (OSPF).

etecting Negative ycles: Application urrency conversion. Given n currencies and exchange rates between pairs of currencies, is there an arbitrage opportunity? Remark. Fastest algorithm very valuable! $ /7 F 00 / / /0 /0 IM /0000 70 M

etecting Negative ycles ellman-ford is guaranteed to work if there are no negative cost cycles. How can we tell if neg. cost cycles exist? We could pick a destination vertex t and check if the cost estimates in ellman-ford converge or not. What is wrong with this? (What if a cycle isn t on any path to t?) - - v -

etecting Negative ycles Theorem. an find negative cost cycle in O(mn) time. Add new node t and connect all nodes to t with 0-cost edge. heck if OPT(n, v) = OPT(n-, v) for all nodes v. if yes, then no negative cycles if no, then extract cycle from shortest path from v to t t 0 0 0 0 0 - - v -

etecting Negative ycles Lemma. If OPT(n,v) = OPT(n-,v) for all v, then no negative cycles are connected to t. Pf. If OPT(n,v)=OPT(n-,v) for all v, then distance estimates won t change again even with many executions of the for loop. In particular, OPT(n,v)=OPT(n-,v). So there are no negative cost cycles. Lemma. If OPT(n,v) < OPT(n-,v) for some node v, then (any) shortest path from v to t contains a cycle W. Moreover W has negative cost. Pf. (by contradiction) Since OPT(n,v) < OPT(n-,v), we know P has exactly n edges. y pigeonhole principle, P must contain a directed cycle W. eleting W yields a v-t path with < n edges W has negative cost. v W t c(w) < 0

etecting Negative ycles: Summary ellman-ford. O(mn) time, O(m + n) space. Run ellman-ford for n iterations (instead of n-). Upon termination, ellman-ford successor variables trace a negative cycle if one exists. See p. 0 for improved version and early termination rule.