Class CycleFinder<T>


  • public class CycleFinder<T>
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      CycleFinder​(Graph<T> graph)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<T> findCycle()
      Returns a list of vertices constituting a cycle in the graph, or an empty list if no cycle was found.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CycleFinder

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

      • findCycle

        public java.util.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.