retagged by
784 views
11 votes
11 votes

Suppose from the set of all possible distinct binary trees with $6$ nodes, one tree is chosen at random. What is the probability that this chosen tree is a heap (either min or max)?

  1. $5 / 33$
  2. $1 / 2376$
  3. $10 / 33$
  4. $1 / 4752$
retagged by

1 Answer

Best answer
8 votes
8 votes
For $n$ nodes the number of distinct binary trees is $^{2n}C_n*n!/(n+1)$. For $6$ nodes we have $95040$ trees possible. Also with $6$ nodes total $40$ heaps are possible ($20$ each for min and max heaps as shown at end).

Therefore required probability is $40/95040 = 1/2376.$

For a max-heap with $6$ nodes, we have $3$ levels. Total possible min-heaps $=\dfrac{6!}{6\times 3\times 2} = 20.$ (We have only one way to select the root.  The two subtrees of the root will have $3$ and $2$ elements. But instead of $3!$ and $2!$ possibilities as in a binary tree, in a max-heap, the number of possibilities will be just $2$ and $1$ respectively as the parent node gets fixed.
selected by
Answer:

Related questions

12 votes
12 votes
2 answers
1
gatecse asked Jan 17, 2021
748 views
The number of possible min-heaps containing each value from $\{1,2,3,4,5,6,7,8\}$ exactly once is __________
4 votes
4 votes
1 answer
2
gatecse asked Jan 17, 2021
284 views
Consider the array $A[ \: ]= \{71,11,36,10,9,13,17,2,1,7,6,12\}$ which satisfies the max heap property. After $5$ delete root operations the sum of leaves comes out to be...