0% found this document useful (0 votes)
160 views

Discrete Math For Computer Science (U of T0 Week 2

1) The document discusses different methods for counting combinations and permutations, including the sum and product rules. It provides examples counting possible passwords, ways to order pizzas, and routes between cities. 2) The document also covers counting arrangements and selections with repetitions, such as counting the number of ways to select 6 bagels from 3 flavors. 3) A key formula presented is that the number of arrangements of n objects with r1 of type 1, r2 of type 2, etc. is n!/(r1!r2!...rm!). This applies when counting permutations or selections with repetitions.

Uploaded by

RahmanShaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views

Discrete Math For Computer Science (U of T0 Week 2

1) The document discusses different methods for counting combinations and permutations, including the sum and product rules. It provides examples counting possible passwords, ways to order pizzas, and routes between cities. 2) The document also covers counting arrangements and selections with repetitions, such as counting the number of ways to select 6 bagels from 3 flavors. 3) A key formula presented is that the number of arrangements of n objects with r1 of type 1, r2 of type 2, etc. is n!/(r1!r2!...rm!). This applies when counting permutations or selections with repetitions.

Uploaded by

RahmanShaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Counting Pizza Toppings Continued...

Q. How do we know that our calculation is the correct answer?


A. One way to convince ourselves is try to nd another way to
count the same problem.
We counted all possible orders and then removed duplicates.
Exercise. Recount using a different method.
Exercise. How many ways are there to order the pizzas, if dou-
ble toppings are allowed (ie., two of the toppings are the same)?
1
Example. Creating a secure password.
To create a account, you are required to give 8 or more
alphanumeric characters.
Q. Why so many? Why not just 4?
A. Lets count how many possible passwords there are of lengths
4 and 8 and compare.
2
Q. How many alphanumeric characters are there?
A.
Q. How many passwords are there of length 4?
A.
Q. Why do we multiply instead of add?
A.
Q. How many passwords are there of length 8?
A.
So there are more than 14 million times as many passwords of
length 8 than of length 4.
3
The Sum Rule
When counting we need to be able to determine whether to sum
or multiply the number of objects.
The Sum Rule. If an operation can be performed in n different
ways, each having x
i
possible outcomes, then the total number
of outcomes possible is
n

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

Q. What does this formula simplify to?


A.
12
Proof.
P(n; r
1
, r
2
, . . . , r
m
) =
n!
r
1
!r
2
! . . . r
m
!
Convert the problem into something we can already solve.
Suppose all objects are distinct. How many permutations
are there?
Consider the i
th
type. It is repeated r
i
times.
Add the subscripts 1, 2, . . . , r
i
to make them unique.
Example. Let our set of objects be the letters {b, a, a, a, n, n}.
We can make the as and ns unique as follows: a
1
, a
2
, a
3
,
n
1
, n
2
.
Q. Number of permutations of {b, a
1
, a
2
, a
3
, n
1
, n
2
}?
A.
We can think of this as the number of ways to arrange
{b, a, a, a, n, n} .
Q. How do we say this mathematically?
A.
6! = ??
13
Q. Suppose we have b, a, a, n, n, a. What are the different
ways to arrange the as?
A.
Q. How many ways to arrange the ns for each arrangement
of as?
A.
Resulting in:
Generally, for the i
th
type, we have ways to arrange
the objects. Therefore:
n! =
n! =
Rearranging gives:
P(n; r
1
, r
2
, . . . , r
m
) =
14
Selections With Repetitions
Example. While shopping at the St. Lawrence market, you
decide to buy half a dozen bagels. There are three avours to
choose from.
Q. How many different ways can you select your 6 bagels?
A. Rephrase as an arrangement problem.
Sesame Poppy Seed Plain
xx xxx x
Q. How is this an arrangement problem?
A.
Q. How can we also think of this as a selection problem?
A.
Let n be the number of choices, r the number of items selected.
Then 8 = r +(n 1) and we are choosing r = 6. This results
in:
15
Theorem. Given r objects and n types of objects to choose from,
the number of selections with repetitions is:

r +(n 1)
r

Proof. Simply generalize the arguments above.


Example.
16

You might also like