2
$\begingroup$

Suppose I have a graph GraphPlot[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4, 5->6}] Now I want to identify the vertices of a subgraph which are isolated from the main graph.(In this case subgraph 5->6 since they are not connected to bigger graph). I have a similar case where there is a huge interconnected graph and there are several subgraphs which have 4-5 vertexes and not a part of big graph.

So I want to identify the vertices of these smaller graphs

$\endgroup$
  • $\begingroup$ Please clarify what you mean by "isolated vertex". The usual definition is a zero-degree vertex, of which there aren't any here. $\endgroup$ – Szabolcs Nov 9 '15 at 22:42
  • 1
    $\begingroup$ You've seen ConnectedComponents[]? $\endgroup$ – J. M. is in limbo Nov 9 '15 at 22:53
  • 1
    $\begingroup$ ... WeaklyConnectedComponents? $\endgroup$ – kglr Nov 9 '15 at 23:01
1
$\begingroup$

Perhaps, you can use Graph and the first (largest) element of WeaklyConnectedComponents:

g1 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4, 
   5 -> 6}, VertexShapeFunction -> "Name"]

Mathematica graphics

wcc = WeaklyConnectedComponents[g1]

{{4, 1, 2, 3}, {5, 6}}

Subgraph[g1, wcc[[1]], VertexShapeFunction -> "Name"]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.