previous | start | next

Data Structures for Topological Sort

First we have to represent the graph. Note that the in-degrees are not stored in the representation.

Next, the in-degrees will be computed in a separate data structure: degreeOf.

An additional separate data structure will be used to hold vertices that are ready to be output: zeroDegree

The graph can be represented by a HashMap whose keys are the graph vertices and whose values are LinkedLists of the adjacent vertices.

Using HashMap and LinkedList to represent the graph



previous | start | next