Counting 1
Counting 1
1
Counting
• Count the number of ways to put things together
into various combinations.
e.g. If a password is 6-8 letters and/or digits, how many
passwords can there be?
• Two main rules:
– Sum rule
– Product rule
2
Sum Rule
3
Generalized Sum Rule
4
EX. A student can choose a computer project from
one of three lists. The three lists contain 23, 15, and
19 possible projects respectively. How many
possible projects are there to choose from?
Solution: The student can choose a project by selecting a
project from the first list, the second list, or the third list.
Because no project is on more than one list, by the sum rule
there are
23 + 15 + 19 = 57 ways to choose a project.
5
Example: The mathematics department must
choose either a student or a faculty member as a
representative for a university committee. How
many choices are there for this representative if
there are 37 members of the mathematics faculty
and 83 mathematics majors and no one is both a
faculty member and a student.
Solution: By the sum rule it follows that there are
37 + 83 = 120 possible ways to pick a representative.
6
Set Theoretic Version
• If A is the set of ways to do task 1, and B the set of
ways to do task 2, and if A and B are disjoint, then:
“the ways to do either task 1 or 2 are
AB, and |AB|=|A|+|B|”
• Let A1, A2, …, Am be pairwise disjoint sets. Then
|A1 A2 … Am | = |A1| |A2| … |Am|
7
Product Rule
8
Set Theoretic Version
• If A is the set of ways to do task 1, and B the set of
ways to do task 2, and if A and B are disjoint, then:
• The ways to do both task 1 and 2 can be represented
as AB, and |AB|=|A|·|B|
9
Example: The chairs of an auditorium are to be
labeled with a letter and a positive integer not to
exceed 100. What is the largest number of chairs
that can be labeled differently?
0 or 1
The total number of bit strings are 2^7 = 128.
11
Example: How many different license plates can be
made if each plate contains a sequence of three
uppercase English letters followed by three digits?
13
Example (Using Both Rules):
Each user on a computer system has a password, which is
six to eight characters long where each character is an
uppercase letter or a digit. Each password must contain at
least one digit. How many possible passwords are there?
Solution: Let P be the total number of passwords, and let P6,
P7, and P8 be the passwords of length 6, 7, and 8.
By the sum rule P = P6 + P7 +P8.
To find each of P6, P7, and P8 , we find the number of
passwords of the specified length composed of letters and
digits and subtract the number composed only of letters.
Choice for one character of password is either from 26 letters
or from 10 digits means total 36 choices. For 6 characters
each have 36 choices so total choices 366 . 14
Example (Using Both Rules)
15
Basic Counting Principles:
Subtraction Rule
16
Example: How many strings of length eight either
start with a 1 bit or end with the two bit string 00?
• Count bit strings that start with 1
– Rest of bits can be anything: 27 = 128
– This is |A1|
• Count bit strings that end with 00
– Rest of bits can be anything: 26 = 64
– This is |A2|
• Count bit strings that both start with 1 and end with 00
– Rest of the bits can be anything: 25 = 32
– This is |A1∩ A2|
• Use formula |A1U A2| = |A1| + |A2| - |A1∩ A2|
=128 + 64 – 32 = 160
17
Pigeonhole Principle
19
Pigeonhole Principle
20
Pigeonhole Principle
Example: Among any group of 367 people, there
must be at least two with the same birthday,
because there are only 366 possible birthdays.
21
Example: How many people do you need in a
school to guarantees that there are two people who
have the same initials.(First and last name only)
23
G.P.P. Example
Example: Among 100 people there are at least
⌈100/12⌉ = 9 who were born in the same month.
(K=12 box and N=100 objects)
Example: There are 280 students in the class. Without
knowing anybody’s birthday, what is the largest value
of n for which we can prove that at least n students
must have been born in the same month?
Solution: N=280 objects, K=12 boxes
280/12 = 23.3 = 24
At least24 students who were born in the same month.24
Example: Show that if 30 dictionaries in a library
contain a total of 61,327 pages then one of the
dictionaries must have at least 2045 pages.
Solution: a)
We assume four boxes; one for each suit.
Using the generalized pigeonhole principle, at least one box
contains at least ⌈N/4⌉ cards.
At least three cards of one suit are selected if ⌈N/4⌉≥3. The
smallest integer N such that ⌈N/4⌉ ≥3.
Therefor N= 2 · 4 + 1 = 9.
26
Example: a) How many cards must be selected from a
standard deck of 52 cards to guarantee that at least
three cards of the same suit are chosen?
b) How many must be selected to guarantee that at
least three hearts are selected?
27
Permutations
28
A Formula for the Number of Permutations
Also,
𝑛!
𝑛𝑝𝑟 =
𝑛−𝑟 !
29
Solving Counting Problems by Counting
Permutations
30
Example: Eight boys and three girls are to sit in a
row for a photograph. Find the the total number of
ways that no two girls are sit together.
The seating arrangement are as follows:
_B_ B_ B_ B_ B_ B_ B_ B_ .
8 boys can sit in any of 8 places.
Number of ways they can sit= 8𝑝8
3 girls can sit any of 9 places marked_ .
Number of ways they can sit= 9𝑝3 Hence, the total
number of ways that no two girls are sit together
8𝑝8 . 9𝑝3 = 8. 7. 6. 5 . 4 . 3 2 . 1 . 9 . 8 . 7
Combinations
n n!
C (n, r )
r r !(n r )!
32
Formula for the Number of Combinations
• 𝑛𝑐𝑟 = 𝑛𝑐𝑛−𝑟
• 𝑛𝑐1 = 𝑛
• 𝑛𝑐𝑛 = 𝑛𝑐0 = 1
33
Combination Example
Example: How many number of ways that 7-card can
be drawn from a standard 52-card deck?
Solution:
52𝑐7
52𝑝7
=
7𝑐7
52·51·50·49·48·47·46
=
7.6.5.4.3.2.1
= 52 · 17 · 10 · 7 · 47 · 46
= 133,784,560
34
Example: Two people are selected at random from
a group of seven men and five women. Find the
number of ways of selections that both are men or
both are women.
Solution:
Out of 7 men, 2 can be selected in 7𝑐2 and out of 5
women, 2 can be selected in 5𝑐2 ways.
Favorable number of cases = 7𝑐2 + 5𝑐2
7 .6 5 .4
= +
2 .1 2 .1
= 21 + 10 = 31
Example: Suppose that there are 9 faculty members in
the mathematics department and 11 in the computer
science department. How many ways are there to
select a committee to develop a discrete mathematics
course at a school if the committee is to consist of
three faculty members from the mathematics
department and four from the computer science
department?
Solution:
To form committee we have to choose 3
mathematics faculty from total 9 mathematics
faculty members and 4 computer science faculty
from total 11 computer science faculty members.
Total number of ways to form committee is
= 9𝑐3 . 11𝑐4
9 .8.7 11.10.9 .8.
= .
3.2.1 4.3.2.1
= 27,720