Mathyessy
Home › Topics › Counting & Probability › Stars and bars

Stars and bars practice problems

How many ways can you share identical candies among kids? Stars and bars turns it into a single combination.

How it works

Write the n identical objects as stars and use k − 1 bars to split them into k groups. Every arrangement of stars and bars is one distribution, so the number of ways to give n identical objects to k people (some may get none) is

C(n + k − 1, k − 1)

This is also the number of nonnegative integer solutions to x₁ + … + xk = n. If every person must get at least one, hand out one each first, then distribute the remaining n − k: that gives C(n − 1, k − 1). Stars and bars only works when the objects are identical; distinct objects need a different count.

Stars And Bars practice problems with solutions

These problems come from Mathyessy's question bank. Try each one before opening the solution.

  1. Seven identical candies are given to 3 kids. How many distributions are possible?

    Show answer and solution

    Answer: 36

    7 stars and 2 bars: C(9, 2) = 9 × 8 ÷ 2 = 36.

  2. Five identical candies are given to 2 kids. How many distributions are possible?

    Show answer and solution

    Answer: 6

    C(5 + 1, 1) = 6. You can also list them: the first kid gets 0, 1, 2, 3, 4 or 5.

  3. How many positive integer solutions does x + y + z = 6 have?

    Show answer and solution

    Answer: 10

    Each variable is at least 1, so give 1 to each first. That leaves 3 to share among 3 variables with zeros allowed: C(5, 2) = 10.

  4. How many nonnegative integer solutions does x + y + z + w + v = 5 have?

    Show answer and solution

    Answer: 126

    5 stars and 4 bars: C(9, 4) = 9 × 8 × 7 × 6 ÷ 24 = 126.

Practice this in Mathyessy →Free, no account needed. Opens the Stars And Bars set with instant feedback.

Keep going

Related topics

Related practice sets in the app

All Counting & Probability topics · Contest math practice by topic · MATHCOUNTS practice · AMC 8 practice