Click or drag to resize
EdgeWeightedDirectedCycle Class

The EdgeWeightedDirectedCycle class represents a data type for determining whether an edge-weighted digraph has a directed cycle. The HasCycle operation determines whether the edge-weighted digraph has a directed cycle and, if 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 edge-weighted digraph is acyclic.

Inheritance Hierarchy
SystemObject
  Algs4NetEdgeWeightedDirectedCycle

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

The EdgeWeightedDirectedCycle type exposes the following members.

Constructors
  NameDescription
Public methodEdgeWeightedDirectedCycle
Determines whether the edge-weighted digraph G has a directed cycle and, if so, finds such a cycle.
Top
Properties
  NameDescription
Public propertyHasCycle
Does the edge-weighted digraph have a directed cycle?
Top
Methods
  NameDescription
Public methodGetCycle
Returns a directed cycle if the edge-weighted digraph has a directed cycle, and null otherwise.
Public methodStatic memberMainTest
Demo test the EdgeWeightedDirectedCycle data type.
Top
Remarks

For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class EdgeWeightedDirectedCycle implementation by the respective authors.

See Also