networkx.full_rary_tree

networkx.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.” [R930]

Parameters:

r : int

branching factor of the tree

n : int

Number of nodes in 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 : networkx Graph

An r-ary tree with n nodes

References

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