Ejemplo n.º 1
0
        public IDictionary <GraphNode <T>, T> DfsConnectedComponents(UndirectedGraph <T> graph)
        {
            _nodeToScc.Clear();

            graph.ClearNodeColors();
            foreach (var node in graph.Nodes)
            {
                if (node.Color == Color.Colored)
                {
                    continue;
                }
                ComponentVisit(node, node.Label, graph.Neighbors);
            }

            return(_nodeToScc);
        }
Ejemplo n.º 2
0
        public static bool IsBipartite(UndirectedGraph <T> graph)
        {
            foreach (var node in graph.Nodes)
            {
                //if a node is colored, it has been assigned to a component and checked
                if (node.Color != Color.Uncolored)
                {
                    continue;
                }

                if (!IsComponentBipartite(graph, node))
                {
                    return(false);
                }
            }
            graph.ClearNodeColors();
            return(true);
        }