I’m searching a practical algorithm for enumerating all full labeled binary tree.
A full binary tree is a tree where all internal nodes has a degree 3, the leaves has degree 1 and the root has a degree 2.
A labeled tree is a tree where all leaves has a unique label.
Example:
*
|\
| \
* *
/| |\
/ | | \
T C D F
From comments, it is clear that the question is to enumerate rooted unordered labelled full binary trees. As explained in this paper, the number of such trees with
nlabels is(2n-3)!!where!!is the double factorial function.The following python program is based on the recursive proof in the referenced paper; I think the code is straight-forward enough that it will pass as an explanation of the algorithm:
For
n == 4, there are(2*4 - 3)!! == 5!! == 1 * 3 * 5 == 15trees:Another possible interpretation of the question was that it sought an enumeration of rooted ordered full binary trees with a specified list of labels. The number of such trees with n leaves is given by
Cn-1, from the Catalan number sequence.For 5 labels, we have
C5-1 == 14: