Holonomic equations and efficient random generation of binary trees
Pierre Lescanne
TL;DR
The paper extends Rémy’s holonomic-recurrence framework for linear-time random generation from binary trees to Motzkin and Schröder trees. It develops a bijective, constructive approach based on the Motzkin (Dulucq–Penaud) and Foata–Zeilberger proofs, introducing leaf- and node-marked slanting-tree structures and concrete vector-based algorithms. A constant-time oracle (or a practical approximation) enables linear-time generation for Motzkin trees on practical sizes, while Schröder-tree generation relies on a related bijection to achieve quasi-linear complexity with a controlled retry mechanism. The work provides implementations in Haskell and Python, benchmarks up to about $9 imes10^6$–$10^7$ size, and situates the results within the broader landscape of Boltzmann samplers and linear-time random-generation methods. Overall, it demonstrates that holonomic recurrences can guide efficient, exact-size random generation across several tree families, with concrete practical performance benefits.
Abstract
Holonomic equations are recursive equations which allow computing efficiently numbers of combinatoric objects. R{é}my showed that the holonomic equation associated with binary trees yields an efficient linear random generator of binary trees. I extend this paradigm to Motzkin trees and Schr{ö}der trees and show that despite slight differences my algorithm that generates random Schr{ö}der trees has linear expected complexity and my algorithm that generates Motzkin trees is in O(n) expected complexity, only if we can implement a specific oracle with a O(1) complexity. For Motzkin trees, I propose a solution which works well for realistic values (up to size ten millions) and yields an efficient algorithm.
