Click or drag to resize
DirectedCycle Class

The DirectedCycle 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 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 HasCycle operation takes constant time; the Cycle operation takes time proportional to the length of the cycle.

See to compute a topological order if the digraph is acyclic.

Inheritance Hierarchy
SystemObject
  Algs4NetDirectedCycle

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

The DirectedCycle type exposes the following members.

Constructors
  NameDescription
Public methodDirectedCycle
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 the DirectedCycle data type.
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 DirectedCycle implementation by the respective authors.

See Also