# DS11_Ch09c - 3 Shortest Path Algorithms Graphs with...

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

§3 Shortest Path Algorithms Graphs with Negative Edge Costs Hey I have a good idea: why don’t we simply add a constant to each edge and thus remove negative edges? Too simple, and naïve… Try this one out: 1 3 4 2 2 – 2 2 1 void WeightedNegative( Table T ) { /* T is initialized by Figure 9.30 on p.303 */ Queue Q; Vertex V, W; Q = CreateQueue (NumVertex ); MakeEmpty( Q ); Enqueue( S, Q ); /* Enqueue the source vertex */ while ( !IsEmpty( Q ) ) { V = Dequeue( Q ); for ( each W adjacent to V ) if ( T[ V ].Dist + Cvw < T[ W ].Dist ) { T[ W ].Dist = T[ V ].Dist + Cvw; T[ W ].Path = V; if ( W is not already in Q ) Enqueue( W, Q ); } /* end-if update */ } /* end-while */ DisposeQueue( Q ); /* free memory */ } /* negative-cost cycle will cause indefinite loop */ /* no longer once per edge */ /* each vertex can dequeue at most |V| times */ T = O( |V| × |E| ) 1/15

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

View Full Document
§3 Shortest Path Algorithms Acyclic Graphs If the graph is acyclic, vertices may be selected in topological order since when a vertex is selected, its distance can no longer be lowered without any incoming edges from unknown nodes. T = O( |E| + |V| ) and no priority queue is needed. Application: AOE ( Activity On Edge ) Networks —— scheduling a project v j a i ::= activity Signals the completion of a i EC[ j ] \ LC[ j ] ::= the earliest \ latest completion time for node v j CPM ( Critical Path Method ) Lasting Time Slack Time EC Time LC Time Index of vertex 2/15
§3 Shortest Path Algorithms 〖 Example 〖 AOE network of a hypothetical project 0 1 2 3 4 5 6 7 8 start finish a0=6 a1=4 a2=5 a3=1 a4=1 a5=2 a6=9 a7=7 a8=4 a9=2 a10=4 Calculation of EC : Start from v0, for any a i = <v, w>, we have } ] [ { max ] [ , ) , ( w v E w v C v EC w EC + = 0 6 4 5 7 7 16 14 18 a11=0 Dummy activity Calculation of LC :

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

DS11_Ch09c - 3 Shortest Path Algorithms Graphs with...

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

View Full Document
Ask a homework question - tutors are online