is_forest {igraph}R Documentation

Decide whether a graph is a forest.

Description

is_forest() decides whether a graph is a forest, and optionally returns a set of possible root vertices for its components.

Usage

is_forest(graph, mode = c("out", "in", "all", "total"), details = FALSE)

Arguments

graph

An igraph graph object

mode

Whether to consider edge directions in a directed graph. ‘all’ ignores edge directions; ‘out’ requires edges to be oriented outwards from the root, ‘in’ requires edges to be oriented towards the root.

details

Whether to return only whether the graph is a tree (FALSE) or also a possible root (TRUE)

Details

An undirected graph is a forest if it has no cycles. In the directed case, a possible additional requirement is that edges in each tree are oriented away from the root (out-trees or arborescences) or all edges are oriented towards the root (in-trees or anti-arborescences). This test can be controlled using the mode parameter.

By convention, the null graph (i.e. the graph with no vertices) is considered to be a forest.

Value

When details is FALSE, a logical value that indicates whether the graph is a tree. When details is TRUE, a named list with two entries:

res

Logical value that indicates whether the graph is a tree.

root

The root vertex of the tree; undefined if the graph is not a tree.

See Also

Other trees: is_tree(), make_from_prufer(), sample_spanning_tree(), to_prufer()

Examples


g <- make_tree(3) + make_tree(5,3)
is_forest(g)
is_forest(g, details = TRUE)


[Package igraph version 2.0.3 Index]