Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Return the path linking two tree nodes specified by their positions
ResourceFunction["FindPathBetweenTreePositions"][start,end] returns a path on that connects the start and end point given their positions on a tree. |
Find a path between two tree positions:
| In[1]:= |
| Out[1]= |
Create a tree:
| In[2]:= |
| Out[3]= | ![]() |
Find the path that connects the given nodes labeled 24 and 21:
| In[4]:= |
| Out[4]= |
| In[5]:= |
| Out[5]= |
Visualize the path that connects the given nodes labeled 63 and 82 on the given tree:
| In[6]:= | ![]() |
| Out[8]= |
| In[9]:= |
| Out[10]= | ![]() |
If one of the starting point or ending point is {}, then the path always starts or ends at the root node:
| In[11]:= | ![]() |
| Out[13]= |
| In[14]:= |
| Out[14]= | ![]() |
| In[15]:= |
| Out[15]= |
| In[16]:= |
| Out[16]= | ![]() |
If the starting point and ending point are identical, then the path is the list of single element if it is valid:
| In[17]:= | ![]() |
| Out[18]= |
| In[19]:= |
| Out[19]= | ![]() |
If any element of the given positions is not a positive integer, the function returns $Failed:
| In[20]:= |
| Out[20]= |
Find all nodes in the tree that are 8 steps away from the node 33 (all values are distinct):
| In[21]:= | ![]() |
| Out[23]= | ![]() |
Obtain a list of all positions on tree and all paths starting from node with value 33:
| In[24]:= | ![]() |
| Out[25]= |
The distribution of the distances between node 33 and other nodes on the tree:
| In[26]:= |
| Out[26]= | ![]() |
| In[27]:= | ![]() |
| Out[28]= | ![]() |
A histogram that resembles Half Dome (a mountain in Yosemite):
| In[29]:= |
| Out[30]= | ![]() |
Compute pair-wise distance for all nodes and plot their frequency with Histogram:
| In[31]:= | ![]() |
| Out[34]= | ![]() |
Compare with the actual mountain:
| In[35]:= |
| Out[35]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License