(Solved) : Excrcise Toposort Suppose Graph Represented Dictionary G Whose Keys Integers Whose Values Q32518916 . . .
![Excrcise on Toposort: Suppose a graph is represented as a dictionary G,whose keys are integers, and whose values are lists of intcgcrs. If a G contains the dictionary item i:I, it mcans that (G has a node i with outgoing arcs from i to each member of L 1. Write a Python function inDegrees satisfying the following specification: if G is a graph, then inDegrees(G) is a dictionary with the same keys as G, such that G[] is the number of arcs in G that lead into i (that is, the number of parents of i in G). 2. If G is a directed graph with N nodes and E edges, the function inDegree can be implemented to run in worst case O(N+E) time, even though the outer loop has N iterations, and the inner loop has E iterations in the worst case (which, on its face suggests OON E time complexity). How can this be? 3. Write a Python function toposort satisfying the following: if G is a graph, then toposor(G) is a list of the nodes of G in topological order if one exists, and None otherwise. Use inDegrees as a helper. You are free to look at the pseudode in the slides as you write your code (the pseudocode will also be available on the test, if this question appears). 4. What is the time complexity of the standard algorithm for toposort?](../../../media.cheggcdn.com/media/428/428c361c-ad0e-46ce-965a-93459e12cbd2/phpcXDoiZ.png)
Excrcise on Toposort: Suppose a graph is represented as a dictionary G,whose keys are integers, and whose values are lists of intcgcrs. If a G contains the dictionary item i:I, it mcans that (G has a node i with outgoing arcs from i to each member of L 1. Write a Python function inDegrees satisfying the following specification: if G is a graph, then inDegrees(G) is a dictionary with the same keys as G, such that G[] is the number of arcs in G that lead into i (that is, the number of parents of i in G). 2. If G is a directed graph with N nodes and E edges, the function inDegree can be implemented to run in worst case O(N+E) time, even though the outer loop has N iterations, and the inner loop has E iterations in the worst case (which, on its face suggests OON E time complexity). How can this be? 3. Write a Python function toposort satisfying the following: if G is a graph, then toposor(G) is a list of the nodes of G in topological order if one exists, and None otherwise. Use inDegrees as a helper. You are free to look at the pseudode in the slides as you write your code (the pseudocode will also be available on the test, if this question appears). 4. What is the time complexity of the standard algorithm for toposort? Show transcribed image text
Expert Answer
Answer to Excrcise Toposort Suppose Graph Represented Dictionary G Whose Keys Integers Whose Values Q32518916 . . .
OR