Overview
Stars and bars is a technique to count the number of ways to distribute identical objects into distinct boxes, hence where its name comes from. We represent objects as stars and dividers between boxes as bars. Counting arrangements of stars and bars can reduce a distribution problem into a binomial coefficient.
Key Ideas
- The number of ways to place identical objects into distinct boxes with non-negative integers is .
- For positive integer solutions (each bin gets at least 1), give each box one object first, then distribute the rest: .
- Stars and bars only applies when objects are identical and boxes are distinct. If objects are distinct, the rule of product can be used.
- Upper-bound constraints (in other words, "each bin gets at most ") require inclusion-exclusion with stars and bars.
- Equations of the form with non-negative integer solutions are equivalent to distributing identical objects into boxes.
Core Skills
Stars and Bars
The scenario we use when we think about stars and bars is when stars in a row with bars placed among them to create groups. Each arrangement corresponds to exactly one way to split objects into boxes. Hence, there are total symbols (stars and bars), and we choose which of those positions are bars:
Both forms are equal by symmetry as said in Binomial Theorem & Pascal's Triangle 1.
Finding Positive Integer Solutions
The number of solutions to with each is .
Think of each as the number of stars in bin . Arranging stars and bars gives us the same way as this. There is also the notation of H that some people use instead of P (Permutations) and C (Combinatorics).
Lower Bounds Other than 0 or 1
In some problems, there may be a condition in which where the Stars and Bars method may be used. , substitute . The equation becomes
and the non-negative formula applies to the .
Upper Bound Constraints
If each , use inclusion and exclusion. First, count all solutions, and then subtract those where at least one variable exceeds .
Let = solutions where . We substitute to count , then apply the two or three-set PIE formula. For more information about PIE, read Inclusion Exclusion 1.
Worked Example
In how many ways can 8 identical books be distributed among 3 children if each child may receive zero or more books?
This is the number of non-negative integer solutions to .
If instead each child must receive at least one book,
More Examples
Example 1: Counting Solutions to an Equation
How many non-negative integer solutions does have?
Four variables, sum 10: .
Example 2: Positive Solutions
How many ways can you write 12 as an ordered sum of 4 positive integers?
Positive solutions to :
Example 3: Lower Bound Shift
How many non-negative integer solutions does have with , , ?
Substitute and :
Thus, we obtain
Example 4: Utilizing Inclusion-Exclusion (PIE)
How many ways can 10 identical balls be placed into 3 boxes with each box holding at most 4 balls?
Total without restriction: .
Let = solutions where box has balls. Substitute : the remaining sum is , giving solutions for each .
We consider if two boxes simultaneously hold . This would require balls in those two boxes alone, leaving for the third, meaning 0 or all remaining go elsewhere. Specifically, forces the third box to have 0: for each pair.
No triple overlap (would need balls).
Solutions with each box : .
Strategy Checklist
- Identical vs. Distinct Objects
| Objects | Bins | Formula |
|---|---|---|
| Identical | Distinct | Stars and bars: |
| Distinct | Distinct | Rule of product: (with repetition) |
| Identical | Identical | Integer partitions (harder, no closed form) |
In summary, always check whether the objects are truly identical before applying stars and bars.
- If there are multiple types of identical objects, apply stars and bars once per type, and then multiply.
Common Pitfalls
- Applying stars and bars to distinct objects. If they are different, use or permutations, not stars and bars.
- Confusing with or . This could come from memorizing the formula by its derivation: stars and bars among total symbols.
- Forgetting to subtract when doing the positive-solution shift , and thus giving one object to each of bins first.
- Treating unlabeled boxes or "spaces" as labeled.
Practice Problems
| Status | Source | Problem Name | Difficulty | Tags | ||
|---|---|---|---|---|---|---|
| AMC 8 | Hard | Show TagsCombinatorics, Stars and Bars | ||||
| AMC 8 | Unknown | |||||
| AMC 8 | Medium | Show TagsDigits, Number Theory | ||||
| AMC 10A | Medium | Show TagsCombinatorics, Stars and Bars | ||||
| AMC 12B | Hard | Show TagsCombinatorics, Probability | ||||
| AMC 10A | Medium | Show TagsCombinatorics, Dice, Probability | ||||
| AMC 10B | Medium | Show TagsCombinatorics, Probability, Symmetry | ||||
Module Progress:
Join the AoPS Community!
Stuck on a problem, or don't understand a module? Join the AoPS community and get help from other math contest students.
