With ' N ' no of nodes, how many different Binary and Binary Search Trees possible? -


For binary trees: There is no need to consider the values ​​of tree nodes, I Only with different tree topology 'N' nodes.

For the binary search tree: We have to consider tree node values.

I recommend by my partner Nick Perlent (when he was still at Stanford). The calculation of a structurally different binary tree (problem 12) is a simple recursive solution (which ends in the form of a Catalan form that is closed, which is already mentioned in @ kodaka).

I am not sure that the numbers will be structurally different from the binary search tree (BST for short period) from the "plain" binary tree - in addition, if "the tree Consider node values ​​"means that each node, eg. Any number corresponding to the position of BST, then the number of different (but structural is not different! -) BST is infinite. I suspect that you mean, therefore, please clarify that you < Em> do mean with an example!


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -