MAS334 Combinatorics

2. Counting solutions

Proposition 2.1.

Consider an equation x1++xk=n, where x1,,xk are required to be strictly positive integers. Then

 number of solutions =(n-1k-1)=( right hand side -1 number of variables -1).
Proof.

Consider a subset A[1,n-1] with |A|=k-1. We can list the elements as 0<a1<a2<<ak-1<n say. We then put

x1 =a1>0
x2 =a2-a1>0
x3 =a3-a2>0
xk-1 =ak-1-ak-2>0
xk =n-ak-1>0.

If we add these equations together, then the a’s will all cancel, and we get x1++xk=n, so we have a solution to the original equation. Conversely, if we have a solution x1++xn=k (with xi>0) then we have a corresponding subset

A={x1,x1+x2,x1+x2+x3,,x1++xk-1}

of size k-1 in [1,n-1]. This gives a one-to-one correspondence between the set of solutions and Pk-1[1,n-1], so the number of solutions is (n-1k-1).

Example 2.2.

We can illustrate the above proof as follows. Take k=4 and n=9, so we are considering the equation x1+x2+x3+x4=9. The proof gives a bijection between the solution set and the set P3[1,8] of subsets of size 3 in [1,8]. One such subset is {1,5,7}; it corresponds to the solution 1+4+2+2=9, as shown below.

Example 2.3.

Consider the equation x1+x2+x3+x4=6 (with xi>0). The proposition tells us that the number of solutions is (53)=10. They can be listed (in dictionary order) as follows.

1+1+1+31+1+2+21+1+3+11+2+1+21+2+2+11+3+1+12+1+1+22+1+2+12+2+1+13+1+1+1.
Proposition 2.4.

Consider an equation y1++yk=m, where y1,,yk are required to be nonnegative integers. Then

 number of solutions =(m+k-1k-1)=( right hand side + number of variables -1 number of variables -1).
Proof.

If we put xi=yi+1, then the variables xi are strictly positive integers, and must satisfy x1++xk=m+k. By Proposition 2.1, the number of solutions to this new equation is (m+k-1k-1), so this is also the number of solutions to the original equation. ∎

Example 2.5.

The above argument shows that nonnegative solutions to y1++yk=m biject with subsets {a1,,ak}[1,m+k-1] of size k. Algebraically, the correspondence is

y1 =a1-10
y2 =a2-a1-10
y3 =a3-a2-10
yk-1 =ak-1-ak-2-10
yk =m+k-1-ak-10.

For a pictorial example, consider the equation y1+y2+y3+y4=5, so k=4 and m=5 and m+k-1=8. The set {1,5,7}P3[1,8] corresponds to the solution 0+3+1+1=5, as illustrated below:

We can also draw this slightly differently, by writing the binary sequence 10001010 corresponding to the set {1,5,7}:

In this representation, the numbers yi are just the lengths of the blocks of zeros between the ones (including the blocks at the left and right hand ends).

Remark 2.6.

We can now give another approach to the problem of counting gappy sets. Suppose we want a gappy set A={a1,,ak} of size k in [1,n]. Let x0 be the size of the gap before a1, and let xk be the size of the gap after ak. These are both allowed to be zero. However, the gap between ai and ai+1 is required to have size at least one, so we can express it as xi+1, where xi0. As A has size k in [1,n], see that the total size of the gaps is n-k. This gives the equation

x0+(x1+1)++(xk-1+1)+xk=n-k.

On the left hand side, we have k-1 extra ones, so we can rearrange to get

x0++xk=n-2k+1.

Here we have k+1 variables and n-2k+1 on the right hand side, so the number of solutions is

( right hand side + number of variables -1 number of variables -1)=((n-2k+1)+kk)=(n-k+1k).

This agrees with the number of gappy sets, as we found in Proposition 1.23.

Problem 2.7.

Consider an n×m grid. Suppose that we want to go from the bottom left to the top right by taking a sequence of steps, each step going one space to the right or one space upwards. For example, two such routes across a 6×3 grid are shown below.

How many different routes are possible?

Solution.

A route from the bottom left to the top right must consist of n+m steps, of which n must be horizontal and m vertical. To choose such a path, we just need to choose which of the steps are horizontal. The number of ways of making that choice is (n+mn). Thus, the number of paths is (n+mn).

Remark 2.8.

