Main Content

Find all cycles in graph

`[`

also returns the edges in each cycle. The output `cycles`

,`edgecycles`

] = allcycles(`G`

)`edgecycles`

is a cell
array where `edgecycles{k}`

gives the edges in the corresponding cycle,
`cycles{k}`

.

`[___] = allcycles(`

specifies additional options using one or more name-value arguments. You can use any of the
output argument combinations in previous syntaxes. For example, you can specify
`G`

,`Name,Value`

)`MaxNumCycles`

and a scalar to limit the number of cycles
returned.

The number of cycles in a graph depends heavily on the structure of the graph. For some graph structures, the number of cycles can grow exponentially with the number of nodes. For example, a complete graph with 12 nodes given by

`G = graph(ones(12))`

contains nearly 60 million cycles. Use the`MaxNumCycles`

,`MaxCycleLength`

, and`MinCycleLength`

options to control the output of`allcycles`

in these cases.