Nonleaf Patterns in Trees: Protected Nodes and Fine Numbers

Nachum Dershowitz School of Computer Science Tel Aviv University Ramat Aviv Israel

                  nachum@cs.tau.ac.il

The barren and fertile fronds [of the Sensitive Fern] are extremely unlike, the former being leaf-like, very sensitive to frost, quickly wilting when plucked, and much taller and more common than the latter which are non-leaf-like and remain

erect, though drying up, through the winter.

—Transactions of the Royal Society of Canada (1884)

Abstract

We derive a closed-form formula for the number of occurrences of matches of a multiset of patterns among all ordered (plane-planted) trees with a given number of edges. A pattern looks like a tree, with internal nodes and leaves, but also contain components that match subtrees or sequences of subtrees. This result extends previous versatile tree-pattern enumeration formulæ to incorporate components that are only allowed to match nonleaf subtrees and provides enumerations of trees by the number of protected (shortest outgoing path has two or more edges) or unprotected nodes.

1 Tree patterns

One routinely asks how often certain patterns occur among a set of combinatorial objects, such as trees. Here, we concern ourselves with patterns in ordered (plane-planted) trees,

f

g

♢w ♢x ♢y h

k

♢z

Figure 1: The 7-edge 4-leaf tree ⟨ ⟨⟨⟩⟨⟩⟩ ⟨⟩ ⟨⟨⟨⟩⟩⟩ ⟩ with labeled nodes for reference.

Figure 2: The lattice path corresponding to the tree in Figure 1, consisting of 7 ↗-steps (pointing to the North) and 7 ↘-steps (East).

which are counted by the Catalan numbers, C_{n} = \frac{1}{n+1} \binom{2n}{n}, sequence \underline{A000108} in Sloane’s Encyclopedia of Integer Sequences [17]. Lattice (Dyck) paths—which may not dip below the abscissa, and very many other interesting objects (including full binary trees), are their equinumerous analogues; see [18, e.g. Thm. 1.5.1]. Ordered trees may be written down linearly as balanced nested brackets. Each balanced bracket pair ⟨⋯⟩ corresponds to a single node. For example, ⟨ ⟨⟨⟩⟨⟩⟩ ⟨⟩ ⟨⟨⟨⟩⟩⟩ ⟩ is a seven-edge, eight-node tree, with four leaves ⟨⟩ and four (nonleaf) internal nodes. Its root has three children, the middle one being a (childless) leaf. We refer to such a level-one leaf as a stump. This tree is drawn in Figure 1, with leaves labeled w, x, y, and z; it corresponds to the path depicted in Figure 2, with peaks at x = 2, 4, 7, 11. The tree stump y turns into the little hill in the middle of the path at x = 7. Stump-less trees are deemed “protected” and form the subject of Section 3. Hills and stumps are further explored in Section 4.

Motivated by enumeration problems such as those in [1, 2], we add the possibility of a sequence of nonleaf children to the versatile pattern enumerations of [7, 9]. With this addition, patterns come in five basic shapes: ♢, △, ▲, ∘∘∘, and •••.

– A lozenge ♢ corresponds to any tree leaf.

– A light triangle pattern △ matches any subtree.

– A dark triangle ▲ matches any nonleaf subtree (that is, a subtree rooted at an internal node).

– A light ellipsis ∘∘∘ can match any sequence of (zero or more) subtrees.

– A dark ellipsis ••• can match any sequence of (zero or more) nonleaf subtrees.

Basic patterns can be composed to form more complicated shapes by placing a sequence of patterns in angle brackets. Specifically, tree patterns P have the following grammar:

P ::= ♢ | ⟨Q Q ⋯ Q⟩
Q ::= ♢ | △ | ▲ | ∘∘∘ | ••• | ⟨Q ⋯ Q⟩

where Q ⋯ Q means zero or more patterns Q, in sequence, and Q Q ⋯ Q means one or more. The lozenge pattern ♢ is the same as ⟨⟩, but we will need to control where leaves appear, so we only allow ⟨⟩ within composites and require the use of ♢ as a top-level pattern. The triangle pattern △ matches any subtree matched by either ♢ or ▲; the ellipsis ∘∘∘ is tantamount to △⋯△, and the dark ellipsis ••• is like ▲⋯▲. Both ⟨∘∘∘⟩ and ⟨•••⟩ match leaves, as they have zero subtrees. (The basic patterns of [9] did not include the dark ellipsis; those of [7] also excluded dark triangles.) Given a bag (multiset) of patterns, we ask how many times those patterns occur in trees of a specified size. Patterns may occur more than once or not at all in any given tree.

Two patterns overlap if their instances share one or more nodes in the tree. We aspire to count non-overlapping instances only. More than one triangle or ellipsis can co-occur at the same point in a tree, without consuming any nodes. For example, △ and ▲ each match any nonleaf subtree, but have no nodes of their own; were we to want to count their joint occurrences in a tree, we would not want the two of them to match the very same node at the same time. As we are interested in counting distinct, non-overlapping occurrences of patterns, triangles and ellipses are not used as standalone patterns (P), but rather only within composites (Q).

