This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.


node_connectivity(G, s=None, t=None)[source]

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 [1]. It works for both directed and undirected graphs.

  • G (NetworkX graph) – Undirected graph
  • s (node) – Source node. Optional. Default value: None.
  • t (node) – Target node. Optional. Default value: None.

K – Node connectivity of G, or local node connectivity if source and target are provided.

Return type:



>>> # Platonic octahedral graph is 4-node-connected
>>> from networkx.algorithms import approximation as approx
>>> G = nx.octahedral_graph()
>>> approx.node_connectivity(G)


This algorithm [1] 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.


[1](1, 2) 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