find_cycle: Finds a cycle in a graph, if there is one

find_cycleR Documentation

Finds a cycle in a graph, if there is one

Description

[Experimental]

This function returns a cycle of the graph, in terms of both its vertices and edges. If the graph is acyclic, it returns empty vertex and edge sequences.

Use is_acyclic() to determine if a graph has cycles, without returning a specific cycle.

Usage

find_cycle(graph, mode = c("out", "in", "all", "total"))

Arguments

graph

The input graph.

mode

Character constant specifying how to handle directed graphs. out follows edge directions, ⁠in⁠ follows edges in the reverse direction, and all ignores edge directions. Ignored in undirected graphs.

Value

A list of integer vectors, each integer vector is a path from the source vertex to one of the target vertices. A path is given by its vertex ids.

Related documentation in the C library

find_cycle().

See Also

Graph cycles feedback_arc_set(), feedback_vertex_set(), girth(), has_eulerian_path(), is_acyclic(), is_dag(), simple_cycles()

Examples


g <- make_lattice(c(3, 3))
find_cycle(g)

# Empty results are returned for acyclic graphs
find_cycle(sample_tree(5))


igraph/rigraph documentation built on June 13, 2025, 1:44 p.m.