Pattern-Avoiding Binary Trees - Generation, Counting, and Bijections

Authors Petr Gregor , Torsten Mütze , Namrata

Thumbnail PDF


  • Filesize: 1.77 MB
  • 19 pages

Document Identifiers

Author Details

Petr Gregor
  • Department of Theoretical Computer Science and Mathematical Logic, Charles University, Prague, Czech Republic
Torsten Mütze
  • Department of Computer Science, University of Warwick, United Kingdom
  • Department of Theoretical Computer Science and Mathematical Logic, Charles University, Prague, Czech Republic
  • Department of Computer Science, University of Warwick, Coventry, UK

Cite AsGet BibTex

Petr Gregor, Torsten Mütze, and Namrata. Pattern-Avoiding Binary Trees - Generation, Counting, and Bijections. In 34th International Symposium on Algorithms and Computation (ISAAC 2023). Leibniz International Proceedings in Informatics (LIPIcs), Volume 283, pp. 33:1-33:19, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2023)


In this paper we propose a notion of pattern avoidance in binary trees that generalizes the avoidance of contiguous tree patterns studied by Rowland and non-contiguous tree patterns studied by Dairyko, Pudwell, Tyner, and Wynn. Specifically, we propose algorithms for generating different classes of binary trees that are characterized by avoiding one or more of these generalized patterns. This is achieved by applying the recent Hartung-Hoang-Mütze-Williams generation framework, by encoding binary trees via permutations. In particular, we establish a one-to-one correspondence between tree patterns and certain mesh permutation patterns. We also conduct a systematic investigation of all tree patterns on at most 5 vertices, and we establish bijections between pattern-avoiding binary trees and other combinatorial objects, in particular pattern-avoiding lattice paths and set partitions.

Subject Classification

