Help in Ways to form max heap with n-1 distinct integers.

Revision en3, by mokoto, 2019-06-13 17:01:13

Given an array of size n consisting of n-1 distinct elements.In other words there is exactly one element that is repeated.It is given that the element that would repeat would be either the maximum element or the minimum element. Find the number of structurally different max heaps possible using all the n elements of the array that is max heap of size n.

Let us take an example with array array elements as

1 5 5

The possible max heaps using the given elements are:- First: 5 on the root. 1 as the left child of root and 5 as the right child of the root

5

/ \

1 5

Second: 5 on the root. 5 as the left child of root and 1 as the right child of the root.

5

/ \

5 1

second example : N = 6, 1 1 2 3 4 5 ans = 11.

N = 5 , 1 1 2 3 4 ans = 4 N can be upto 1000.

when integers are all different T[N] = (n-1)C(left) * T[L] *T[R] , but what will be the recusion in this case.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English mokoto 2019-06-13 17:01:13 31 Tiny change: 's = 11. \nN can be' -> 's = 11. \n\nN = 5 , 1 1 2 3 4\nans = 4\nN can be'
en2 English mokoto 2019-06-13 16:47:39 8
en1 English mokoto 2019-06-13 16:47:15 960 Initial revision (published)