At each step the underlying fold deletes the contracted positions from the working list and appends either the chosen leaf (singleton step) or the pair of children (binary step) as a tree-level node, so the order in which leaves appear in the output is determined by the path.