Combinatorics is a branch of mathematics which is about counting. Here we are concerned with problems which basically ask the total number of ways to do something. Combinatorics is just a fancy word for counting techniques.

Combinatorial problems have attracted the attention of mathematicians since early times. If you are interested in the earlier development and history of this branch of mathematics, you can read this, Wikipedia – History of Combinatorics. Today, I’ll pick some basic problems and try to solve then using the basic tools we already know (e.g addition, multiplication).

### Some Basic Problems

Q1: How many 3 digit numbers can be formed using the digits 1, 2 and 3 (use one digit only once)?

Let’s count it by writing down the sequences. There are 6 ways: (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1). There is no doubt that the answer is 6, but what if n is huge? It’s not practical to write sequences and keep counting. Can we use combinatorics to solve the problem?

Q2: How many 4 digit numbers can be formed using the digits 1, 2, 3 and 4 (use one digit only once)?

As I’ve said, It’s not practical to write down all possible sequences. Can we somehow use the answer of previous problem to solve this problem? There are 6 ways for digits 1, 2 and 3: (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1). Let’s take the first one, (1, 2, 3) and notice that, we can place the new digit 4 in the following positions:

• Before the first digit. (4, 1, 2, 3)
• Between the first and second digit. (1, 4, 2, 3)
• Between the second and third digit. (1, 2, 4, 3)
• After the last digit. (1, 2, 3, 4)

There are 4 sequences that we can form when we try to insert 4 at different places of (1, 2, 3). So we need to repeat the same process 5 other sequences (1, 3, 2), (2, 1, 3), \dots and for each sequence we are going to get 4 ways. So there are 4 \times 6 = 24 ways.

### Number of ways to form n digit numbers using digits 1, 2, 3, \dots, n

This problem is the generalization of the previous two problems. Let us consider a function f(n) which denotes the number of ways we can use n digits to form a number.

We know from the previous problems that f(3) = 6 and f(4) = 24. Now, What should f(5) be? We know f(4) = 24 and there are 5 places where we can put a new digit. For each of the 24 sequences of 4 digits, we get 5 sequences of 5 digits. So the answer should be 5 \times 24 = 5 \times f(4).

We’ve found a recurrence formula to generalize this, f(n) = n * f(n – 1) where f(n) means the number of ways we can use n distinct digits to form numbers of n digit. Note that f(0) = 1, since there is only 1 way to use 0 digits which is to use nothing, just like a empty list { }.

Notice that f(n) = n * f(n – 1) simply equals to the product of all the positive integers less than or equal to n stopping at 1. This is known as factorial function (symbol: !). For example: 4! = 4 × 3 × 2 × 1 = 24. So there are n! different ways to arrange n distinct digits / items.

### Fundamental Principles of Counting

We got a glimpse of a few combinatorics problems. Let’s now take a look at the on the fundamental principles of counting. There are 2 rules, the addition rule and the product rule. We’ve already used the product rule in the previous problems. According to the problem specification, we’ll have to decide when to use addition rule and when to use product rule.

Suppose we have 2 or more events A, B, \dots. Let E be an event where in which only one of the event occurs. Then the number of ways event E can occur n(E) = n(A) + n(B) + \dots For example,

Suppose you are travelling from city A to city B. There exists several options, you can go either by Bus or by Train or by Air. There are 2 different options if you choose Bus, 3 different options if you choose air and 2 different options if you choose train. We’ll go either by Bus or by Train or by Air. So, the total number of ways you can travel from city A to city is 2 + 3 + 2 = 7.

### The product Rule

Suppose we have 2 or more events A, B, dots Let E be an event where in which all the events A, B, dots occurs. Then the number of ways event E can occur n(E) = n(A) \times n(B) \times dots For example,

Suppose this time, you are travelling from city A to city C. Unfortunately, there is no way that you can use to go directly to city C. So, you first need to visit city B and from city B you go to city C. According to the addition principle, there are 4 ways to go to city B from city A and there are 7 ways to go to city C from city B. How many total ways are there?

To go to city B we have 4 options. And for each of the 4 options we have another 7 options for going to city C from city B. So, how many total options are there? The answer is 4 \times 7 = 28 ways. Using the product rule, we can solve a lot of problems. Let’s take a look some of the problems.

How many 4 digit numbers can be formed using the digits 1, 2, 3, 4, 5 (repetition not allowed)?

We have to form a 4 digit number. Picking a digit is an event. We have to pick all the 4 digits, so it’s under the multiplication rule. Suppose there are 4 vacant spaces.

We have 5 options to fill the 1st cell with a digit. Once we have used a digit, we now have 4 options to fill the 2nd cell. Simillarly there are 3 and 2 options respectively for the 3rd and the 4th cell.

5      4      3      2

Now we just used the product rule and the number of ways are 5 \times 4 \times 3 \times 2 = 120. Let’s try to generalize the problem now.

### Total number of ways to arrage r objects out of n distinct objects

We have already seen the number of ways to arrange n objects out of n objects. Now we want to know the number of ways to arrange r objects out of n distict objects. Notice that this problem is just the generalized version of the previous problem. Let’s take the an example, we have to arrange 3 objects from 5 distinct objects. If we fill the vacant spaces with possible options, it looks like this.

5      4      3

Can we express that in terms of factorials? The number of ways are 5 \times 4 \times 3 = frac{5 \times 4 \times 3 \times 2 \times 1}{2 \times 1} = \frac{5!}{2!}. Simmilarly, now we have to arrange r objects from n distinct objects, we can fill the vacant spaces with possible options just like below. The total ways are just the product of all the values in the cells.

n      n-1      dots      n-r+1

So, the number of ways to arrage r objects out of n distinct objects are (denoted as ^n P_r)
\Rightarrow \quad ^n P_r = n \times (n – 1) \times \dots \times (n – r + 1)

\Rightarrow \quad ^nP_r = \frac{n \times (n – 1) \times \dots \times 1}{(n – r) \times (n – r – 1) \times \dots \times 1}

\Rightarrow \quad ^n P_r = \frac{n!}{(n – r)!}

From this relation, number of ways to arrange n objects out of n are ^n P_n = \frac{n!}{(n-n)!} . Since 0! = 1, the total ways are n! , exactly what we’ve seen earlier. That’s it for today. See you in the next part of Basic Combinatorics. 😄

Do you like Naimul Haque's articles? Follow on social!