Distribution of 5 distinct balls into 3 distinct boxes — counting problems

medium JEE-MAIN JEE Main 2023 3 min read

Question

In how many ways can 5 distinct balls be distributed into 3 distinct boxes such that no box is empty?

(JEE Main 2023, similar pattern)


Solution — Step by Step

Each of the 5 balls can go into any of the 3 boxes independently. So the total number of ways (with no restriction):

Total=35=243\text{Total} = 3^5 = 243

Let AiA_i = set of distributions where box ii is empty.

We want: Total A1A2A3- |A_1 \cup A_2 \cup A_3|

By inclusion-exclusion:

A1A2A3=AiAiAj+A1A2A3|A_1 \cup A_2 \cup A_3| = \sum|A_i| - \sum|A_i \cap A_j| + |A_1 \cap A_2 \cap A_3|

Ai|A_i| = distributions with one specific box empty = 25=322^5 = 32 (5 balls into remaining 2 boxes)

There are (31)=3\binom{3}{1} = 3 such terms: 3×32=963 \times 32 = 96

AiAj|A_i \cap A_j| = distributions with two specific boxes empty = 15=11^5 = 1 (all balls in the remaining 1 box)

There are (32)=3\binom{3}{2} = 3 such terms: 3×1=33 \times 1 = 3

A1A2A3|A_1 \cap A_2 \cap A_3| = all three boxes empty = 00 (impossible, balls must go somewhere)

A1A2A3=963+0=93|A_1 \cup A_2 \cup A_3| = 96 - 3 + 0 = 93

Number of distributions with no box empty:

24393=150243 - 93 = \boxed{150}

Why This Works

The inclusion-exclusion principle systematically removes overcounted cases. First, we subtract all distributions where at least one box is empty. But this double-subtracts distributions where two boxes are empty, so we add those back. The formula ensures exact counting.

This is actually a specific case of the Surjective function count: the number of onto functions from a set of 5 elements to a set of 3 elements. The general formula for surjections from nn elements to rr elements is:

S(n,r)=k=0r(1)k(rk)(rk)nS(n, r) = \sum_{k=0}^{r} (-1)^k \binom{r}{k}(r-k)^n

For n=5,r=3n = 5, r = 3: (30)(3)5(31)(2)5+(32)(1)5=24396+3=150\binom{3}{0}(3)^5 - \binom{3}{1}(2)^5 + \binom{3}{2}(1)^5 = 243 - 96 + 3 = 150.


Alternative Method — Using Stirling numbers

The number of distributions = r!×S(n,r)r! \times S(n, r) where S(n,r)S(n, r) is the Stirling number of the second kind.

S(5,3)=25S(5, 3) = 25 (number of ways to partition 5 objects into 3 non-empty groups).

Since the boxes are distinct: 3!×25=6×25=1503! \times 25 = 6 \times 25 = 150.

For JEE, the distribution formula with inclusion-exclusion is the most reliable method. For small numbers, you can also enumerate: the possible distributions of 5 balls into 3 non-empty boxes are (3,1,1), (2,2,1) types. Count each separately. But for larger numbers, inclusion-exclusion scales better.


Common Mistake

Students sometimes try to split the problem as “choose 3 balls for 3 boxes, then distribute the remaining 2.” This leads to complicated casework and double-counting. The inclusion-exclusion approach is cleaner: start with all 353^5 distributions and subtract the ones with empty boxes. Don’t overcomplicate it with manual casework.

Want to master this topic?

Read the complete guide with more examples and exam tips.

Go to full topic guide →

Try These Next