edited by
748 views

2 Answers

Best answer
13 votes
13 votes
We need $4$ levels for $8$ nodes in a min-heap. This means one sub-tree of root will have $4$ nodes and other one $3$ nodes.
Now, number of min-heaps with $4$ nodes $=3$  and that with $3$ nodes $ = 2.$
Since $4!/3 = 8$ and $3!/2 = 3$ to find the number of min-heaps with $8$ nodes we can divide $8!$ first with $8$ -- since root is fixed instead of having $8$ ways and then by $8$ and $3.$
Thus, number of min-heaps with $8$ nodes $ = \dfrac{8!}{8.8.3} = \dfrac{7!}{24} = 210$
Reference: https://cs.stackexchange.com/questions/6456/how-many-different-max-heaps-exist-for-a-list-of-n-integers
selected by
12 votes
12 votes
root will take the smallest one.so remaining element are 7.

now lets consider the right subtree which have 3 nodes,here possibilities are 7C3 * 2.

now we have 4 keys in our hand,out of that the smallest one will go to root of left subtree.remaining are 3 nodes.

3C1 for right child of left subtree of node.

remaing 2 elements have only one choice as the largest among them will go to last level node & remaing is top of that.

7C3 * 2 * 3C1 = 210
Answer:

Related questions

4 votes
4 votes
1 answer
2
gatecse asked Jan 17, 2021
285 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...
11 votes
11 votes
1 answer
3
gatecse asked Jan 17, 2021
785 views
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 m...