CSCI 2824: Lecture 22 Notes

We will start chapter 5 on combinatorics.


Combinatorics is the mathematics behind counting discrete structures. Often, it is important to know how many objects of a particular type exist to make some decisions. Eg.,

  • How many routes exist between two nodes in a network?

  • How many steps does a program take to run on an input of size n?

  • How many solutions exist for a particular constraint problem?

  • and so on…

In this module (Chapter 5 of the book), we will study the basics of counting objects. We will start from some basic puzzles.


We have three envelopes colored red, green and violet. We could invite one of three people Alice, Bob and Carol.

How many possible ways are there of choosing a person and a color for their invitation?


There are 9 possible ways. To understand why, we will construct a concept of choice-set. This set will represent the set of all the possible choices we have. In this case, our choices are

 { (red, Alice), (green, Alice), (violet, Alice), (red, Bob), (green, Bob), (violet, Bob), (red, Carol), (green, Carol), (violet, Carol) } ,.

We have 3 times 3 = 9 choices.

Constructing a choice set is very tedious, and often impossible. We would like to count directly, without actually constructing each choice separately.


We have three tee shirts. Two are red (indistinguishable) and one is violet. We have three people interested in these tee-shirts: Alice, Bob and Carol.

How many possibilities ways are there of choosing a color for every person?


Let us just enumerate possibilities.

  • Alice, Bob: Red, Carol: Violet

  • Alice, Carol: Red, Bob: Violet

  • Carol, Bob: Red, Alice: Violet.

There are three in all.

Another way to represent it is to use the notion of a choice set. If we choose who gets the violet shirt, the other two have to get the red (there is no choice for these two). Therefore choice set is

 { (violet, Alice), (violet, Bob), (violet, Carol) } ,.


Let us say that CU, Nebraska and Texas are contending for the basketball playoffs in a round-robin. Each team needs to play the other exactly once. How many games will be there?


We know that two of the games will have CU in it. This leaves one game with Nebraska and Texas. So we arrive at 3 games in all.


There are 10 teams that need to play each other in a tournament. Each team needs to play the other exactly once. How many games will be played?


Let us number the teams T_1,ldots,T_{10}.

  • T_1 needs to play 9 games.

  • T_2 plays 9 games but we already counted one against T_1, so that leaves 8 more games.

  • T_3 plays 7 more games (we discount its games against T_1 and T_2).

  • T_4 plays 6 more games.

  • T_8 plays one more game.

  • We have already counted all the games that T_9 will play.


Basic Rules for Counting

When asked to count the number of possibilities, we need to be careful of two things:

  • Do not double count a possibility.

  • Do not skip some possibility.

In the former case, our count will be larger than what it should be. In the latter case, the count will be smaller. If we commit both types of errors, the count may as well be a random number!!

Product Rule

Let us say that we have to choose 2 items, in order. There are m choices for item 1 and independently there are n choices for item 2. Then there are m * n choices for both together.

Let us revisit the first example:

We have three envelopes colored red, green and violet. We could invite one of three people Alice, Bob and Carol.

How many possible ways are there of choosing a person and a color for their invitation?


There are two items: We need to choose (a) person amongst Alice, Bob and Carol and (b) color among red, green and violet. Therefore m= 3 and n= 3. The number of possibilities is m * n = 9.


Tom, Mary and Francois go to an avant garde french restaurant. For their dessert, they have a choice between three things:

  • A: Creme Brulee,

  • B: Confiture de drole Canard aux tarte tatin and

  • C: Tarte aux fruits de mer et pomme de terre de Lorraine

How many possible ways are there of placing an order?


3 times 3  times  3


Let us say we have work to do in Paris, Bangkok or Budapest. There are Brian and Carla to send out. How many possible ways are there to send at most one person to one place?


Let us take it from the point of view of the person. There are three options for Brian. Once we fix that, there are two remaining places that Carla could go to. This gives us 3 * 2 = 6 options.


Let us take the previous puzzle, where we have 3 places: Paris, Bangkok or Budapest and 2 personnel (forget their names now). We do not care which person goes to which place.

In other words, sending Brian to Paris and Carla to Bangkok is now the same as sending Carla to Paris and Brian to Bangkok. In this problem, we just care about which places get visited.

How many possibilities are there now?


