Problem

Queue-based topological sort.Develop a topological sort implementation that maintains a ve...

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:

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 4.2
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT