Java program to find the total number of possible Binary Search Trees with N keys17 Mar 2025 | 2 min read In 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 |
In this program, we create a circular linked list and search a node in the list. 9->5->2->7->3 Consider, above example. Suppose we need to search for node 5. To solve this problem, we will iterate through the list and compare each node with 5. If match is...
5 min read
Java Program to remove duplicate element in an Array We can remove duplicate element in an array by 2 ways: using temporary array or using separate index. To remove the duplicate element from array, the array must be in sorted order. If array is not sorted,...
5 min read
We can capitalize each word of a string by the help of split() and substring() methods. By the help of split("\\s") method, we can get all words in an array. To get the first character, we can use substring() or charAt() method. Let's see the example...
1 min read
Java program to print the following pattern on the console 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Algorithm: STEP 1: START STEP 2: SET n=5. STEP 3: SET i=0. REPEAT STEP 4 to STEP 8 UNTIL i<=n. STEP 4: SET j=0.REPEAT STEP 5 to STEP 6 UNTIL...
1 min read
ISBN is another special number in Java. ISBN stands for the International Standard Book Number that is carried by almost each every book. The ISBN is a ten-digit unique number. With the help of the ISBN, we can easily find any book. The ISBN number is...
3 min read
A number is prime if it is divisible by 1 and itself. In other words, a prime number is a natural number with exactly two distinct natural number divisors 1 and itself. For example, 2, 3, 5, 7, 11, etc. are the prime numbers. Note that...
5 min read
In this program, we need to check whether two trees are identical or not. For two trees to be identical, they have to satisfy two conditions: Structure of both the trees should be the same. Nodes present in one tree should be present in another tree. Above diagram...
4 min read
It is a very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going...
7 min read
In this program, we will create a circular linked list and delete a node from the beginning of the list. If the list is empty, print the message "List is empty". If the list is not empty, we will make the head to point to...
6 min read
In this program, we need to find the duplicate characters in the string. Great responsibility To find the duplicate character from the string, we count the occurrence of each character in the string. If count is greater than 1, it implies that a character has a duplicate...
3 min read
We request you to subscribe our newsletter for upcoming updates.
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