edited by
721 views
2 votes
2 votes

edited by

3 Answers

2 votes
2 votes
Min Heap

 

edited by
0 votes
0 votes

so the Min heap is a complete tree.  With the given numbers {1, 2, 3, 4, 5, 6, 7}  the tree will be of the form 

         

 

so at the top will be 1 and in 2nd level there is 2 and 3 which can be swapped hence 2 ways

At leaf there are 4,5,6,7 and they all can be permuted in 4! ways    

So total ways are 2*4!   

probablity  2*4! / 7!  =  0.009

0 votes
0 votes

Array element is {1,2,3,4,5,6,7} .

The number of all possible permutations in these elements = 7! .

Since, we have to satisfy min heap property, always root element is smallest among all the elements .

So, "1" should be root node. Remaining element is {2,3,4,5,6,7} .

Therefore, there are 3 elements out of 6 elements going to left subtree in 6C3 ways and remaining going to right subtree. Suppose, {2,4,5} going to left subtree and since, minimum element is 2 so, "2" should be root of left subtree. There are 2 remaining elements {4,5} being children of "2" in 2! ways [Either "4" would be left child of "2" and "5" would be right child of "2" Or "4" would be right child of "2" and "5" would be left child of "2"].

So, remaining elements {3,6,7} going to right subtree in 3C3 ways. Since, Minimum element is 3, so "3" should be root of right subtree. There are 2 remaining elements {6,7} being children of "3" in 2! ways. 

So, probability = (6C3 x 2! x 3C3 x 2! ) / 7!

                           = 1/63 = 0.016

Related questions

0 votes
0 votes
0 answers
1
10 votes
10 votes
5 answers
2
Tushar Shinde asked Jan 18, 2016
4,140 views
The number of ways we can insert elements { 1, 2, 3, .... 7 } to make an AVL tree, so that it does not have any rotation are _______ ?
0 votes
0 votes
1 answer
3
Sandeep Singh asked Dec 27, 2015
492 views
Consider the below code which run on any tree.In-order traversalPost-order traversalPre-order traversalNone of these
1 votes
1 votes
2 answers
4
CHïntän ÞäTël asked Dec 10, 2018
1,011 views
four vertices {A,B,C,D} is given which has only vertex D as a leaf total number of binary tree are possible when every binary tree has four node!