Stars and Bars
Ways to distribute n identical items into k distinct groups.
Formula
Variables
Example
5 candies to 3 kids: C(7,2) = 21
How it works
This formula counts the number of nonnegative integer solutions to x1 + x2 + ... + xk = n, where each xi is the number of identical items placed in group i. It works by imagining the n items as stars and using k - 1 dividers to split them into k groups; arranging n stars and k - 1 bars in a line gives a unique distribution, and the number of such arrangements is the binomial coefficient shown. Because only the positions of the bars matter, the count is choose n + k - 1 positions from the total n + k - 1 slots, or equivalently choose where the k - 1 separators go.
When to use it
Use this when you are counting ways to split identical objects among distinct categories, such as assigning candies to children, placing balls into boxes, or distributing identical tasks across teams. It is especially useful in combinatorics, integer partition-style counting, and problems that ask for nonnegative whole-number solutions.
Worked example, step by step
Example: Distribute 8 identical books among 4 distinct shelves. Step 1: Identify the parameters: n = 8 items, k = 4 groups. Step 2: Apply stars and bars: C(n + k - 1, k - 1) = C(8 + 4 - 1, 4 - 1). Step 3: Simplify: C(11, 3). Step 4: Compute: 11! / (3! 8!) = (11 × 10 × 9) / (3 × 2 × 1) = 165. Final answer: There are 165 ways to distribute the books.
Common mistakes to avoid
- Using this formula for distinct items instead of identical items
- Forgetting that the groups are distinct, so swapping two groups counts as a different arrangement
- Using k instead of k - 1 in the binomial coefficient
Did You Know?
A classic technique for counting non-negative integer solutions.
Share this formula
More in Probability & Combinatorics
View allPermutations
BasicNumber of ordered arrangements of r items from n.
Combinations
BasicNumber of unordered selections of r items from n.
Factorial
BasicProduct of all positive integers up to n.
Permutations with Repetition
BasicOrdered arrangements of r items from n when repetition is allowed.
Permutations of a Multiset
IntermediateArrangements of n items where some are identical.
Classical Probability
BasicProbability of an event with equally likely outcomes.