0

I know how to count the number of possible heaps with distinct elements such as {1, 2, 3, 4}. But if I wanted to count the number of heaps looking like this:

{1, 2, 3, 3, 4}

How do I rewrite f(N) = (N−1 C L) * f(L) * f(R) to be able to work with duplicates?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • http://math.stackexchange.com – Patrick Artner Jan 31 '18 at 23:08
  • 1
    Happy Coding. SO is about fixing Code - yours is a bit math-heavy and code-light. Please go over [how to ask](https://stackoverflow.com/help/how-to-ask) and [on-topic](https://stackoverflow.com/help/on-topic) again to see what kind of topics SO handles. math.stackexchange.com would be a good thing to search for this kind of questions ( before posting it there as well ). – Patrick Artner Jan 31 '18 at 23:10
  • If there are 3 items, there are two possible heaps. But if one of those items is a duplicate, then there's really only one heap. You can probably generalize this: that if there are duplicates, the answer is `f(n) / (maxDuplicates)`. – Jim Mischel Feb 01 '18 at 18:16
  • @PatrickArtner Im sorry, Ill try to post only related stuff from now on. – elinoria Feb 01 '18 at 19:57
  • @JimMischel Thank you for the reply. I was thinking about this, but it doesnt work for higher numbers in general. With for example 5 elements in heap, you can build 8 heaps. But when there are 2 duplicite numbers, you can build 6. I have even written a program in Python to prove me right, but since I need the written formula with N elements, it does not help me much. – elinoria Feb 01 '18 at 20:13
  • With the items 1-5, you have the following 8 valid heaps: `[1,2,3,4,5], [1,2,3,5,4],[1,3,2,4,5],[1,3,2,5,4],[1,2,5,3,4],[1,2,5,4,3],[1,2,4,5,3],[1,2,4,3,5`. If you have the items `1,2,3,3,5`, you end up with 8 valid heaps, but only four of them are unique. The other four are duplicates. – Jim Mischel Feb 01 '18 at 20:54

0 Answers0