Warning

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

networkx.generators.classic.full_rary_tree

full_rary_tree(r, n, create_using=None)[source]

Creates a full r-ary tree of n vertices.

Sometimes called a k-ary, n-ary, or m-ary tree. “… all non-leaf vertices have exactly r children and all levels are full except for some rightmost position of the bottom level (if a leaf at the bottom level is missing, then so are all of the leaves to its right.” [1]

Parameters:
  • r (int) – branching factor of the tree
  • n (int) – Number of nodes in the tree
  • create_using (NetworkX graph constructor, optional (default=nx.Graph)) – Graph type to create. If graph instance, then cleared before populated.
Returns:

G – An r-ary tree with n nodes

Return type:

networkx Graph

References

[1]An introduction to data structures and algorithms, James Andrew Storer, Birkhauser Boston 2001, (page 225).