node_connectivity(G, s=None, t=None)¶
Returns an approximation for node connectivity for a graph or digraph G.
Node connectivity is equal to the minimum number of nodes that must be removed to disconnect G or render it trivial. By Menger’s theorem, this is equal to the number of node independent paths (paths that share no nodes other than source and target).
If source and target nodes are provided, this function returns the local node connectivity: the minimum number of nodes that must be removed to break all paths from source to target in G.
This algorithm is based on a fast approximation that gives an strict lower bound on the actual number of node independent paths between two nodes . It works for both directed and undirected graphs.
- GNetworkX graph
Source node. Optional. Default value: None.
Target node. Optional. Default value: None.
Node connectivity of G, or local node connectivity if source and target are provided.
This algorithm  finds node independents paths between two nodes by computing their shortest path using BFS, marking the nodes of the path found as ‘used’ and then searching other shortest paths excluding the nodes marked as used until no more paths exist. It is not exact because a shortest path could use nodes that, if the path were longer, may belong to two different node independent paths. Thus it only guarantees an strict lower bound on node connectivity.
White, Douglas R., and Mark Newman. 2001 A Fast Algorithm for Node-Independent Paths. Santa Fe Institute Working Paper #01-07-035 http://eclectic.ss.uci.edu/~drwhite/working.pdf
>>> # Platonic octahedral graph is 4-node-connected >>> from networkx.algorithms import approximation as approx >>> G = nx.octahedral_graph() >>> approx.node_connectivity(G) 4