Discrete MathematicsCounting: Choices, Arrangements and Selections7 of 7
Counting: Choices, Arrangements and Selections · 7
Stars and Bars: Distributing Identical Objects
When we hand out distinct items, we choose a recipient for each item one by one, but when the items are identical, only the final count each person receives matters.
1
Distributing Identical Objects
Suppose we want to find how many ways we can distribute 7 identical cookies to 3 kids (Alice, Bob, and Charlie) if each kid can receive any number of cookies, including 0.
Distributing Identical Objects with Stars and Bars
Text solution
Turn cookies and kids into stars and barsDraw the 7 identical cookies as 7 stars in a row, and use 2 vertical bars to divide the row into 3 sections for Alice, Bob, and Charlie.
Alice: 4⋆⋆⋆⋆Bob: 2⋆⋆Charlie: 1⋆
Choose spaces for the barsEvery arrangement of the 7 stars and 2 bars uses 7+2=9 total spaces, and choosing which 2 spaces get the bars automatically fills the other 7 spaces with stars.
C(9,2)=29×8=36
So there are 36 ways to distribute the 7 identical cookies to the 3 kids.
Notice in the figure how placing a bar at the end or two bars right next to each other leaves a kid with 0 cookies.
Every choice of 2 spaces for the bars splits the remaining 7 stars into a unique cookie count for Alice, Bob, and Charlie.
2
Minimums and Integer Equations
What if nobody is allowed to get zero, or different groups have different required minimums? We want to count the ways to give 7 cookies to 3 kids when every kid must get at least 1, and then solve the same kind of question written as an algebra equation: finding the number of integer solutions to x1+x2+x3=12 where x1≥2,x2≥0, and x3≥3.
Minimums and Integer Equations
When every group needs at least 1 star, placing the 2 bars into the 6 gaps between the 7 stars gives C(6,2)=15 ways. Handing out the minimums upfront gets the same C(6,2)=15 ways and also works when the minimums are uneven, as in x1+x2+x3=12 with x1≥2,x2≥0, and x3≥3:
Text solution
Hand out the minimums upfrontPut 2 ones into x1 and 3 ones into x3 right away so the minimum requirements are already satisfied, leaving 7 stars that can be distributed with no restrictions.
12−(2+0+3)=7 stars left
Place the bars among the remaining starsSeparating the 3 variables still takes 2 bars, which gives 7+2=9 blank spaces to choose from.
C(9,2)=36
So there are 36 integer solutions to x1+x2+x3=12 that satisfy the minimums.
3
Inequalities and the Cookie Jar
So far, every distribution has used up the entire total. Now we want to find how many ways we can hand out at most 7 cookies to 3 kids without having to give them all away. In algebra, this asks how many integer solutions there are to the inequality x1+x2+x3≤7 where x1≥0,x2≥0, and x3≥0.
Inequalities and the Cookie Jar
Text solution
Add a cookie-jar group for the leftoversAny cookies not given to the 3 kids stay in the cookie jar, which acts as a 4th group (a slack variable) that turns the inequality back into an exact equation.
x1+x2+x3+jar=7
Choose spaces for the 3 barsSplitting all 7 stars among 4 groups (3 kids and the jar) requires 3 bars, giving 7+3=10 total spaces.
C(10,3)=3×2×110×9×8=120
So there are 120 integer solutions to x1+x2+x3≤7, counting every possible sum from 0 through 7 at once.
Because the cookie jar gets whatever the 3 kids don't, handing out at most 7 cookies to 3 kids is the same as handing out all 7 cookies to 4 recipients.
When the cookie jar holds the leftovers, handing out up to 7 cookies to 3 kids is just splitting all 7 cookies across 4 groups with 3 bars.
4
Choosing with Repetition
Stars and Bars also shows up when we choose a collection of items from several categories with repeats allowed. Suppose you are buying a box of 7 donuts from a bakery that sells 3 flavors (Glazed, Chocolate, and Jelly) with plenty of each in stock, and we want to know how many different boxes of 7 donuts you can walk out with.
Choosing with Repetition
Text solution
Write the fixed total as an equationWhatever combination of flavors you choose, the flavor counts must add up to the 7 donuts in the box, which makes the 7 donuts the stars and the 3 flavors the groups.
Glazed+Chocolate+Jelly=7
Place the bars between the flavor columnsSplitting the 7 stars across 3 flavor categories takes 2 bars, giving 7+2=9 total spaces.
C(9,2)=36
So there are 36 different boxes of 7 donuts you can buy.
Each donut in the box adds one star tally to its flavor column on the order form, so the 7 donuts are the stars and the 3 flavors are the groups.
Every box of 7 donuts from 3 flavors matches a row of 7 stars and 2 bars on the order form.
5
Upper Limits by Complement
Giving stars upfront sets a minimum, because a group can still receive more stars afterward. What if a group has a maximum instead? We want to find the number of integer solutions to x1+x2+x3=7 (with x1,x2,x3≥0) when x1 is limited to x1≤3.
Upper Limits by Complement
Text solution
Count all distributions without the upper limitWith 7 stars and 2 bars for the 3 variables, find the total number of solutions where x1,x2,x3≥0.
Total=C(9,2)=36
Turn the upper limit into a minimum to count the bad casesBreaking the rule x1≤3 means having x1≥4, so give 4 stars to x1 upfront and distribute the remaining 7−4=3 stars using 2 bars.
Bad=C(3+2,2)=C(5,2)=10
Subtract the bad cases from the totalRemove the distributions that give x1 too many stars.
36−10=26
So there are 26 solutions where x1≤3.
Notice that this single subtraction handles a single upper limit; if two or more groups have upper limits at the same time, subtracting each group's bad cases separately would subtract overlapping violations more than once, which requires Inclusion-Exclusion.
Key concepts
Before using Stars and Bars, check that the items being distributed are actually identical: if 7different cookies go to 3 kids, each cookie has 3 choices for a total of 37 ways, whereas Stars and Bars applies when only the count in each group matters.
Whether a problem distributes identical items (7 cookies to 3 kids) or selects items with repetition allowed (7 donuts chosen from 3 flavors), you can always write it as an addition equation like x1+x2+x3=7. The fixed total on the right side is the number of stars(7), and the k distinct groups or categories on the left are separated by k−1bars(2 bars), giving 7+2=9 spaces and C(9,2) ways to place the bars.
From that starting setup, three adjustments handle extra conditions on the equation:
Minimums (≥)
Hand out the required minimums upfront so every variable can start at 0. For x1+x2+x3=12 with x1≥2,x2≥0,x3≥3, give away 2+3=5 stars first, leaving 7 stars and 2 bars for C(9,2) ways.
At most a total (≤ on the sum)
Add a cookie-jar variable to hold the leftovers and turn the inequality into an equation. For x1+x2+x3≤7, write x1+x2+x3+jar=7, which uses 7 stars and 3 bars for C(10,3) ways.
A single maximum (≤ on one variable)
Subtract the complement to turn the maximum into a minimum. For x1≤3 in x1+x2+x3=7, breaking the rule means x1≥4, which leaves C(9,2)−C(5,2) ways.
6
Practice
1
In how many ways can 10 identical coins be distributed among 4 children if each child can receive any number of coins, including 0?
Be careful not to use 4 bars for 4 children, which would give C(14,4)=1001.Don't forget to add the 3 bars to the total spaces and compute C(10,3)=120.
How many bars does it take to split a row of 10 stars into 4 sections?
We have 10 stars for the coins, and splitting them among 4 children takes 4−1=3 bars (be careful not to use 4 bars for 4 children, which would give C(14,4)=1001, or forget to add the 3 bars to the total spaces and compute C(10,3)=120). With 10+3=13 total spaces, choosing 3 spaces for the bars gives
C(13,3)=3×2×113×12×11=286
2
A smoothie shop offers 6 different fruit add-ins. You order a smoothie with 4 scoops of add-ins, and repeats are allowed. How many different combinations of 4 scoops can you choose?
Don't swap the stars and groups by treating the 6 fruits as stars and the 4 scoops as groups, which gives C(6+3,3)=84.
Write an equation for the total number of scoops in your cup: which number is the fixed total of stars, and which is the number of categories?
The counts of the 6 fruit add-ins must add up to the fixed total of 4 scoops in your cup, so there are 4 stars and 6 categories separated by 5 bars (don't swap the stars and groups by treating the 6 fruits as stars and the 4 scoops as groups, which gives C(6+3,3)=84). With 4+5=9 spaces, choosing where the 5 bars (or 4 stars) go gives
C(9,5)=C(9,4)=4×3×2×19×8×7×6=126
3
A teacher has 11 identical pencils to place into 4 distinct supply bins so that every bin gets at least 1 pencil. In how many ways can she do this?
Be careful not to forget to add the 3 bars to the 7 remaining stars when counting spaces (which would give C(7,3)=35).Be careful not to use 4 bars instead of 3 (which would give C(11,4)=330).
Take care of the "at least 1" rule first: how many pencils are left to distribute freely once every bin has 1?
Put 1 pencil into each of the 4 bins upfront, leaving 11−4=7 stars to distribute freely among the 4 bins using 3 bars (or place 3 bars directly into the 10 gaps between the 11 stars). Be careful not to forget to add the 3 bars to the 7 remaining stars when counting spaces (which would give C(7,3)=35) or use 4 bars instead of 3 (which would give C(11,4)=330). Choosing 3 spaces out of 7+3=10 gives
C(10,3)=3×2×110×9×8=120
4
How many integer solutions are there to x1+x2+x3+x4=15 where x1≥3,x2≥1,x3≥0, and x4≥2?
Watch that x3≥0 needs 0 stars upfront; giving x3 a star out of habit leaves 8 stars and gives C(11,3)=165.
Hand out the required minimums to x1,x2, and x4 first so that all four variables can start at 0.
Hand out the minimums 3+1+0+2=6 upfront, leaving 15−6=9 stars to distribute freely (watch that x3≥0 needs 0 stars upfront; giving x3 a star out of habit leaves 8 stars and gives C(11,3)=165). Splitting the 9 remaining stars among 4 variables takes 3 bars, so with 9+3=12 spaces we get
C(12,3)=3×2×112×11×10=220
5
How many integer solutions are there to x1+x2+x3≤8 where x1≥0,x2≥0, and x3≥0?
Don't use just 2 bars for the 3 original variables, which only counts the exact sum x1+x2+x3=8 and gives C(10,2)=45.
Where does the unused part of the 8 go when x1+x2+x3 is less than 8?
Add a fourth variable for the leftovers so that x1+x2+x3+slack=8. That gives 8 stars split among 4 groups using 3 bars (don't use just 2 bars for the 3 original variables, which only counts the exact sum x1+x2+x3=8 and gives C(10,2)=45). Choosing 3 spaces out of 8+3=11 gives
C(11,3)=3×2×111×10×9=165
6
A baker is packing a box of 9 pastries chosen from 4 types: croissants, scones, muffins, and danishes. There are plenty of scones, muffins, and danishes, but only 4 croissants left. How many different boxes of 9 pastries can the baker pack?
Be careful not to use 4 croissants as the bad case, which leaves 5 stars, C(8,3)=56, and gives 220−56=164.
Having only 4 croissants sets an upper limit (croissants≤4): how many croissants would a box need to break that rule?
With no limit on croissants, 9 pastries (stars) chosen from 4 types (3 bars) gives C(9+3,3)=C(12,3)=220 total boxes. A box breaks the rule croissants≤4 when it has at least 5 croissants (be careful not to use 4 croissants as the bad case, which leaves 5 stars, C(8,3)=56, and gives 220−56=164). Putting 5 croissants in the box upfront leaves 9−5=4 stars and 3 bars, or C(4+3,3)=C(7,3)=35 bad boxes. Subtracting the bad boxes from the total gives
220−35=185
7
How many integer solutions are there to x1+x2+x3=11 where 1≤x1≤4,x2≥2, and x3≥0?
Don't forget that x2≥2 still holds in the bad cases: subtracting only 5 from 11 gives C(8,2)=28 and 45−28=17.Don't add 5 on top of the 1 already in x1 to get x1≥6, which gives C(5,2)=10 and 45−10=35.
First count all solutions that satisfy the minimums x1≥1 and x2≥2, then subtract the ones that break the upper limit x1≤4 while still keeping x2≥2.
First satisfy the minimums x1≥1 and x2≥2 by handing out 1+2=3 stars upfront, leaving 11−3=8 stars and 2 bars for C(8+2,2)=C(10,2)=45 solutions. Among these, a solution breaks the upper limit x1≤4 when x1≥5 and x2≥2 (don't forget that x2≥2 still holds in the bad cases: subtracting only 5 from 11 gives C(8,2)=28 and 45−28=17; and don't add 5 on top of the 1 already in x1 to get x1≥6, which gives C(5,2)=10 and 45−10=35). Handing out 5 stars to x1 and 2 stars to x2 leaves 11−7=4 stars and 2 bars, giving C(4+2,2)=C(6,2)=15 bad solutions. Subtracting the bad solutions leaves