how many distinct binary trees with 4 distinct keys

how many distinct binary trees with 4 distinct keys

4 hours ago 4
Nature

The number of distinct binary trees with 4 distinct keys is 14. This result comes from the Catalan number formula, which counts the number of distinct binary search trees (BSTs) that can be formed with nnn distinct keys:

Cn=1n+1(2nn)C_n=\frac{1}{n+1}\binom{2n}{n}Cn​=n+11​(n2n​)

For n=4n=4n=4:

C4=15(84)=15×70=14C_4=\frac{1}{5}\binom{8}{4}=\frac{1}{5}\times 70=14C4​=51​(48​)=51​×70=14

Thus, there are 14 distinct binary trees possible with 4 distinct keys

. This count refers specifically to binary search trees, where the structure depends on the insertion order of keys but the keys themselves are distinct and uniquely placed according to BST properties. The same count applies to the number of distinct shapes of binary trees with 4 nodes, since each unique BST shape corresponds to a unique binary tree structure with distinct keys. In summary:

  • Number of distinct binary trees with 4 distinct keys = 14
  • This is given by the 4th Catalan number
  • Formula: Cn=1n+1(2nn)C_n=\frac{1}{n+1}\binom{2n}{n}Cn​=n+11​(n2n​)

This is a well-known combinatorial result in data structures and algorithms related to binary search trees

Read Entire Article