The leaf pattern ♢ matches every childless (leaf) node, of which there are four in the example tree of Figure 1. The pattern ⟨△⟩ matches “only children”, of which there are two in the figure (h and k). The pattern ⟨∘∘∘ ♢⟩ matches each node whose youngest (rightmost) child is childless; that also happens twice in the example (at g and at k). So, a pair of two copies of this pattern shows up exactly once (at the node pair g & k), covering those two occurrences; three such, not at all. The pattern ⟨•••♢⟩ matches a node whose youngest child is the only one who is not a parent; there is one such (k). The pattern ⟨△∘∘∘♢∘∘∘⟩ matches a leaf provided it is not the eldest child; there are two (x and y). The pattern ⟨△∘∘∘▲∘∘∘△⟩ would match a nonleaf middle child were there one. The pair of patterns ⟨♢∘∘∘⟩ and ⟨∘∘∘♢⟩, having a leftmost leaf and having a rightmost leaf, occurs twice in the tree: the first pattern at node g on account of its leaf-child w and the second at k with its childless child z; and reversed, at k-z and g-x. Though these two patterns do co-occur at g and also at k, such overlapping occurrences do not count.

2 Pattern enumerations

We need to know the number of tree nodes that appear within patterns, which we calculate as follows:

v(△) = v(▲) = 0  v(∘∘∘) = v(•••) = 0
v(♢) = 1  v(⟨p_{1} ⋯ p_{k}⟩) = 1 + Σ_{j}v(p_{j}) .

Our primary enumeration result is the following:

Theorem 1 (Pattern Enumeration). Let p_{1}, …, p_{q}, q ≥ 1, be various composite patterns. The number of non-overlapping occurrences among all n-edge ordered trees of n_{j} of each of the patterns p_{j} and of ℓ ≥ 0 leaf patterns ♢ is

\binom{m}{n_{1}, …, n_{q}} ∑_{k=1} \frac{1}{k}\binom{k}{m}\binom{u − k}{ℓ} ∑_{i=0}^{m+e−k} \binom{d + i − 1}{i}\binom{e + b − i − 1}{b − m + k − 1}\binom{e + a − i}{u − k} , (1)

where

• a is the number of light triangles △ appearing in them,

• b is the number of light ellipses ∘∘∘,

• c is the number of dark triangles ▲,

• d is the number of dark ellipses •••,

• m = Σn_{j} is the total number of patterns—presumed to be nonzero,

• v = Σ_{j}v(p_{j}) is the total number of nodes in the composite patterns,

• e = n + m − v − c − a is the number of edges not accounted for by the patterns, and

• u = n + m − v + 1.

Proof. The m nonleaf patterns leave n + 1 − v = u − m nodes unaccounted for, any of which could be a leaf. The patterns require at least ℓ of them to be leaves. We count separately for each possible number of “loose” (unattached to composite patterns) tree leaves, k = ℓ, ℓ + 1, …, u − m. The number of tree nodes that are accounted for by the original patterns and all these leaves is v + k.

The proof proceeds in several steps:

1. Arrange the given m nonleaf patterns in a row, in any of \binom{m}{n_{1},...,n_{q}} ways.

2. Intersperse an extra n + 1 − v − k = u − m − k patterns of the form ⟨△∘∘∘⟩ among the m patterns, to cover all the missing internal (nonleaf) nodes, in \binom{u−k}{m} ways, for a total of u − k patterns.

3. There are e − (n + 1 − v − k) = m + e − u + k missing edges (of the e missing from the given patterns; n + 1 − v − k were just added in the previous step). Split them into two categories: i edges that may not take leaves and v + k − n + e − i − 1 that may. This adds a summation Σ_{i}.

4. Distribute these i edges as sequences ▲ ⋯ ▲ of restricted triangles, in place of the d restricted ellipses •••. There are \binom{d+i−1}{i} ways to do this.

5. Similarly, distribute the remaining v + k − n + e − i − 1 edges as sequences △ ⋯ △ of unrestricted triangles, in place of the b + n + 1 − v − k light ellipses ∘∘∘ (b original and n + 1 − v − k added). There are \binom{e+b−i−1}{n−v+b−k} ways to do this.

6. Place the k leaves in some of the e + a − i unrestricted, light triangles (a in the original patterns, plus n + 1 − v − k from step 2 and v + k − n + e − i − 1 from step 5), in \binom{e+a−i}{k} ways.

7. Select ℓ leaves to match those in the given patterns in \binom{k}{ℓ} ways.

8. The cyclic arrangement of the resultant m + (u − m − k) = u − k patterns corresponds to exactly one occurrence of the patterns in a tree. (This is an application of Dvoretsky and Motzkin’s cycle lemma [12]; see [8].) To see this, graft the patterns into one tree by repeatedly picking any pattern in the sequence and inserting it into the closest (rightmost) available triangle slot among the patterns preceding it, wrapping back around from the end when necessary. The u − k patterns contain a total of a + c + (u − m − k) + (m − a − c + k − 1) − ℓ − (k − ℓ) = u − k − 1 slots. So, in fact, a single tree results from the grafting, with each pattern occurring at the point it ends up in the reconstructed tree. Thus, the enumeration has an additional factor of \frac{1}{u−k}.

