A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Stars and Bars: Combinations with Repetition

College Depth 65 in the knowledge graph I know this Set as goal
116topics build on this
282prerequisites beneath it
See this on the map →
CombinationsCounting Principles: Addition and Multiplication RulesDouble Counting PrincipleIntroduction to Generating Functions
stars-and-bars combinations-with-repetition counting combinatorics

Core Idea

The stars-and-bars technique counts the number of ways to distribute k identical objects into n distinct bins where each bin can hold any number, giving C(n+k−1, k). The idea is to arrange k stars (objects) and n−1 bars (dividers between bins) in a row — each arrangement corresponds to a distribution. This formula solves a wide class of problems: choosing k items from n types with repetition allowed, or counting non-negative integer solutions to x₁ + x₂ + ⋯ + xₙ = k.

How It's Best Learned

Draw literal stars and bars diagrams: 'ooo|o|oo' represents 3 in bin 1, 1 in bin 2, 2 in bin 3. Converting between the visual and the formula builds reliable intuition. Extend to variations with minimum or maximum constraints using variable substitution.

Common Misconceptions

Explainer

You already know combinations: C(n, k) counts the ways to choose k distinct items from n, where order doesn't matter. That formula assumes you can't pick the same item twice. Stars and bars extends this to the case where repetition is allowed — you can pick any item as many times as you like. The trick is finding a clever bijection that reduces this new problem to a combinations problem you already know how to solve.

Imagine you have k identical balls and n labeled boxes, and you want to count every possible distribution (some boxes may be empty). Represent each ball as a star (★) and use n−1 bars (|) as dividers between boxes. A row of k stars and n−1 bars uniquely describes a distribution: count the stars in each segment. For example, with k=5 balls and n=3 boxes, the arrangement ★★|★|★★ means 2 in box 1, 1 in box 2, 2 in box 3. Every arrangement of 5 stars and 2 bars corresponds to exactly one distribution, and vice versa. So the count is just the number of ways to arrange k stars and n−1 bars — choose which k positions (out of k + n−1 total) hold stars: C(n+k−1, k).

The same formula covers a problem that looks unrelated: how many non-negative integer solutions does x₁ + x₂ + ⋯ + xₙ = k have? Each solution is a tuple (x₁, …, xₙ) where xᵢ counts how many balls go into box i. It's the same problem in disguise, so the answer is the same: C(n+k−1, k). This equivalence is worth internalizing — whenever you see "sum equals a constant, all terms non-negative integers," that's stars and bars.

Constraints change the formula through substitution. If each box must hold at least 1 ball (strict positivity), put one ball in each box first, leaving k−n balls to distribute freely. The answer becomes C(n + (k−n) − 1, k−n) = C(k−1, k−n). If a box has an upper bound (say, box 1 holds at most 3), use inclusion-exclusion: count all distributions, then subtract those where box 1 holds 4 or more. The power of stars and bars is that it turns distribution and allocation problems — which feel open-ended — into straightforward combinations calculations, as long as you correctly encode the constraints.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Making 10 as an Addition StrategyAddition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts Through 10Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineOpposites and Additive InversesAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesStars and Bars: Combinations with Repetition

Longest path: 66 steps · 282 total prerequisite topics

Prerequisites (2)

Leads To (2)