## Counting Rules and Techniques

Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.

### Learning Objectives

Describe the different rules and properties for combinatorics

### Key Takeaways

#### Key Points

• The rule of sum (addition rule), rule of product (multiplication rule), and inclusion-exclusion principle are often used for enumerative purposes.
• Bijective proofs are utilized to demonstrate that two sets have the same number of elements.
• Double counting is a technique used to demonstrate that two expressions are equal. The pigeonhole principle often ascertains the existence of something or is used to determine the minimum or maximum number of something in a discrete context.
• Generating functions and recurrence relations are powerful tools that can be used to manipulate sequences, and can describe if not resolve many combinatorial situations.
• Double counting is a technique used to demonstrate that two expressions are equal.

#### Key Terms

• polynomial: An expression consisting of a sum of a finite number of terms: each term being the product of a constant coefficient and one or more variables raised to a non-negative integer power.
• combinatorics: A branch of mathematics that studies (usually finite) collections of objects that satisfy specified criteria.

Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures. Combinatorial techniques are applicable to many areas of mathematics, and a knowledge of combinatorics is necessary to build a solid command of statistics. It involves the enumeration, combination, and permutation of sets of elements and the mathematical relations that characterize their properties.

Aspects of combinatorics include: counting the structures of a given kind and size, deciding when certain criteria can be met, and constructing and analyzing objects meeting the criteria. Aspects also include finding “largest,” “smallest,” or “optimal” objects, studying combinatorial structures arising in an algebraic context, or applying algebraic techniques to combinatorial problems.

### Combinatorial Rules and Techniques

Several useful combinatorial rules or combinatorial principles are commonly recognized and used. Each of these principles is used for a specific purpose. The rule of sum (addition rule), rule of product (multiplication rule), and inclusion-exclusion principle are often used for enumerative purposes. Bijective proofs are utilized to demonstrate that two sets have the same number of elements. Double counting is a method of showing that two expressions are equal. The pigeonhole principle often ascertains the existence of something or is used to determine the minimum or maximum number of something in a discrete context. Generating functions and recurrence relations are powerful tools that can be used to manipulate sequences, and can describe if not resolve many combinatorial situations. Each of these techniques is described in greater detail below.

### Rule of Sum

The rule of sum is an intuitive principle stating that if there are $a$ possible ways to do something, and $b$ possible ways to do another thing, and the two things can’t both be done, then there are $a + b$ total possible ways to do one of the things. More formally, the sum of the sizes of two disjoint sets is equal to the size of the union of these sets.

### Rule of Product

The rule of product is another intuitive principle stating that if there are $a$ ways to do something and $b$ ways to do another thing, then there are $a \cdot b$ ways to do both things.

### Inclusion-Exclusion Principle

The inclusion-exclusion principle is a counting technique that is used to obtain the number of elements in a union of multiple sets. This counting method ensures that elements that are present in more than one set in the union are not counted more than once. It considers the size of each set and the size of the intersections of the sets. The smallest example is when there are two sets: the number of elements in the union of $A$ and $B$ is equal to the sum of the number of elements in $A$ and $B$, minus the number of elements in their intersection. See the diagram below for an example with three sets.

### Bijective Proof

A bijective proof is a proof technique that finds a bijective function $f: A \rightarrow B$ between two finite sets $A$ and $B$, which proves that they have the same number of elements, $|A| = |B|$. A bijective function is one in which there is a one-to-one correspondence between the elements of two sets. In other words, each element in set $B$ is paired with exactly one element in set $A$. This technique is useful if we wish to know the size of $A$, but can find no direct way of counting its elements. If $B$ is more easily countable, establishing a bijection from $A$ to $B$ solves the problem.

### Double Counting

Double counting is a combinatorial proof technique for showing that two expressions are equal. This is done by demonstrating that the two expressions are two different ways of counting the size of one set. In this technique, a finite set $X$ is described from two perspectives, leading to two distinct expressions for the size of the set. Since both expressions equal the size of the same set, they equal each other.

### Pigeonhole Principle

The pigeonhole principle states that if $a$ items are each put into one of $b$ boxes, where $a>b$, then at least one of the boxes contains more than one item. This principle allows one to demonstrate the existence of some element in a set with some specific properties. For example, consider a set of three gloves. In such a set, there must be either two left gloves or two right gloves (or three of left or right). This is an application of the pigeonhole principle that yields information about the properties of the gloves in the set.

### Generating Function

Generating functions can be thought of as polynomials with infinitely many terms whose coefficients correspond to the terms of a sequence. The (ordinary) generating function of a sequence $a_n$ is given by:

$\displaystyle f(x) = \sum_{n=0}^{\infty} a_{n}x^{n}$

whose coefficients give the sequence $\left \{ a_{0}, a_{1}, a_{2},… \right \}$.

### Recurrence Relation

A recurrence relation defines each term of a sequence in terms of the preceding terms. In other words, once one or more initial terms are given, each of the following terms of the sequence is a function of the preceding terms.

The Fibonacci sequence is one example of a recurrence relation. Each term of the Fibonacci sequence is given by $F_{n} = F_{n-1} + F_{n-2}$, with initial values $F_{0}=0$ and $F_{1}=1$. Thus, the sequence of Fibonacci numbers begins:

$\displaystyle 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,…$

## Permutations

A permutation of a set of objects is an arrangement of those objects in a particular order; the number of permutations can be counted.

### Learning Objectives

Calculate the number of arrangements of ordered objects using permutations

### Key Takeaways

#### Key Points

• Informally, a permutation of a set of objects is an arrangement of those objects into a particular order. For example, there are six permutations of the set ${1,2,3}$, namely $(1,2,3)$, $(1,3,2)$,$(2,1,3)$, $(2,3,1)$, $(3,1,2)$, and $(3,2,1)$.
• The number of permutations of $n$ distinct objects is $n \cdot (n − 1) \cdot (n − 2) \cdots 2 \cdot 1$. This is called $n$ factorial, and written $n!$.
• When deciding permutations of a subset from a larger set, it is often useful to divide one factorial by another to determine the number of permutations possible. For example, the first six cards from a deck of cards would have $\frac {52!}{46! }$ permutations possible, or about 14.7 billion.

#### Key Terms

• factorial: The result of multiplying a given number of consecutive integers from $1$ to the given number. In equations, it is symbolized by an exclamation mark ($!$). For example, $5! = 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 = 120$.
• permutation: An ordering of a finite set of distinct elements.

### Permutations

A permutation of a set of objects is an arrangement of those objects into a particular order. For example, there are six permutations of the set ${1,2,3}$: $(1,2,3)$, $(1,3,2)$, $(2,1,3)$, $(2,3,1)$, $(3,1,2)$, and $(3,2,1)$. One might define an anagram of a word as a permutation of its letters.

The 6 permutations of 3 balls: If one has three different colored balls, there are six distinct ways to order them, as shown. These six distinct orderings are as follows: red-green-blue, red-blue-green, green-red-blue, green-blue-red, blue-red-green, and blue-green-red.

The number of permutations of $n$ distinct objects is given by:

$\displaystyle n \cdot (n − 1) \cdot (n − 2) \cdots 2 \cdot 1$

This is called $n$ factorial and is written $n!$.

In other words, a factorial is to multiply all the numbers from $1$ up to this number. So $5!$ means $1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 = 120$. Thus, $120$ is the number of permutations possible for a set of five distinct objects.

### Example

In the game of Solitaire, seven cards are dealt out at the beginning: one face-up, and the other six face-down. A complete card deck has $52$ cards. Assuming that the only card that is seen is the $7$ of spades, how many possible “hands” (the other six cards) can be underneath? What makes this a permutation problem is that the order matters: if an ace is hiding somewhere in those six cards, it makes a difference whether the ace is on the first position, the second, etc. Permutation problems can always be addressed as an example of the multiplication rule, with one small twist.

One stack of cards in a game of solitaire: To find out how many possible combinations of cards there are below the seven of spades, we use the concept of permutations to calculate the possible arrangements of cards.

How many cards might be in the first position, directly under the showing $7$? The answer is 51. That card can be anything except the $7$ of spades.

If any given card is in the first position, how many cards might be in second position? The answer is $50$. The seven of spades and the next card have both been dealt. So there are possible cards left for the second position.

So how many possibilities are there for the first two positions combined? The answer is $51 \cdot 50$.

How many possibilities are there for all six positions? The answer is $51 \cdot 50 \cdot 49 \cdot 48 \cdot 47 \cdot 46$, or approximately $1.3 \cdot 10^{10}$; about $13$ billion possibilities!

This result can be expressed more concisely by using factorials.

Note that $\frac {7!}{5! }$ can also be written as $\frac {1\cdot 2\cdot 3\cdot 4\cdot 5\cdot 6\cdot 7}{1\cdot 2\cdot 3\cdot 4\cdot 5}$. Most of the terms cancel, leaving only $6×7=42$.

Consider another example, $\frac {51!}{45! }$. If all of the terms are written out, the first $45$ terms cancel, leaving $46 \cdot 47 \cdot 48 \cdot 49 \cdot 50 \cdot 51$ in the numerator. Instead of typing into a calculator six numbers to multiply, or sixty numbers or six hundred depending on the problem, the answer to a permutation problem can be found by dividing two factorials. In many calculators, the factorial option is located under the “probability” menu for this reason.

### General Considerations

In mathematics, the notion of permutation is used with several slightly different meanings, all related to the act of permuting (rearranging) objects or values. Informally, a permutation of a set of objects is an
arrangement of those objects into a particular order. The study of permutations generally belongs to the field of combinatorics.

Permutations occur, in more or less prominent ways, in almost every domain of mathematics. They often arise when different orderings on certain finite sets are considered, possibly only because one wants to ignore such orderings and needs to know how many configurations are thus identified. For similar reasons, permutations arise in the study of sorting algorithms in computer science.

## Permutations of Distinguishable Objects

The number of permutations of distinct elements can be calculated when not all elements from a given set are used.

### Learning Objectives

Calculate the number of permutations of $n$ objects taken $k$ at a time

### Key Takeaways

#### Key Points

• If all objects in consideration are distinct, they can be arranged in $n!$ permutations, where $n$ represents the number of objects.
• If not all the objects in a set of $n$ unique elements are chosen, the above formula can be modified to: $\displaystyle \frac {n!}{(n-k)! }$, where $k$ represents the number of selected elements.
• When solving for quotients of factorials, the terms of the denominator can cancel with the terms of the numerator, thus eliminating perhaps the majority of terms to be multiplied.

#### Key Terms

• factorial: The result of multiplying a given number of consecutive integers from $1$ to the given number. In equations, it is symbolized by an exclamation mark ($!$). For example, $5! = 1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 = 120$.
• permutation: An ordering of a finite set of distinct elements.

Recall that, if all objects in a set are distinct, then they can be arranged in $n!$ possible permutations, where $n$ represents the number of objects. The quantity $n!$ is given by:

$\displaystyle n\cdot (n-1)\cdot (n-2)\cdots 2\cdot 1$

It is easy enough to use this formula to count the number of possible permutations of a set of distinct objects; for example, the number of permutations of three differently-colored balls. However, consider a situation where not all of the elements in a set of distinct objects are used in each permutation. For example, what if $7$ cards are chosen from among a full deck of $52$? In this case, not all of the cards from the deck are chosen for each possible permutation. There exists a formula for solving permutation problems such as this one, which would otherwise be nearly impossible to determine.

### Permutations of a Partial Set

If not all of the objects in a set of unique elements are chosen, the following formula is used. This formula determines the number of possible permutations of $k$ elements selected from the set of $n$ elements:

$\displaystyle \frac {n!}{(n-k)! }$

To understand the application of this concept, consider a race in which $3$ different prizes are awarded to the top $3$ fastest competitors. If $25$ competitors participate in the race, in how many distinct orders could the $3$ prizes be awarded?

To solve this problem, we want to evaluate the number of possible permutations of  $3$elements from the set of $25$ elements; in other words, $k = 3$ and $n=25$. Plugging these values into the formula, we have:

$\displaystyle \frac {25!}{(25-3)! } = \frac {25!}{22!}$

Remember that both $25!$ and $22!$ contain the terms $22 \cdot 21 \cdots 2 \cdot 1$. Thus, these values cancel from the numerator and denominator, and the equation can be simplified:


\displaystyle \begin{align} \frac{25!}{22!} &= \frac{25 \cdot 24 \cdot 23 \cdot 22 \cdot 21 \cdots 2 \cdot 1}{22 \cdot 21 \cdots 2 \cdot 1} \\ &= 25 \cdot 24 \cdot 23 \\ &= 13,800 \end{align}

There are $13,800$ possible permutations in which the $3$ top prizes may be awarded to the $25$ race competitors.

### General Considerations

It is worth noting that this formula does not exclude what we might call ‘duplicate’ permutations. In other words, the order of the elements selected does matter. Consider $3$ cards drawn from a pack: an ace of spades, a $10$ of diamonds, and a $3$ of clubs. The hand is exactly the same as the following: a $10$ of diamonds, an ace of spaces and a $3$ of clubs. If you are playing a game in which the order of your cards does not matter, you will only want to count each permutation of cards once. The formula introduced here does not apply to such situations.



## Permutations of Nondistinguishable Objects

The expression revealing the number of permutations of distinct items can be modified if not all items in the set are distinct.

### Learning Objectives

Calculate the number of permutations of a given set of objects, some being non distinguishable

### Key Takeaways

#### Key Points

• Some sets include repetitions of certain elements. In these cases, the number of possible permutations of the items cannot be expressed by $n!$, where $n$ represents the number of elements, because this calculation would include a multiplicity of possible states.
• To correct for the multiplicity of certain permutations, divide the factorial of the total number of elements by the product of the factorials of the number of each repeated element.
• The expression for number of permutations with repeated elements is: $\frac {n!}{n_1!n_2!n_3!… }$ where $n$ is the total number of terms in a sequence and $n_1$, $n_2$, and $n_3$ are the number of repetitions of different elements.

#### Key Terms

• multiplicity: The number of values for which a given condition holds.
• permutation: An ordering of a finite set of distinct elements.

Recall that the number of possible permutations of a set of $n$ distinct elements is given by $n!$:

$\displaystyle n \cdot (n-1) \cdot(n-2) \cdots 2 \cdot 1$

This can be easily tested. The number $1$ can be arranged in just one $1!$ way. The numbers $1$ and $2$ can be arranged in two $2!$ ways: $(1,2)$ and $(2,1)$. The numbers $1$, $2$, and $3$ can be arranged in $3!$ ways: $(1,2,3)$, $(1,3,2)$, $(2,1,3)$, $(2,3,1)$, $(3,1,2)$, and $(3,2,1)$. This rule holds true for sets of any size, so long as the elements are all distinct. But what if some elements are repeated?

Repetition of some elements complicates the calculation of permutations, because it allows for there to be multiple ways in which a specific order of elements can be arranged. For example, given the numbers $1$, $3$, and $3$ in a set, there are 2 ways to obtain the order $(3,1,3)$.

To correct for the “multiplicity” of certain permutations, we must divide the factorial of the total number of elements by the product of the factorials of the number of each repeated element. This can generally be represented as:

$\displaystyle \frac {n!}{n_1!n_2!n_3!… }$

Where $n$ is the total number of terms in a sequence, and $n_1$, $n_2$, and $n_3$ represent the number of repetitions of different elements.

To understand why we would divide by the number of repetitions, consider that $2$elements can be arranged in a total of $2!$ distinct ways, $3$ elements can be arranged in a total of $3!$ distinct ways, and so on. When we encounter multiplicity in a permutation, we must account for it by dividing these possible arrangements out of the total number of permutations that would be possible if all of the elements were distinct.

### Example: Consider the set of numbers:

$\displaystyle (15, 17, 24, 24, 28)$

There are five terms, so $n=5$. However, two of the terms are the same; their value is $24$. Thus, the number of possible distinct permutations in the set is:

$\displaystyle{\frac {5!}{2! }=60}$

The same logic can apply to more complicated systems.

### Example: Consider the set:

$\displaystyle (0, 0, 0, 2, 4, 4, 7, 7, 7, 7, 7, 8, 8)$

In total, there are $13$ elements. These include many repetitions: $0$ is seen 3 times, $4$and $8$ each are observed twice, and there are $5$ instances of the number $7$. Thus, the number of possible distinct permutations can be calculated by:

$\displaystyle \frac {13! }{2!\cdot 2!\cdot 3!\cdot 5! }= 2,162,160$

This logic can be applied to problems involving anagrams of given words.

### Example: Consider how many distinct ways you can order the letters of the word “waterfall.”

The word waterfall consists of $9$ letters in total, so $n=9$. The letter “a” appears twice, giving a value of $2$ for $n_{1}$. Similarly, the letter “l” appears twice, yielding $n_{2} = 2$. Thus, the number of distinct permutations for the letters in “waterfall” can be calculated as:

$\displaystyle \frac {9! }{2!\cdot 2!}= 90,720$

## Combinations

A combination is a way of selecting several things out of a larger group, where (unlike permutations) order does not matter.

### Learning Objectives

Calculate the number of ways of selecting several things out of a larger group (where order doesn’t matter) using combinations

### Key Takeaways

#### Key Points

• A combination is a mathematical concept where one counts the number of ways one can select several elements out of a larger group.
• Unlike a permutation, when determining the number of combinations, order does not matter.
• Formally, a $k$-combination of a set $S$ is a subset of $k$ distinct elements of $S$. If the set has $n$ elements the number of $k$-combinations is equal to the binomial coefficient: $\begin{pmatrix} n\\ k \end{pmatrix} = \frac {n(n-1)…(n-k+1)}{k(k-1)…1}$, which can be written using factorials as $\frac {n!}{k!(n-k)! }$ whenever $k \le n$ and which is zero when $k > n$.

#### Key Terms

• combination: A way of selecting elements from a set, where order does not matter.
• binomial coefficient: A coefficient of any of the terms in the expansion of the binomial power $(1+x)^n$.

In mathematics, a combination is a way of selecting several things out of a larger group, where (unlike permutations) order does not matter. In smaller cases, it is possible to count the number of combinations. For example, given $3$ pieces of fruit: an apple, an orange and a pear. There are $3$ combinations of $2$ that can be drawn from this set: an apple and a pear, an apple and an orange, or a pear and an orange.

Combinations can refer to the combination of $n$ things taken $k$ at a time with or without repetition. In the above example, repetition was not allowed. If, however, it was possible to have $2$ of any $1$ kind of fruit there would be $3$ more combinations: $2$ apples, $2$ oranges, and $2$ pears.

To understand the difference between a permutation and combination, consider a deck of $52$ cards, from which a poker hand ($5$ cards) is dealt. How many possible poker hands are there?

At first glance, this may seem like a permutation question, where one might consider how many distinct ways there are to make a stack of cards. However, there is one important difference: order does not matter in this problem. When dealt a poker hand during a game, order does not matter so you will have the same hand regardless of the order in which the cards are dealt. Combination problems involve such scenarios.

To approach such a question, begin with the permutations: how many possible poker hands are there, if order does matter?

Recall the permutation formula: $\displaystyle{\frac{n!}{(n-k)!}}$, where $n$ is the number of distinct objects in the set, and $k$ is the number of objects selected. In this case, we can calculate the number of permutations as:

 \displaystyle \begin{align} \frac{52!}{(52-5)!}&=\frac{52!}{47!}\\ &=52 \cdot 51 \cdot 50 \cdot 49 \cdot 48 \end{align}

This yields approximately $311.9$ million possible poker hands. However, one has to count every possible hand many different times in this calculation. How many different times is one counting each distinct hand?

The key insight is that this second question—”How many different times is one counting each distinct hand?” is itself a permutation question. It is the same as the question “How many different ways can these five cards be rearranged in a hand?” There are $5$ possibilities for the first card, $4$ for the second, and so on. The answer is $5!$, which is $120$. So, since every possible hand has been counted $120$ times, divide our earlier result by $120$ to find that there are $\frac {52!}{(47!)(5! )}$, or about $2.6$ million possible poker hands.

Combinations turn out to have a surprisingly large number of applications. Consider the following questions:

• A school offers $50$ classes. Each student must choose $6$ of them to fill out a schedule. How many possible schedules can be made?
• A basketball team has $12$ players, but only $5$ will start. How many possible starting teams can they field?
• Your computer contains $300$ videos, but you can only fit $10$ of them on your phone. How many possible ways can you load your phone?

Each of these is a combinations question, and can be answered exactly like the card scenario. Since this type of question comes up in so many different contexts, it is given a special name and symbol. The last question would be referred to as “$300$ choose $10$” and written $\begin{pmatrix} 300\\ 10 \end{pmatrix}$. It is calculated as $\frac {300!}{(290!)(10! )}$, for reasons explained above.

Each possible combination of $k$ distinct elements of a set $S$ is known as a $k$-combination. If the set has $n$ elements, the number of $k$-combinations is equal to

$\begin{pmatrix} n\\ k \end{pmatrix} = \dfrac {n(n-1)…(n-k+1)}{k(k-1)…1}$

Which can be written using factorials as

$\dfrac {n!}{k!(n-k)! }$

Whenever $k \leq n$, and which is zero when $k > n$. The set of all $k$-combinations of a set $S$ is often denoted by $\begin{pmatrix} S \\ k \end{pmatrix}$, which is read as “$S$ choose $k$,” such as in the phone example above. The set of $k$-combinations may also be denoted in certain texts by $C(n,k)$, or by a variation such as $C_k^n$, $_nC_k$, or $^nC_k$.

### General Considerations

The number of $k$-combinations, or $\begin{pmatrix} S \\ k \end{pmatrix}$, is also known as the binomial coefficient, because it occurs as a coefficient in the binomial formula. The binomial coefficient is the coefficient of the $x^k$ term in the polynomial expansion of $(1+x)^n$.