Collecting everything and summing for k, we have

\binom{m}{n_{1}, …, n_{q}} ∑_{k=ℓ}^{u−m} \frac{1}{u − k} \binom{u − k}{m}\binom{k}{ℓ} ∑_{i=0}^{m+e−u+k}\binom{d + i − 1}{i}\binom{e + b − i − 1}{n − v + b − k}\binom{e + a − i}{k} .(2)

Reversing the order of summation for k (swapping k and u − k) and avoiding a 0 denominator, gives the stated enumeration (1). The sum for k in (1) can run from max{1, m} to u − ℓ.

For instance, nodes parenting exactly 2 (childless) leaves match the pattern ⟨•••♢•••♢•••⟩. So the number of such among the 14 size-4 trees (having 4 edges and 5 nodes) is obtained

♢ ♢ ♢ ♢ ^{♢ ♢ ♢} ^{♢ ♢ ♢} ^{♢ ♢ ♢} ^{\begin{aligned}♢ \\ & ♢ \end{aligned} ♢} ^{♢ \begin{aligned}♢ \\ & ♢ \end{aligned}}

♢ ♢ ^{♢ ♢} ^{♢ ♢} ^{♢ ♢ ♢} ^{♢ ♢} \begin{aligned}♢ \\ & ♢ \end{aligned} \begin{aligned}♢ \\ & ♢ \end{aligned} ♢

Figure 3: The C_{4} = 14 four-edge trees with 11 protected nodes in black.

by setting n = 4, m = 1, ℓ = a = c = b = 0, d = v = 3, e = 2, and u = 3:

\binom{1}{1} ∑_{k=1} \frac{1}{k}\binom{k}{1}\binom{3 − k}{0} ∑_{i}\binom{2 + i}{i}\binom{1 − i}{k − 2}\binom{2 − i}{3 − k}

= ∑_{i=0}^{1} \binom{2 + i}{i} ∑_{k=2}^{3} \binom{1 − i}{k − 2}\binom{2 − i}{3 − k} = [2 + 1] + 3[1] = 6 .

See Figure 3, where the pattern matches one node in each of the second through sixth trees and one in the penultimate tree.

Whenever there can be at most one occurrence of the patterns per tree, our formula counts trees—rather than mere instances of patterns. This is the case, in particular, when the patterns cover each of the n + 1 nodes and when those patterns are unambiguous, in the sense that only one of the patterns can match at any one of the nodes.

Call any internal node protected [2] when it is a grandparent via each and every one of its children, and unprotected when at least one child is childless. This notion of protection was recently extended in [3] to k-protection, that is, that no path from the node contains fewer than k edges. For the time being, k = 2.

The unambiguous pattern ⟨•••♢∘∘∘⟩ matches each unprotected internal node in a unique manner, with the leftmost leaf child singled out. Another way of looking at this pattern is as counting the eldest among leaf siblings. There are 24 such in Figure 3; the other 11 leaves in the figure have childless elder siblings. On the other hand, ⟨∘∘∘♢∘∘∘⟩, though it also matches unprotected nodes, it does so as many times as a node has childless children (viz. 35 times in Figure 3). So it counts leaf children, rather than counting nodes having leaf children.

Whenever there are no dark ellipses (d = 0) in the patterns, i only takes 0 in formula (2), for otherwise \binom{d+i−1}{i} = 0. For this to be possible, we also need for k ≥ u − m − e, or else the sum over i is empty. Accordingly, formula (2) simplifies substantially:

\binom{m}{n_{1}, …, n_{q}} ∑_{k=u−m−e}^{u−m} \frac{1}{u − k} \binom{u − k}{m}\binom{k}{ℓ}\binom{e + b − 1}{n − v + b − k}\binom{e + a}{k}

= \binom{m}{n_{1}, …, n_{q}}\binom{e + a}{ℓ} ∑_{k=u−m−e}^{u−m} \frac{1}{u − k} \binom{u − k}{m}\binom{e + a − ℓ}{k − ℓ}\binom{e + b − 1}{n − v + b − k} , (3)

with e = n + m − v − c − a and u = n + m − v + 1. This matches the main result of [9, Thm. 4.1] with various notational changes. When, in addition, there are no dark triangles (c = 0), this reduces to a much simpler formula, as given in [7, Thm. 2.1], namely,

\frac{1}{n − v − ℓ + 1}\binom{n + m − v}{n_{1}, …, n_{q}, ℓ, n − v − ℓ}\binom{2n + m − 2v − ℓ − a + b}{n − v − ℓ + b} .

