CPE204 Discrete Mathematics (Week 5)
CPE204 Discrete Mathematics (Week 5)
Counting Methods
Dr. Nehad Ramaha,
Computer Engineering Department
Karabük Universities 1
The class notes are a compilation and edition from many sources. The instructor does not claim intellectual property or ownership of the lecture notes.
Basic Counting Rules
2
The product rule:
◦ Suppose that a procedure can be broken down into a sequence of
two tasks. If there are n1 ways to do the first task and there are
n2 ways to do the second task, then there are n1.n2 ways to do
the procedure.
The sum rule:
◦ If a task can be done either in one of n1 ways or in one of n2
ways, where none of the set of n1 ways is the same as any of the
set of n2 ways, then there are n1 + n2 ways to do the task. (example:
choose one person from computer engineering[teacher or student])
3
Example 1:
◦ The chairs in an auditorium are labeled by upper
case English letters followed by an integer between
0 and 99. What’s the largest numbers of chairs that
can be labeled this way?
◦ Solution: There are 26 ways to pick letters. There
are 100 ways to pick integers. So, by Product Rule,
there are 26 . 100 = 2600 ways to label chairs.
4
The Product Rule can be easily generalized from 2 tasks to
k tasks for any integer k.
Example 2:
◦ How many different bit strings of length 6 are there?
◦ Solution: 2.2.2.2.2.2=26 = 64.
Example 3:
◦ How many different license plates can be made if each plate
contains a sequence of three uppercase English letters followed by
three digits (and no sequences of letters are prohibited, even if
they are obscene)?
◦ Solution: There are 26 choices for each of the three uppercase
English letters and ten choices for each of the three digits.
◦ Hence, by the product rule there are a total of 26 · 26 · 26 · 10 ·
10 · 10 = 17,576,000 possible license plates..
5
Example 4:
◦ In a high school, 32 students take French class, 45 students
take Spanish. Assuming no student take both French and
Spanish, how many students take either French or Spanish?
◦ Solution: Simple enough: 32+45= 77.
It is simple because we assumed Ai ∩ Aj =∅. What if
we drop this assumption?
6
Example 4a:
◦ In a high school; 32 students take French class, 45
students take Spanish. 15 student take both French
and Spanish. How many students take either French
or Spanish?
◦ Solution: 32 + 45 - 15 = 62.
7
Example 5:
◦ How many bit strings of length eight either start with a 1 bit or end
with the two bits 00?
Either the first bit is 1;
Or the last two bits are 00.
Solution:
◦ Let A be the set of 8-bits binary strings whose first bit is 1.
◦ Let B be the set of 8-bits binary strings whose last two bits
are 00.
◦ We want to determine |A∪ B|.
◦ |A| = 27 (because the first bit is fixed.)
◦ |B| = 26 (because the last two bits are fixed.)
◦ |A ∩ B| = 25 (because the first and the last two bits are fixed.)
◦ So |A ∪ B| = 27 + 26 - 25 = 160.
This principle can be generalized to more than two sets.
8
The Pigeonhole Principle
9
10
THEOREM 1:
11
EXAMPLE 1: Among any group of 367 people, there must
be at least two with the same birthday, because there are
only 366 possible birthdays.
EXAMPLE 2: In any group of 27 English words, there must
be at least two that begin with the same letter, because
there are 26 letters in the English alphabet.
EXAMPLE 3: How many students must be in a class to
guarantee that at least two students receive the same
score on the final exam, if the exam is graded on a scale
from 0 to 100 points?
◦ Solution: There are 101 possible scores on the final. The
pigeonhole principle shows that among any 102 students there
must be at least 2 students with the same score.
12
THEOREM 2:
13
There are 8 million people in NYC.
It is known that the maximum number of hairs a person can have
is 500,000.
Each person is a “pigeon”.
The “ith pigeonhole” holds the people with i hairs. So there are
500,001 “pigeonholes”.
So at least one pigeonhole contains at least
⌈8000000/500001⌉ = ⌈15.999968⌉ = 16 people.
14
EXAMPLE 3: Among 100 people there are at least ⌈100/12⌉
= 9 who were born in the same month.
EXAMPLE 4: What is the minimum number of students
required in a discrete mathematics class to be sure that at
least six will receive the same grade, if there are five
possible grades, A, B, C, D, and F?
◦ Solution: The minimum number of students needed to ensure that
at least six students receive the same grade is the smallest integer
N such that ⌈ N/5 ⌉ = 6 (the max number 6 . 5 =30). The smallest
such integer is N = 5 · 5 + 1 = 26. If you have only 25 students, it
is possible for there to be five who have received each grade so that
no six students have received the same grade. Thus, 26 is the
minimum number of students needed to ensure that at least six
students will receive the same grade.
15
Note: A standard deck of playing cards consists of 52 cards.
All cards are divided into 4 suits. There are two black suits
— spades (♠) and clubs (♣) and two red suits — hearts (♥)
and diamonds (♦). In each suit there are 13 cards including
a 2, 3, 4, 5, 6, 7, 8, 9, 10, a jack, a queen, a king and an
ace.
16
Permutations and Combinations
17
18
Solution:
◦ We can select any of the 5 students for the first position.
◦ After the first position is selected, we can choose any of the 4
remaining students for the 2nd position.
◦ After the 1st and the 2nd positions are selected, we can choose any
of the 3 remaining students for the 3rd position.
◦ So, the answer is: 5 . 4 . 3 = 60.
In this example, we are counting the number of distinct 3-
permutations of a set with 5 elements. What we have
shown is: P(5,3) = 5 . 4 . 3 = 60.
19
20
21
22
23
24
25