• edited by
1,629 views
2 2 votes

3 Answers

2 2 votes
Min Heap

 

• edited by
0 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 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

Position:
Show:

Related questions

1 1 vote
2 2 answers
2.1k
2.1k views
CHïntän ÞäTël asked Dec 10, 2018
2,050 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!
0 0 votes
0 0 answers
745
745 views
sunaina rawat asked Nov 7, 2017
745 views
Consider programint foo(struct node *tree){if(tree==0)return 0;int lh=ht(tree->left);int rh=ht(tree->right);int ld=foo(tree->left);int rd=foo(tree->right);return max(lh+r...
0 0 votes
1 1 answer
638
638 views
0 0 votes
1 1 answer
1.2k
1.2k views