Class DirectedGraphs

java.lang.Object
io.aleph0.yap.core.util.DirectedGraphs

public final class DirectedGraphs extends Object
  • Method Details

    • isWeaklyConnected

      public static boolean isWeaklyConnected(Map<String,Set<String>> graph)
      Checks if the given directed graph is weakly connected.

      A directed graph is weakly connected if there is a path between any two nodes when ignoring the direction of the edges.

      Parameters:
      graph - the directed graph represented as an adjacency list. Each key is a node, and the value is a set of nodes that point to it.
      Returns:
      true if the graph is weakly connected, false otherwise
    • findCycle

      public static Optional<List<String>> findCycle(Map<String,Set<String>> graph)
      Finds some cycle in the given directed graph, if any exist. Otherwise, returns empty. Only ones cycle is returned, even if multiple cycles exist. There is no guarantee made regarding which cycle is returned, only that one is returned if any exist.
      Parameters:
      graph - the directed graph represented as an adjacency list. Each key is a node, and the value is a set of nodes that point to it.
      Returns:
      an optional containing a list of nodes in the cycle if one exists, or an empty optional if no cycle exists