Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Convert a list into a complete binary tree
ResourceFunction["ListToCompleteBinaryTree"][list] arrange the elements from list row-wise in a binary tree which is complete except for the last row. |
Arrange 20 elements on a complete binary tree:
| In[1]:= |
| Out[1]= | ![]() |
ListToBinaryTree accepts the same options as Tree:
| In[2]:= | ![]() |
| Out[2]= | ![]() |
ListToBinaryTree accepts multiple options:
| In[3]:= | ![]() |
| Out[3]= | ![]() |
A complete binary tree of height h has at least 2h nodes and at most 2h+1-1 nodes. For instance when h=4:
| In[4]:= |
| Out[4]= | ![]() |
| In[5]:= |
| Out[5]= | ![]() |
The height of the tree are the same for both complete binary trees:
| In[6]:= |
| Out[6]= |
A complete binary tree of 2k-1 nodes is the same as complete Kary tree with (k-1) 2's:
| In[7]:= |
| In[8]:= |
| Out[8]= | ![]() |
| In[9]:= |
| Out[9]= | ![]() |
The length of the input must be at least one. Otherwise the function returns unevaluated:
| In[10]:= |
| Out[10]= |
Complete binary tree with 2n-1 nodes has beautiful "RadialEmbedding" configuration:
| In[11]:= |
| Out[11]= | ![]() |
Use binary expansion of n as input to create a complete binary tree and then read those bits in pre-order (OEIS A380856):
| In[12]:= | ![]() |
| Out[12]= | ![]() |
Specify TreeTraversalOrder to implement pre-order traversal:
| In[13]:= |
| Out[13]= |
The new number and its associated complete binary tree:
| In[14]:= |
| Out[14]= | ![]() |
Every integer is associated with a permutation group using the operation from OEIS A380856:
| In[15]:= | ![]() |
Use n=65537 for example:
| In[16]:= |
| Out[16]= |
The order of the permutation group associated with 65537 is 15:
| In[17]:= |
| Out[17]= |
Repeat 15 times the rearrangement of binary bits of 65537 on complete binary tree using pre-order traversal will return to the original number:
| In[18]:= |
| In[19]:= |
| Out[19]= |
| In[20]:= | ![]() |
| Out[20]= | ![]() |
List the numbers and their complete binary tree representation:
| In[21]:= | ![]() |
| Out[21]= | ![]() |
Remove unused items in the deque:
| In[22]:= |
| Out[22]= |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License