DirectedCycleX Class |
The DirectedCycleX class represents a data type for determining whether a digraph has a directed cycle. The HasCycle operation determines whether the digraph has a directed cycle and, and of so, the Cycle operation returns one.
This implementation uses a nonrecursive, queue-based algorithm. 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 HasCycle operation takes constant time; the Cycle operation takes time proportional to the length of the cycle.
See for a recursive version that uses depth-first search. See or to compute a topological order when the digraph is acyclic.
Namespace: Algs4Net
public class DirectedCycleX
The DirectedCycleX type exposes the following members.
Name | Description | |
---|---|---|
![]() | DirectedCycleX |
Determines whether the digraph G has a directed cycle and, if so,
finds such a cycle. |
Name | Description | |
---|---|---|
![]() | GetCycle |
Returns a directed cycle if the digraph has a directed cycle, and null otherwise. |
![]() ![]() | MainTest | Demo test for the DirectedCycle class |
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 DirectedCycleX implementation by the respective authors.