# In how many ways balls be distributed in boxes?

There are 5 different boxes and 7 different balls.All the balls are to be distributed in the 5 boxes placed in a row so that any box can recieve any number of balls.

I am confused on whether the answer should be $5^7$ or $7^5$.

-
If no boxes should be empty then what will be logic? –  prem shekhar Apr 24 '11 at 8:22
This is the thumb rule: $where^{what}$ Eg 5 persons in a lift and 8 floors Then (where) 8 floors ^ (what) 5 persons!!! Hence $8^5$ –  user99314 Oct 7 at 8:20

Hint: Suppose there were only 1 ball, and 5 different boxes. How many ways of putting the ball in the boxes would there be then?

If there were now 2 balls, you can break up your decision about where to put the balls by saying, "First I will decide where Ball 1 goes; then I will decide where Ball 2 goes." Each of these two choices are completely independent - whatever box you choose to put Ball 1 in, it doesn't affect which boxes you might put Ball 2 in. So how many pairs of choices $$\text{(box for Ball 1, box for Ball 2)}$$ are there?

Can you generalize what is going on to $n$ balls and 5 boxes? In fact it should not be too hard to find the formula for $n$ balls and $k$ boxes.

-
I got your logic......If no boxes should be empty then what will be logic........can you assist me –  prem shekhar Apr 24 '11 at 8:10
@prem - if there are no boxes, then there are no choices to make - the answer is 0. –  Zev Chonoles Apr 24 '11 at 8:24
I am asking that if No boxes are empty then..?? –  prem shekhar Apr 24 '11 at 9:53
@prem, sorry, I misunderstood your question. If you want no boxes to be empty, in that case the answer is given by these numbers. –  Zev Chonoles Apr 24 '11 at 14:00
@prem Multiplied by (number of boxes)! because the Stirling numbers Zev Chonoles referred you to are for indistinguishable boxes. For the specific case of $7$ balls and $5$ boxes, with no box left empty, the number of ways is $5!S(7,5)=120\cdot140=16800$. Or something like that. –  bof Oct 7 at 10:46

It should be $5^7$ because first ball can go to any of the $5$ boxes and even after that all balls have equal chances to go to all the $5$ boxes. so $5\cdot5\cdot5\cdot5\cdot5\cdot5\cdot5$ ways. On the othere hand if you think that first box can contain any of the $7$ balls then there is no chance that another box can also receive $7$ balls.

-

The answer will be $5^7$.

Here the balls are different and the boxes are diffrent. Suppose the boxes are $A$, $B$, $C$ and $D$ and the balls are $x$, $y$, $z$. x can pair with either A , B , C ,D

$$x \times ( A, B, C, D) \tag{1}$$

Likewise,

$$y \times (A, B, C, D) \tag{2}$$ $$z \times (A, B, C, D) \tag{3}$$

From equation $(1)$ we have 4 choices, and for each choice we have 4 choices from equation $(2)$, and for each choice from equation $(2)$ we have 4 choices from equation $(3)$.

So, $4 \times 4 \times 4 = 4^3$.

Sometime we may think as follows, which is wrong:

In box $A$ we can put $x$, $y$, $z$, therefore

$$(x, y, z) \times A$$

Similarly,

$$(x ,y ,z) \times B$$

$$(x, y, z) \times C$$

$$(x, y, z) \times D$$

Meaning the total number of choices $= 3 \times 3 \times 3 \times 3$, which is wrong.

Since we have used one ball in $A$, we can not use it for $B$, $C$, or $D$.

-

Hint: You can think of this problem as placing 7 people into 5 rooms. Observe that placing the people is the same as giving each of them a sign (or a key) with the room number, when the people are standing in a prior chosen order.

-

Are the balls distinguishable? If so, we have 5^7, as each ball has the option of going into any box. If the balls are not distinguishable, then we can use hockey-stick, using four placeable dividers- we have 8C4.

-
If each box had to have at least $1$ ball, then you put a ball in all the boxes first, then see how many ways you can put $2$ balls in $5$ boxes, which is $5^2$.