Note

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.

rustworkx.digraph_find_cycle#

digraph_find_cycle(graph, /, source=None)#

Return the first cycle encountered during DFS of a given PyDiGraph, empty list is returned if no cycle is found

Parameters:
  • graph (PyDiGraph) – The graph to find the cycle in

  • source (int) – Optional index to find a cycle for. If not specified an arbitrary node will be selected from the graph.

Returns:

A list describing the cycle. The index of node ids which forms a cycle (loop) in the input graph

Return type:

EdgeList