Click or drag to resize
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.

Inheritance Hierarchy
SystemObject
  Algs4NetDirectedCycleX

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class DirectedCycleX

The DirectedCycleX type exposes the following members.

Constructors
  NameDescription
Public methodDirectedCycleX
Determines whether the digraph G has a directed cycle and, if so, finds such a cycle.
Top
Properties
  NameDescription
Public propertyHasCycle
Does the digraph have a directed cycle?
Top
Methods
  NameDescription
Public methodGetCycle
Returns a directed cycle if the digraph has a directed cycle, and null otherwise.
Public methodStatic memberMainTest
Demo test for the DirectedCycle class
Top
Remarks

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.

See Also