Discrete Math For Computer Science (U of T0 Week 2
Discrete Math For Computer Science (U of T0 Week 2
i=1
x
i
Example. Ordering pizza. Suppose a pizza shop offers 5 types
of toppings, and one has the choice of a 3 topping, 2 topping or
1 topping pizza.
Determine how many different pizzas can be ordered.
Number of Toppings Number of Pizza Choices (x
i
)
1
2
3
Total number of ways to order a pizza:
3
i=1
x
i
=
4
The Product Rule
The Product Rule. Suppose an operation takes k steps and that
the rst step can be performed in x
1
ways
the second step can be performed in x
2
ways
.
.
.
the k
th
step can be performed in x
k
ways
then the whole operation can be performed in
k
i=1
x
i
= x
1
x
2
x
k1
x
k
ways.
Example. Given 4 cities A, B, C and D. Suppose that there are
5 routes between A and B,
3 routes between B and C and
4 routes between C and D.
How many different routes are there from A to D?
Number of AD routes =
5
Q. We have seen two different counting scenarios - creating a
Google password and ordering a pair of pizzas. Which one in-
volved the Sum Rule and which one involved the Product Rule?
A.
Arrangements
An arrangement is a grouping of objects. There are two types of
arrangements:
Denition. A permutation is an arrangement in which order mat-
ters.
Denition. A combination is an arrangement in which order does
not matter.
Permutations
Denition An r-permutation of n distinct objects is an ordered
arrangement of r of the n objects. We use the notation P(n, r).
We can derive the formula as follows:
P(n, r) = . . .
r
6
Q. In terms of factorials, how can we rewrite this formula?
A.
Given n objects, how many ways can we rearrange or permute
them?
P(n, n) =
Combinations
Denition. An r-combination of n distinct objects is an unordered
selection, or subset of r of the n objects.
We can think of combinations in terms of permutations.
Q. Given P(n, r), the number of r-permutations of n objects,
how can we derive the number C(n, r) of r-combinations of n
objects?
A.
7
Example. In Poker each player has 5 cards. A standard deck
has 52 cards. How many 5-card hands are possible?
A ush is when all 5 cards are of the same suit. If there are 4
suits, i.e., 13 cards per suit, how many ways are there to obtain
a ush?
Q. Should ushes happen very often?
Exercise. How many different 8-digit binary sequences are there
with six 1s and two 0s?
8
Exercise. Given n non-parallel lines such that no three intersect
in a point, determine how many triangles are formed.
a
b
c
d
e
f
Triangles acf, bcd, def, abe are formed by four lines.
Q. How many triangles are formed by 3 lines?
A.
Q. How many triangles are formed by 4 lines?
A.
Q. How can we phrase this question in terms of choose?
A.
Q. How would you prove your answer?
A.
9
Counting With Repetitions
The genetic code of an organism stored in DNA molecules con-
sist of 4 nucleotides:
Adenine, Cytosine, Guanine and Thymine.
It is possible to sequence short strings of molecules.
One way to sequence the nucleotides of a longer string of
DNA is to split the string into shorter sequences.
A C-enzyme will split a DNA-sequence at each C. This
means that each fragment will end at a C except possibly
the last fragment.
Similarly for A-enzymes, G-enzymes and T-enzymes.
If the original nucleotide is split on each of C, A, G and
T then it can be sequenced as it is most likely a unique
sequence that can be constructed by each of the four sets
of fragments.
10
Example. Given a 20-nucleotide string split at the Cs, one might
have the fragments:
AC, AC, AAATC, C, C, C, TATA, TGGC
Q. How many different 20-nucleotide strings could have given
rise to the above set of fragments? In other words, how many
different arrangements are there of these fragments?
A.
11
Theorem. Given n objects, with r
1
of type 1, r
2
of type 2, . . . ,
r
m
of type m where
r
1
+r
2
+. . . +r
m
= n
then the number of arrangements of the n objects, denoted by
P(n; r
1
, r
2
, . . . , r
m
) is:
=
n
r
1
n r
1
r
2
n r
1
r
2
r
3
n r
1
r
2
r
m
r
m
r +(n 1)
r