3

So i came across the general combinatoric problem as stated in the title. I have $N$ distinct balls and $K$ distinct boxes $\left( N \geqslant 2K \right)$. I need to find the total number of ways to arrange these balls in these boxes so that every box has more than one ball.

Any help would be greatly appreciated. Thank you.

bui
  • 208
  • 1
  • 7
  • did you try to attack it with inclusion-exclusion? if the constraint were "at least one" that would certainly work out (you'd get Stirling numbers of the second kind). This seems at a glance just slightly more complicated. – Badam Baplan Apr 26 '17 at 03:24
  • The inclusion-exclusion method works well for the case of indistinguishable boxes, but i think this is not the case. Furthermore, "each box has at least one" and "each box has at least two" can be drastically different when all boxes and balls are distinct. – bui Apr 26 '17 at 03:46
  • inclusion-exclusion works quite well for distinguishable boxes, i.e. the problem of counting surjective functions.

    I agree that the "at least one" and "at least two" cases can be drastically different, but here I don't think they are.

    – Badam Baplan Apr 26 '17 at 03:51
  • For fixed $K$ the exponential generating function is $(e^x-1-x)^K,$ so the number of ways is equal to the $N^{\text{th}}$ derivative of $(e^x-1-x)^K$ evaluated at $x=0.$ – bof Apr 26 '17 at 03:57
  • @bof I have tried evaluating your mentioned derivative at $x = 0$ using MATLAB, but the result is always 0 regardless of the order of the derivative – bui Apr 26 '17 at 04:32
  • For $K=1$ the second derivative of $f(x)=(e^x-1-x)^1$ is $f''(x)=e^x$ and $f''(0)=1.$ For $K=2,$ I get $$g(x)=(e^x-1-x)^2=e^{2x}-(2x+2)e^x+x^2+2x+1$$ $$g'(x)=2e^{2x}-(2x+4)e^x+2x+2$$ $$g''(x)=4e^{2x}-(2x+6)e^x+2$$ $$g'''(x)=8e^{2x}-(2x+8)e^x$$ $$g''''(x)=16e^{2x}-(2x+10)e^x$$ so $g''''(0)=6$ which is the right number. But I did the work by hand so I may have made mistakes. What are the smallest values of $K$ and $N$ for which you got the wrong answer from the formula I posted? – bof Apr 26 '17 at 05:07
  • Anyway, $f_K(x)=(e^x-1-x)^K$ is an analytic function (given that $K$ is a natural number), and it's not identically zero, so it's not possible that its derivatives of all orders vanish at $x=0.$ – bof Apr 26 '17 at 05:14
  • You are right, i checked again using $K = 2$ and the result is just as you wrote. But i manually tested with $K = 18$ and haven't found a value for $N$ that does not yield 0. – bui Apr 26 '17 at 05:31
  • Of course (as you noted in the question) you need $N\ge2K$ to get a nonzero result, so $N\ge36$ when $K=18.$ I get $$f(x)=(e^x-1-x)^{18}=\left(\frac{x^2}{2!}+\frac{x^3}{3!}+\cdots\right)^{18}=\left(\frac{x^2}{2!}\right)^{18}+\cdots=\frac{x^{36}}{2^{18}}+\cdots=\frac{36!}{2^{18}}\cdot\frac{x^{36}}{36!}+\cdots$$ so $f^{(36)}(0)=\frac{36!}{2^{18}}.$ – bof Apr 26 '17 at 06:07
  • Oops, my bad. I forgot the condition of $N \geqslant 2K $. Thank you for your solution :) It's nice to have different solutions from different viewpoints :) – bui Apr 26 '17 at 06:13

4 Answers4

2

Here's a start with inclusion-exclusion.

Let $P_j^0$ be all ball-box arrangements such that the $jth$ box contains exactly $0$ balls, and let $P_j^1$ be similarly those in which the $jth$ box contains exactly 1 ball.

The total number of ball-box arrangements is $K^N$, so the number you are looking for is $K^N - \big| \bigcup\limits_{j=1}^{K} P_j^0 \cup P_j^1 \big|$. Inclusion exclusion is how you'll approach that big union.

