// implements Kosaraju's algorithm (https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm) public IDictionary <GraphNode <T>, T> KosarajuScc(DirectedGraph <T> graph) { _nodeToScc.Clear(); _visitOrder = new LinkedList <GraphNode <T> >(); foreach (var node in graph.Nodes) { Visit(graph, node); } graph.ClearNodeColors(); var inNeighbors = graph.GetInNeighbors(); foreach (var node in _visitOrder) { if (node.Color == Color.Colored) { continue; } ComponentVisit(node, node.Label, inNeighbors); } return(_nodeToScc); }
public List <GraphNode <T> > GetDepthFirstOrder(DirectedGraph <T> graph) { graph.ClearNodeColors(); _dfsOrder.Clear(); foreach (var node in graph.Nodes) { if (node.Color == Color.Colored) { continue; } DfsVisit(graph, node); } return(_dfsOrder); }