Number of binary search trees over n distinct elements

后端 未结 3 1157
青春惊慌失措
青春惊慌失措 2020-12-05 01:24

How many binary search trees can be constructed from n distinct elements? And how can we find a mathematically proved formula for it?

Example:

3条回答
  •  渐次进展
    2020-12-05 01:45

    I am sure this question is not just to count using a mathematical formula.. I took out some time and wrote the program and the explanation or idea behind the calculation for the same.

    I tried solving it with recursion and dynamic programming both. Hope this helps.

    The formula is already present in the previous answer:

    So if you are interested in learning the solution and understanding the apporach you can always check my article Count Binary Search Trees created from N unique elements

提交回复
热议问题