Introduction to combinatorics (CSCI 2824, Spring 2015)

In this lecture we start the chapter on combinatoics, the art of counting discrete objects.

This page covers the following topics:

  • Counting distinct length-n binary strings

  • The product rule

  • Counting the number of (injective/surjective) functions from a finite set to another finite set

  • Four different types of discrete structures.

(Sections 5.1, 5.2 of the textbook)

Case study: counting distinct length-n binary strings.

Let's consider the simple question: how many distinct binary strings of length 4 are there?

It is not too difficult to list all the possible strings out and count; in this way, we would find out that there are 16 possibilities.

If we change the question a bit, by asking for the number of distinct binary strings of length 100, it would take much longer to obtain the answer (by hand or by using a computer) if we use the same technique, i.e., listing all possibilities and then counting them. A more intelligent method would be to note that, as you probably observed in the previous question, there are two choices (0 or 1) for each bit. So in the previous question, the answer would be

2times 2times 2times 2 = 2^4,

each factor corresponding to the choice for one of the four bits. Similarly, we can expect that the number of distinct binary strings of length n is

underbrace{2times2timescdotstimes2}_{n text{ factors}}  =   2^n.

In particular, the number of distinct binary strings of length 100 would be 2^100.

A takeaway from this case study is that, except for terribly small instances, it can often be very hard to use brute force methods to count the number of objects in a given collection. It is possible, however, to make use of the patterns present in the problem to help us count the number of elements in even very large collection. In this chapter, we will learn how to do just that.

Product rule

One simple and useful rule of counting is the product rule.

Product rule

Suppose that there are n_1 ways to perform task 1, and there are n_2 ways to perform task 2. If tasks 1 and 2 can be performed independently of one another, then there are n_1n_2 ways to perform task 1 and task 2.

We can apply the product rule to count the number of length n binary strings. There are two choices for each bit, and we need to make a choice for each of the n bits. So by the product rule, there are 2^n choices.

Case Study: number of distinct functions from a finite set to another finite set

Suppose we have two nonempty finite sets A and B, with |A|=n and |B|=m.

What is the number of distinct functions from A to B?

  • By definition, any function f from A to B must send each element of A to exactly one element of B.

  • In other words, for each element x of A, we have to choose one out of the m elements in B as the output of x under the function f.

  • Since A has n elements, by the product rule there would be n^m different functions from A to B.

What is the number of distinct injective functions from A to B?

  • Let's say A={a_1,a_2,ldots,a_n} and B={b_1,b_2,ldots,b_m}. (Note that for a set, the elements are always distinct, so e.g. a_ineq a_j for distinct i,j!)

  • Then for any function f, there must be some iin{1,ldots,m} such that b_i=f(a_1).

  • If f is injective, then f(a_2)neq f(a_1), that is, f(a_2) can only be chosen from m-1 elements of B.

  • Inductively, we get that for any integer k bewteen 2 and n, if ngeq m and we have already fixed the values of f(a_j) for j=1,ldots,k-1, then there are m-k+1 different choices for the value f(a_k)in B.

  • Using the product rule, we get that there are a total of m(m-1)(m-2)cdots(m-n+1) distinct injective functions from A to B.

Note that if n>m, one of the factors in m(m-1)(m-2)cdots(m-n+1) would be zero. so there would be no injective function from A to B. This agrees with what we learned in Chapter 4, that

if f:Ato B is injective, then n=|A|geq|B|=m.

Four different structure types in combinatorics

Very often, we are given a set D, and we are interested in counting the number of combinations of elements from D with certain features.

  • In the example of bit strings, we take combinations from the elements of Dtriangleq{0,1}. The ordering of the elements does not matter, and repetitions are allowed.

  • In the example of functions from A to B, we take combinations of {a,b}in D = triangleq Atimes B.

When we talk about counting the number of combinations of elements from a set D, it is very important to identify the following two features:

  • are we allowed to draw the same element from D repeatedly?

  • does it matter which element from D is drawn first?

These two features defines four different basic discrete structures relevant to combinatorics:

  • ordered lists

  • unordered lists

  • permutations

  • combinations

Ordering matters Ordering does not matter
Repetitions allowed Ordered lists unordered lists
Repetitions not allowed Permutations Combinations

In the next lecture, we will study these four structures in depth.