- Published on
Stars and Bars
- Authors
- Name
- Muhammad Hasan
- @muhammadhasan01
Motivation
Stars and Bars Theorem is quite a cool mathematics technique, it's usually used in solving this problem:
Given a non-negative integer and a positive integer , find the number of solution of:
where is a non-negative integer.
For an example, when and then some of the possible solutions for are:
Theorem
To solve the problem above, we can use the Stars and Bars Theorem which states that:
The number of ways to put identical objects into labeled boxes is:
The proof involves turning the objects into stars and separating the boxes using bars (therefore the name). E.g. we can represent with:
The above situation: in the first box is one object, in the second box are two objects, the third one is empty and in the last box are two objects. This is one way of dividing objects into boxes.
It should be pretty obvious, that every partition can be represented using stars and bars and every stars and bars permutation using stars and bars represents one partition.
Therefore the number of ways to divide identical objects into labeled boxes is the same number as there are permutations of stars and bars. The Binomial Coefficient gives us the desired formula.
Solving The Problem
Now back on solving the previous problem, for and we wanted to find the number of possible solutions of:
where is a non-negative integer for .
We can represent this with stars and bars, let's have stars and bars, then will have the following image:
The above image states that , , and .
Another example is when we have:
Then we will have , , and .
Therefore, we can just find every possible combinations of stars and bars to solve this solution.
So using the theorem, the number of solution is then:
Solving With Lower Bound Constraint
Let's have one more constraint, let's introduce new non-positive integers such that for each
Now the original problem remains the same, but we have to make sure that for each the constraint is satisfied.
Formally, given a non-negative integer and a positive integer , find the number of solution of:
where is a non-negative integer and .
To solve this problem, let , now we have and now the equation becomes:
This is the same as the original problem, but now the right equation becomes different, now let:
Therefore the number of solution is now: