I am learning to implement tree algorithms and often I need to test my algorithms by generating different binary tree, which i do manually. I tried writing functions for it but it will not generate all possible trees. Any help is highly appreciated.
Asked
Active
Viewed 870 times
1
-
specify programming language – Andriy Ivaneyko Dec 27 '15 at 06:30
-
python, java or c++ will do the job. – Vikrant Singh Dec 27 '15 at 06:38
-
for given n number of nodes the number of binary trees is equal Catalan number of 2*n+1 which is very large. generating all possible tree for even n > 15 is computationally very difficult. – Daga Dec 27 '15 at 14:59
1 Answers
1
if you use Python, maybe the binarytree
module is what you need
>>> from binarytree import tree
>>> t = tree(height=3)
>>> t.pprint()
_______8_____
/ \
___3___ 2
/ \ / \
14 _4 _5 12
/ \ / \ / \
6 7 10 0 13 11

Su Kai
- 21
- 4