Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

# networkx.generators.classic.balanced_tree¶

balanced_tree(r, h, create_using=None)[source]

Returns the perfectly balanced r-ary tree of height h.

Parameters: r (int) – Branching factor of the tree; each node will have r children. h (int) – Height of the tree. create_using (NetworkX graph constructor, optional (default=nx.Graph)) – Graph type to create. If graph instance, then cleared before populated. G – A balanced r-ary tree of height h. NetworkX graph

Notes

This is the rooted tree where all leaves are at distance h from the root. The root has degree r and all other internal nodes have degree r + 1.

Node labels are integers, starting from zero.

A balanced tree is also known as a complete r-ary tree.