Since there are just two people, one place has to be left out. There are three ways to choose this place, and therefore, three possible choices.


How many 4 digit numbers can be formed by the numerals { 0,4,8, 9 }. There are four digits d_1 d_2 d_3 d_4.

  • How many options are there for d_1? Note that a number cannot start with a zero (that makes it 3 digits).

  • What about d_2,d_3,d_4?

Combine these to conclude that there are 192 such numbers.


Let us take n distinct objects A_1,ldots,A_n. A permutation of 1 leq k leq  n objects consists of choosing an ordered sequence of k objects from the n objects.

  • We cannot repeat objects.

  • Order in which we select matters. It matters what object we select first, what we select next and so on.


List all permutations of two elements from the set { A,B,C}. The elements are AB, BA, AC, CA, BC, CB giving rise to six permutations of 2 objects.


List all permutations of all the 4 words in the phrase “University Of Colorado Boulder”. Note that in a permutation, (1) we cannot repeat objects and (2) order in which we place object matters.

  • “University of Colorado Boulder”

  • “University Boulder of Colorado”

  • “Colorado University of Boulder”

  • “Of Boulder Colorado University”

  • “University of Boulder Colorado”

  • “Of Colorado Boulder University”

  • “Boulder of Colorado University”

  • Looks like too many here. Let us reason this out formally: After rearrangement the new phrase is going to be:

 W_1 W_2 W_3 W_4

We have 4 choices for W_1. Once we fix that we have 3 choices for W_2, 2 for W_3 and the remaining goes to W_4. This gives rise to 4 * 3 * 2 * 1 = 24 options.


Let us modify the previous example to require a phrase of 3 words (instead of all 4) from the set { University, Colorado, Of, Boulder }.

Formal Rules for Counting

We will now start to understand the intuition we have developed more precisely.

Basic Rules for Counting

Rule of products: If |A| = m and |B| = n then |A times B| = m * n.


We have 3 tee shirts with colors { red, green, blue } and 2 caps with labels {A,B}. How many possible ways are there of choosing a tee shirt and a cap?


Let us say that in a tournament teams A, B and C play matches against each other in a round robin. How many matches are played?

How many possible outcomes are there for the tournament?


To count matches is easy, we know that there are three matches to be played M1: A vs. B, M2: A vs. C and M3: B vs. C.

Each match has two outcomes. Winner1 = {A,B}, Winner2 = {A,C}, Winner3 = {B,C}. Therefore, applying the product rule are 2 2 2 = 8 outcomes overall.

Rule of Sums

Rule of sums: If A and B are disjoint then |A cup B| = |A| + |B|.


We are allowed to make up a positive integer from the digits {1,3,5,7}. Each digit is to be used at most once (we may decide to skip a digit).

  • example of legal digits are: 13, 1, 3, 137, 7135, ….

Solution We split the problem into 4 disjoint counts: count all one digit numbers, two digit numbers, three digit and four digit numbers that can be formed. Together, using the rule of sums, we can simply add these counts and get the required overall count.

  • One digit numbers: 4 possible choices.

  • Two digit numbers: {}^4P_2 = frac{4!}{2!} = 12 possible choices.

  • Thee digit numbers: {}^4P_3 = frac{4!}{1!} = 24 possible choices.

  • Four digit numbers: {}^4P_4 = frac{4!}{0!} = 24 possible choices (remember 0! =1).

Adding them up we have 4 + 12 + 24 + 24 = 64 possible numbers.

Rule of Complements

Recall that overline{A} = U - A for a set U where A subseteq U.

Rule of complements Let us say that instead of counting |A|, we can count |overline{A}|. Then |A| = |U| - |overline{A}|.


How many odd numbers are there between 45 and 101 (include both limits in your count).

First let us just count the even numbers 46,48,... Why?

  1. 46 -> 1 even number

  2. 48 -> 2 even numbers

  3. 50 -> 3 even numbers

  4. n -> frac{(n-44)}{2} even numbers.

  5. 100 -> frac{56}{2} = 28 even numbers.

There are a total of 101-44= 57 numbers between 45 and 101.

Therefore, odd number count is 57 - 28 = 29.


Let us say we toss a coin ten times. Each time we toss, we get a head or a tail.

  • How many possible outcomes are there for the ten tosses?

  • How many outcomes are there where we see two heads in succession or two tails in succession?