Counting
The main idea is to apply the rules, and ideas from Sets and Functions, to analyze and enumerate possible outcomes of a computational problem.
Basic counting principles
Two sets are said to be mutually exclusive (or pairwise disjoint) if they have no elements in common.
"If there are ways to do task 1, and ways to do task 2, then there are ways to do both tasks."
If are finite sets, then:
Example
Suppose you have different types of ice cream, different types of cones, and different toppings. The number of different sundaes you can make is:
"If a task can be done either in one of ways or in one of ways (n_1 and n_2 are mutually exclusive), then there are ways to do the task."
If are mutually exclusive finite sets, then:
Example
Suppose you can choose your FYP from 3 lecturers. Lecturer A has 2 projects, lecturer B has 3 projects, and lecturer C has 4 projects. The number of different FYPs you can choose is:
"If a task can be done in either or ways, then number of ways to do task is , where is the number of ways to do the task in both ways."
The subtraction rule is inclusion-exclusion principle for two sets. The following is the general formulation:
If are finite sets, then:
Example
The number of integers from 1 to 100 that are divisible by 2, 3 or 5 is:
"If a task can be done in ways, and if there are indistinguishable objects, then the number of ways to do the task is ."
If a finite set , where are pairwise mutually exclusive (disjoint) finite sets, then:
Example
To sit four people around a circular table, when two seatings are consider to be the same, if each person has same left and right neighbour:
We know that there are ways to arrange four people in a line. However, when we arrange them in a circle, we can rotate the arrangement without changing the relative positions of the people. Hence, we need to divide by 4 (the number of people), which .
If items are placed into boxes, then there is at least one box that contains at least items.
Example
During a month with 30 days, a basketball team plays at least one game a day, but no more than 45 games in a month.
To show that there must be a period of some numbers of consecutive days, during which the team plays exactly games.
Let be the number of games played cummulative.
Observe , and , which .
Combining sequences, we have .
Key 1: There are a total of items, but they must be less than .
Key 2: As team must be at least one game a day, each is unique in (and all are unique).
This implies that in the combined sequence, at least one of the and must be equal, which means that there is a period of some numbers of consecutive days, during which the team plays exactly games.
Permutations and Combinations
To arrange objects where there are indistinguishable objects of type 1, indistinguishable objects of type 2, ..., indistinguishable objects of type , the number of arrangements is:
The number of ways to arrange of objects, where each object can be chosen more than once, is:
The property of binomial coefficients states that the number of ways to choose objects from objects is equal to the number of ways to choose objects from objects:
This is because choosing objects from objects is equivalent to leaving out objects from objects.
The number of ways to put indistinguishable items in distinguisable boxes, where each box can hold any number of items, is:
This is also called the stars and bars theorem.
Example 1
The number of solution to equation , where , is the number of ways to put 10 indistinguishable items in 3 distinguishable boxes, which is:
Example 2
The number of solution to equation , can be solved by using the equation , where is the number of items in the third box, which is empty. The number of ways to put 10 indistinguishable items in 3 distinguishable boxes, which is:
Example 3
The number of solutions to equation , :
First shift the condition to match Example 1: , where . The equation becomes .
The number of ways to solve , where is
But note the upper bound of is . Using the Inclusion-Exclusion principle, we need to subtract the cases where . Let , where .
For the equation , the number of ways to solve is . There are ways to choose which is greater than 21. Hence, the total number of solutions is:
The number of ways to choose objects from objects, where each object can be chosen more than once, is:
The number of ways to arrange objects such that no object is in its original position is called a derangement. The number of derangements of objects is denoted by and can be calculated using the following formula:
The number of surjections from a set of size to a set of size is given by the following formula:
This can also be expressed as:
- The number of functions such that is a surjection.
- Distribute distinguishable objects into distinguishable boxes, such that no box is empty.
- The number of equivalence relations on a set of size with exactly equivalence classes.