Abstract
In this paper we consider the enumeration of binary trees avoiding noncontiguous binary tree patterns. We begin by computing closed formulas for the number of trees avoiding a single binary tree pattern with 4 or fewer leaves and compare these results to analogous work for contiguous tree patterns. Next, we give an explicit generating function that counts binary trees avoiding a single noncontiguous tree pattern according to number of leaves and show that there is exactly one Wilf class of leaf tree patterns for any positive integer . In addition, we enumerate binary trees that simultaneously avoid more than one tree pattern. Finally, we explore connections between patternavoiding trees and patternavoiding permutations.
NonContiguous Pattern Avoidance in Binary Trees
Michael Dairyko^{1}^{1}1Partially supported by NSF grant DMS0851721
Department of Mathematics
Pomona College
Claremont, CA 91711, USA
Lara Pudwell^{1}^{1}footnotemark: 1
Department of Mathematics and Computer Science
Valparaiso University
Valparaiso, IN 46383, USA
Lara.Pudwell@valpo.edu
Samantha Tyner^{1}^{1}footnotemark: 1
Department of Mathematics
Augustana College
Rock Island, IL 61201, USA
Casey Wynn^{1}^{1}footnotemark: 1
Department of Mathematics and Computer Science
Hendrix College
Conway, AR 72032, USA
1 Introduction
The notion of one object avoiding another has been studied in permutations, words, partitions, and graphs. Much recent work has been devoted to the study of patternavoiding permutations. Given permutations and , we say that contains as a (classical) pattern if there exist indices such that is orderisomorphic to ; that is, if and only if . Otherwise, is said to avoid . For example contains the pattern as evidenced by , , and , but avoids the pattern because has no decreasing subsequence of length 3. One variation on this definition of pattern avoidance is to place the restriction on the indices for . If there exists such a subsequence of that is orderisomorphic to , then is said to contain as a consecutive permutation pattern. For each of these definitions, two natural questions arise: “Given a permutation , how many permutations of length avoid ?” and “When do two distinct permutations and yield the same avoidance generating function?” Patterns and with this property are said to be Wilfequivalent.
In this paper we consider analogous questions of pattern avoidance for plane trees. All trees in the paper are rooted and ordered. We will focus on full binary trees, that is, trees in which each vertex has 0 or 2 (ordered) children. Two children with a common parent are sibling vertices. A vertex with no children is a leaf and a vertex with 2 children is an internal vertex. A binary tree with leaves has internal vertices, and the number of such trees is (OEIS A000108). For simplicity of computation, we adopt the convention that there are zero rooted binary trees with zero leaves. The first few binary trees are depicted in Figure 2.
Conceptually, a plane tree avoids a tree pattern if there is no instance of anywhere inside . Pattern avoidance in vertexlabeled trees has been studied in various contexts by Steyaert and Flajolet [16], Flajolet, Sipala, and Steyaert [7], Flajolet and Sedgewick [6], and Dotsenko [3]. Recently, Disanto [2] studied pattern containment of caterpillar subgraphs in binary trees while Khoroshkin and Piontkovski [9] considered generating functions for general unlabeled tree patterns in a different context.
In 2010, Rowland [13] explored contiguous pattern avoidance in binary trees (that is, rooted ordered trees in which each vertex has 0 or 2 children). He chose to work with binary trees because there is natural bijection between leaf binary trees and vertex trees. His study had two main objectives. First, he developed an algorithm to find the generating function for the number of leaf binary trees avoiding a given tree pattern; he adapted this to count the number of occurrences of the given pattern. Second, he determined equivalence classes for binary tree patterns, classifying two trees and as equivalent if the same number of leaf binary trees avoid as avoid for . He completed the classification for all binary trees with at most eight leaves, using these classes to develop replacement bijections between equivalent binary trees.
In 2012, Gabriel, Peske, Tay, and the second author [8] considered Rowland’s definition of tree pattern in ternary, and more generally in ary, trees. After generalizing Rowland’s algorithmic approach to compute functional equations for the avoidance generating functions of arbitrary ternary tree patterns, they explored bijections between equinumerous sets of patternavoiding trees. Along the way they found sets of patternavoiding trees whose enumeration yielded a number of wellknown sequences.
In this paper, we extend Rowland’s work in a new direction. The work of [8] and [13] may be seen as parallel to the definition of consecutive permutation patterns given at the beginning of this section. In those papers, tree was said to contain tree as a (contiguous) pattern if was a contiguous, rooted, ordered, subtree of . In this paper, we modify the definition of tree pattern to mirror the idea of classical pattern avoidance in permutations. In the case of patternavoiding permutations, there are more Wilfclasses for consecutive patterns of a given length than for classical patterns (as a small example, there are 7 Wilf classes of consecutive permutation patterns of length 4, compared to 3 Wilf classes for classical permutation patterns of length 4). This parallel holds true in the case of trees. In fact, as we show in Section 4, there is precisely one Wilf class of leaf patterns for any .
As with previous work, given any binary tree pattern we present a technique to compute the generating function that enumerates trees avoiding according to the number of leaves. This enumeration shows that there is exactly one Wilf class of leaf patterns. We also consider trees avoiding multiple tree patterns and explore relationships between sets of patternavoiding trees and patternavoiding permutations.
2 Definitions and Notation
In this paper, a tree contains as a (noncontiguous) tree pattern if there is a tree , obtained from via a finite sequence of edge contractions, such that is a contiguous, rooted, and ordered subtree of . Conversely, avoids if there is no such that contains as a subtree. For example, consider the three trees shown in Figure 1. avoids as a contiguous pattern, but contains noncontiguously (contract all nonbolded edges). On the other hand, avoids both contiguously and noncontiguously since no vertex of has a left child and a right child, both of which are internal vertices.
We define to be the set of leaf binary trees that avoid the pattern noncontiguously, and . We will also write for the set of leaf binary trees that avoid contiguously, and . We will be particularly interested in determining the generating function
for various tree patterns .
Before we explore particular binary tree patterns, we list all of the 1, 2, 3, and 4leaf binary trees. We label trees with a double subscript notation. The first subscript gives the number of leaves of the tree, and the second subscript distinguishes between distinct tree patterns with the same number of leaves. We also note that if is the leftright reflection of tree , then by symmetry, so we omit leftright reflections. We will use these labels throughout the remainder of the paper.
3 Avoiding Simple Tree Patterns
In this section, we find generating functions for the number of trees avoiding each of the tree patterns in Figure 2. For each tree, we discuss the structure of trees that avoid the given tree pattern and explain how to find a recurrence and generating function from this structure. We also compare these generating functions to previously known results for contiguous tree patterns.
3.1 Avoiding , , and
Clearly, a tree avoids if and only if it has no vertices. This is also true for contiguous avoidance, so we have
Next, a tree avoids if and only if it has no vertex with two children. In other words, only avoids . Again, we have
Finally, we observe that tree avoids if and only if has no vertex whose left child is not a leaf. For each there is precisely one such tree, so we have
From these few cases, it may seem that noncontiguous and contiguous avoidance is the same for many trees. The reader should suspect that this similarity does not hold for larger tree patterns based on the example of Figure 1. This suspicion is confirmed when we consider 4leaf tree patterns.
Rowland showed that for
where is the th Motzkin number (OEIS A001006).
It turns out that noncontiguous avoidance is even more wellbehaved for 4leaf tree patterns. We will show that for
3.2 Avoiding
To find , we consider the structure of a general leaf binary tree that avoids . We have two cases. Let be the root of . In the first case, ’s left child has no children, while ’s right child is the root of an leaf subtree avoiding . In the second case, ’s left child has two children, but the leftmost of these children is a leaf. If the right child of ’s left child is the root of a subtree with leaves (), then ’s right child is the root of a subtree with leaves. Further, the leaf subtree must avoid the tree pattern .
In the first case, we considered possible trees. In the second case, we considered trees. However, since we know that for , we have
Together with the base case , we see that
3.3 Avoiding
Next, we consider the structure of a general leaf binary tree that avoids where is the root of . Again, we have two cases. As before, in the first case, ’s left child has no children, while ’s right child is the root of an leaf subtree avoiding . In the second case, ’s left child has two children, but now the rightmost of these children is a leaf. The subtree whose root is the left child of ’s left child must avoid the tree pattern . After a nearly identical calculation to that of avoiding , we see that
3.4 Avoiding
Finally, we consider the structure of a general leaf binary tree that avoids where is the root of . Again, we have two cases: either ’s left child has children or ’s right child has children, but not both. There are trees that fall into the first case, and trees that fall into the second case, which yields
We have
4 Generating Functions for PatternAvoiding Trees
We have just seen that all 4leaf binary tree patterns produce the same avoidance sequence when considered as noncontiguous patterns. This observation leads naturally to the main theorem of this paper, which provides a particularly clean answer to both questions stated in the introduction. Namely, “given a tree pattern , how many trees with leaves avoid ?” and “given two distinct tree patterns and , when do and produce the same avoidance sequence?” In fact, we see that not only is exact enumeration possible for any noncontiguous tree pattern, we see that all avoidance generating functions are rational and of a particularly attractive form.
Theorem 1.
Let and let be a binary tree pattern with leaves. Then
The reader can check that this indeed matches the generating functions computed in the previous section when . Further, notice that the generating function given in Theorem 1 depends only on the number of leaves of , and not on itself; that is, there is precisely one Wilf class of leaf tree patterns for each . As we will see in Section 7 and the Appendix, the analogous statement for pairs of trees is not true. In this section we build the necessary framework to prove Theorem 1.
First, following [8, 13] we say that contains pattern at the root if contains a contiguous copy of where the root of coincides with the root of . Now, let be the generating function that enumerates binary trees avoiding tree pattern noncontiguously and containing the contiguous tree pattern at their root according to number of leaves. Because all binary trees have a root vertex, it follows that the generating function for all trees avoiding is given by . Also, let and denote the subtrees descending from the left and right children of the root of respectively.
Since we are working with full binary trees, the root has either zero or two children. When there are zero children, we have a 1leaf tree. When there are two children, we have a tree with pattern at the root. Such trees are enumerated with the generating function . Thus, we have
(1) 
Next, we determine a recurrence for . Consider a tree that avoids and has the contiguous pattern at the root. Either the subtree extending from the left child of the root of avoids , the subtree extending from the right child of the root of avoids , or both. Inclusionexclusion gives
(2) 
Now, solve for to obtain
(3) 
This computation yields one immediate result:
Proposition 1.
For any tree pattern , is a rational function of .
Proof.
We have already seen that is rational for all tree patterns with leaves. Thus, by induction and Equation 3, the proposition follows. ∎
Equation 3 simplifies further for one particular family of binary tree patterns. Let the leaf left comb be the unique leaf binary tree where every right child is a leaf. Write for the leaf left comb. Then , , , and .
Lemma 1.
for .
This nice relationship between and seems natural because of the large overlap between copies of and . Our next lemma shows that there is a simple relationship between generating functions for noncomb tree patterns as well.
Lemma 2.
Fix . Let and be two leaf binary tree patterns. Then
Proof.
Assume the lemma holds for tree patterns with leaves where . Since we suppose that all leaf trees have the same avoidance generating function, we have that any leaf tree has avoidance generating function . Suppose that tree has leaves to the left of its root and leaves to the right of its root. Similarly, suppose that tree has leaves to the left of its root and leaves to the right of its root. We will show that .
From Equation 3, we have
(4) 
Similarly,
(5) 
Thus
Since this holds for , by transitivity, all leaf tree patterns have the same noncontiguous avoidance generating function. ∎
Finally, to prove the main theorem, it suffices to show that
It is a straightforward induction proof, using the fact that to show that this formula holds in general.
We have now explicitly enumerated trees avoiding any single binary tree pattern noncontiguously and determined all equivalences for when two trees exhibit the same avoidance sequence. We display the explicit generating function, first 8 sequence terms, and appropriate OEIS entry for tree patterns with leaves where in Table 1.
Sequence  Growth rate  OEIS number  