ACM Subject Classification
  • Mathematics of computing → Enumeration
  • Mathematics of computing → Permutations and combinations
  • Mathematics of computing → Combinatorial algorithms
  • Generation
  • binary tree
  • pattern avoidance
  • permutation
  • bijection


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. K. Anders and K. Archer. Rooted forests that avoid sets of permutations. European J. Combin., 77:1-16, 2019. URL:
  2. A. Asinowski, A. Bacher, C. Banderier, and B. Gittenberger. Analytic combinatorics of lattice paths with forbidden patterns: enumerative aspects. In Language and automata theory and applications, volume 10792 of Lecture Notes in Comput. Sci., pages 195-206. Springer, Cham, 2018. URL:
  3. E. Babson and E. Steingrímsson. Generalized permutation patterns and a classification of the Mahonian statistics. Sém. Lothar. Combin., 44:Art. B44b, 18 pp., 2000. Google Scholar
  4. J.-L. Baril and S. Kirgizov. Bijections from Dyck and Motzkin meanders with catastrophes to pattern avoiding Dyck paths. Discrete Math. Lett., 7:5-10, 2021. URL:
  5. A. Bernini, L. Ferrari, R. Pinzani, and J. West. Pattern-avoiding Dyck paths. In 25th International Conference on Formal Power Series and Algebraic Combinatorics (FPSAC 2013), Discrete Math. Theor. Comput. Sci. Proc., AS, pages 683-694. Assoc. Discrete Math. Theor. Comput. Sci., Nancy, 2013. Google Scholar
  6. D. Bevan, D. Levin, P. Nugent, J. Pantone, L. Pudwell, M. Riehl, and M. L. Tlachac. Pattern avoidance in forests of binary shrubs. Discrete Math. Theor. Comput. Sci., 18(2):Paper No. 8, 22 pp., 2016. Google Scholar
  7. J. Bloom and S. Elizalde. Pattern avoidance in matchings and partitions. Electron. J. Combin., 20(2):Paper 5, 38, 2013. URL:
  8. J. Bloom and D. Saracino. Pattern avoidance for set partitions à la Klazar. Discrete Math. Theor. Comput. Sci., 18(2):Paper No. 9, 22 pp., 2016. URL:
  9. P. Brändén and A. Claesson. Mesh patterns and the expansion of permutation statistics as sums of permutation patterns. Electron. J. Combin., 18(2):Paper 5, 14 pp., 2011. Google Scholar
  10. The Combinatorial Object Server: Generate binary trees. URL:
  11. M. Dairyko, L. Pudwell, S. Tyner, and C. Wynn. Non-contiguous pattern avoidance in binary trees. Electron. J. Combin., 19(3):Paper 22, 21 pp., 2012. URL:
  12. F. Disanto. Unbalanced subtrees in binary rooted ordered and un-ordered trees. Sém. Lothar. Combin., 68:Art. B68b, 14 pp., 2012. Google Scholar
  13. V. Dotsenko. Pattern avoidance in labelled trees, 2011. URL:
  14. S. Elizalde and M. Noy. Consecutive patterns in permutations. Adv. in Appl. Math., 30:110-125, 2003. Formal power series and algebraic combinatorics (Scottsdale, AZ, 2001). URL:
  15. N. Gabriel, K. Peske, L. Pudwell, and S. Tay. Pattern avoidance in ternary trees. J. Integer Seq., 15(1):Article 12.1.5, 20 pp., 2012. Google Scholar
  16. S. Giraudo. Tree series and pattern avoidance in syntax trees. J. Combin. Theory Ser. A, 176:105285, 37, 2020. URL:
  17. A. Godbole, A. Goyt, J. Herdan, and L. Pudwell. Pattern avoidance in ordered set partitions. Ann. Comb., 18(3):429-445, 2014. URL:
  18. A. M. Goyt. Avoidance of partitions of a three-element set. Adv. in Appl. Math., 41(1):95-114, 2008. URL:
  19. A. M. Goyt and L. K. Pudwell. Avoiding colored partitions of two elements in the pattern sense. J. Integer Seq., 15(6):Article 12.6.2, 17 pp., 2012. Google Scholar
  20. P. Gregor, T. Mütze, and Namrata. Combinatorial generation via permutation languages. VI. Binary trees, 2023. Full preprint version of the present article available at URL:
  21. E. Hartung, H. P. Hoang, T. Mütze, and A. Williams. Combinatorial generation via permutation languages. I. Fundamentals. Trans. Amer. Math. Soc., 375(4):2255-2291, 2022. URL:
  22. V. Jelínek and T. Mansour. On pattern-avoiding partitions. Electron. J. Combin., 15(1):Research paper 39, 52 pp., 2008. URL:
  23. V. Jelínek, T. Mansour, and M. Shattuck. On multiple pattern avoiding set partitions. Adv. in Appl. Math., 50(2):292-326, 2013. URL:
  24. M. Klazar. On abab-free and abba-free set partitions. European J. Combin., 17(1):53-68, 1996. URL:
  25. M. Klazar. Counting pattern-free set partitions. I. A generalization of Stirling numbers of the second kind. European J. Combin., 21(3):367-378, 2000. URL:
  26. M. Klazar. Counting pattern-free set partitions. II. Noncrossing and other hypergraphs. Electron. J. Combin., 7:Research Paper 34, 25 pp., 2000. URL:
  27. G. D. Knott. A numbering system for binary trees. Commun. ACM, 20(2):113-115, 1977. URL:
  28. D. E. Knuth. The Art of Computer Programming. Vol. 1: Fundamental algorithms. Addison-Wesley, Reading, MA, 1997. Third edition. Google Scholar
  29. G. Kreweras. Sur les partitions non croisées d'un cycle. Discrete Math., 1(4):333-350, 1972. URL:
  30. D. Levin, L. K. Pudwell, M. Riehl, and A. Sandberg. Pattern avoidance in k-ary heaps. Australas. J. Combin., 64:120-139, 2016. Google Scholar
  31. J. M. Lucas, D. Roelants van Baronaigien, and F. Ruskey. On rotations and the generation of binary trees. J. Algorithms, 15(3):343-366, 1993. URL:
  32. T. Mansour and M. Shattuck. Pattern avoiding partitions and Motzkin left factors. Cent. Eur. J. Math., 9(5):1121-1134, 2011. URL:
  33. T. Mansour and M. Shattuck. Pattern avoiding partitions, sequence A054391 and the kernel method. Appl. Appl. Math., 6(12):397-411, 2011. Google Scholar
  34. A. Merino and T. Mütze. Combinatorial generation via permutation languages. III. Rectangulations. Discrete Comput. Geom., 70:51-122, 2023. URL:
  35. T. Mütze. Combinatorial Gray codes - an updated survey. Electron. J. Combin., DS26:93, 2023. URL:
  36. OEIS Foundation Inc. The on-line encyclopedia of integer sequences, 2023. URL:
  37. L. Pudwell, C. Scholten, T. Schrock, and A. Serrato. Noncontiguous pattern containment in binary trees. International Scholarly Research Notices, 2014, 2014. URL:
  38. E. S. Rowland. Pattern avoidance in binary trees. J. Combin. Theory Ser. A, 117(6):741-758, 2010. URL:
  39. B. E. Sagan. Pattern avoidance in set partitions. Ars Combin., 94:79-96, 2010. Google Scholar
  40. A. Sapounakis, I. Tasoulas, and P. Tsikouras. Counting strings in Dyck paths. Discrete Math., 307(23):2909-2924, 2007. URL:
  41. C. Savage. A survey of combinatorial Gray codes. SIAM Rev., 39(4):605-629, 1997. URL:
  42. A. Williams. The greedy Gray code algorithm. In Algorithms and data structures, volume 8037 of Lecture Notes in Comput. Sci., pages 525-536. Springer, Heidelberg, 2013. URL: