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.
Namespace: Algs4Net
public class Cycle
The Cycle type exposes the following members.
Name | Description | |
---|---|---|
![]() | Cycle | Determines whether the undirected graph G has a cycle and,
if so, finds such a cycle. |
Name | Description | |
---|---|---|
![]() | GetCycle |
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.
|
![]() ![]() | MainTest |
Demo test the Cycle data type. |
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.