Geeklovenerds
Geeklovenerds

Reputation: 327

Number of Min Heaps possible?

The number of possible min-heaps containing each value from {1,1,1,1,1,1,1} exactly once is ?

=====================================================================

If the question would have been The number of possible min-heaps containing each value from {1,2,3,4,5,6,7} exactly once is ?

Then the answer is 80 and I know, how to solve it, but how to deal with when all values are same?

Upvotes: 0

Views: 1395

Answers (2)

HariUserX
HariUserX

Reputation: 1334

The main property of heap is that the structure of the heap always remains same, only the values of the node change.

Here we only have one distinct element and all nodes have same value. So the answer is 1.

So, can we say we get an unique Min/Max heap when all elements are same?

Yes, as there is only one heap possible.

Upvotes: 2

MBo
MBo

Reputation: 80327

When elements are not distinguishable, then only one heap exists.

For completeness: If heap elements contain secondary keys, we can say that number of different heaps might be at most n! (for all different secondary keys)

Upvotes: 1

Related Questions