extract_largest_component

extract_largest_component#

graph_tool.topology.extract_largest_component(g, directed=None, prune=False)[source]#

Extract the largest (strong) component in the graph as a GraphView (or Graph if prune==True).

If the graph is directed, then the largest strongly connected component is returned.

Parameters:
gGraph

Graph to be used.

directedbool (optional, default: None)

Treat graph as directed or not, independently of its actual directionality.

prunebool (optional, default: False)

If True, a pruned copy of the component is returned. Otherwise a GraphView is returned.

Returns:
compGraphView or Graph

Largest (strong) component.

Notes

The algorithm runs in \(O(V + E)\) time.

Examples

>>> g = gt.random_graph(100, lambda: poisson(1), directed=False)
>>> u = gt.extract_largest_component(g)
>>> print(u)
<GraphView object, undirected, with 28 vertices and 27 edges, edges filtered by (<EdgePropertyMap object with value type 'bool', for Graph 0x..., at 0x...>, False), vertices filtered by (<VertexPropertyMap object with value type 'bool', for Graph 0x..., at 0x...>, False), at 0x...>