This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.


chain_decomposition(graph, /, source=None)#

Returns the chain decomposition of a graph.

The chain decomposition of a graph with respect to a depth-first search tree is a set of cycles or paths derived from the set of fundamental cycles of the tree in the following manner. Consider each fundamental cycle with respect to the given tree, represented as a list of edges beginning with the nontree edge oriented away from the root of the tree. For each fundamental cycle, if it overlaps with any previous fundamental cycle, just take the initial non-overlapping segment, which is a path instead of a cycle. Each cycle or path is called a chain. For more information, see [Schmidt].


The function implicitly assumes that there are no parallel edges or self loops. It may produce incorrect/unexpected results if the input graph has self loops or parallel edges.

  • PyGraph – The undirected graph to be used

  • source (int) – An optional node index in the graph. If specified, only the chain decomposition for the connected component containing this node will be returned. This node indicates the root of the depth-first search tree. If this is not specified then a source will be chosen arbitrarly and repeated until all components of the graph are searched.


A list of list of edges where each inner list is a chain.

Return type:

list of EdgeList


Jens M. Schmidt (2013). “A simple test on 2-vertex- and 2-edge-connectivity.” Information Processing Letters, 113, 241–244. Elsevier. <>