Tree operators.
This load the graph package (for drawing and computing with graph).
In[196]:=
We define a constructor for a leaf, for unary and binary trees.
In[197]:=
In[198]:=
Some examples of trees built with Leaf, MK1, MK2. We first apply MK2 to two complete graphs of 2,3 points.
In[200]:=
Out[200]=
In[201]:=
Out[201]=
We draw a single leaf.
In[202]:=
Out[202]=
We use the first node of the tree as root for the tree.
In[203]:=
In[204]:=
Out[204]=
We define the height of a tree rooted in 1 as the maximum distance between the node 1 and any node.
In[205]:=
In[206]:=
Out[206]=
We define a map, Add, taking a tree g, an integer i, and adding to the point number i of the tree one new child.
In[207]:=
When the point to which we add a child is unspecified, then it is the last point of the graph (vertices of each graph are numbered 1, ..., n). ``Add'' applied to the empty graph yields a leaf.
In[208]:=
In[209]:=
Out[209]=
An example of the use of Add.
In[210]:=
In[211]:=
Out[211]=
Created by Mathematica (October 17, 2006)