Queue-based topological sort.Develop a topological sort implementation that maintains a vertex-indexed array that keeps track of the indegree of each vertex. Initialize the array and a queue of sources in a single pass through all the edges, as in exercise4.2.7. Then, perform the following operations until the source queue is empty:
■ Remove a source from the queue and label it.
■ Decrement the entries in the indegree array corresponding to the destination vertex of each of the removed vertex’s edges.
■ If decrementing any entry causes it to become 0, insert the corresponding vertex onto the source queue.
Exercise 4.2.7:
The indegreeof a vertex in a digraph is the number of directed edges that point to that vertex. The outdegreeof a vertex in a digraph is the number of directed edges that emanate from that vertex. No vertex is reachable from a vertex of outdegree 0, which is called a sink;a vertex of indegree 0, which is called a source,is not reachable from any other vertex. A digraph where self-loops are allowed andevery vertex has outdegree 1 is called a map(a function from the set of integers from 0 to V-1 onto itself). Write a program Degrees.java that implements the following API:
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.