search
Log In
14 votes
1.8k views
1)The number of min heap trees are possible with 15 elements such that every leaf node must be greater than all non-leaf nodes of the tree are ________.

--------------------------------------------------------------------------------------------------------------------------

2)The number of min heap trees are possible with 15 elements_________________
in Programming
edited by
1.8k views
1
answer given by Made easy is wrong, it must be 3225600

7 Answers

28 votes
 
Best answer

1)i am getting 3225600
if numbers are 1,2,3,4...15,
level-1: can be arranged in only one way.
level-2: need to discuss
level-3: need to discuss
level-4: can be arranged in 8! ways. bcoz we need to choose highest 8 elements and rannage them here.
now we are left with 2 subtrees S1 and S2(shown in figure below) 
and 6 elements 2,3,4,5,6,7. 
take any 3 elements and you can arrange these 3 elements in 2 ways in the left subtree, now take the ramaining 3 elements and arrange them in 2 ways in right subtree. (in any 3 elements chosen, one will be the minimum among them, that one element will be the root and remaining two elements can be arranged in 2! ways as children of respective root)
6C3*2*3c3*2
total ways =(6C3*2*3C3*2)*8! = 3225600

2)
this in similar way, root can be arranged in one way
we will be left with 2 subtrees and 14 elements.
choose any 7 elements, minimum among them will be root of left subtree, this root has two subtrees same like previous problem, these two subtrees can be arranged in 6C3*2*3C3*2. so the entire left subtree of the main root can be arranged in 14C7( 6C3*2*3C3*2)
now coming to ryt subtree similar way,
here we choose 7 elements from the remaining. so number of ways of arranging this entire right subtree =7C7( 6C3*2*3C3*2)
total ways=14C7( 6C3*2*3C3*2)*7C7( 6C3*2*3C3*2)

dont know if this is correct. let me know if you find some mistake


selected by
1
well explained !!
0
but in 2)

14C7

u r choosing 1 subtree.

Say u choose left subtree.

Now, in 6C3 again u r choosing from left subtree and right subtree (from both)

Which should not be there

right?
0
sorry,i did not get your doubt
why 6C3 shudnt be there?
14C7- means i chose 7 elements from 14 elements to fill in left subtree. minimum of these 7 elements will be root of left subtree. i need to arrange two children of this left subtree. same like the 1st problem let left subtree be S1 and right subtree be S2. we will have 6 elements as we already arranged 1 elemnt in root. this becomes similar to first problem.
0
level 1 :1
level 2: 2,5
level3: 3,4,6,7
level-4:  8,9,10,11,12,13,14,15.

is it also maintaining in this solution?
0
yes..
0
u r fixing root, not selecting root anyway.rt?

then how do u know

level 2: 2,5 orlevel 2: 2,3 ?
0

@srestha,


Question 2
 https://gateoverflow.in/102171/min-heap

Question 1

n=15 is a special case where we can solve this like

  • last level nodes = 8 can be permutted in 8!
  • Now the question reduces to The number of min heap trees are possible with 7 nodes

The story will be different when n is  <15 
  see https://gateoverflow.in/101374/test-series

0

@ Anusha Motamarri

both ans r correct

0
In question 2) you are indirectly calculating no if binary trees ,  but in min heap the heap condition should  hold right  ?
0
for 2) ans is getting 21964800
2 votes

Suppose consider 15 elements 1,2,3,4,....15.

It is min heap ,level by level elements are stored.Root is at 1st level.

1st level; 1

2nd level: 2,3

3rd level: 4,5,6,7

4th level: 8,9,10,11,12,13,14,15.

In the second level elements are nodes 2,3 occupies 2 ways.no matter because it satisfies the heap property.

In the 3rd level also same nodes are 4,5,6,7 can be arranged in 4! ways.

In the 4th level 8!

SO TOTAL NO OF TREES ARE 1!*2!*4!*8*=1935360

3
What about a heap like this:

1st level: 1

2nd level: 2 5

3rd level: 3 4 6 7

4th level: 8 9 10 11 12 13 14 15

This is also valid according to the question but the answer does not account for these type of heaps.
0
i miss it,but this type of problems construct every min heap tree construction is so difficult.

so i think nearest no of min neaps consideration is better.
1
This is worng.Level 2 needn't have 2,3 the.The other valid combinations are 2,4 and 2,5
1

https://gateoverflow.in/100154/heap

refer this one.. this handles the said cases also. 

1 vote

Suppose consider 15 elements 1,2,3,4,....15.

It is min heap ,level by level elements are stored.Root is at 1st level.

1st level; 1

2nd level: 2,3

3rd level: 4,5,6,7

4th level: 8,9,10,11,12,13,14,15.

In the second level elements are nodes 2,3 occupies 2 ways.no matter because it satisfies the heap property.

In the 3rd level also same nodes are 4,5,6,7 can be arranged in 4! ways.

In the 4th level 8!

SO TOTAL NO OF TREES ARE 1!*2!*4!*8*=1935360

0
Plz answer 2nd part too I have added
0
@aman level-2,level3 can also contain 2,5 and  3,4,6,7 respectively.
0
no Anusha

See this line "every leaf node must be greater than all non-leaf nodes "

i.e why I added 2nd question
1
yes there are 4 levels.
4th level is leaf nodes level.
but, levels 2,3 are like normal heap ryt?
level 1 :1
level 2: 2,5
level3: 3,4,6,7
level-4:  8,9,10,11,12,13,14,15.
level -4 is greater than all other internal(non-leaf) nodes. this tree satisfies given condition isnt it?
0

yes, good point

then 1935360+1935360 will be ans.rt?

0
It doesn't contain because you have to find out heap tree .which alwayz a Complete binary tree or almost complete  binary tree so its not possible
1
hey, what r u telling??

