Skip to main content

TL;DR

Stars and Bars: Count ways to put n identical balls into k distinct bins: C(n+k-1, k-1). This concept is essential for quantitative trading interviews and is frequently tested at top firms.

By Valenke Exam Prep Team·Last updated 2026-06-01
Combinatorics

Stars and Bars

Count ways to put n identical balls into k distinct bins: C(n+k-1, k-1).

Stars and bars (also "balls in bins") counts the number of ways to distribute nn identical objects into kk distinct bins. Intuition: Line up nn stars (the objects) and insert k1k-1 bars (dividers) among them. Everything to the left of the first bar goes in bin 1, between bars 1 and 2 goes in bin 2, and so on. The total number of symbols is n+k1n + k - 1, and you choose where to place the k1k-1 bars. Formula (non-negative bins): (n+k1k1)\binom{n + k - 1}{k - 1} Concrete example: Distribute 5 identical candies among 3 children. We need to place k1=2k-1 = 2 bars among n+k1=7n + k - 1 = 7 positions: (72)=21 ways\binom{7}{2} = 21 \text{ ways} One distribution: \star\star | \star \star \star | means child 1 gets 2, child 2 gets 3, child 3 gets 0. Bin 1: 2 Bin 2: 3 Bin 3: 0 Variant (positive bins): If each bin must have at least 1 object, pre-place one object in each bin. Then distribute the remaining nkn-k among kk bins: (n1k1)\binom{n - 1}{k - 1} When to use: "How many non-negative integer solutions does x1+x2++xk=nx_1 + x_2 + \cdots + x_k = n have?" This is the same problem in disguise. Also: distributing identical items, counting multisets, and partitioning integers with an upper bound on parts (with inclusion-exclusion). Alternative approach: Stars and bars is itself a fundamental technique. Many occupancy and distribution problems reduce to it.

Ready to practice for the Valenke Finance Exam?

Adaptive practice powered by Item Response Theory targets your weak areas. Start with 3 free sessions.

Start free practice →