Question: 6. (10 points) Trace the execution of TopologicalSort algorithm (as given on page 326) on the following graph. Show the graph after each iteration of

6. (10 points) Trace the execution of TopologicalSort algorithm (as given on page 326) on the following graph. Show the graph after each iteration of the while loop, and display the incounter and the currently assigned topological sorting labels at each one of these iterations 9 To review, here is the pseudo-code for the algorithm: Input: A digraph G with n vertices Output: A topological ordering v1, v2, ...n of G 1: function ToPOLOGICALSORT (G) 2 Let S be an initially empty stack 3 for each vertex u of G do Let incounter(u) be the in-degree of u if incounter(u) = 0 then 5: S.push(u) while S is not empty do 8: 9: uS.pop Let u be vertex number i in the topological ordering for each outgoing edge e(u, w of do 12: 13: 14: 15: 16: if i> n then 17: 18 else 19: incounter(w)ncounter(w) -1 if incounter(w) 0 then S.push(w) return v1, U2, Vn return "digraph G has a directed cycle" 6. (10 points) Trace the execution of TopologicalSort algorithm (as given on page 326) on the following graph. Show the graph after each iteration of the while loop, and display the incounter and the currently assigned topological sorting labels at each one of these iterations 9 To review, here is the pseudo-code for the algorithm: Input: A digraph G with n vertices Output: A topological ordering v1, v2, ...n of G 1: function ToPOLOGICALSORT (G) 2 Let S be an initially empty stack 3 for each vertex u of G do Let incounter(u) be the in-degree of u if incounter(u) = 0 then 5: S.push(u) while S is not empty do 8: 9: uS.pop Let u be vertex number i in the topological ordering for each outgoing edge e(u, w of do 12: 13: 14: 15: 16: if i> n then 17: 18 else 19: incounter(w)ncounter(w) -1 if incounter(w) 0 then S.push(w) return v1, U2, Vn return "digraph G has a directed cycle
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
