Cycle Detection

Download

Download jar file or use maven. psjava requires Java 1.6 (or above)

<dependency>
    <groupId>org.psjava</groupId>
    <artifactId>psjava</artifactId>
    <version>0.1.19</version>
</dependency>

Example Code

// Let's prepare a simple graph.

MutableDirectedUnweightedGraph<String> graph = MutableDirectedUnweightedGraph.create();
graph.insertVertex("A");
graph.insertVertex("B");
graph.insertVertex("C");

graph.addEdge("A", "B");
graph.addEdge("B", "C");
graph.addEdge("C", "B");

boolean hasCycle = CycleDetection.hasCycle(graph); // must be true

See Also

Implementation


Copyright 2014 psjava team. View on GitHub