Click or drag to resize
Cycle Class

The Cycle class represents a data type for determining whether an undirected graph has a cycle. The HasCycle operation determines whether the graph has a cycle and, if so, the GetCycle 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.

Inheritance Hierarchy
SystemObject
  Algs4NetCycle

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

The Cycle type exposes the following members.

Constructors
  NameDescription
Public methodCycle
Determines whether the undirected graph G has a cycle and, if so, finds such a cycle.
Top
Properties
  NameDescription
Public propertyHasCycle
Returns true if the graph G has a cycle.
Top
Methods
  NameDescription
Public methodGetCycle
Returns a cycle in the graph G. A property in place of a method would be better; however the compiler will not allow a property having the same name as the defining class.
Public methodStatic memberMainTest
Demo test the Cycle data type.
Top
Remarks

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

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

See Also