This implementation uses a nonrecursive, queue-based algorithm. 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 and cycle operations take constant time.
This implementation uses a nonrecursive, queue-based algorithm. The constructor takes time proportional to V