# Deleting Isolated subgraph in a graph

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

• Please clarify what you mean by "isolated vertex". The usual definition is a zero-degree vertex, of which there aren't any here. Commented Nov 9, 2015 at 22:42
• You've seen ConnectedComponents[]? Commented Nov 9, 2015 at 22:53
• – kglr
Commented Nov 9, 2015 at 23:01

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"]


wcc = WeaklyConnectedComponents[g1]


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

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