oak (version 0.2.1)

height: Height of a tree

Description

This function returns the height of a tree, defined as the number of nodes of the longest subchain. For an empty tree, the height is conventionally equal to 0.

Usage

height(.tree)

# S3 method for rtree height(.tree)

height(x) <- value

Arguments

.tree, x

A tree.

value

integer. Height to assign to the tree x (this calls the function prune).

Value

An integer.

Examples

Run this code
# NOT RUN {
## Rooted tree
(tr0 = c_("Bob", "Carl", "Daniel"))
tr1 = r_("Dimitri", s = list(c_("Enoc"), c_("Ferdinand")))
tr1 = r_("Caroline", s = list(tr1))
(tr1 = r_("Bill", s = list(tr1)))
(tr2 = r_("Alice", s = list(tr0, tr1)))
height(empty_tree())
height(tr0)
height(tr1)
height(tr2)

## Unrooted tree
(tr3 = r_(s = list(tr2, c_("Grand-Mother", "Father", "Son"))))
height(tr3)

# }

Run the code above in your browser using DataCamp Workspace