Toward an enumeration of unlabeled trees
Pedro Recuero

TL;DR
This paper introduces an algorithm capable of enumerating all unlabeled trees of a given size, facilitating comprehensive analysis of tree structures in combinatorics.
Contribution
The paper presents a novel algorithm for systematically listing all unlabeled trees of a specified order, advancing enumeration methods in graph theory.
Findings
Efficient enumeration of unlabeled trees for various sizes
Algorithm correctness and completeness demonstrated
Potential applications in combinatorics and network analysis
Abstract
We present an algorithm that, on input , lists every unlabeled tree of order .
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAdvanced Graph Theory Research
Toward an enumeration of unlabeled trees
Recuero, P. M
Abstract
We present an algorithm that, on input , lists every unlabeled tree of order .
1 Introduction
The enumeration of structures is a primal theme of combinatorics. Whereas the problem of enumerating the labeled tree graphs has been solved by Borchardt [1]—and subsequently improved by Cayley [2]—over one century ago, an analogue for the unlabeled case remained elusive. Here, we present an algorithm that, on input , lists every [unlabeled] tree of order exactly once.
Before we begin, a couple remarks on notational conventions and terminology: a multiset is a duple , where is a set, called the underlying set and is the so-called . A partition of a natural number is a multiset , such that . We denote by the set of all partitions of , and exceptionally, cortiously let (0,(0,1)) be the unique partition of zero.
Additionally, by we denote the linear [sometimes called “path”] graph on vertices, that connected graph which either contains exactly two vertices of degree one, all other vertices having degree two, or is the unique graph on one vertex.
2 Main Result
Our algorithm works in a series of steps, illustrated below for the case where our input .
Fig. 1
That is, at the step, we have the linear graph , which we call our backbone, plus “free” vertices. Within each of these steps, we append the free vertices to the backbone—that is, add an edge between a free vertex and a vertex of the backbone—in every possible way, while avoiding repetitions and conserving diameter—i.e. all trees generated at step must have diameter —, and then print out the resulting trees.
Fig. 2
Above we have a few examples of trees we might run into upon initialization of our algorithm on input at steps zero, and three through five, respectively. Moreso, the figure above evinces a phenomenon to keep in mind: not only can we append our free vertices directly to our backbone, as in the second tree above, but we can also combine them with one another before doing so, as in the third and fourth trees, forming compound appendices; to the free vertices that were added directly to our backbone, as in the second tree, we by contrast refer as singular appendices. Appendices, compound or not, can also be linear, as in the second and third trees, or nonlinear. Appendices that have already been connected to the backbone we call substituents.
But there is more than seemingly unnecessary terminological conventions to the figure above: as a matter of fact, instead of jumping straight into our algorithm, we will visit the two simpler cases exemplified by the second and third trees above, viz. those where we can only append the free vertices to our backbone directly or as halves of linear graphs, so as to warm us up and gather insight which shall later come to us useful.
2.1 Singular appendices
How many ways are there to append free vertices directly to a backbone of order ? The naïve way tells us that there are possibilities; however this of course leads to redundancies.
Fig. 3
In any given backbone, appending free vertices directly to vertices of same color as in the figure above results in the same tree. Of course, if we only have one free vertex to append then we might as well just cut our backbone in half. Things do get more complicated as the number of free vertices that are to be appended grows, however in fact, cutting our trees into “half-trees” shall prove to be a didactic experiment, helping us deal with the aforeseen symmetry.
Fig. 4
Above we have a half-backbone of order four with three free vertices to be directly appended. Being devoid of symmetry, unlike their ‘complete’ congeners, the matter of appending a given number of free vertices directly to a half-backbone of a given order is trivial. Indeed, the figure below hints at a mechanical method we can employ to generate all the possible trees that could arise therefrom, without repetitions.
Fig. 5
And with some further thought, one can see that there are ways to append free vertices directly to a half-backbone of order , where
[TABLE]
Now to pass from half-backbones to full backbones, we proceed as follows: we regard a backbone of order as two half-backbones, ; if we are to append free vertices directly to this backbone, then there are the following options: we can append free vertices directly to and zero to ; or we can append free vertices directly to and one to ; or to and two to , and so on, up until to and to —if we went further than that then we would be going backwards—, as illustrated in the figure below for the case where we have a backbone of order six, split into two half-backbones of order three, and four vertices to append.
Fig. 6
And at each of these steps, we can “glue” our half-trees into trees. But how many ways are there to do that? If we append free vertices to and free vertices to , then there are only two options:
(a) , in which case, the sets of half-trees generated [from appending free vertices to and free vertices to ] have no elements in common, and thus there are in total trees that result from the gluing of the half-trees— assumed to be the order of the half-trees;
(b) , in which case the sets are the same, and as such there are trees resulting from the gluing of the half-trees.
From the above we can thus derive that there are
[TABLE]
ways to directly append free vertices to a backbone of order , where
[TABLE]
is our gluing function.
This however only solves the case for even backbones. To deal with odd backbones, we proceed as follows: we regard a backbone of order as two half-backbones of order —the “sides”— and one extra vertex—the “middle”. And now we do as earlier: if we are to append free vertices directly to an odd backbone, we can append free vertices to the sides and zero to the middle; or we can append free vertices to the sides and one to the middle, and so on, up until zero free vertices to the sides and to the middle.
As such we obtain that there are
[TABLE]
ways to append free vertices to a backbone of order , where is just a function that maps its input to one, if it is odd, and to zero otherwise.
Fig. 7
There is yet another thing that we must note. Recall how we stated that our algorithm requires that all trees resulting from the appending of the free vertices to the backbones have the same diameter as their backbones. Above we see a tree with diameter eight generated by the appending of two free vertices to a backbone of diameter six. Were we to allow this genre of thing in our algorithm, we would have repetitions: indeed, were we to initialize our algorithm on input , then the tree above would be listead [at least] twice: once on the zeroth step, as the backbone of order eight with no substituents; and then again at step two.
In our case dealing only with the direct appending of free vertices to backbones, the solution to this is simple: we just forbid substituents at end vertices of our backbones. We shall see how things play out in other settings shortly.
2.2 Linear appendices
Here, we can combine our set of free vertices into halves of linear graphs before appending them to our backbone. First let us examine how the simplest cases of this episode behave: those where all appendices are equal.
Notice how we can use the very same methods from the previous subsection here to append linear appendices to our backbones and half-backbones. The sole difference lies in how we can commit to our conservation of diameter restriction.
Fig. 8
The tree above was obtained from a backbone of diameter four, and yet displays diameter five, despite the fact that the substituent is not found on the end vertex. Nonetheless, the solution to this is simple: we stipulate that appendices of radius must be appended to vertices of the backbone with distance equal to or greater than from an end vertex, the end vertices themselves having distance zero.
With this, we can obtain that there are
[TABLE]
ways to append appendices of radius to a backbone of order such that the resulting trees all have diameter .
However even though we are equipped to compute the number of and mechanically generate trees obtained by the appending of linear appendices to backbones, we can only do so when all appendices in question are all of equal radii. Let us see how things go when we are without this prerogative.
The first thing to note is that, evidently, the dividing of a set of free vertices into halves of linear graphs coincides with integer partitions of .
Now suppose we are faced with the following:
Fig. 9
We know how to both generate [while conserving diameters] the trees from the appending of the two singular vertices and from the appending of the one half line graph of order two, though so far only separately.
Fig. 10
To attain simultaneity, we can “combine” the trees generated from appendices of different radii.
Fig. 11
Above we see the results of combining the top-right tree with the top-left and bottom trees [Fig. 10]. One can see that there are two ways to combine the top-right tree with the top-left one, though only one way to combine the top-right one with the bottom one. Evidently this is a matter of symmetry. Without much thought one can notice that whenever a symmetric tree is combined with another tree—be this second one symmetric or asymetric—there is only one possible combination, and when two asymmetric trees are combined, there are two possibilites.
Let us then introduce the operation: for two sets of trees of same diameter, let denote the set of all trees resulting from combining with ; patently we have that
[TABLE]
Where by we denote the number of symmetric, resp. asymmetric trees in .
Let us denote by the set of all trees generated by appending linear appendices of radius to a backbone of order without altering its diameter; we can calculate this set’s cardinality with equation (5); however if we are interested in the cardinality of the set of trees generated by combining several ’s, then we also need to calculate their and . Clearly, if is odd, then , and if is even, then ; from these, can trivially be derived.
Armed with these, we can calculate the number of trees that arise from the combination of two sets of trees generated by the appending of halves of linear graphs of two different radii; however we will also want to calculate combinations of combinations of several sets of graphs. By noting that the combination of an asymmetric tree with any other tree—be it symmetric or asymmetric—yields an asymmetric tree, and that the combination of two symmetric trees yields a symmetric tree, we can determine that
[TABLE]
whence again can trivially be inferred.
There is just one last thing with which we must deal before concluding our work here, and as in the previous subsection, it pertains to odd graphs and their middles. In the case where all appendices were singular, we proceeded by gradually increasing the number of free vertices directly appended to the middle; but in this here case, we are dealing with partitions, and if we just increase those blindly, mistakes can happen.
Fig. 12
In the bottom-left tree above, for example, the middle substituent has radius greater than the distance between the vertex to which it is appended and an end vertex, violating our rule; indeed, even though it was generated from a backbone of diameter five, it displays diameter six. We need, as such, to discard those partitions.
Putting all of the above together, we can obtain that there are
[TABLE]
trees generated by appending a set of free vertices as halves of linear graphs to a backbone of order , where
[TABLE]
is the function that prevents appendices that are “too long” to be appended to the middle vertex by checking the greatest element of the underlying set of the given partition—corresponding to the appendix of greatest radius.
2.3 Nonlinear appendices
We are now ready to tackle the case where the free vertices are allowed to combine with one another in any way they please. The first challenge thus to us presented is finding all possible such combinations—of compound appendices. Note how compound appendices coincide with half-trees. The following is an overview of a procedure to list all half-trees of a given order.
Fig. 13
Just as we said that our algorithm for the listing of trees would be divided in steps, so will be our algorithm for the listing of half-trees: at the step we have a (half-)backbone of order and free vertices, being our input; illustrated above is the case for . Within each of those steps we do as follows: we go over the partitions of , and for each of those we “apply” them to our set of free vertices. That is, if , say, and we have as our given partition, then we shall divide our free vertices into three half-trees of order two, and three half-trees of order three.
Fig. 14
And for each of those sets of half-trees of same order, we can choose from the set of all half-trees of that given order to form our fixed order half-three multiset, as seen above for the case of the aforementioned partition on : there are only two half-trees of order three; in our partition we must have three of those, so naturally there are possible fixed order half-three multisets to choose from. Meanwhile, there is only one half-three of order two. Now, we can choose any combination of fixed order half-tree multisets to “manifest” our partition, yielding us our appendix set, itself a multiset whose underlying set has half-trees as elements, the union of its fixed order half-tree multiset constituents.
Fig. 15
We go over all appendix sets, and for each of them, for each , we list all of the half-trees generated by appending appendices to our half-backbone in question while conserving radius. In the figure above, for example we have chosen one of the appendix sets from Fig. 14 and apply it to a half-backbone of order four.
So far, everything is just like earlier when all substituents were linear. Indeed, most of the times we can treat nonlinear substiuents in the same manner we treat linear ones, but as we shall see later they have a behavior of their own. For the purpose of this overview, we can simply ignore that and assume that we already know how to deal with them.
Now, as earlier, we combine our half-trees and obtain our set of half-trees generated from appendix set applied to the given half-backbone.
Recapitulating in a clumsy mixture of prose and pseudocode,
HT_n := { } for k in [0,n-2]: for p in P(k): for AS generatable from p: for a in AS: generate h.-t.’s by appending M_AS(a) a’s to half-backbone of order n-k combine h.-t.’s generated from different a’s append the results to HT_n
Where HT_n is meant to be the set of all half-trees of order , to which we add the sets of half-trees generated by appending free vertices, combined as per every appendix set generatable from every partition of to half-backbones of order .
And now we turn to the aforementioned peculiarity of nonlinear appendices.
Fig. 16
Consider the two half-trees above. Each was generated by appending three free vertices to a half-backbone of order four, though by different appendix sets and partitions, and as such—were we to ignore the peculiarities of nonlinear appendices; above we have assumed that we already know how to deal with those—would both be listed, were we to initialize our algorithm for listing half-trees on input , at the third step. However note how they are isomorphic.
Let us call a substituent of radius that is appended to a vertex of the half-backbone with distance exactly from the half-backbone [such as the nonlinear substituent on the tree to the left in the figure above] terminal. One can easily verify that often times, when appending nonlinear substituents terminally, the resulting half-tree is isomorphic to another half-tree generated from the same number of free vertices, but with different appendix set. Other times, this does not happen, as in the top tree in the figure below.
Fig. 17
To deal with this, we will introduce an ordering relation on the half-trees. In a tree with a terminal substiuent, call the half-tree formed by cutting the edge between the vertex of the half-backbone to which the substituent in question is appended and its neighbor closer to the end vertex—in Fig. 17 above, merely everything to the left of the blue vertex—of the half-backbone the tip induced by that substituent. We stipulate that an appendix can only be appended terminally if we have that , where is the tip it shall thereby induce.
The idea behind shall be simple. Consider an expanded version of the aforementioned algorithm for the listing of all half-trees of a given order wherein all half-trees of all orders are listed: we simply go over the positive integers, starting from one, and run the algorithm above at each of those. We will say that for two half-trees , we have that if by this expanded algorithm, is listed before .
As such it is required of us that we order the for’s within our first algorithm, define an ordering on the partitions of a given integer, and then on the appendix sets of a given partition. To order these last ones in turn, we need an ordering on the fixed order half-tree multisets.
Let us begin with the ordering on the partitions. To decide the relationship between two given partitions of the same integer, we proceed as follows:
- X_p := p*
- X_q := q*
- if max{i in X_p} < max{j in X_q}: then p < q else: if M_p(max{i in X_p}) < M_q(max{j in X_q}: then p < q else: X_p -= max{i in X_p} X_q -= max{j in X_q} go to step 3
That is, we compare the greatest part of the partitions, and then its multiplicity, and then the second greatest part, and then its multiplicity and so on. In the procedure described above, at some point, X_p and X_q (our containers) will become empty, and then, seeing as all previous comparison of parts and their multiplicities led to a tie, the partitions will be equal. It also doesn’t hurt to notice that it is impossible for one of the X’s become empty before the other—if a partition has fewer parts than another partition on the same integer, by our definition we will have and our algorithm will decide that before we run out of parts.
Next, an ordering on the appendix sets. First, only appendix sets generated from the same partition are important to us. This ordering here will be similar to our ordering on the partitions: recall that an appendix set consists of fixed order half-three multisets, each derived from a part of the partition whence the appendix set was generated. Assuming an ordering on these last ones, we simply proceed just like we did for partitions: for two appendix sets generated from the same partition , we compare first the fixed order half-three multiset derived from and so on.
Thus, on to the ordering on the fixed order half-three multisets. Let us denote by the set of all half-trees of order . To each we assign a prime number as follows: to the first half-tree that is listed by the first half-tree listing algorithm (the one that lists half-trees of a given input), is assigned; to the second, is assigned, and so on. For a half-tree , let us denote by the prime number thereto assigned. Now for a fixed order half-tree multiset we let
[TABLE]
Now we define that for two fixed order half-tree multisets (of half-three of same order) , we have that iff .
Now, at first sight it might seem self-referential, impossible or illegal devise an ordering on the half-trees based on an ordering on fixed order half-tree multisets that is itself based on the ordering on the half-trees. However notice that the smallest half-trees, by virtue of being simple, are greater or lesser than one another not because of the fixed order half-tree multisets that make up their appendix set, but rather because of petty differences in their radii or even partitions on their free vertex set: these minimal trees are too little to make room for such complexity. As our half-trees grow and the first half-trees start to exhibit big free vertex sets allowing diverse appendix sets, these last ones, in their turn, will be made out of the simpler half-trees, which will have already been ordered, and induce themselves an ordering on the larger half-trees.
Armed with all of the above, we are now able to go in greater depth into our half-tree listing algorithm, whence we shall subsequently, at last, derive our tree listing algorithm. Having fixed our input,
For natural :
For each :
For each appendix set generatable from :
For each :
Generate ;
Combine all of the ’s;
List the half-trees in the resulting set.
A few comments are warranted:
— In keeping with the orderings we devised above, at the second, third and fourth bullets we go over the partitions, appendix sets and half-trees respectively in increasing order;
— Here, is an extension of our from the previous subsection; whereas the latter only took numbers as inputs—seeing as all graphs with which it dealt coincided with numbers—the former’s second argument is a half-tree; as such, is the set of all half-trees generated by appending half-trees to a half-backbone of order while conserving radius (here we allow nonlinear appendices to be appended terminally, for our half-trees are not done yet);
— It is in the combine step that lie the nottiness the nonlinear appendices bring to the table; trees without terminal nonlinear substituents can be combined freely, however when combining a tree with terminal nonlinear substituents , it must be verified if the induced tip is such that . As such, it must be the case that when combining the ’s, we begin from the half-trees of substituents of least radius, so that when the time comes to deal with a half-tree with a nonlinear terminal substituent, all appendices that could have been appended to the tip have already been;
— At last the listing of the half-trees must be orderly. For many half-trees arise from the same appendix set, partition and half-backbone and yet we must order these as well. Here, we do so according to the position of the substituents. The simple idea is that the trees that have the smallest (by ) substituents closer to the end are lesser, in keeping with the the mechanical method we employ to append a given number of free vertices onto a half-backbone (cf. Fig. 5 and many others). This is solved for the case were all substituents are equal, however we still must with half-trees with varied substituents. We do this as follows: for two trees with the same substituents , we first verify how close to the end vertex the substituents are in both trees; there being a tie there, we go on to consider the substituents and so on.
At last, our algorithm for the listing of trees—which by now should look like an obvious extension of the one for half-trees above, seeing as the only additions are the steps where we fuse the half-trees and deal with the middle vertices: having our input been fixed,
For natural :
If is even:
For :
For each appendix set generatable from :
For each :
For natural :
Generate ;
Generate ;
Fuse the ’s into trees, yielding a set of trees;
Combine all of the ’s;
List the trees in the resulting set.
If is odd:
For natural :
For :
For each appendix set generatable from :
For each :
For natural :
Generate ;
Generate ;
Fuse the ’s into trees, yielding a set of trees;
Combine all of the ’s, call the resulting set of trees ;
For every :
For every appendix set generatable from :
Check if the of greater radius has radius greater than ;
If it does, discard this appendix set and move on to the next; if not, proceed;
Append the appendices to the middle vertex of a backbone of order as per ;
Combine the resulting tree to all of those in ;
List the resulting trees;
3 Epilogue
Evidently, from here, the elaboration of a closed-form expression for the number of trees listed by our algorithm on a given input, whence an enumeration on the unlabeled tree graphs would be yielded, presents an interesting task; such shall be the subject of a future writing. In passing, an implementation of the algorithm is also on its way.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Borchardt, C. W. (1860); “Über eine Interpolationsformel für eine Art Symmetrischer Functionen und üben Deren Anwendung”; Math. Abh. der Akademie der Wiessenschaften zu Berlin , pp. 1–20.
- 2[2] Cayley, A. (1889); “A theorem on trees”; Quart. J. Math. , Vol. 23, pp. 376–8.
