Java program to find the total number of possible Binary Search Trees with N keysIn this program, we need to find out the total number of binary search trees can be constructed with n values. Below diagram shows a possible binary search tree with the key value as 3. So, we can construct a total of five binary search trees. When we choose node 1 as the root node, we get two trees. Similarly, one tree with 2 as root nodes and two trees when we select 3 as the root node. This approach involves selecting a node recursively as the root node and create possible binary search tree. An easy way to calculate the total number of possible binary search trees are through Catalan number: Algorithm
a. numOfBST() will find out total possible binary search tree for given key:
Program:Output: Total number of possible Binary Search Trees with given key: 42 Next TopicJava Programs |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India