You can attack it straight on because the number of ball-box arrangements having $J$ particular boxes empty and disjoint $I$ particular boxes containing exactly one ball is easily calculated. We pick $I$ of our $N$ balls and permute them into the designated boxes, and then accounting for the $J$ boxes that are off limits, we have $N-I$ balls to put into $K - J - I$ boxes. In other words, if $A_I$ and $A_J$ are disjoint subsets of $[1,\ldots,K]$ with $|A_I| = I$ and $|A_J| = J$, then

$$ \big| \bigcap\limits_{j \in A_J} P_j^0 \cap \bigcap\limits_{i \in A_I} P_i^1 \big| = \frac{N!}{(N-I)!} (K - I - J)^{N-I} $$

To account for all of the ways to choose $J$ and $I$ such boxes, you have a multiplicative factor of ${{K} \choose {I}} {{K-I} \choose {J}}$

The theorem of inclusion exclusion gives you that

$$ \big| \bigcup\limits_{j=1}^{K} P_j^0 \cup P_j^1 \big| = \sum_{A_I,A_J \subset [1,\ldots,K] \\ A_I \cap A_J = \emptyset} (-1)^{I+J+1} \big| \bigcap\limits_{j \in A_J} P_j^0 \cap \bigcap\limits_{i \in A_I} P_i^1 \big| $$

