Topological Class |
The Topological class represents a data type for determining a topological order of a directed acyclic graph (DAG). Recall, a digraph has a topological order if and only if it is a DAG. The HasOrder operation determines whether the digraph has a topological order, and if so, the Order operation returns one.
This implementation uses depth-first search. The constructor takes time proportional to V + E (in the worst case), where V is the number of vertices and E is the number of edges. Afterwards, the HasOrder and Rank operations takes constant time; the Order operation takes time proportional to V.
See , , and to compute a directed cycle if the digraph is not a DAG. Also, see for a nonrecursive queue-based algorithm to compute a topological order of a DAG.
Namespace: Algs4Net
public class Topological
The Topological type exposes the following members.
Name | Description | |
---|---|---|
![]() | Topological(Digraph) |
Determines whether the digraph G has a topological order and, if so,
finds such a topological order. |
![]() | Topological(EdgeWeightedDigraph) |
Determines whether the edge-weighted digraph G has a topological
order and, if so, finds such an order. |
Name | Description | |
---|---|---|
![]() ![]() | MainTest |
Demo test the Topological data type. |
![]() | Order |
Returns a topological order if the digraph has a topologial order,
and null otherwise. |
![]() | Rank |
The the rank of vertex v in the topological order;
-1 if the digraph is not a DAG |
For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class Topological implementation by the respective authors.