Class CycleFinder<T>


  • public class CycleFinder<T>
    extends Object

    Applies the three-color algorithm to detect a cycle in a directed graph. If there are multiple cycles, this implementation only detects one of them and does not guarantee that the shortest cycle is found.

    Author:
    gjoranv
    • Constructor Detail

      • CycleFinder

        public CycleFinder​(Graph<T> graph)
    • Method Detail

      • findCycle

        public List<T> findCycle()
        Returns a list of vertices constituting a cycle in the graph, or an empty list if no cycle was found. Only the first encountered cycle is returned.