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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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 0 3. for every vertex v in G , taken in reverse topologically sorted order 4. do count [ v ] 0 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
Image of page 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.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern