This has been bothering me for a while. I know that given N keys to arrange in the form of a binary search tree, the possible number of trees that can be created correspond
catalan http://www.nohre.se/publicImages/catalan.png
Any binary search tree can be encoded by visiting all nodes pre-order and encode a 1 for every parent and a 0 for every leaf. If the tree has n parents it will have n+1 leafs and consequently the binary code will have n 1:s and (n+1) 0:s. Moreover, and any prefix of the code will have at least as many 1:s as it has 0:s. Therefore, the number of possible trees equals the number of paths below the diagonal.