hw11s.f11

hw11s.f11 - ECE608, Homework #11 Solution (1) CLR 24.1-3...

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: ECE608, Homework #11 Solution (1) CLR 24.1-3 The proof of Lemma 24.2 shows that for every v , d [ v ] has attained its final value after length (any shortest-weight path to v ) iterations of Bellman-Ford . Thus after m passes, Bellman-Ford can terminate. We don’t know m in advance, so we can’t make the algorithm loop exactly m times and then terminate. But if we just make the algorithm stop when nothing changes any more, it will stop after m +1 iterations (i.e., after one iteration without a change), unless there is a negative weight cycle. Hence, we should also make sure that the number of iterations does not exceed | V [ G ] | − 1. BELLMAN-FORD-( M + 1)( G,w,s ) 1. INITIALIZE-SINGLE-SOURCE ( G,s ) 2. changes ← True 3. iteration ← 1 4. while ( changes = True ) ∧ ( iteration ≤ | V [ G ] | − 1) 5. do changes ← False 6. iteration ← iteration + 1 7. for each edge ( u,v ) ∈ E [ G ] 8. do Relax-M ( u,v,w ) 9. for each edge ( u,v ) ∈ E [ G ] 10. do if d [ v ] > d [ u ] + w ( u,v ) 11. then return FALSE 12. return TRUE Relax-M ( u,v,w ) 1. if d [ v ] > d [ u ] + w ( u,v ) 2. then d [ v ] ← d [ u ] + w ( u,v ) 3. π [ v ] ← u 4. changes ← True (2) CLR 24.1-4 Change line 7 of the BELLMAN-FORD algorithm, as given in the CLR text, to: then d [ v ] ← −∞ (3) CLR 24.2-4 Consider a node v in a directed acyclic graph G . The paths in G starting from v must go from any outgoing edge from v . Let < V,u ) be one of such edges, then the paths starting from v and containing ( v,u ) can either stop at u or continue from u 1 to some other vertices. Since G is a directed acyclic graph, any edge can only appear at most once in any path. We can thus conclude that the number of paths starting from v and containing ( v,u ) equals the number of paths starting from u plus one. We give the algorithm for calculating the total number of paths in G below. DAG-COUNTPATHS-( G ) 1. topologically sort the vertices of G 2. totalcount ← 3. for every vertex v in G , taken in reverse topologically sorted order 4. do count [ v ] ← 5. for each u ∈ Adj [ v ] 6. do count [ v ] ← count [ v ] + count [ u ] + 1 7. totalcount ← totalcount + count [ v ] The running time of this algorithm is Θ( V + E ). (4) CLR 24.3-2 Consider the graph below: a26a25 a27a24 a26a25 a27a24 a26a25 a27a24 a26a25 a27a24 a45 a45 a54 a64 a64 a64 a64 a64 a64 a82 a82 1 3-7 4 2 s t u x The predecessor subgraph returned by Dijkstra ’s algorithm will look like this: 2 a26a25 a27a24 a26a25 a27a24 a26a25 a27a24 a26a25 a27a24 a54 a64 a64 a64 a64 a64 a64 a82 a82-7 4 2 s t u x The correct answer should use the path s → x → t → u instead of s → u , since δ ( s,u ) = 0....
View Full Document

This note was uploaded on 01/10/2012 for the course ECE 565 taught by Professor Pai during the Fall '11 term at Purdue.

Page1 / 7

hw11s.f11 - ECE608, Homework #11 Solution (1) CLR 24.1-3...

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