You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mark Junker edited this page Jun 7, 2018
·
1 revision
A strongly connected component of a graph is a set of vertices such that for each pair u,v of vertices in the component, there exists a path from u to v and v to u.
This algorithm sorts the vertices in the different strongly connected components of the graph. It is implemented by the StronglyConnectedComponentsAlgorithm which uses the DepthFirstSearchVertexAlgorithm internally. Again, AlgorithmExtensions contains extension methods that hides these implementation details for you.
The concept of strong connectivity is very important in many algorithms because it means there is always “a way back”. For example, one expects that the directed graph that represent the different states of a dialog window is strongly connected, i.e. the user can always go back or undo.
This sample shows how to compute and display the component information from a directed graph:
IVertexListGraph<Vertex,Edge>g=…;IDictionary<Vertex,int>components=newDictionary<Vertex,int>();intcomponentCount=g.StronglyConnectedComponents(components);if(componentCount!=0){Console.WriteLine(“Warningthe graph is not stronglyconnected”);foreach(KeyValuePair<Vertex,int>kvin components)
Console.WriteLine("{0}-{1}",kv.Value,kv.Key);}