Function Repository Resource:

CompleteLevelsKaryTree

Compute the complete k-ary tree with different amounts of branches per level

Contributed by: Sander Huisman
 ResourceFunction["CompleteLevelsKaryTree"][{n1,n2,n3,…}] gives the complete k-ary tree with ni branches at level i.

Details and Options

ResourceFunction["CompleteLevelsKaryTree"][…, DirectedEdges True] gives a directed complete tree.

Examples

Basic Examples (1)

Create a k-ary tree with two branches on the top level, three branches in the level below, and four in the bottom level:

 In[1]:=
 Out[1]=

Scope (2)

There can be one branch for a certain level:

 In[2]:=
 Out[2]=

Use directed edges:

 In[3]:=
 Out[3]=

Options (2)

DirectedEdges (2)

By default, an undirected graph is generated:

 In[4]:=
 Out[4]=

Use DirectedEdges True to generate a directed graph:

 In[5]:=
 Out[5]=

Properties and Relations (1)

CompleteKaryTree and CompleteLevelsKaryTree can be the same:

 In[6]:=
 Out[6]=

Possible Issues (1)

If a zero is present the branching is stopped:

 In[7]:=
 Out[7]=

Neat Examples (2)

Here is a complete k-ary tree:

 In[8]:=
 Out[8]=

Using the radial embedding emphasizes the symmetry:

 In[9]:=
 Out[9]=

SHuisman

Version History

• 1.0.0 – 06 May 2022