Returns a directed cycle if the digraph has a directed cycle, and [] otherwise.
a directed cycle if the digraph has a directed cycle, and [] otherwise.
Does the digraph have a directed cycle?
true if the digraph has a directed cycle, false otherwise.
Generated using TypeDoc
The DirectedCycle class represents a data type for determining whether the underlying 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.
Be aware that this algorithm just detects whethere there is at least one cycle. So if there are several cycles,DirectedCycle returns only one of them without any guarantee which one.
Underlying digraph is anylized during creating instance of DirectedCycle. It means that if you have another digraph or even if you've changed underlying digraph after creating an instance of DirectedCycle, you should create new instance of DirectedCycle for new/changed digraph. Graph analysis runs in O(E + V) time during the instance creating. Than running times of hasCycle and cycle are O(1).For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.