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.


cycle_basis(graph, /, root=None)#

Return a list of cycles which form a basis for cycles of a given PyGraph

A basis for cycles of a graph is a minimal collection of cycles such that any cycle in the graph can be written as a sum of cycles in the basis. Here summation of cycles is defined as the exclusive or of the edges.

This is adapted from algorithm CACM 491 [1].


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

  • graph (PyGraph) – The graph to find the cycle basis in

  • root (int) – Optional index for starting node for basis


A list of cycle lists. Each list is a list of node ids which forms a cycle (loop) in the input graph

Return type: