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 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.