count_nonisomorphic_trees#
- graph_tool.generation.count_nonisomorphic_trees(N)[git][source]#
Return the number of nonisomorphic (unlabeled) trees with \(N\) vertices.
- Parameters:
- N
int Number of vertices.
- N
- Returns:
- n
int Number of trees.
- n
See also
nonisomorphic_treesEnumeration of the nonisomorphic trees
Notes
The number is obtained with Otter’s formula [otter-number-1948] \(T_N = t_N - \sum_{j=1}^{\lfloor N/2\rfloor}t_jt_{N-j} + [N\text{ even}]\binom{t_{N/2}+1}{2}\), from the numbers \(t_n\) of rooted trees, computed with the recurrence \(t_m = \frac{1}{m-1} \sum_{k=1}^{m-1}\left(\sum_{d|k}dt_d\right)t_{m-k}\), evaluated exactly (with GMP integers) by a divide-and-conquer convolution that needs \(O(\log N)\) products of integers with \(O(N^2)\) bits.
References
[otter-number-1948]Richard Otter, “The number of trees”, Annals of Mathematics 49, 583-599 (1948), DOI: 10.2307/1969046 [sci-hub, @tor]
Examples
>>> print([gt.count_nonisomorphic_trees(n) for n in range(1, 11)]) [1, 1, 1, 2, 3, 6, 11, 23, 47, 106]