The statement of the main theorem above assumed that m > 0, but the formulæ still make sense for m = 0, as long as we take care to avoid a 0 denominator. When there are no composite patterns and, hence, m = 0, only the number of leaf patterns ℓ ≥ 0 is given. So, all that is being counted is the number of occurrences of ℓ leaves within trees comprising n edges. A tree with k ≥ ℓ leaves has \binom{k}{ℓ} such instances. With no composite patterns, all of a, b, c, d, v must be zero, whereas e = n and u = n + 1. So formula (3) becomes

\binom{n}{ℓ} ∑_{k=ℓ}^{n} \frac{1}{n + 1 − k} \binom{n − ℓ}{k − ℓ}\binom{n − 1}{n − k} = \frac{1}{n}\binom{n}{ℓ} ∑_{k} \binom{n − ℓ}{k}\binom{n}{n − ℓ + 1 − k}

= \frac{1}{n}\binom{n}{ℓ}\binom{2n − ℓ}{n − 1} .  (4)

For example, for n = 4 and ℓ = 3, there are 6 trees with exactly three leaves plus one tree with four leaves, leaving 4 ways of choosing just three of them, for a total of \frac{1}{4} \binom{4}{3}\binom{8−3}{4−1} = 10 occurrences of a triad of leaves. See Figure 3.

At the opposite end of the spectrum, when all edges are accounted for by the patterns, that is, when e = 0, there is nothing left to place in any ellipsis, so we can ignore them for all intents and purposes, imagining b = d = 0. We have u = a + c + 1 and v = n + m − c − a. Looking at (3), we obtain

\binom{m}{n_{1}, …, n_{q}}\binom{a}{ℓ} ∑_{k=a+c+1−m}^{a+c+1−m} \frac{1}{a + c + 1 − k} \binom{a + c + 1 − k}{m}\binom{a − ℓ}{k − ℓ}\binom{−1}{c + a − m − k} ,

which simplifies to

\frac{1}{m}\binom{m}{n_{1}, …, n_{q}}\binom{a}{ℓ}\binom{a − ℓ}{m − c − 1} .  (5)

For example, (full) binary trees with 2r edges have r binary nodes ⟨△△⟩ and r + 1 leaves. Substituting m = n_{1} = r, a = 2r, c = 0, and ℓ = r + 1, we get

\frac{1}{r}\binom{r}{r}\binom{2r}{r + 1}\binom{r − 1}{r − 1} = \frac{1}{r + 1}\binom{2r}{r} = C_{r} ,

the Catalan numbers, as expected. Alternatively, letting ℓ = 0, so the leaves are not specified, we get again

\frac{1}{r}\binom{r}{r}\binom{2r}{0}\binom{2r}{r − 1} = \frac{1}{r + 1}\binom{2r}{r} = C_{r} .

If we want to count binary trees in which none of 2r + 1 binary nodes has only one leaf child, then we need exactly r binary nodes of the form ⟨▲▲⟩ and r + 1 of the form ⟨♢♢⟩, giving (n_{1} = r, n_{2} = r + 1, m = 2r + 1, ℓ = a = 0, and c = 2r) once again

\frac{1}{2r + 1}\binom{2r + 1}{r} = \frac{1}{r + 1}\binom{2r}{r} = C_{r} ,

the Catalan number that counts the number of binary trees with r internal nodes of either kind.

Likewise, when all nodes are accounted for, that is, when v+ℓ = n+1, then k = u−m = ℓ in formula (2), which reduces to

\frac{1}{m}\binom{m}{n_{1}, …, n_{q}} ∑_{i=0}^{e−ℓ} \binom{d + i − 1}{i}\binom{e + b − i − 1}{b − 1}\binom{e + a − i}{ℓ} ,  (6)

where e = m + ℓ − a − c − 1. For example, if a tree has exactly ℓ leaves and, hence, n + 1 − ℓ internal (nonleaf) nodes ⟨△∘∘∘⟩, then setting m = a = b = n + 1 − ℓ and c = d = 0, we get (after simplification)

\frac{1}{n + 1}\binom{n + 1}{ℓ}\binom{n − 1}{ℓ − 1}  (7)

since, again, i can only be 0. This is the Narayana distribution [14] (\underline{A001263}), which counts ℓ-leaf ordered trees [15].

When there is a single composite pattern and ℓ additional leaf patterns, we have m = n_{1} = q = 1. The main formula (1) becomes

∑_{k=1} \binom{u − k}{ℓ} ∑_{i=0}^{e−k+1} \binom{d + i − 1}{i}\binom{e + b − i − 1}{b + k − 2}\binom{e + a − i}{u − k}

= ∑_{i=0} \binom{d + i − 1}{i} ∑_{k=1} \binom{e + b − i − 1}{b + k − 2}\binom{e + a − i}{u − k}\binom{u − k}{ℓ}

= ∑_{i=0}^{w−a} \binom{d + i − 1}{i}\binom{w − i}{ℓ} ∑_{k=0}^{w+c−ℓ} \binom{w − a + b − i − 1}{b + k − 1}\binom{w − ℓ − i}{w + c − ℓ − k} ,

where w = e + a = n − v − c + 1. Simplifying with Vandermonde’s convolution, we derive the following:

