50 50 votes How many distinct binary search trees can be created out of $4$ distinct keys? $5$ $14$ $24$ $42$ Data Structures gatecse-2005 data-structures binary-search-tree counting normal + – Kathleen 40.0k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments Lakshman Bhaiya commented Aug 16, 2023 reply Follow flag Thanks, done now👍 0 0 replyShare R2-D2 commented Aug 31, 2025 reply Follow flag Catalan number 🙏 2 2 replyShare Umesh Shelke commented Sep 21, 2025 reply Follow flag $\text{ Option B) 14 is the answer.}$ Catalan number = $\frac{^{2n}C_n}{n+1}$ or $\frac{(2 * n)!}{(n+1)! * n!}$ $\frac{(2 * 4 )!}{(4+1)! * 4!}$ = $\frac{8 !}{5! * 4!}$ = $\frac{8 * 7 * 6 }{ 4 * 6}$ = $14$ 2 2 replyShare Please log in or register to add a comment.
Best answer 59 59 votes answer - (B) number of distinct BSTs = $\frac{^{2n}C_n}{n+1}$ (or) =$\frac{(2n)!}{(n+1)!n!}$ For a given Binary tree structure, there can be only $1$ BST. Hence, no. of different BSTs with $n$ nodes will be equal to the no. of different binary tree structures possible for $n$ nodes assuming nodes are unlabeled. For derivation: http://gatecse.in/number-of-binary-trees-possible-with-n-nodes/ ankitrokdeonsns answered Oct 4, 2014 • edited Jan 24, 2023 by Abhrajyoti00 ankitrokdeonsns comment Share Follow See all 11 Comments 11 11 Comments reply Show 8 previous comments tusharp commented Dec 4, 2018 reply Follow flag Distinct Key BST and Unlabeled node BST Both are same and It is equal to Catalan Number? @Lakshman Patel RJIT If you have given a particular structure of n nodes(any structure among all possible as in un labeled nodes) there is only one way to fill it to satisfy BST property. Here they are asking BST possible using 4 distinct keys. What you can do is form all possible structure of un labeled nodes(Catalan number) and then in each structure fill the keys using BST property. Hence your statement is true. 3 3 replyShare Praful932 commented May 26, 2020 reply Follow flag It should be 1/n+1 not 1/(n+1!). Please correct it. 0 0 replyShare Divyanshu Shukla commented Nov 12, 2020 reply Follow flag @Praful932 Answer is correct, please remove flag. $\frac{\binom{2n}{n}}{n+1}=\frac{2n!}{n!*n!*(n+1)}=\frac{2n!}{n!* (n+1)!}$ 6 6 replyShare Please log in or register to add a comment.
9 9 votes Number of binary trees with unlabeled $n-vertices $ $T(n) = T(0)\times T(n-1)+T(1)\times T(n-2)+ \space ... \space+ T(n-1)\times T(0)$ $T(0)=T(1)=1$ $T(4) = T(0)\times T(3) + T(1)\times T(2) + T(2)\times T(1) + T(3)\times T(0) \rightarrow$ eqn #1 $T(2) = T(0)\times T(1) + T(1)\times T(0) = 2$ $T(3) = T(0)\times T(2) + T(1)\times T(1) + T(2)\times T(0) = 2+1+2 = 5$ Just put values in eqn #1 $T(4)=5+2+2+5=14$ Rishi yadav answered Aug 22, 2017 • edited Apr 20, 2019 by Rishi yadav Rishi yadav comment Share Follow 0 reply Please log in or register to add a comment.
6 6 votes Incase you forgot the formula, Number of BST's with 2 keys (1,2) = 2 Number of BST's with 3 keys (1,2,3) = 2 + 2 + 1 = (Root is 3) + (Root is 1) + (Root is 2) = 5 Number of BST's with 4 keys (1,2,3,4) = 5 + 5 + 2 + 2 = 14 Number of BST's with 5 keys (1,2,3,4,5) = 14 + 14 + 5 + 5 + 2 * 2 = 42 Number of BST's with 5 keys (1,2,3,4,5) = Root 5 + Root 1 + Root 4 + Root 2 + Root 3 (2 trees with 2 keys on either side) Mk Utkarsh answered Aug 23, 2018 Mk Utkarsh comment Share Follow 0 reply Please log in or register to add a comment.
6 6 votes In general the BST is of the form i.e. 1 node at root, 2 its children, another 4 as its children and so on. Hence for root= 4C1 for the next two children= 3C2 and the next= 1C1 also we will add the 2 skew trees thus total BST= 4C1 * 3C2 * 1C1 + 2 = 14 trees rish1602 answered Jun 3, 2021 rish1602 comment Share Follow 0 reply Please log in or register to add a comment.
2 2 votes AnswerThe number of distinct binary search trees that can be created out of 4 distinct keys is 14 (Option B).ExplanationThe number of distinct Binary Search Trees (BSTs) that can be formed using $n$ distinct keys is equal to the number of structurally unique binary trees with $n$ nodes. This value is determined by the $n^{th}$ Catalan number, denoted as $C_n$.1. The Logic Behind the CalculationFor any unlabeled binary tree structure with $n$ nodes, there is exactly one way to fill it with $n$ distinct keys to satisfy the BST property (because the keys must appear in sorted order during an Inorder traversal). Therefore:Number of distinct BSTs with $n$ keys = Number of unique binary tree structures with $n$ nodes.2. The Catalan FormulaThe formula for the $n^{th}$ Catalan number is: $$C_n = \frac{1}{n+1} \binom{2n}{n} = \frac{(2n)!}{(n+1)! n!}$$3. Step-by-Step Calculation for $n=4$To find the answer for 4 distinct keys:Step 1: Calculate the Binomial Coefficient $$\binom{2n}{n} = \binom{8}{4} = \frac{8 \times 7 \times 6 \times 5}{4 \times 3 \times 2 \times 1} = 70$$Step 2: Apply the divisor $(n+1)$ $$C_4 = \frac{70}{4+1} = \frac{70}{5} = 14$$ addressisvivek answered Jan 12 addressisvivek comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes can be done by 2 techniques : 1) by formulae : 1 / (n + 1) * (2n c n) 2) by recurence : t(n) = summition k =1 to n t(k-1) * t(n-k). జై బాబు అనాలి answered Jun 9 జై బాబు అనాలి comment Share Follow 0 reply Please log in or register to add a comment.