1  0  0  trivial  
2  0  trivial  
3  trivial  
4  A000079  
5  A001519  
6  A007051  
7  A080937  
8  A024175  
9  A080938 
Because all generating functions are rational it follows that for any leaf binary tree the sequence satisfies a linear recurrence with constant coefficients. In fact, when tree pattern has leaves, grows exponentially. Because there are Catalanmany binary trees with leaves, the growth of these sequences is bounded above by . In Table 1 we display also the asymptotic growth rate for .
5 Recurrences for Binary Trees
While we gave explicit combinatorial explanations for the recurrences satisfied by when has or leaves in Section 3, the rest of our work has been algebraic. It is possible, however, to derive the recurrences satisfied by tree enumeration sequences through other techniques. In this section, we give a combinatorial explanation for these recurrences by considering the structure of trees that avoid the leaf left comb.
First, we define a manytoone correspondence between the set of leaf binary trees and the set of leaf binary trees. Given a tree with leaves, let be rightmost leaf whose sibling vertex is also a leaf. Then, let the parent tree of be the leaf tree obtained by deleting and its sibling. If is the parent tree of , then we say that is a descendent tree of . While the parent tree of a tree is unique, a given tree may have multiple descendent trees. For example, , , and are descendent trees of . Similarly, and are descendent trees of .
Now, for any leaf tree , we can use this parent/descendent relationship to generate a list where , has leaves for and is a descendant tree of . We refer to such a sequence of trees as the ancestry of . Because parent trees are unique, the ancestry of tree must be unique. For example, the tree has ancestry
Given an leaf tree , we may also generate all descendent trees of in a systematic way. Call an internal vertex of closed if ’s right child is not a leaf. The number of descendent trees of is equal to the number of leaves of that appear to the right of all closed vertices. In fact, to produce a descendent tree of , we need only attach a pair of children to any one such leaf. The descendent tree relationship is further articulated in the following proposition.
Proposition 2.
Suppose that tree has descendant trees. Then those descendant trees will have descendant trees respectively. Further, if has descendant trees then the leftmost vertex to which one may add children is the leftmost vertex in a copy of an leaf left comb.
Proof.
Both claims in the proposition are consequences of the fact that the number of descendent trees of is equal to the number of leaves of appearing to the right of all closed vertices.
Let be the th leaf from the right of these leaves. When we append two children to , ’s parent is closed, and this new tree has only descendents.
Further, if has leaves to the right of all closed vertices, by definition of closed, none of these leaves’ parents have right children that are internal vertices. The only way to arrange a collection of vertices so that no internal vertices are right children is in the shape of an leaf left comb. ∎
Now, consider the descendant relation restricted to trees that avoid the leaf left comb. Any tree with descendant trees contains an leaf comb, so we are only concerned with trees that have at most descendent trees. As in Proposition 2, a tree with descendant trees will have descendant trees with descendants respectively.
Notice further that for a tree which would have descendent trees, one of these descendent trees contains the leaf left comb, so such a tree only has descendent trees that avoid the leaf comb. Consequently, for a tree with descendent trees, those descendents will have descendent trees respectively that avoid the leaf left comb.
Let be the number of leaf trees that avoid the leaf left comb and have exactly leaf descendants, and let .
We have the base cases and .
More generally, for
Ultimately, we seek a recurrence for . Adding the above equations and algebraic manipulation produces the result
From the discussion above, trees avoiding an leaf comb can be constructed with a finitely labeled generating tree (in particular with a generating tree using precisely labels), and one may use the transfer matrix method to obtain an alternate proof of Theorem 1 for the case of avoiding the leaf left comb.
6 Connections to patternavoiding permutations
As evidenced in the Appendix, many sequences obtained by counting trees that avoid noncontiguous binary tree patterns are already known in the literature for other reasons. In this section we present a theorem that fully explains this connection for the case of avoiding a single binary tree pattern.
To this end, let denote the set of permutations of length . As in the introduction, given and we say that contains as a pattern if there exist indices such that if and only if . Let , and . For example, for since the only way to avoid the pattern 12 is to be the decreasing permutation of length . It is also wellknown that if , then where is the th Catalan number.
Theorem 2.
Let be any binary tree pattern with leaves. Then
Proof.
It is well known that the set of binary trees with leaves is in bijection with the set of permutations of length which avoid the pattern 231.
To see this, label the root of tree with the label . Now, suppose there are internal vertices to the left of the root and internal vertices to the right of the root. The vertices on the left will receive labels from the set and the vertices on the right will receive labels from the set . For each subtree, give the root the largest available label and continue recursively until each internal vertex has been labeled.
Now, there is a natural lefttoright ordering of the vertices of . Read the labels of the vertices from left to right to obtain a permutation . Necessarily, avoids because all labels to the left of a given vertex have smaller labels than all labels to the right.
Further, we can see that the leaf right comb encodes the unique decreasing permutation of length . It is not hard to see that if a tree avoids the leaf right comb, then the corresponding permutation avoids the decreasing permutation of length and vice versa. ∎
We note that this correspondence between avoiding permutations and binary trees is not new. If one ignores the leaves in our trees, the bijection given in the proof of Theorem 2 is identical to the correspondence between postorderlabeled trees with inorderread permutations found in [5]. Further work connecting permutations to binary trees in the context of sorting can be found in [1], [4], [10], [11], [12], and [14].
It is worth considering when Theorem 2 generalizes and how. The correspondence given in the proof of Theorem 2 does not necessarily work with trees other than the right comb. For example, while the permutation corresponding to is 123. However, () while (). Thus even if the sequence obtained from avoiding a set of tree patterns is also the avoidance sequence for some set of patternavoiding permutations, there may be other bijections required to demonstrate the equivalence. It remains open to give a natural interpretation of Theorem 2 for trees other than the right comb.
7 Avoiding two or more binary trees simultaneously
Thus far, we have analyzed generating functions and enumeration sequences for trees avoiding a single noncontiguous binary tree pattern. We will now consider trees that avoid two tree patterns simultaneously. To this end, let be the generating function that enumerates trees avoiding and with pattern at the root according to number of leaves. For brevity, we may abbreviate .
(6) 
and
(7)  
This latter expression follows again from inclusionexclusion. One can solve this pair of equations for to obtain a rational combination of rational generating functions and see that for any pair of binary trees, is indeed rational.
To compactly state the equivalent expression to Equation 7 for trees avoiding binary tree patterns (), we need to introduce more efficient notation. Notice that all terms on the right hand sides of Equations 2 and 7 are of the form where for each tree , there are 3 possibilities: (i) and , (ii) and , or (iii) and . Let and let where (i) if then and , (ii) if then and , and (iii) if then and . Further, for , define .
By inclusionexclusion we have:
(8) 
Notice that this expression is linear in . In fact, only appears in two terms: the ones corresponding to and , so we see that is rational for any finite set of tree patterns.
We used Equations 6 and 7 to compute for any pair of binary tree patterns where and have no more than 5 leaves. A summary of these results is given in the Appendix.
In light of Theorem 2 one might wonder if for every set of binary tree patterns , is identical to the avoidance sequence for some set of permutation patterns. This, however turns out not to be the case. For example consider the sequence
If this were the avoidance sequence for some set of permutation patterns , we see from the fact that that contains a pattern of length 3. Further, since it is known that for any pattern , must contain precisely two patterns of length 4. However, exhaustive checking of for sets of patterns consisting of one pattern of length 3 and two patterns of length 4 yields no match for this sequence.
8 Conclusion
Throughout this paper, we have investigated noncontiguous pattern avoidance in binary trees. Unlike Rowland’s work for contiguous patterns, our avoidance generating functions are always rational, and the Wilf classes obtained for avoidance of single patterns are easy to describe: two tree patterns are Wilfequivalent if and only if they have the same number of leaves. The results in this paper not only give a complete characterization of trees avoiding a single pattern, but we also present a computational technique to quickly determine the number of trees avoiding any finite set of noncontiguous tree patterns. Finally we explore combinatorial proofs of our results and give an explicit bijection between certain patternavoiding trees and patternavoiding permutations.
Acknowledgement
The authors thank Eric Rowland for assistance with generating the tree graphics for this paper and for several helpful presentation suggestions.
Appendix
This appendix lists pairs of binary tree patterns each of which have at most 5 leaves, classifying them by their avoidance generating function and sequence. For each class, we give the generating function , and we list the first 15 terms of the corresponding avoidance sequence. If the avoidance sequence for a class is listed in the Online Encyclopedia of Integer Sequences [15], we include the appropriate reference. For brevity, left–right reflections are omitted.
Avoiding a 3Leaf & a 4Leaf Tree
Class A


Sequence:
Avoiding a 3Leaf & a 5Leaf Tree
Class A


Sequence:
Avoiding a 4Leaf & a 5Leaf Tree
Class A


Sequence:
Class B


Sequence:

OEIS A016777: for
Class C


Sequence:

OEIS A152947:
Class D