A recursive algorithm for trees and forests
Song Guo, Victor J. W. Guo

TL;DR
This paper introduces recurrence relations for counting rooted forests with varying numbers of roots, enabling derivation of classical formulas for different types of trees.
Contribution
It presents a recursive approach to relate counts of rooted forests with k and k+1 roots, simplifying derivation of known tree enumeration formulas.
Findings
Derived recurrence relations for rooted forests with k and k+1 roots.
Unified framework for counting various types of trees.
Simplified derivation of classical tree enumeration formulas.
Abstract
Trees or rooted trees have been generously studied in the literature. A forest is a set of trees or rooted trees. Here we give recurrence relations between the number of some kind of rooted forest with roots and that with roots on . Classical formulas for counting various trees such as rooted trees, bipartite trees, tripartite trees, plane trees, -ary plane trees, -edge colored trees follow immediately from our recursive relations.
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.
A recursive algorithm for trees and forests
Song Guo and Victor J. W. Guo111Corresponding author.
School of Mathematical Sciences, Huaiyin Normal University, Huai’an, Jiangsu 223300, People’s Republic of China
[email protected], [email protected]
Abstract. Trees or rooted trees have been generously studied in the literature. A forest is a set of trees or rooted trees. Here we give recurrence relations between the number of some kind of rooted forest with roots and that with roots on . Classical formulas for counting various trees such as rooted trees, bipartite trees, tripartite trees, plane trees, -ary plane trees, -edge colored trees follow immediately from our recursive relations.
Keywords: forests; rooted trees; bipartite trees; tripartite trees; plane trees; -edge colored trees.
MR Subject Classifications: 05C05, 05A15, 05A19.
1 Introduction and notations
The famous Cayley’s formula for counting trees states that the number of labeled trees on is . Clarke [7] first gives a refined version for Cayley’s formula by setting up a recurrence relation. Erdlyi and Etherington [11] gives a bijection between semilabeled trees and partitions. This bijection was also discovered by Haiman and Schmitt [14]. A general bijective algorithm was given by Chen [4]. Aigner and Ziegler’s book [1] collected four different proofs of Cayley’s formula. We refer the reader to [5, 6, 8, 15, 13, 20] for several recent results on the enumeration of trees. The goal of this paper is to establish simple linear recurrences between certain forests with roots and forests with roots , from which one can deduce several classical results on counting trees.
The set of forests of rooted trees on with roots is denoted by . Suppose that and is a vertex of , the subtree rooted at is denoted by . We say that a vertex of is a descendant of , if is a vertex of , i.e., is on the path from the root of to the vertex , and is denoted by .
For any edge of a tree in a forest , if is a vertex of , we call the father vertex of , the child vertex of , the father of , and a child of , sometimes we also say is out of . The degree of a vertex in a rooted tree is the number of children of , and is denoted by , or . As usual, a vertex with degree zero is called a leaf.
An unrooted labeled tree will be treated as a rooted tree in which the smallest vertex is chosen as the root. Moreover, if is a set of trees, then we will use to denote the subset of all elements of satisfying the condition .
2 The fundamental recursion
One of our main results is as follows.
Theorem 2.1
For , we have the following recurrence relation:
[TABLE]
Proof. Suppose that . First, remove the subtree from and add it to be a new tree in the forest. Second if is not a descendant of in the new forest, must be a descendant of , exchange labels of the vertices and . Thus, we obtain a forest .
Conversely, for a forest , we can attach to any vertex of the other trees in as a subtree, or attach to any vertex of as a subtree and exchange labels of the vertices and . The proof then follows from the fact that has vertices altogether.
It is clear that
[TABLE]
We have the following corollaries.
Corollary 2.2
(Cayley [3])* The number of labeled trees on vertices is .*
Corollary 2.3
(Cayley [3], Clarke [7])* The number of rooted trees on vertices with a specific root and root degree is .*
Proof. It follows from (2.1) and (2.2) that
[TABLE]
Exchanging the labels of the vertices and for , we establish a bijection between and . Therefore,
[TABLE]
from which one can see that the number of forests with vertices and trees is
[TABLE]
Remark. It is worth mentioning the third and fourth proofs of Cayley’s formula in Aigner and Ziegler’s book [1, Chapter 30]. The third proof in [1, Chapter 30], essentially due to Riordan [19] and Rényi [18], is as follows: Let denote the number of forests on consisting trees where the vertices of appear in different trees. Consider such a forest and suppose that is adjacent to vertices. Removing the vertex , we obtain a forest of trees. As we can reconstruct by first fixing , then selecting the neighbors of , and then the forest , this gives
[TABLE]
from which we can prove Cayley’s formula by induction on .
The fourth proof in [1, Chapter 30], due to Pitman [17], is as follows: Let denote the set of all forests that consist of rooted trees on . A sequence of forests is called a refining sequence if and is obtained from by removing one edge for all . Fix and denote by
- •
the number of rooted trees containing ,
- •
the number of refining sequences ending in
Then it is easy to see that and by counting in two ways, first by starting a tree and secondly by starting at . Hence,
[TABLE]
Since contains isolated nodes, we get , and thus Cayley’s formula.
Therefore, both our proof of Cayley’s formula and the third proof in [1, Chapter 30] are recursive. But the latter requires more algebraic computations. Our proof is very similar to Pitman’s proof. The difference is that Pitman considers all forests with rooted trees while we only consider forests with roots . Pitman’s proof uses the idea of double counting and our proof is a little more straightforward and combinatorial.
3 Bipartite trees and tripartite trees
A complete -partite graph is a graph with the vertex set partitioned into parts , where , any two vertices are adjacent if and only if and do not belong to the same part . A spanning tree of is called a -partite tree.
Corollary 3.1
(Fiedler and Sedlek [12])* The number of spanning trees of the complete bipartite graph is .*
Proof. Let and . Denote by the set of forests of rooted bipartite trees on with roots .
Note there is no edge connecting vertices and if and belong to the same set . In a similar way to Theorem 2.1, we have
[TABLE]
It is easy to see that
[TABLE]
We complete the proof by (3.3) and (3.4).
Corollary 3.2
For , we have
[TABLE]
Here we set .
Proof. It follows from (3.3) and (3.4) that
[TABLE]
On the other hand, both of the trees in a forest of are bipartite trees. Applying Corollary 3.1, we complete the proof.
Corollary 3.3
(Austin [2])* The number of spanning trees of the complete tripartite graph is .*
Proof. Let , , and . Denote by (respectively, ) the set of forests of rooted tripartite trees on with roots (respectively, ).
In exactly the same way as in the proof of Corollary 3.1, we have
[TABLE]
It follows that
[TABLE]
We have the following important fact:
[TABLE]
because and are in the same tree in each forest, what is different is that we choose as the root of the tree on the left-hand side, while we choose on the right-hand side. Again, similarly to the proof of Corollary 3.1, we get
[TABLE]
On the other hand, we have
[TABLE]
In fact, there are forests such that is a child of , and forests such that the father of is a child of , which comes from .
The proof then follows from combining (3.5)–(3.8).
Remark. A bijective proof of Corollary 3.1 was found by Stanley [21, pp. 125-126]. Austin [2] proved that the number of spanning trees of the complete -partite graph is , where . Eǧecioǧlu and Remmel[9] found a bijective proof of the enumeration of bipartite trees and tripartite trees and later they [10] found a bijection for the -partite trees. The reader is encouraged to find a simple proof of Austin’s formula by modifying our recursive algorithm for trees and forests.
4 Plane trees
A labeled plane tree is a rooted labeled tree for which the children of any vertex are linearly ordered. Denote by the set of forests of labeled plane trees on vertices with roots .
Corollary 4.1
For , the following holds
[TABLE]
Proof. The first step is the same as Theorem 2.1. For the reversal step, we suppose that . For the first case, there are ways for us to attach to the vertex of the other trees in as a subtree. The second case is the same. The proof then follows from the fact
[TABLE]
Corollary 4.2
The number of labeled plane trees on vertices is , i.e., the number of unlabeled plane trees on vertices is the well-known Catalan number
[TABLE]
Proof. It follows from (4.9) and that the number of labeled plane trees on with root is , but the total number of plane trees is times that.
We say that a plane tree is non-leaf vertex labeled if all the leaves are not labeled, while all of the other vertices are labeled. Denote by the set of forests of non-leaf vertex labeled plane trees on vertices with leaves and with roots .
Theorem 4.3
For , the following holds
[TABLE]
Proof. The proof is analogous to that of Theorem 2.1. But this time when a subtree is removed, its root is left and is considered as an unlabeled vertex. Thus, the number of the leaves (unlabeled vertices) of the forest is increased by one. The reverse is clear and straightforward.
For , an example is given in Figure 2.
A plane tree is called a -ary plane tree if every non-leaf vertex has degree .
Corollary 4.4
The number of forests of non-leaf vertex labeled -ary plane trees on vertices with roots equals
[TABLE]
Proof. The recurrence (4.10) also holds for -ary plane trees. But in this case, is replaced by . Hence, we have
[TABLE]
Here the factor occurs because there are possibilities for to be a child of . The proof then follows from the fact that .
Corollary 4.5
The number of unlabeled -ary plane trees on vertices equals
[TABLE]
Proof. For any -ary plane tree on vertices, it has non-leaf vertices. We have ways to label its non-leaf vertices with the root labeled . Therefore, dividing the number of non-leaf labeled plane trees on vertices with root by , we obtain the desired number for unlabeled -ary plane trees.
Corollary 4.6
For , we have
[TABLE]
Proof. Let . The forest of non-leaf labeled trees may be treated as the union of two small forests, namely, the forest of trees with roots , and the forest of trees with roots . It follows from Corollary 4.4 that
[TABLE]
Dividing both sides of the identity by , we complete the proof.
Corollary 4.7
(Narayana [16])* The number of unlabeled plane trees on vertices with leaves equals*
[TABLE]
Proof. It follows from (4.10) that
[TABLE]
For any , one sees that is a child of and so the number of forests in with the vertex having degree is equal to (there are possibilities for to be a child of ). It follows that
[TABLE]
It is well known that the number of solutions in positive integers to the equation
[TABLE]
is . So the right-hand side of (4.12) is equal to
[TABLE]
Together with (4), we obtain
[TABLE]
Dividing this number by , we get the desired formula for unlabeled plane trees.
Corollary 4.8
For any nonnegative integer sequence satisfying , there are plane trees on with the degree of being .
Proof. Without loss of generality, suppose that if and only if . Just like (4), we see that the number of non-leaf vertex labeled plane trees with root and with the degree of being for is , so the total number is
[TABLE]
But there are ways to label the leaves of each plane tree with . This completes the proof.
Corollary 4.9
For any nonnegative integer sequence satisfying , the number of rooted trees on with the degree of being is
[TABLE]
Proof. For any rooted tree on with the degree of being , there are plane trees with the same degree sequence. The proof then follows from Corollary 4.8.
Corollary 4.10
(Erdlyi-Etherington [11])* Let be a partition of , i.e., , and . Then the number of unlabeled plane trees having vertices with degree is equal to*
[TABLE]
Proof. It follows from the proof of Corollary 4.7 (replace by ) that the number of such non-leaf vertex labeled plane trees is equal to the product of and , where ranges over all the permutations of the multiset . It is not hard to see that
[TABLE]
That is, the multiplication equals
[TABLE]
Dividing it by , we obtain the desired number for unlabeled plane trees.
5 -Edge colored trees
A -edge colored tree is a tree whose edges are colored from a set of colors such that any two edges with a common vertex have different colors. For convenience, the set of colors is denoted by .
A special -edge colored tree is a rooted -edge colored tree such that all the edges out of the root are colored with the first colors, i.e., . Note that for such a tree, the degree of the root is less than or equal to . Denote by the set of forests of special -edge trees with roots .
Theorem 5.1
For , we have the following recurrence relations:
[TABLE]
Proof. For , assume that the edge with child vertex has the color , then none of the edges with father vertex could have color .
- •
First, remove the subtree from and add it to be a new tree in the forest.
- •
Second, if one edge with father vertex is colored by , we recolor it by .
- •
Third, if is not a descendant of in the new forest, must be a descendant of , exchange the labels of vertices and .
Thus we obtain a forest .
Conversely, for a forest , we can use the following steps to recover :
- •
First, attach back to any vertex of the other trees in as a subtree, or attach to any vertex of as a subtree and exchange the labels of the vertices and . Note that there is an uncolored edge. i.e., the edge with child vertex . Denote by the father vertex of , and the set of colors of the other edges incident with .
- •
Second, if is one of the roots in the forest, i.e., , we can color with any color in , whenever it is not empty. Otherwise, we color with any color in , whenever it is not empty.
- •
Third, if the color of , say , is the same as some edge incident with vertex , then recolor by .
Note that if , we have , and . Otherwise, we have . Therefore, the number of ways to recover is given by
[TABLE]
This completes the proof of (5.13).
Figure 3 gives an example for the case . In order to make the figure clear, we replace the colors set by .
Corollary 5.2
The number of forests of special -edge colored trees on with roots is
[TABLE]
Proof. It follows immediately from (5.13) and the fact .
The following result is due to Gessel (see [21, pp. 124]), and can also be deduced in the same way as before.
Corollary 5.3
The number of -edge colored trees on is
[TABLE]
Proof. The case of Corollary 5.2 implies that the number of special -colored trees with root is
[TABLE]
Note that a -colored tree is not special if and only if one of the edges out of the root is colored by , and we can delete this edge to obtain a forest of two special -colored trees such that one of the roots is . But Corollary 5.2 says that the number of forests of two special -edge colored trees with roots is
[TABLE]
so is the number of forests with roots , where . Hence, the number of -colored trees on (with root ) is given by
[TABLE]
This completes the proof.
Corollary 5.4
The number of -edge colored trees on with a specific root and root degree is
[TABLE]
Proof. Suppose that the root of the tree is . Then there are ways to choose the children of from the set , and ways to color the edges out of the root. Obviously, each of subtrees of may be regarded as a special -edge colored tree, because the edges out of its root are colored from a definite set of colors. It follows from Corollary 5.2 that there are ways to construct the forest of special -edge trees on vertices with specific roots. Therefore, the number of the required trees is
[TABLE]
as desired.
Acknowledgments. The authors would like to thank the anonymous referees for helpful comments on a previous version of this paper. The first author was partially supported by the Natural Science Research Project of Ordinary Universities in Jiangsu Province of China (grant no. 13KJB110001).
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] M. Aigner and G.M. Ziegler, Proofs from The Book, Fourth Ed., Springer-Verlag, Berlin, 2010.
- 2[2] T.L. Austin, The enumeration of point labelled chromatic graphs and trees, Canad. J. Math. 12 (1960), 535–545.
- 3[3] A. Cayley, A theorem on trees, Quart. J. Math. 23 (1889), 376–378.
- 4[4] W.Y.C. Chen, A general bijective algorithm for trees, Proc. Natl. Acad. Sci. USA 87 (1990), 9635–9639.
- 5[5] W.Y.C. Chen and V.J.W. Guo, Bijections behind the Ramanujan polynomials, Adv. Appl. Math. (2001), 336–356.
- 6[6] W.Y.C. Chen and J.F.F Peng, Disposition polynomials and plane trees, European J. Combin. 36 (2014), 122–129.
- 7[7] L.E. Clarke, On Cayley’s formula for counting trees, J. London Math. Soc. 33 (1958), 26–28.
- 8[8] R.R.X. Du and J. Yin, Counting labelled trees with given indegree sequence, J. Combin. Theory Ser. A 117 (2010), 345–353.