Corollary 2 (Single Pattern). The number of occurrences of a single composite pattern containing v nodes, a light triangles, b light ellipses, c dark triangles, and d dark ellipses, along with ℓ leaves, among the ordered trees with n edges is

∑_{i=0}^{w−a} \binom{d + i − 1}{i}\binom{w − i}{ℓ}\binom{2w − a + b − ℓ − 2i − 1}{w + b + c − ℓ − 1} ,  (8)

where w = n − v − c + 1.

For example, the lone pattern ⟨▲•••∘∘∘△⟩, with v = a = b = c = d = 1, occurs twice in the trees with at least three leaves (ℓ = 3) of Figure 3 (n = 4), specifically at the roots of the second and fifth trees.

When there are no leaf patterns (ℓ = 0), this formula becomes

∑_{i=0}^{n−v−c−a+1} \binom{d + i − 1}{i}\binom{2n − 2v − a + b − 2c − 2i + 1}{n − v + b} .  (9)

There are a total of 5 instances of ⟨▲•••∘∘∘△⟩ among all the trees in the figure.

On the other hand, when there are no dark ellipses in the pattern (d = 0), we have instead

\binom{n − v − c + 1}{ℓ}\binom{2(n − v − c) − a + b − ℓ + 1}{n − v + b − ℓ} .

For example, there are 2 instances of ⟨▲∘∘∘△⟩ (a = b = c = v = 1) along with three leaves (ℓ = 3) in the figure (n = 4). In fact, in this situation, where there is only one composite pattern besides the leaves and hence no fear of overlapping patterns, there is no need for dark triangles at all: each ▲ in a pattern may be replaced by ⟨△∘∘∘⟩, adding c to each of a, b, and v, and setting c = 0.

When there are neither dark ellipses nor leaf patterns, we are left with just

\binom{2(n − v − c) − a + b + 1}{n − v + b} ,

which conforms with [7, §3.2] for the c = 0 case. Figure 3 has 5 occurrences of ⟨▲∘∘∘△⟩ all told.

3 Protected nodes and Fine trees

As mentioned, an internal (nonleaf) node is deemed protected when all its children have offspring [2]. In the size 4 case, as can be seen in Figure 3, there are 6 trees with no protected nodes, 6 with one, and 1 each with two and three. There are 10 trees with exactly two unprotected nodes, and there are 4 with only one, including 1 with one of each. Like sequence \underline{A143362}, but unlike the enumeration in [1], roots are included here in the node count.

Suppose we wish to count the number of trees with n edges, j ≥ 1 leaves, and no protected nodes at all. Referring to Figure 3, there are 5 such for n = 4, j = 3. We simply need m = n + 1 − j patterns ⟨•••♢∘∘∘⟩ for all the unprotected internal nodes, plus ℓ = 2j − n − 1 additional leaf patterns ♢ for any remaining leaves. Letting d = b = m = n+1−j, a = c = 0, v = 2m, e = j − 1, and u = j in (1), we get

∑_{k=1}^{j} \frac{1}{k}\binom{k}{n − j + 1}\binom{j − k}{2j − n − 1} ∑_{i=0}^{j−1} \binom{n − j + i}{n − j}\binom{n − i − 1}{k − 1}\binom{j − i − 1}{j − k} .

For the first binomial to be nonzero, we need n−j+1 ≤ k and for the second, 2j−n−1 ≤ j−k. So k can only take n−j+1. Since all nodes are accounted for, this counts trees. Summing for all j (starting from n and going down) and simplifying, we obtain a closed form for sequence \underline{A143363}:

Proposition 3. The number of ordered trees with n edges and no protected nodes is given by

∑_{j=0}^{n} \frac{1}{j + 1} ∑_{i=0}^{n−j−1} \binom{j + i}{j}\binom{n − i − 1}{j}\binom{n − j − i − 1}{n − 2j − 1} .  (10)

More generally, suppose we wish to count the number of trees with n edges, r protected nodes, and s unprotected. For this, we need r patterns ⟨▲•••⟩ for (nonleaf) protected nodes, s patterns ⟨•••♢∘∘∘⟩ to account for the unprotected nodes, and ℓ = n + 1 − r − 2s pure-leaf patterns. Letting m = d = r + s, a = 0, b = s, c = r, and e = n − r − s in formula (6), and summing for all j = r + s, yields a closed form for sequence \underline{A143362}:

Proposition 4. The number of ordered trees with n edges and r protected nodes is given by

∑_{j=r+1}^{n} \frac{1}{j}\binom{j}{r} ∑_{i=j}^{2j−r−1} \binom{i − 1}{j − 1}\binom{n − r − i + j − 1}{j − r − 1}\binom{n − i}{n + r − 2j + 1} .  (11)

Exchanging the rôles of protected and unprotected, we get an analogous enumeration by unprotected nodes:

Proposition 5. The number of ordered trees with n edges and s unprotected nodes is given by

∑_{j=s}^{n} \frac{1}{j}\binom{j}{s} ∑_{i=j}^{s+j−1} \binom{i − 1}{j − 1}\binom{n + s − i − 1}{s − 1}\binom{n − i}{n − s − j + 1} .

