  We present an algorithm for generating merger histories of dark matter
haloes. The algorithm is based on the excursion set approach with moving
barriers whose shape is motivated by the ellipsoidal collapse model of halo
formation. In contrast to most other merger-tree algorithms, ours takes
discrete steps in mass rather than time. This allows us to quantify effects
which arise from the fact that outputs from numerical simulations are usually
in discrete time bins. In addition, it suggests a natural set of scaling
variables for describing the abundance of halo progenitors; this scaling is not
as general as that associated with a spherical collapse. We test our algorithm
by comparing its predictions with measurements in numerical simulations. The
progenitor mass fractions and mass functions are in good agreement, as is the
predicted scaling law. We also test the formation-redshift distribution, the
mass distribution at formation, and the redshift distribution of the most
recent major merger; all are in reasonable agreement with N-body simulation
data, over a broad range of masses and redshifts. Finally, we study the effects
of sampling in discrete time snapshots. In all cases, the improvement over
algorithms based on the spherical collapse assumption is significant.