We now have a new way to think about Proposition 2.4. Consider for example the equation x1+x2+x3+x4=6. The proposition tells us that the number of solutions is (6+4-14-1)=(93)=84. Given any solution, we can construct a grid path like this: we start at (0,0), then take x1 horizontal steps, then a vertical step, then x2 horizontal steps, then a vertical step, then x3 horizontal steps, then a vertical step, then x4 horizontal steps. Altogether this gives x1+x2+x3+x4=6 horizontal steps and 3 vertical steps, so we have a grid path from (0,0) to (6,3). For example, the path on the left below has horizontal segments of length 1, 2, 1 and 2, so it corresponds to the equation 1+2+1+2=6. The path on the right starts by going upwards, which we count as having an initial horizontal segment of length 0. We then have a horizontal segment of length 4, then a vertical segment of length 2. We count this as two vertical segments of length one, with a horizontal segment of length 0 in between. Finally, we have a horizontal segment of length 2. Thus, the corresponding solution is 0+4+0+2=6.

With this construction, we get one grid path for every solution to the equation, and vice-versa. Thus, the number of solutions is the same as the number of grid paths. Any such path consists of 9 steps, of which 3 must be vertical. Thus, the number of grid paths is (93)=84, and the number of solutions to our equation is also 84. All this can be generalised in a straightforward way: if we have a nonnegative solution to the equation x1++xk=n, then we can use it to make a grid path consisting of horizontal segments of lengths x1,,xk, and a single vertical step between these, making k-1 vertical steps and x1++xk=n horizontal steps altogether. To specify such a path, we take n+k-1 steps and choose which k-1 of them should be vertical. The number of solutions is the number of possible ways to make this choice, which is (n+k-1k-1). This agrees with Proposition 2.4.

Proposition 2.9.

For 0<kn we have

(nk)=(k-1k-1)+(kk-1)++(n-1k-1)=m=kn(m-1k-1).
Bijective proof.

The left hand side is the number of subsets A[1,n] of size k. We will show that the right hand side can also be interpreted in the same way. To choose A, we can start by choosing the largest element of A, say m. Then we need to choose k-1 additional elements, which must all be less than m. This will only be possible if mk, so we can assume that kmn. Once we have chosen m, the remaining k-1 elements must be taken from [1,m-1], and there are (m-1k-1) ways to do this. The total number of possible choices is therefore m=kn(m-1k-1), as required. ∎

Inductive proof.

We will argue by induction on n. The base case is when n=1. As 0<kn, we must also have k=1 in this case. The claim is then that (11)=m=11(0m-1)=(00), and this is true because (11)=(00)=1.

Now suppose that n>1 and 0<kn. We can assume as an induction hypothesis that

(n-1k)=(k-1k-1)++(n-2k-1)=m=kn-1(m-1k-1).

Adding (n-1k-1) to both sides gives

(n-1k)+(n-1k-1)=(k-1k-1)++(n-2k-1)+(n-1k-1)=m=kn(m-1k-1).

However, Proposition 1.19 tells us that the left hand side is the same as (nk), so we see that (nk)=m=kn(m-1k-1) as claimed. ∎

Proposition 2.10.

In a triangle as shown, the sum of all the entries is (N+23).

Proof.

Let T be the sum of all the numbers in the triangle. We can divide the triangle into stripes as follows:

The sum of the terms in the p’th stripe is 1+2++p, which is the same as (p+12) by Proposition 1.18. Thus, the sum of all the numbers in the triangle is T=p=1N(p+12). On the other hand, we can take n=N+2 and k=3 in Proposition 2.9 to get

(N+23)=q=3N+2(q-12).

If we put q=p+2, this becomes

(N+23)=p=1N(p+12)=T,

as claimed. ∎

Problem 2.11.

Consider the same triangle again.

We have marked four different upward-pointing subtriangles. How many such subtriangles are there in total?

Solution.

Consider the following picture:

The shaded triangle appears as the bottom right corner of three different subtriangles, one of size 1, one of size 2 and one of size 3, which are also shown in the picture. Because of this, we have marked the shaded triangle with a 3. In the same way, for each upward triangle T of size one, we can count all the subtriangles that have T as the bottom right corner, and mark T with that number. We get the following picture:

The total number of all subtriangles is the sum of the numbers in this picture. This is just the same as the sum considered in Proposition 2.10 (with N=6), so the total number of subtriangles is (6+23)=(83)=56.

More generally, if we start with a triangle of size N, the total number of upward-pointing subtriangles is (N+23).

Definition 2.12.

The Fibonacci numbers fn are defined by f0=1 and f1=1 and fn=fn-2+fn-1 for all n0. For example, we have