There are 11 protected nodes in the trees displayed in Figure 3, of which 6 are roots and 5 are not. Call a tree protected when its root is. There are, then, 6 protected 4-edge trees.

The pattern ⟨▲•••⟩ matches protected nodes; hence, occurrences of ⟨∘∘∘ ⟨▲•••⟩ ∘∘∘⟩ correspond to protected nonroots. The difference between occurrences of those two patterns counts protected roots (a trick used in [7, §3.3]).

Plugging in the appropriate values in (9) (d = c = v = 1, a = b = 0, w = n − v − c + 1 = n − 1 for the first; d = c = 1, a = 0, b = v = 2, w = n − 2 for the second) gives

∑_{i=0} \binom{i}{i}\binom{2n − 2i − 3}{n − 1} − ∑_{i=0} \binom{i}{i}\binom{2n − 2i − 3}{n}

= ∑_{i=1} [\binom{2n − 2i − 1}{n − 1} − \binom{2n − 2i − 1}{n}] .  (12)

This sum of ballot numbers gives the Fine numbers [1], listed at \underline{A000957}:

Proposition 6 ([11, §1(F)]). The Fine numbers

∑_{i=1}^{n−1} \frac{i}{n − i}\binom{2n − 2i}{n}  (13)

count protected trees with n edges.

See also [11, §4] and references therein.

Let us refer to a leaf on level one, just below the root of a tree, as a stump. Protected trees are stump-free.

Stumps in trees correspond to hills—that is, level 1 peaks—in lattice paths. The path in Figure 2 has one hill, just as the tree in Figure 1 has one stump. So, trees sans stumps are one and the same as paths without hills. It follows that the above proposition counts hill-less paths, a.k.a. Fine paths. In other words, the number of lattice paths of length 2n starting and ending on the baseline y = 0 with no hills peaking at y = 1 is also counted by the Fine numbers [10].

4 Tree stumps and Dyck hills

A lone lozenge pattern ♢ in formula (4) counts leaves. The total number of leaves in all trees with n edges is known to be \binom{2n−1}{n−1} = \frac{1}{2} \binom{2n}{n}, which is half the nodes in all the trees [4], [6, Cor. 2.1]. The number of stumps in a set of trees is the number of leaves minus the number of non-stump leaves, the latter counted by ⟨∘∘∘ ⟨∘∘∘♢∘∘∘⟩ ∘∘∘⟩. There are 35 leaves in Figure 3, 14 of which are stumps.

Generalizing this example and that of the prior section, we focus on the case of a single unambiguous tree pattern p. Let p′ be the embedded pattern ⟨∘∘∘ p ∘∘∘⟩. We can use (9) to count occurrences of both p and p′, the disparity between them only being that the latter has one more node ⟨⋯⟩ and two extra ellipses ∘∘∘. Taking the difference between their two enumerations, we have

∑_{i=0}^{w−a} \binom{d + i − 1}{i} [\binom{2w − a + b − 2i − 1}{w + b + c − 1} − \binom{2w − a + b − 2i − 1}{w + b + c}] ,  (14)

where the parameters refer to p and w = n − v − c + 1. This brings us to the following:

Theorem 7 (Root Pattern). The number of n-edge trees with an occurrence of an unambiguous pattern at the root— a pattern containing v nodes, a light triangles, b light ellipses, c dark triangles, and d dark ellipses— is

∑_{i=0}^{w+(b−a)/2−1} \frac{a + b + 2c + 2i}{2w − a + b − 2i}\binom{d + i − 1}{i}\binom{2w − a + b − 2i}{w + b + c} ,  (15)

where w = n − v − c + 1.

As a trivial example, trees with a unary root—called planted trees— are characterized by the root pattern ⟨△⟩, with v = a = 1 and b = c = d = 0, forcing i = 0:

\frac{1}{2n − 1}\binom{2n − 1}{n} = C_{n−1} ,

just as one should expect. As long as n > 1, the planted trees are also characterized by ⟨▲⟩, with v = c = 1 and a = b = d = 0:

\frac{1}{n − 1}\binom{2n − 2}{n} = C_{n−1} .

If the pattern is ⟨∘∘∘⟩, then all (nonleaf) trees are counted, with v = b = 1 and a = c = d = 0:

\frac{1}{2n + 1}\binom{2n + 1}{n} = C_{n} .

On the other hand, the root pattern is ⟨•••⟩ counts protected trees having no stumps with v = d = 1 and a = b = c = 0:

∑_{i=0}^{n−1} \frac{i}{n − i}\binom{2n − 2i}{n} ,

the Fine numbers, as before, except that ⟨•••⟩ may match an edgeless (n = 0) tree ⟨⟩, while the pattern ⟨▲•••⟩, which we used earlier, cannot.

Suppose now that we wish to count 3-protected trees, that is, trees whose root has neither childless children nor childless grandchildren [3]. (This generalizes the 2-protection example in Figure 3, as studied in the previous section.) The pattern

