Distribution Problems (Balls and Boxes)
Almost every counting problem in combinatorics can be viewed as distributing \(n\) objects (balls) into \(k\) groups (boxes). To choose the right formula without hesitation, always ask two decisive questions first:
- Are the objects distinct or identical?
- Are the boxes distinct (distinguishable) or identical (indistinguishable)?
Within each of these four quadrants, the answer also depends on whether boxes may remain empty, must be non-empty, or have fixed capacities—and whether the order of objects inside each box matters. Keep this four-quadrant roadmap in mind as we derive each case systematically:
1. Distribution of Distinct Objects into Distinct Boxes
Suppose we have \(n\) distinct objects and \(k\) distinct boxes—imagine putting numbered stickers Box 1, Box 2, ..., Box k on them so every box is uniquely identifiable.
Case A: Order Inside Each Box Does Not Matter
1. Each box can contain any number of objects (empty boxes allowed): A box may stay completely empty, or a single box may receive all \(n\) objects. Each of the \(n\) distinct objects independently chooses any one of the \(k\) boxes (Box 1, Box 2, ..., or Box k). By the Multiplication Principle:
2. Each box must contain at least one object (\(n \ge k\)): Now no box may be empty. Apply the Principle of Inclusion–Exclusion (Section 08):
Let \(U\) be all \(k^n\) unrestricted distributions, and let \(A_r\) (\(1 \le r \le k\)) be the set of distributions in which Box r is empty. We want none of the boxes to be empty, i.e., \(|A_1' \cap A_2' \cap \dots \cap A_k'|\).
- If \(r\) particular boxes are forced to stay empty, all \(n\) objects must be placed into the remaining \(k - r\) boxes in \((k - r)^n\) ways, and there are \(\binom{k}{r}\) ways to choose those \(r\) empty boxes.
By PIE:
3. Each box has a fixed capacity (\(n_1 + n_2 + \dots + n_k = n\)): Suppose Box 1 must receive exactly \(n_1\) objects, Box 2 exactly \(n_2\) objects, ..., and Box k exactly \(n_k\) objects, where \(n_1 + n_2 + \dots + n_k = n\).
- Choose \(n_1\) objects out of \(n\) for
Box 1in \(\binom{n}{n_1}\) ways. - Choose \(n_2\) objects from the remaining \(n - n_1\) for
Box 2in \(\binom{n - n_1}{n_2}\) ways. - Continue until the last \(n_k\) objects go to
Box kin \(\binom{n_k}{n_k} = 1\) way.
Multiplying and canceling consecutive factorials produces the exact same multinomial formula we met in MISSISSIPPI (Section 06):
Case B: Order Inside Each Box Also Matters (Bank Cash Counters)
Now add one further condition: the objects placed inside each box are also arranged in order—like \(n\) distinct customers forming queues at \(k\) distinct bank cash counters.
1. Each counter may have any number of customers (empty queues allowed): In Section 03, we counted this using the rising factorial: Person \(1\) has \(k\) choices, Person \(2\) has \(k + 1\), ..., and Person \(n\) has \(k + n - 1\), giving:
We can also derive this visually using identical wooden wedges (analogous to binary strings): arrange all \(n\) distinct people and \(k - 1\) identical red wooden wedges in one long row. The \(k - 1\) wedges slice the row into \(k\) ordered queues—the segment before the first wedge goes to Counter \(1\) in that exact order, the segment between the first and second wedges goes to Counter \(2\), and so on!
We are permuting \(n + k - 1\) items in which \(k - 1\) wedges are identical, giving \(\frac{(n + k - 1)!}{(k - 1)!}\) ways.
2. Each counter must have at least one customer (\(n \ge k\)): Using wooden wedges, a counter is empty if and only if two wedges sit next to each other or a wedge sits at either end of the line. Therefore:
- Arrange all \(n\) distinct customers in a single row in \(n!\) ways.
- This creates \(n - 1\) interior gaps between consecutive customers. Choose \(k - 1\) of these \(n - 1\) gaps to insert the \(k - 1\) identical wedges in \(\binom{n - 1}{k - 1}\) ways.
By the Multiplication Principle:
3. Each counter has a fixed queue length (\(n_1 + \dots + n_k = n\)): Here the positions of the wedges are completely fixed by the required capacities—only the \(n\) people permute among the \(n\) ordered slots, giving simply \(n!\) ways.
2. Distribution of Identical Objects into Distinct Boxes
Now suppose we have \(n\) identical objects (such as \(100\) identical oranges) and \(k\) distinct boxes (Box 1, ..., Box k). Because the oranges are indistinguishable, only the number of oranges \(x_i\) in Box i matters, where:
This is identical to the integral equation solved in Section 07 (Stars and Bars):
- Each box may contain any number of objects (\(x_i \ge 0\)):
- Each box must contain at least one object (\(x_i \ge 1\), \(n \ge k\)):
3. Distribution of Distinct Objects into Identical Boxes
Before counting distributions into identical boxes, pause and make sure you know when boxes are truly identical.
When Are Two Boxes Truly Identical?
Boxes are identical only if we have no way to distinguish one from another—no labels, no distinct spatial positions, and no different capacities! For instance, a box of capacity \(5\) is automatically distinguishable from a box of capacity \(10\). Likewise, four rows of chairs in a classroom may all have the exact same capacity, yet they are distinct because Row \(1\) (front), Row \(2\), Row \(3\), and Row \(4\) (back) occupy different physical locations in the room.
A. Identical Boxes of Equal Fixed Capacity
Suppose we distribute \(nk\) distinct objects into \(k\) identical boxes, each having the exact same fixed capacity of \(n\) objects.
To see the effect of removing box labels, take \(6\) distinct objects \(\{a, b, c, d, e, f\}\) and \(3\) identical boxes of capacity \(2\). Look at one single distribution into identical boxes: \(\{\{a, b\},\; \{c, d\},\; \{e, f\}\}\).
If we now attach three distinct stickers—Box 1, Box 2, and Box 3—onto these three boxes, we can place the stickers in \(3! = 6\) different ways, turning one identical-box distribution into \(6\) distinct-box distributions:
In general, let \(x\) be the number of distributions of \(nk\) distinct objects into \(k\) identical boxes of capacity \(n\). For every such distribution, attaching \(k\) distinct box stickers in \(k!\) ways generates all distinct-box distributions:
Remember the simple rule: when \(k\) boxes of equal capacity are identical instead of distinct, divide by \(k!\).
Example 1 (Handshakes vs. Numbered Tables): At a party of \(100\) guests, all guests divide into \(50\) pairs. In how many ways can this happen if: (a) they simply pair up to shake hands, (b) they sit in pairs at \(50\) tables placed around the banquet hall?
Solution:
(a) Forming \(50\) handshake pairs: Each pair is an unlabeled group of capacity \(2\)—all \(50\) groups are identical! Thus:
(b) Sitting in pairs at \(50\) tables in the hall: Now each table is distinguishable by its physical position in the hall (near the entrance, near the stage, etc.), so the \(50\) boxes are distinct! We do not divide by \(50!\):
B. Mixed Fixed Capacities
Suppose there are no labels on the boxes, yet some boxes share one capacity and other boxes share a different capacity—for example, \(5\) boxes of capacity \(25\) and \(2\) boxes of capacity \(10\) (total objects \(= 5 \times 25 + 2 \times 10 = 145\)).
The \(5\) boxes of capacity \(25\) are identical to one another (divide by \(5!\)), and the \(2\) boxes of capacity \(10\) are identical to one another (divide by \(2!\)), while a \(25\)-object box can never be confused with a \(10\)-object box. Thus the number of distributions is:
C. Arbitrary Non-Empty Groups: Stirling Numbers of the Second Kind
Now drop fixed capacities completely: suppose we wish to partition \(n\) distinct objects into \(r\) non-empty identical (unlabeled) groups of any non-zero sizes.
To appreciate the subtlety, divide \(4\) distinct objects \(\{a, b, c, d\}\) into \(2\) non-empty unlabeled groups by direct enumeration:
There are \(7\) ways in total. Do not let your brain treat the left group as "Group 1" and the right group as "Group 2"! If you did, you would think swapping \(\{a, b\}\) and \(\{c, d\}\) creates an eighth way. Because the groups have no names, \(\{\{a, b\}, \{c, d\}\}\) and \(\{\{c, d\}, \{a, b\}\}\) are the exact same partition.
Definition (Stirling Number of the Second Kind): Denoted \(S(n, r)\) (or \(\left\{\begin{matrix} n \\ r \end{matrix}\right\}\)), the Stirling number of the second kind is the number of ways to distribute \(n\) distinct objects into \(r\) non-empty identical boxes (\(1 \le r \le n\)).
Let us calculate key special cases directly from first principles:
- \(S(n, 1) = 1\): All \(n\) objects go into the single box.
- \(S(n, n) = 1\): Each object sits alone in its own box.
- \(S(n, 2) = 2^{n - 1} - 1\): Temporarily name the two boxes Group I and Group II. Each of the \(n\) objects has \(2\) choices (\(2^n\) ways); subtracting the \(2\) cases where one box is empty leaves \(2^n - 2\) distributions into labeled groups. Removing the two labels divides by \(2! = 2\), giving:
(Checking \(n = 4\): \(S(4, 2) = 2^3 - 1 = 7\), matching our enumeration!)
- \(S(n, n - 1) = \binom{n}{2}\): To split \(n\) objects into \(n - 1\) non-empty groups, exactly one group must contain a pair of \(2\) objects while the remaining \(n - 2\) groups are singletons. Choose the pair in \(\binom{n}{2}\) ways.
- \(S(n, n - 2) = \binom{n}{3} + 3\binom{n}{4}\): Splitting \(n\) objects into \(n - 2\) non-empty groups occurs in two disjoint size patterns:
- One group of size \(3\) and \(n - 3\) singletons: Choose the \(3\) objects in \(\binom{n}{3}\) ways.
- Two groups of size \(2\) and \(n - 4\) singletons: Choose \(4\) objects in \(\binom{n}{4}\) ways and divide them into \(2\) identical pairs in \(\frac{4!}{(2!)^2\,2!} = 3\) ways, giving \(3\binom{n}{4}\) ways.
Theorem (Explicit PIE Formula for \(S(n, r)\)): Attaching \(r!\) distinct labels to the \(r\) non-empty identical boxes yields all non-empty distributions into \(r\) distinct boxes. By the Division Principle:
Theorem (Recurrence Relation for \(S(n, r)\)): For all \(1 < r < n\):
Combinatorial Proof: Single out one specific object \(x\) among the \(n\) objects. In any partition of the \(n\) objects into \(r\) non-empty unlabeled groups, either:
- \(x\) forms a singleton group \(\{x\}\) by itself: The remaining \(n - 1\) objects must be partitioned into \(r - 1\) non-empty groups, which can be done in \(S(n - 1, r - 1)\) ways.
- \(x\) shares a group with at least one other object: First partition the other \(n - 1\) objects into \(r\) non-empty groups in \(S(n - 1, r)\) ways. Because those \(r\) groups now hold distinct objects, they are distinguishable! Hence \(x\) has \(r\) choices of which group to join, giving \(r \cdot S(n - 1, r)\) ways.
Adding the two disjoint cases proves \(S(n, r) = r\,S(n - 1, r) + S(n - 1, r - 1)\). \(\blacksquare\)
Here are the first five rows of the Stirling triangle built directly from this recurrence:
| \(n \backslash r\) | \(1\) | \(2\) | \(3\) | \(4\) | \(5\) | Row Sum \(B_n\) |
|---|---|---|---|---|---|---|
| \(1\) | \(1\) | \(1\) | ||||
| \(2\) | \(1\) | \(1\) | \(2\) | |||
| \(3\) | \(1\) | \(3\) | \(1\) | \(5\) | ||
| \(4\) | \(1\) | \(7\) | \(6\) | \(1\) | \(15\) | |
| \(5\) | \(1\) | \(15\) | \(25\) | \(10\) | \(1\) | \(52\) |
Bell Numbers (Empty Identical Boxes Allowed)
If \(n\) distinct objects are placed into \(k\) identical boxes where empty boxes are allowed, the number of occupied boxes can be \(1, 2, \dots, \min(n, k)\), yielding \(\sum_{r=1}^{\min(n, k)} S(n, r)\) ways.
When \(k \ge n\), this sum counts the total number of partitions of an \(n\)-element set into any number of non-empty blocks. This famous sequence is the \(n\)-th Bell Number, \(B_n\):
(As we will see in Section 10, \(B_n\) also counts the exact number of equivalence relations on an \(n\)-element set!)
4. Distribution of Identical Objects into Identical Boxes (Integer Partitions)
In the fourth and final quadrant, both the \(n\) objects and the \(k\) boxes are identical. Neither object identities nor box order matter—only the sorted multiset of box sizes distinguishes one distribution from another!
Definition (Integer Partition): Writing a positive integer \(n\) as a non-increasing sum of \(r\) positive integers:
is called an integer partition of \(n\) into \(r\) parts, and the number of such partitions is denoted \(p_r(n)\).
- Each of \(k\) identical boxes non-empty: \(p_k(n)\) ways.
- Empty boxes allowed: \(\sum_{r=1}^{\min(n, k)} p_r(n)\) ways (partitions into at most \(k\) parts). When \(k \ge n\), this is the total partition function \(p(n)\).
No simple closed-form formula exists for \(p_r(n)\) or \(p(n)\); for small \(n\), list non-increasing tuples systematically.
Example 2: In how many ways can \(6\) identical marbles be distributed into \(3\) identical bowls if: (a) no bowl is empty, (b) bowls may be empty?
Solution:
(a) Non-empty (\(p_3(6)\)): List all non-increasing triples of positive integers summing to \(6\): \((4, 1, 1)\), \((3, 2, 1)\), and \((2, 2, 2)\). Thus \(p_3(6) = 3\).
(b) Empty bowls allowed (\(p_1(6) + p_2(6) + p_3(6)\)):
- \(1\) non-empty bowl: \((6) \implies 1\) way.
- \(2\) non-empty bowls: \((5, 1),\; (4, 2),\; (3, 3) \implies 3\) ways.
- \(3\) non-empty bowls: \(3\) ways from part (a).
Total ways \(= 1 + 3 + 3 = 7\).
Master Summary of Distribution Problems
| Objects (\(n\)) | Boxes (\(k\)) | Empty Boxes Allowed | Every Box Non-Empty (\(n \ge k\)) |
|---|---|---|---|
| Distinct | Distinct (unordered inside) | \(k^n\) | \(k!\,S(n, k) = \sum_{r=0}^k (-1)^r \binom{k}{r}(k - r)^n\) |
| Distinct | Distinct (ordered inside) | \(k^{\overline{n}} = \frac{(n + k - 1)!}{(k - 1)!}\) | \(n! \binom{n - 1}{k - 1}\) |
| Identical | Distinct | \(\binom{n + k - 1}{k - 1}\) | \(\binom{n - 1}{k - 1}\) |
| Distinct | Identical | \(\sum_{r=1}^{\min(n, k)} S(n, r)\) (\(B_n\) if \(k \ge n\)) | \(S(n, k)\) |
| Identical | Identical | \(\sum_{r=1}^{\min(n, k)} p_r(n)\) (\(p(n)\) if \(k \ge n\)) | \(p_k(n)\) |