f2 =f0+f1=1+1=2 f3 =f1+f2=1+2=3
f4 =f2+f3=2+3=5 f5 =f3+f4=3+5=8
f6 =f4+f5=5+8=13 f7 =f5+f6=8+13=21.
Proposition 2.13.

For all n0 we have

fn=(n0)+(n-11)+(n-22)+=k0(n-kk).

(Recall here that (mk) is defined to be zero if k>m, so the terms in the sum are eventually zero.)

Proof.

Put gn=k0(n-kk), so the claim is that gn=fn. We will prove this by induction. For the first few cases, we have

g0 =(00)+(-11)+(-22)+=1+0+0+=1=f0
g1 =(10)+(01)+(-12)+=1+0+0+=1=f1
g2 =(20)+(11)+(02)+=1+1+0+=2=f2.

Now suppose that n>2, and consider gn=k0(n-kk). Proposition 1.19 tells us that (n-kk)=(n-k-1k)+(n-k-1k-1). This gives

gn=k0(n-k-1k)+k0(n-k-1k-1).

The first sum here directly matches the definition of gn-1. In the second sum, we note that the term for k=0 is (n-1-1)=0, so we can start from k=1 instead of k=0. We can then rewrite the sum in terms of the variable j=k-1, so that j0 and k=j+1 and n-k-1=n-2-j. The second sum then becomes j0(n-2-jj), which is gn-2. We now see that gn=gn-1+gn-2. We can assume as an inductive hypothesis that gn-1=fn-1 and gn-2=fn-2, so we have gn=fn-1+fn-2. Using the definition of the Fibonacci numbers, this becomes gn=fn, as claimed. ∎

Proposition 2.14.

Suppose we have points a1,,an in anticlockwise order around the unit circle, and we draw a line lij from ai to aj for each ij. Suppose that the points are in general position, so there is no point where more than two of the lines cross. Then the resulting diagram has (n2) lines, and (n4) interior crossing points, and 1+(n2)+(n4) regions.

Example 2.15.

The following picture shows the case shows the case n=5. The number of lines is 10, which is (52) as expected. The number of interior crossing points (marked in black) is 5, which is (54) as expected. The lines divide the disk into 16 regions, and 16=1+(52)+(54) as expected.

Proof of Proposition 2.14.

As lij=lji, we see that the number of lines is the number of possible subsets {i,j}{1,,n} of size two, which is (n2).

Now suppose we have a subset A{1,,n} of size 4. We can list the elements in order as h,i,j,k with h<i<j<k. As we have numbered the points ap in order around the circle, we find that the line lhj meets the line lik at a single point bA lying inside the circle:

This construction gives a bijection from the set of subsets of size 4 to the set of internal crossing points, so the number of such points is (n4) as claimed.

Now suppose we start with an empty disc, and add in the lines lij one by one. At each stage, we keep track of the number L of lines, the number C of internal crossings and the number R of regions. We also keep track of the number E=R-L-C. At the beginning (stage 0) there are no lines or crossings, and the disc is a single undivided region, so L=C=0 and R=1 and E=1-0-0=1. More compactly, we can write (L,C,R,E)=(0,0,1,1). At stage 1, we add a single line, which splits the disk into two regions, but there are still no crossings. We therefore have L=1 and C=0 and R=2 and E=2-1-0=1, or in other words (L,C,R,E)=(1,0,2,1). At stage 2, we add a second line, and there are several different possibilities, depending on how the two lines are placed relative to each other. However, we find that all three possibilities still have E=1.

In fact, we claim that E stays equal to 1 throughout the whole process. Indeed, suppose we add in a new line lij from ai to aj. This may create new crossing points. We list these in order (moving from ai to aj) as x1,,xr say, and we also write x0=ai and xr+1=aj. This divides the new line into segments si=[xi-1,xi], for i=1,,r+1. Each of these r+1 segments cuts one of the old regions into two new regions, so the number R of regions increases by r+1. At the same time, L increases by 1 and C increases by r, so the combination E=R-L-C is unchanged. (It can also happen that there are no new crossing points; then everything works in essentially the same way, but with r=0.) At stage 0 we have E=1, so at the last stage we still have E=1. However, at the last stage we have added in all the lines, so by our previous discussion we have L=(n2) and C=(n4). We now see that

1=E=R-L-C=R-(n2)-(n4),

and we can rearrange this to get R=1+(n2)+(n4) as claimed. ∎