it is not violating heap property or binary tree property in any way
0
Actually i am just giving a answer which you have ask above and in question ask every leaf node must be greater than all non-leaf nodes of the tree are that why i have do so and if it is not there same as question 2 they you are right every case possible
0
plz chk the command again.

U r missed the case what we are discussing.

It should include in answer as well
1 vote

Let us take 15 elements [1,2,3,4.....15]. To satisfy the condition mentioned in the problem all the 8 largest element should come to the last level. means element {8,9,10,11,12,13,14,15} must come in the last level. 

So total no of ways to arrange the elements in the last level = 8!

now for the remaining elements {1,2,3,4,5,6,7} there are no restriction hence they can come in any order in min heap. Hence it will be equivalent  to construct the min heap using  elements {1,2,3,4,5,6,7}. = 80 ways. for this please see below. link http://karmaandcoding.blogspot.com/2012/02/number-of-min-heaps-from-array-of-size.html

hence total no will be = 80 * 8! = 3225600.

If the same question is little bit modified and let us say - The number of min heap trees are possible with 15 elements such that every node at a particular level must be greater than all the nodes of the tree which are above that level. ex. all the nodes present at level 3 must be greater than all the nodes present at level 2 and so on....

Then the explanation given by @Aman Chauhan seems more meaningful.

Suppose consider 15 elements 1,2,3,4,....15.

It is min heap ,level by level elements are stored.Root is at 1st level.

1st level; 1

2nd level: 2,3

3rd level: 4,5,6,7

4th level: 8,9,10,11,12,13,14,15.

In the second level elements are nodes 2,3 occupies 2 ways.no matter because it satisfies the heap property.

In the 3rd level also same nodes are 4,5,6,7 can be arranged in 4! ways.

In the 4th level 8!

SO TOTAL NO OF TREES ARE 1!*2!*4!*8*=1935360

0

https://gateoverflow.in/100154/heap This seems like correct answer. Correct answer must be 3225600.

1 vote
  1. The $8$ leaf nodes are always be last 8 elements in the sorted sequence (increasing order). So these elements in these $8$ nodes can be permuted. Now there are $7$ non-leaf nodes remaining to make heap. For this case, there are $\frac{7}{7\times3^2}$ ways to make heap using the rest $7$ elements. So the total number of ways is $\frac{7!}{7\times3^2}\times 8!=3225600$.
  2. This is straight forward, the total number of ways is $\frac{15!}{15\times7^2\times3^4}=21964800$.
0 votes
Ans should be 8!*7! max 8 values will be tere in leaf, there are 8 nodes they can be arrange in any way and 7 in non leaf they can be arrange in any way.
0 votes

Let us take 15 elements [1,2,3,4.....15]. To satisfy the condition mentioned in the problem all the 8 largest element should come to the last level. means element {8,9,10,11,12,13,14,15} must come in the last level. 

So total no of ways to arrange the elements in the last level = 8!

now for the remaining elements {1,2,3,4,5,6,7} there are no restriction hence they can come in any order in min heap. Hence it will be equivalent  to construct the min heap using  elements {1,2,3,4,5,6,7}. = 80 ways. for this please see below. link http://karmaandcoding.blogspot.com/2012/02/number-of-min-heaps-from-array-of-size.html

hence total no will be = 80 * 8! = 3225600.

If the same question is little bit modified and let us say - The number of min heap trees are possible with 15 elements such that every node at a particular level must be greater than all the nodes of the tree which are above that level. ex. all the nodes present at level 3 must be greater than all the nodes present at level 2 and so on....

Then the explanation given by @Aman Chauhan seems more meaningful.

Suppose consider 15 elements 1,2,3,4,....15.

It is min heap ,level by level elements are stored.Root is at 1st level.

1st level; 1

2nd level: 2,3

3rd level: 4,5,6,7

4th level: 8,9,10,11,12,13,14,15.

In the second level elements are nodes 2,3 occupies 2 ways.no matter because it satisfies the heap property.

In the 3rd level also same nodes are 4,5,6,7 can be arranged in 4! ways.

In the 4th level 8!

SO TOTAL NO OF TREES ARE 1!*2!*4!*8*=1935360

Related questions

2 votes
1 answer
1
140 views
what is the time complexity of various problems such as: 1) Creating the heap 2) Getting maximum element in the max heap 3) Getting minimum element in the max heap 4) Getting maximum element in min heap 5) Getting minimum element in min heap 6) Heapify the element 7) ... ) Deletion of an element in the max heap 10) Insertion of an element in the max heap 11) Insertion of an element in min heap
asked Jan 1, 2019 in Programming Hira Thakur 140 views
3 votes
1 answer
2
802 views
A min heap having 1024 distinct elements with keys ranging from 0 to 1023 is stored in array of 1024 indices. The maximum difference between element 512 present at maximum level and minimum level is ________. [Assume root is ... are taking maximum level 11 and minimum level 2 __________________________________________________________________________ why minimum level 2, and why it is not 1?
asked Jun 24, 2018 in Programming srestha 802 views
5 votes
0 answers
3
191 views
Answer given : 1935360 but I m getting 3225600 please check..
asked Dec 29, 2017 in Programming vamp_vaibhav 191 views
0 votes
0 answers
4
589 views
In a binary min heap with n elements, the 7th smallest element can be found in _____ ? Answer given is O(logn) and solution:- Delete the 1st smallest element O(logn) Delete the 2nd smallest element O(logn) .... Delete the 7th smallest element O(logn). ... O(logn). In this solution the data arrangement of the heap will be changed after performing these operation. any better solution than this???
asked Oct 18, 2017 in Programming Shubhanshu 589 views
...