\left⟨{\underbrace{⟨▲•••⟩ ⋯ ⟨▲•••⟩} \atop c times}\right⟩

counts nodes with c children, all of whom are (2-) protected. Using formula (14) for root patterns, with d = c, v = c + 1, and a = b = 0, and summing for c, and assuming n ≥ 3, we obtain

∑_{c=1}^{n/2} ∑_{i=0}^{n−2c} \binom{c + i − 1}{i} [\binom{2n − 4c − 2i − 1}{n − c − 1} − \binom{2n − 4c − 2i − 1}{n − c}]

for the number of 3-protected trees with n edges. This is equivalent to the closed form ^{1}

∑_{c=1}^{(2n−1)/5}(−1)^{c−1} [\binom{2n − 5c − 1}{n − c − 2} − \binom{2n − 5c − 1}{n − c + 1}]

(here binomials are 0 if either argument is negative), which is the k = 3 case of the general formula for k-protection given in [13, Prop. 5.5]. For n = 4, this is [2 − 0] − [0 − 0] = 2, the last two trees in Figure 3. It likewise counts the number of hill-free Dyck paths having also no peaks at level 2; see sequence \underline{A114627}.

Trees with n edges and root pattern

\left⟨{r times \atop \overbrace{△∘∘∘ ⋯ △∘∘∘△∘∘∘}}\right⟩

are equinumerous to ordered forests (the order of the trees in the forest matters) with n edges and r trees—disallowing edgeless trees in the forest. We need the triangles because an ellipsis alone can match an empty sequence of subtrees; this way we have partitioned the children of the root into r groups, each representing a nonempty tree in the forest. There may be many ways to partition, but each corresponds to a different forest.

We derive

∑_{k=0} \binom{n − 1}{r + k − 1}\binom{n}{n − k} − ∑_{k=0} \binom{n}{r + k + 1}\binom{n − 1}{n − k − 1}

= ∑_{k=0} \binom{n − 1}{n − r − k}\binom{n}{k} − ∑_{k=0} \binom{n}{n − r − 1 − k}\binom{n − 1}{k}

= \binom{2n − 1}{n − r} − \binom{2n − 1}{n − r − 1} .  (16)

Accordingly,

Proposition 8. The number of ordered forests consisting of r nonleaf trees and containing n edges altogether is

\frac{r}{n}\binom{2n}{n − r} .

1I have not found an independent argument for this equivalence.

This is Catalan’s triangle, as per [16], listed at \underline{A039598}, with special cases: r = 2 \underline{A002057}; r = 3 \underline{A003517}; r = 4 \underline{A003518}; r = 5 \underline{A003519}; and r = n − 2 \underline{A014106}.

In [5], it was shown that the sequence \underline{A001700} enumerates n-edge forests, and indeed it is easy to see that

∑_{r=1}^{n}(16) = \binom{2n − 1}{n} .

The pattern ⟨•••♢∘∘∘⟩ counts eldest leaves. Since any one tree can have only one eldest stump, subtracting occurrences of ⟨∘∘∘⟨•••♢∘∘∘⟩∘∘∘⟩ counts trees with at least one stump— making it unprotected. There are 8 such unprotected trees in Figure 3.

Using formula (14), with v = 2, a = c = 0, and b = d = 1, we obtain the following enumeration of unprotected trees:

∑_{i=0} \binom{2n − 2i − 2}{n − 1} − ∑_{i=0} \binom{2n − 2i − 2}{n}  (17)

for n > 1. This is the difference between two recorded sequences, \underline{A014300} and \underline{A172025}, and provides an alternative closed form for the latter.

As must be the case, the protected (12) and unprotected (17) trees add up to all trees, which are counted by the Catalan numbers:

∑_{i=0} [\binom{2n − 2i − 1}{n} + \binom{2n − 2i − 2}{n}] − ∑_{i=0} [\binom{2n − 2i − 1}{n − 1} + \binom{2n − 2i − 2}{n − 1}]

= \binom{2n}{n} − \binom{2n}{n − 1} = C_{n} .

When there can be more than one occurrence of a pattern at the root, formula (15) still counts root occurrences, if not trees. For example, the pattern ⟨∘∘∘♢∘∘∘⟩ occurs once at the root for each stump. Letting v = 2, a = c = d = 0, and b = 2 in (15), we obtain

\frac{1}{n + 1}\binom{2n + 2}{n} .

It follows that

Proposition 9. The number of stumps (level-one leaves) within ordered trees is counted by the Catalan numbers.

This comes as no surprise, since a stump (or for that matter any fixed subtree of the root) splits ordered trees with n edges into two trees with a total of n−1 edges (or n minus the size of any other divider), and the Catalan numbers are well-known to satisfy the corresponding recurrence, as illuminated by the binary trees.

Consider now what a tree with r ≥ 1 stumps looks like. The pattern

⟨•••\overbrace{♢••• ⋯ •••♢•••}^{r times} ⟩

