A note on naturally embedded ternary trees
In this note we consider ternary trees naturally embedded in the plane in a deterministic way such that the root has position zero, or in other words label zero, and the children of a node with position have positions , , and , for all . We derive the generating function of ternary trees where all nodes have labels which are less or equal than , with , which generalizes a result of  and , and the generating function of ternary trees counted with respect to nodes with label , with . Moreover, we discuss generalizations of the counting problem to several labels at the same time. Furthermore, we use generating functions to study the depths of the external node , or in other words leaf with , where the external nodes of a ternary tree are numbered from the left to the right according to an inorder traveral. The three different types depths – left, right and center – are due to the embedding of the ternary tree in the plane. Finally, we discuss generalizations of the considered enumeration problems to embedded -ary trees.
Key words and phrases:Ternary trees, Embedded trees, Labelled trees
The study of tree families embedded in the plane has recently received a lot of attention. Binary trees, complete binary trees, more generally simply generated tree families, and several different families of planar trees have been considered in a series of papers [4, 5, 13, 8, 3, 2, 11, 12, 7, 15]. It has been shown that embedded trees are closely related to a random measure called ISE (Integrated SuperBrownian Excursion). For example, in the recent paper of Devroye and Janson  a conjecture of Bousquet-Mélou and Janson  is proven, saying that the vertical profile of a randomly labelled simply generated tree converges in distribution, after suitable normalization, to the density of the ISE. However, enumerative properties of deterministically embedded trees have not been intensively studied, except for binary trees, a particular subclass of ternary trees, and families of plane trees. Motivated by the results of Bousquet-Mélou  and Panholzer  for embedded binary trees, and the results of Schaeffer and Jacquard , and Del Lungo, Del Ristoro and Penaud  for a specific subclass of embedded ternary trees, we study several combinatorial properties of ternary trees embedded in the plane in a deterministic manner. We consider the following natural embedding. The root has position zero, or in other words label zero, and the three children of the root have positions , and . More generally, the labels of the children of a node with label are given by , with . A similar embedding of ternary trees has been considered before [9, 6], where the authors studied a particular subclass of embedded ternary trees named skew ternary trees , or left ternary trees , which are embedded ternary trees with no node having label greater than zero. Using bijections between embedded ternary trees with no label greater than zero and non-separable rooted planar maps with edges they obtained amongst others an explicit result for the number of such trees of size . The aim of this work is to use a generating functions approach to study several parameters in embedded ternary trees: we analyze the distribution of the different types of depths of external nodes in ternary trees, stemming from the embedding of the tree, assuming that the external nodes are enumerated from the left to the right, or in other words with respect to an inorder-traversal. Related parameters have been studied for binary trees in [16, 17, 15]. Moreover, we are interested in the number of embedded ternary trees of size where all internal nodes have label smaller or equal than , with , where we extend the results of  and  for the special case to arbitrary , and also in the number of embedded ternary of size counted with respect to the number of internal nodes with label , with . We also show how the extend the counting problem to several types of labels considering the nodes with label and the number of nodes with labels in , and also discuss generalizations.
1.1. Plan of the paper
This note is structured as follows. In the next section we recall some well known properties of the family of ternary trees. In Section 3 we discuss the natural embedding of (ternary) trees in the plane, and also provide a formalism for embedded trees. Section 4 is devoted to the study of ternary trees with small label and to ternary trees counted by the number of nodes labelled . In Subsection 4.2 we discuss the enumeration problem of counting the number of nodes with label , and at the same time the number of nodes with labels in . In Section 5 we study the distribution of depths of the -th external node or leaf in ternary trees, with , where the leaves are enumerated from the left to the right. In the final section we discuss some generalizations and open problems, i.e. the extensions of the obtained results to embedded -ary trees.
2.1. The family of ternary trees
The family of ternary trees can be described in a recursive way, which says that a ternary tree is either a leaf (an external node) or an internal node followed by three ordered ternary trees, visually described by the suggestive “equation”
Here is the symbol for an internal node and is the symbol for a leaf or external node. A trivial consequence of this description is the fact that a ternary tree with internal nodes has exactly external nodes; moreover, by taking external nodes into account any node has either outdegree zero or three. Note that throughout this work the notion size of a tree is with respect to the number of internal nodes, a tree of size has internal nodes. We assume that the external nodes of a size ternary tree are numbered from left to right according to a so-called inorder traversal. We start at the root node of a tree. If the tree has internal nodes, we recursively traverse them by going first to the left subtree, then the center subtree, and finally to the right subtree. The external nodes are numbered as visited on the traversal process, see Figure 2. The generating function of the number of ternary trees of size satisfies the equation
Concerning the series expansion of the generating function it is convenient consider the shifted series . This corresponds to discarding external nodes (the empty tree) in the discription above; we obtain simply generated ternary trees ), defined by the formal equation
with a node, the cartesian product, and the substituted structure. We refer to  for the general definition of simply generated trees. Let denote the number of ternary trees of size , and the number of simply generated ternary trees of size . By the formal description above (2) the counting series satisfies the functional equation
Due to the Lagrange inversion formula, see e.g. , the number of ternary trees of size is given by
Note that due to the definition the series and are related by . In contrast to the case of binary trees, where the generating function , satisfying , may be expressed in terms of radicals, , for , the case of ternary trees is more complicated due to the third order equation (3); however, there exist appealing closed form expressions of for real values of , i.e. and ,
which are obtained by Cardano’s method; note that the radius of convergence of and is given by . We obtain by the Lagrange inversion formula the more general formula
Note that since , this immediately implies that for we have
It turns out that the last representation is valued for all . The result above follows by the binomial theorem, Equation 4 and a variant of the Chu-Vandermonde summation formula.
3. The embedding of ternary trees
Motivated by the results of Bousquet-Mélou , and Panholzer  for naturally embedded binary trees, and the results of Schaeffer and Jacquard , and Del Lungo, Del Ristoro and Penaud  for a subclass of ternary trees, we embedd ternary trees in the plane in the following way. The root node has position zero. By definition of ternary trees each internal node with no children has exactly three positions to attach a new node, which are as usual called external nodes or leaves, see Figure 2. We recursively define the embedding of ternary increasing trees as follows: an internal node with label/position has exactly three children, being internal or external, placed at positions , and . Following , we call this embedding the natural embedding of ternary trees, because the label a node is its abscissa in the natural integer embedding of the tree. \setcaptionwidth0.3
Equivalent to the embedding, we can think of the edges of a ternary tree being decomposed into three different types, , and . We assume that each internal nodes has exactly one of each edge type pointing away from . Hence, if we assume that an edge of type , with , corresponds to a step , the label of a node in a tree corresponds to the sum over all edges on the unique path from node to the root,
Note that we associate two different kind of labels to external nodes, first the number of the external node according to the inorder-traversal, and second the label of its position according to the natural embedding. This definition readily extends to -ary trees; following the embedding of Bousquet-Mélou  of binary trees and the present one stated for ternary trees. It seems natural to assume that for -ary trees each internal node with label has exactly children, internal or external, placed at positions , with , and for -ary trees each internal node with label has exactly children, internal or external, placed at positions , with ; see Figure 3. Equivalently, we have or different types of edges , with either or which correspond to the steps in the obvious way. We point out that the terminology “natural embedding” may be not unique. One could alternatively define the embedding of -ary trees by the increments , which could be considered more natural than , depending on the taste. \setcaptionwidth0.8
3.1. A formalism for embedded trees
Previously we have stated a definition for embedded ternary trees and more general models of embedded - and -ary trees. However, we have not presented a formalism to actually encode a specific embedded (ternary) tree. Moreover, there exist several different “natural” embeddings of -ary trees. In the following we will give a simple natural way of encoding families of embedded trees, with respect to a set of step vectors. Let denote a given finite non-empty set of step vectors of size , with and , for ; moreover let denote the alphabet . An embedded tree of size one, , is defined as a single point located as the origin with an additional label , denoting the empty word, where the first two entries of the triple encode the points coordinate, and the third entry is the label. An embedded tree of size is defined as a set of labelled points , satisfying two conditions stated below, with denoting a triple , where denote the coordinates of point and denote its label consisting of a word of length over the alphabet , with . We impose two conditions on embedded trees. First, we impose that , and that no other point has a label of length zero. Second, for each labelled point , with , there exists an index with corresponding point and an index , with , such that the point is given by . Equivalently, given an embedded tree of size , we may obtain a size embedded tree by adding the points of the form to , with and .
Informally speaking, the stated description of embedded trees corresponds to a reflection followed by a 90 degree rotation of the usual pictures of embedded tree, see Figure 4. Since there may be multiple points at the same coordinate , we use their labels to distinguish between them; more precisely the labels of the points encode how they are reached from the origin with respect to the given set of step vectors . The first condition says nothing else that all trees are rooted at the origin, and the second imposes that each non-root node has a unique parent node. The set of vectors , i.e. the set of vectors of Motzkin paths , leads to embedded ternary trees; , i.e. the set of vectors of Dyck paths , leads to embedded binary trees as considered in . More generally, the family of embedded -ary and -ary trees, with respect to the natural embedding such that each internal node with label has exactly and children, internal or external, placed at positions , with and , is described using the stepsets , and .
The family of naturally embedded ternary trees with and the family of naturally embedded binary trees with , considered in , are symmetric: if then also .
For a given set of step vectors let denote the corresponding family of embedded trees. It is easy to see that the generating function satisfies the equation , where we assume that there exists exactly one embedded tree of size zero. Consequently, with respect to enumeration, embedded trees with can be considered as models of -ary trees.
4. The number of embedded ternary trees with small labels
Let denote the generating function of ternary trees having no label greater than , with , and with the generating function of ternary trees, as specified by (1). The starting point of our considerations is the following system of equations.
The series satisfies
First we observe that the infinite system of equations is well defined and complete determines the generating functions . Moreover, following  we note that replacing each label by shows that the series is also the generating function of trees rooted at a node with label , and having only non-negative labels for its children. Considering such a tree it has at most three subtrees rooted at , with , which have again only non-negative labels. We have the formal description sketched below in Figure 5, which translates in the stated system of equations and the result follows. ∎
We obtain the following result for the series .
Let be the generating function of ternary trees with no label greater than . Then is given by the the following expression
where is defined by (1), i.e. , and the series is defined as the unique formal power series with , satisfying the relations
Moreover, the series has non-negative coefficients and satisfies
with , as defined in (3).
Let denote the -th Chebyshev polynomial of the second kind, recursively defined by , and for . Following Bouttier et al.  we use the well known closed form expression of ,
and observe that can be expressed as the quotient of Chebyshev polynomials of the second kind evaluated at , we have for the expression
An immediate consequence of our result above are explicit formulas for , i.e. and , stated in the following corollary, which is obtained by elimination of using standard algorithms from the theory of Gröbner bases.
The series and , counting the number of embedded ternary trees with no label greater than zero, and one is given by following simple expression.
The coefficients and are for given by the expressions
where denotes the -th Fibonacci number, and the golden ratio.
The result of the case above has already been obtained in [9, 6] using bijections with maps and 2-stack sortable permutations. We remark that the sequence of coefficients of given by appear as sequence in the Online Encyclopedia of Integer Sequences . The coefficients of given by are not listed there.
Banderier and Flajolet  have studied directed lattice paths in the plane and pointed out the importance of the so-called characteristic polynomial. For so-called simply paths, defined by the set of steps , with and , for , the characteristic polynomial is given by , and the characteristic equation of simple paths is given by . Note that the equation for the series for embedded ternary trees with step set is given by ; for embedded binary trees  with step set it is given by . We conjecture that an equation of a similar type , where , is important at least for the analysis of embedded trees with a symmetric step set , where denotes the generating function of the number of embedded trees.
In order to proof the result above it is sufficient to check that the series satisfies Equation 6 and the initial condition , which is a simple task. In order to discover the solution we use the method from Bouttier et al. , see also Di Francesco . Following  we use that fact that for tending to infinity we have . Hence, for tending to infinity one expects that can be written as . We make the Ansatz , with as tends to infinity. We expend Equation 6 with respect to the Ansatz and compare the terms tending at a similar rate to zero as tends to infinity. We get
We assume that is a formal power series such that for a given with , where denotes the radius of convergence of . An Ansatz leads to the so-called characteristic equation
Note that the equation above is identical to the characteristic equation of Motzkin path with being replaced by , where , see ,. The equation above implies several other relations with respect to ,
Moreover, the equations relating the series and of Theorem 1 are easily derived in a similar manner. Consequently, we define the series as the solution of the equation above with and . We make the improved Ansatz and compare the terms with the same order of magnitude in (6) as tends infinity. Using the fact that we obtain the system of recurrences
which determine uniquely in terms of and rational functions of , with unspecified yet. Although it seems at first glance hopeless to obtain a closed form solution, it is possible to guess a solution with the help of computer algebra software, i.e. the help of Maple, which is easily verified using induction. We obtain the surprisingly simple solution
By our initial assumption we have for small enough. We set , where being small enough and independent of . Consequently, we get after summation the solution
which is easily seen to be true for all , with respect to and . Finally, adapting to the initial condition implies that . ∎
4.1. The number of vertices with a given label
Following  we are interested in the number of ternary trees of size with a given number of vertices with label . In order to treat this problem we introduce a sequence of bivariate generating functions , where marks the number of internal nodes, and the number of nodes with label , with . Our first observations is already the key point, namely that due to the definition of the embedding of ternary trees, or in other words the symmetry of the step set , we have the symmetry , for all ; moreover we have . The starting point of our considerations is the following lemma.
The series satisfies
Let be the generating function of ternary trees with counting the number of nodes with label . Then is given by the the following expression
We have to determine in such a way that the equation for in Lemma 2 is satisfied. Using the general solution stated above and the formulas expression and as functions of we obtain the equation
Now we simply write , and obtain after simple manipulations
We set , and obtain the stated result. ∎
4.2. The number of vertices with given labels
In this section we derive a generalization of our previous result concerning the enumeration of embedded ternary trees of size with respect to the number of nodes with label . The crucial fact in the derivation of the previous result was the symmetry relation , which allowed to conclude the special equation for the case . Hence, when generalizing the counting problem we have to take care to preserve some symmetry in order to set up a system of suitable equations. First, we are interested in counting two statistics at the same time, namely the number of nodes with label , and the number of nodes with label contained in . Let denote the generating function of ternary trees, where the variable counts the number of nodes with label and counts the number of nodes with labels contained in . Since we both types of labels and are counted by the same variable, we have symmetry with respect to the vertical line . More precisely, we obtain the following result.
The series satisfies the symmetry relation
for all . Moreover, is determined by the system of equations
The generating function of ternary trees, counting the number of nodes with label and the number of nodes with label in is given by the the following expression
Consequently, we obtain by substituting the equation for into the equation for the result
Simple manipulations leads to the stated result with respect to . ∎
Now discuss a more general counting problem. We are interested in the number of nodes with labels in , counted by the variable , labels in , counted by , up to labels in , counted by . Note that the cases and corresponds to the counting problems treated in Theorems 2,3. We use the vector notation . Let denote the generating function of ternary trees, where the variable counts the number of nodes with label in , for .
The series satisfies the symmetry relation for all . Moreover, is determined by the system of equations
Consequently, the system of equations stated in Lemma 4 for implies, with respect to the notation above, the equation
We will use the following lemma.
The finite continued fraction , defined in (8), can be written in terms of the family of polynomials in the following way,
The finite continued fraction