networkx.generators.classic.balanced_tree¶
-
balanced_tree
(r, h, create_using=None)[source]¶ Return the perfectly balanced
r
-ary tree of heighth
.Parameters: - r (int) – Branching factor of the tree; each node will have
r
children. - h (int) – Height of the tree.
- create_using (Graph, optional (default None)) – If provided this graph is cleared of nodes and edges and filled with the new graph. Usually used to set the type of the graph.
Returns: G – A balanced
r
-ary tree of heighth
.Return type: NetworkX graph
Notes
This is the rooted tree where all leaves are at distance
h
from the root. The root has degreer
and all other internal nodes have degreer + 1
.Node labels are integers, starting from zero.
A balanced tree is also known as a complete r-ary tree.
- r (int) – Branching factor of the tree; each node will have