with r embedded leaf patterns matches a node with exactly r childless children. Subtracting occurrences of ⟨∘∘∘ ⟨•••♢••• ⋯ •••♢•••⟩ ∘∘∘⟩ gives the number of roots with r stumps. With the appropriate values in (14), viz. a = b = c = 0 and v = d = r + 1, we obtain the following enumeration:

Proposition 10. The number of trees with n edges and r stumps is 1 for r = n, is 0 for r = n − 1, and, for r < n − 1, is

∑_{i} \frac{i}{n − r − i}\binom{r + i}{r}\binom{2n − 2r − 2i}{n − r} .  (18)

For n = 4, as in Figure 1, the number of trees with r = 0, 1, 2, 3, 4 stumps is 6, 4, 3, 0, 1, respectively.

When r = 0, we retrieve the Fine numbers (13). When r = n − 2, this yields n − 1, with all but one of the n − 1 children of the root being childless. When r = n − 3, this yields 2(n − 2), with two ways to bless each of n − 2 children with two progeny.

On account of the bijection with lattice paths, Proposition 10 also enumerates paths of length 2n sporting r > 0 hills.

5 Discussion

Our tree enumeration formulæ—with their ability to capture a wide variety of patterns— have been used here, in particular, to count trees with various conditions on the number of leaves just below the root. We note that many of the summations we have seen have double the index appearing within the binomial coefficients (eqs. 8–18).

6 Acknowledgment

I thank the referee for suggesting applying the method herein to the enumeration of (k > 2)- protected trees.

References

[1] David Callan, Some bijections and identities for the Catalan and Fine numbers, Séminaire Lotharingien de Combinatoire 53 (2006), Art. B53e. http://www.mat.

    univie.ac.at/~slc/s/s53callan.ps.

[2] Gi-Sang Cheon and Louis W. Shapiro, Protected points in ordered trees, Appl. Math.

    Letters 21(5) (2008), 516–520. http://dx.doi.org/10.1016/j.aml.2007.07.001.

[3] Keith Copenhaver, k-protected vertices in unlabeled rooted plane trees, Graphs Combin.

    33(2) (2017), 347–355. https://arxiv.org/pdf/1606.00083.pdf.

[4] Balakrishnan Dasarathy and Cheng Yang, A transformation on ordered trees, Computer J. 23(2) (1980), 161–164.

[5] Nachum Dershowitz, 1700 forests, August 31 2016. Arxiv preprint, https://arxiv.

org/abs/1608.08740.

[6] Nachum Dershowitz and Shmuel Zaks, Enumerations of ordered trees, Discrete Math. 31(1) (1980), 9–28.

[7] Nachum Dershowitz and Shmuel Zaks, Patterns in trees, Discrete Appl. Math. 25 (1989),

241–255. http://nachum.org/papers/PatternsInTrees.pdf.

[8] Nachum Dershowitz and Shmuel Zaks, The Cycle Lemma and some applications, Eu-

ropean J. Combin. 11 (1990), 35–40. http://nachum.org/papers/CL.pdf.

[9] Nachum Dershowitz and Shmuel Zaks, More patterns in trees: Up and down, young and old, odd and even, SIAM J. Discrete Math. 23(1) (2009), 447–465. http://nachum.

org/papers/UpDown.pdf.

[10] Emeric Deutsch, Dyck path enumeration, Discrete Math. 204 (1999), 167–202.

[11] Emeric Deutsch and Louis Shapiro, A survey of the Fine numbers, Discrete Math. 241(1–3) (2001), 241–265.

[12] Aryeh Dvoretzky and Theodore Motzkin, A problem of arrangements, Duke Math. J. 14 (1947), 305–313.

[13] Clemens Heuberger and Helmut Prodinger, Protection number in plane trees, Appl. Anal. Discrete Math. 11 (2017), 314–326. http://pefmath.etf.rs/vol11num2/

AADM-Vol11-No2-314-326.pdf.

[14] Tadepalli V. Narayana, A partial order and its applications to probability, Sankhya 21 (1959), 91–98.

[15] John Riordan, Enumeration of plane trees by branches and endpoints, J. Combin. Theory Ser. A 19 (1975), 215–222.

[16] Louis W. Shapiro, A Catalan triangle, Discrete Math. 14(1) (1976), 83–90.

[17] Neil J. Sloane et al., The On-Line Encyclopedia of Integer Sequences, 2020. https://

oeis.org.

[18] Richard P. Stanley, Catalan Numbers, Cambridge University Press, 2015.

2010 Mathematics Subject Classification: Primary 05A15. Keywords: tree enumeration, tree pattern, lattice path, Dyck path, Fine path, Fine number, protected node, hill.

(Concerned with sequences \underline{A000108}, \underline{A000957}, \underline{A001263}, \underline{A001700}, \underline{A002057}, \underline{A003517}, \underline{A003518}, \underline{A003519}, \underline{A014106}, \underline{A014300}, \underline{A039598}, \underline{A114627}, \underline{A143362}, \underline{A143363}, \underline{A172025}.)

Received September 27 2018; revised versions received March 6 2020. Published in Journal of Integer Sequences, June 27 2020.

Return to Journal of Integer Sequences home page.