retagged by
1,625 views
1 votes
1 votes

The number of binary search trees possible with 12 keys, when keys 1, 2, 3, 4, ........ 12 are inserted into empty Binary Search Tree with condition such that 4  is the root of binary search tree and 8 is immediate right child of 4 are ________.

retagged by

3 Answers

5 votes
5 votes
note that given that it is a binary search tree,

root is fixed to 4 and root immediate right child is fixed to 8, therefore

total elements less than 4, should be left side of root ==> there are 3 elements  ( 1, 2, 3) ===> 5 tree structures we can get

 total elements grater than 8, should be right side of node 8 ==> there are 4 elements ( 9,10,11,12 ) ===> 14 tree structures we can get

therefore total elements grater than 4 and less than 8, should be left side of node 8 ==> there are 3 elements ( 5,6,7 ) ===> 5 tree structures we can get.

 

For required a complete Binary Search Tree structure, we have to these three process ===> 5*5*14 = 350 possible structures possible
0 votes
0 votes

///now rest of the element 5,6,7,9,10,11,12 they can also come in order , s0 it becomes = 7! =5040

this line is false as suppose u take 12 after 8 ,then 12 in right of 8 after that u insert 5 then as it insert at leaf 5 <12 and 5 also <8 but it is in right of 8 so false statement

Insertion of a key 
A new key is always inserted at leaf. We start searching a key from root till we hit a leaf node. Once a leaf node is found, the new node is added as a child of the leaf node

same case for 1,2,3,8

see JUST REMEMBER WE ALWAYS INSERT NODES AT LEAF LEVEL NOT UPPER .

so if u inert 8 then 8 is leaf then u r of no good again.

so total ways according to me is  

5 ( for 3nodes total  5 bst ) * 5 * 14 = 350

Related questions

9 votes
9 votes
9 answers
1
ajit asked Sep 23, 2015
14,718 views
How many different trees are there with four nodes $\text{A, B, C}$ and $\text{D}?$$30$$60$$90$$120$
0 votes
0 votes
1 answer
2
sandeep singh gaur asked Mar 22, 2019
718 views
The number of possible ordered trees with 3 nodes A,B,C is ??