so with the above observations you should be all set! (we're summing over all ways to pick two disjoint subsets of the boxes.)

This post on Stirling numbers of the second kind may be helpful, since this application of inclusion-exclusion is just a slightly more complicated version of that one.

Badam Baplan
  • 9,123
  • Sorry if i misunderstand it, but doesn't your multiplicative term of $\left(K-I-J\right)^{N-I}$ also includes all the cases where each of the remaining $\left(K-J-I\right)$ boxes can contain either 0, 1 or more than 1 ball? If it's so, then the number of single-ball boxes may not be $I$ anymore. – bui Apr 26 '17 at 04:27
  • No it's my fault, the notation is too sparse. The number of single ball boxes likely isn't $I$ anymore, nor is the number of empty boxes $J$, I meant to be summing over a particular index set. i'll update for clarity – Badam Baplan Apr 26 '17 at 04:37
  • I mean that, if you are assuming that there are $I$ single-ball boxes, $J$ no-ball boxes and $K-I-J$ more-than-one-ball boxes, then the new problem is, again, finding the total number of ways to distribute $N' = N-I$ balls into $K' = K-I-J$ boxes so that each box get more than one ball. That is no different from the original problem but just a change in the value of $N$ and $K$. – bui Apr 26 '17 at 04:42
  • I'm not assuming anything about the other $K-I-J$ boxes, that's the crux of inclusion-exclusion. All of the overcounting is dealt with by adding/subtracting the number of ball-box arrangements for other sizes of $I,J$ – Badam Baplan Apr 26 '17 at 04:45
  • Sorry that i took so long to reply. I am not familiar with counting and it took me a while to (intuitively) grasp the inclusion-exclusion method. A small problematic part is that we must also include the sum over all value pair of $\left( I,J \right)$ given that $\left( I + J \right)$ is a fixed value somewhere between $1$ and $K$. I have one more question: should we also count the cases where $I=0$ and/or $J=0$? From my understanding, we should. – bui Apr 26 '17 at 05:47
  • Ok, so we should not count in the case where $I = J = 0$ because there is no arrangement that can satisfy that case. I think my question is now solved. Thank you very much. – bui Apr 26 '17 at 05:57
  • Well, we can count that case if we want to, but in our formula it contributes precisely the cardinality of the empty set! From an informational perspective, all ball-box arrangements are described by $I = J = 0$ (which says nothing about an arrangement). Hence the case is irrelevant to our enumeration of arrangements possessing particular properties. It's really up to you whether to leave it out or adopt a notation that accommodates it with a $0$ value. – Badam Baplan Apr 26 '17 at 06:45
  • As for summing over pairs of $(I,J)$, yes, this is really a double sum! – Badam Baplan Apr 26 '17 at 06:46
  • Substituting $I\mapsto i$ and $J\mapsto j-i$ equates the double sum in your answer with the double sum in mine. Although I think a single sum is more aesthetic than a double sum, I also think that the double sum is about as good as one can get without using Stirling Numbers of the Second Kind. (+1) – robjohn Apr 26 '17 at 08:36
2

For Inclusion-Exclusion, let us count the number of ways that $j$ of the $K$ bins have less than $2$ of the $N$ balls. We will break things down into cases where $i$ of the bins have $1$ ball and $j-i$ have $0$ balls:

Choose the $j$ bins to have less than $2$: $\binom{K}{j}$
Choose $i$ of those $j$ bins to have $1$ ball: $\binom{j}{i}$
Choose $i$ of the $N$ balls for those $i$ bins: $\binom{N}{i}$
Choose an order for those $i$ balls: $i!$
Fill in the remaining $K-j$ bins with the remaining $N-i$ balls: $(K-j)^{N-i}$

Therefore, $$ N(j)=\sum_{i=0}^j\binom{K}{j}\binom{j}{i}\binom{N}{i}i!(K-j)^{N-i}\tag{1} $$ Thus, $$ \newcommand{\stirtwo}[2]{\left\{#1\atop#2\right\}} \begin{align} \sum_{j=0}^K(-1)^jN(j) &=\sum_{j=0}^K(-1)^j\sum_{i=0}^j\binom{K}{j}\binom{j}{i}\binom{N}{i}i!(K-j)^{N-i}\tag{2}\\ &=\sum_{j=0}^K(-1)^j\sum_{i=0}^j\binom{K}{i}\binom{K-i}{j-i}\binom{N}{i}i!\sum_m\stirtwo{N-i}{m}\binom{K-j}{m}m!\tag{3}\\ &=\sum_{i=0}^K\binom{K}{i}\binom{N}{i}i!\sum_m\stirtwo{N-i}{m}m!\sum_{j=i}^K(-1)^j\binom{K-i}{j-i}\binom{K-j}{m}\tag{4}\\ &=\sum_{i=0}^K\binom{K}{i}\binom{N}{i}i!\sum_m\stirtwo{N-i}{m}m!\sum_{j=i}^K(-1)^j\binom{K-i}{K-j}\binom{K-j}{m}\tag{5}\\ &=\sum_{i=0}^K\binom{K}{i}\binom{N}{i}i!\sum_m\stirtwo{N-i}{m}m!\sum_{j=i}^K(-1)^j\binom{K-i}{m}\binom{K-i-m}{K-j-m}\tag{6}\\ &=\sum_{i=0}^K\binom{K}{i}\binom{N}{i}i!\stirtwo{N-i}{K-i}(K-i)!(-1)^i\tag{7}\\ &=\bbox[5px,border:2px solid #C0A000]{K!\sum_{i=0}^K(-1)^i\binom{N}{i}\stirtwo{N-i}{K-i}}\tag{8} \end{align} $$ Explanation:
$(2)$: Inclusion-Exclusion and $(1)$
$(3)$: $\binom{K}{j}\binom{j}{i}=\binom{K}{i}\binom{K-i}{j-i}$ and $(K-j)^{N-i}=\sum\limits_m\stirtwo{N-i}{m}\binom{K-j}{m}m!$
$(4)$: rearrange terms and order of summation
$(5)$: $\binom{K-i}{j-i}=\binom{K-i}{K-j}$
$(6)$: $\binom{K-i}{K-j}\binom{K-j}{m}=\binom{K-i}{m}\binom{K-i-m}{K-j-m}$
$(7)$: $\sum\limits_{j=i}^K(-1)^j\binom{K-i-m}{K-j-m}=(-1)^i[m=K-i]$
$(8)$: $\binom{K}{i}i!(K-i)!=K!$

where the $\stirtwo{n}{k}$ are the Stirling Numbers of the Second Kind.

robjohn
  • 353,833
  • Thank you for your solution. This is another way to interpret the Inclusion-Exclusion method and should yield the same result as in Badam's solution :) – bui Apr 26 '17 at 08:09
  • I think that reducing the double sum to a single sum makes the answer a bit more palatable. – robjohn Apr 26 '17 at 08:14
  • I like this reduction to a single sum! It's good to show the connection to the Stirling numbers of the second kind. Originally I guessed this was a homework problem so I was trying (in many iterations) not to provide a full answer, but I would definitely prefer to write it this way in the end.

    The only merit in leaving it as double sum is that it's somewhat "transparent". To solve the problem we had to decompose the $K$ propositions "box j has less than 2 balls" into the $2K$ propositions "...has exactly one..." and "...has exactly 0..."

    – Badam Baplan Apr 26 '17 at 13:56
1

The combinatorial species here is the labeled species $\mathfrak{S}_{=K}(\mathfrak{P}_{\ge 2}(\mathcal{Z}))$ which gives the generating function

$$(\exp(z)-z-1)^K.$$

The desired statistic is then given by

$$N! [z^N] (\exp(z)-z-1)^K = N! [z^N] \sum_{q=0}^K {K\choose q} (-1)^q z^q (\exp(z)-1)^{K-q} \\ = N! \sum_{q=0}^K {K\choose q} (-1)^q [z^{N-q}] (\exp(z)-1)^{K-q} \\ = N! K! \sum_{q=0}^K \frac{1}{q!} (-1)^q [z^{N-q}] \frac{(\exp(z)-1)^{K-q}}{(K-q)!} \\= N! K! \sum_{q=0}^K \frac{1}{q! (N-q)!} (-1)^q (N-q)! [z^{N-q}] \frac{(\exp(z)-1)^{K-q}}{(K-q)!} \\= K! \sum_{q=0}^K {N\choose q} (-1)^q {N-q\brace K-q}.$$

This matches the answer by @robjohn.

Marko Riedel
  • 64,728
0

First find the number of ways to put 2 balls into every box. Since the balls are distinguishable, there are $N\choose{2K}$ ways to pick $2K$ balls, and there are $\frac{(2K)!}{2^K}$ ways to divvy those $2K$ balls into the $K$ distinguishable boxes (think of lining up all $2K$ balls where the first two go into box 1, the next two into box 2, etc. There are $(2K)!$ possible line-ups, but the order of the $K$ pairs does not matter, so we should divide by $2^K$)

Then, for the remaining $N-2K$ balls you have $K^{N-2K}$ options to distribute those.

Now multiply all those together:

$$\frac{{N\choose{2K}}(2K)!K^{N-2K}}{2^K}$$

EDIT

This does NOT work, since it overcounts: I could initially pick a pair of balls A and B to go into some box, and later add ball C, but I could also initially pick pair A and C, and later add B. This ends up with the same balls in that box, but the above calculation counts these as different. :(

I'll leave this flawed formula up here until someone finds the actual correct formula ... Maybe it's still of some use, if only to show what does NOT work!

Bram28
  • 103,721
  • But please do note that all the balls and boxes are distinguishable. In that sense, can the way of choosing the 2 balls into every boxes affect the result? – bui Apr 26 '17 at 02:33
  • Oh, You should definitely add that to the problem statement! – Bram28 Apr 26 '17 at 02:34
  • The "distinct" property was right there from the beginning, both in my problem statement and the title – bui Apr 26 '17 at 02:35
  • @UnknownGuy Quite, my bad! OK, yes, of course that changes the answer ... I updated it – Bram28 Apr 26 '17 at 02:45
  • I think your new solution may overcount the number of possibilities. It is true that the order of the 2-ball pair does not matter. However, it is also true that the order of the balls in a particular boxes also does not matter. Thus, there is a chance that the 2-ball you selected for one box may re-appear in that box in other combinations – bui Apr 26 '17 at 02:54
  • @UnknownGuy Oh, I see what you mean: If I first pick balls 7 and 13 for box 4, and later on I add ball 9, then that's that same as first picking 7and 9 for that box, and later on adding 13. Argh! Yes, you're right! Back to the drawing board ... – Bram28 Apr 26 '17 at 02:59
  • It's ok, i also made the same mistake when i first try to do it. Badam's solution using inclusion-exclusion produces correct result (i have tested it), so that should be the answer to this problem :) – bui Apr 26 '17 at 08:12
  • @UnknownGuy Ah, I'm glad someone knew how to do it! It was clearly over my head :) – Bram28 Apr 26 '17 at 12:57