lec16 - n CS 323 Lecture 16 o Design and Analysis of...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n CS 323 Lecture 16 o Design and Analysis of Algorithms Hoeteck Wee · hoeteck@cs.qc.cuny.edu http://www.cs.qc.edu/~hoeteck/f09/ Detecting a Negative Cycle BELLMAN-FORD I Input: weighted, directed graph G = ( V , E ) , start node s , destination t . I each edge e has a cost/weight/length ce and no negative cycles I Output: the shortest directed path from s to t or a negative cycle I Running time: O ( mn ) time SUBPROBLEM I opt [ i , v ] : cost of shortest v- t path using at most i hops I recursion: opt [ i , v ] = min { c ( v , w ) + opt [ i- 1 , w ] | ( v , w ) ∈ E } I no negative cycles ⇒ need at most n- 1 hops i.e. opt [ n , v ] = opt [ n- 1 , v ] for all nodes v I ∃ negative cycle ⇒ ∃ node v such that opt [ n , v ] < opt [ n- 1 , v ] then, shortest path from v to t with n hops contains a negative cycle Hoeteck Wee CS 323 Nov 9, 2009 2 / 5 Computing the minimum PROBLEM. compute the minimum of n numbers p ( ) , . . . , p ( n- 1 ) ....
View Full Document

Page1 / 11

lec16 - n CS 323 Lecture 16 o Design and Analysis of...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online