5 Counting
5 Counting
Discrete Structures
Counting
The Basics of counting
Combinatorics is the mathematics of counting
and arranging objects.
4
The Basics of counting
(Examples)
5
The Basics of counting
(Examples)
6
The Basics of counting
(Examples)
7
The Basics of counting
(Examples)
8
The Basics of counting
(Examples)
9
The Basics of counting
(Examples)
10
The Basics of counting
(Examples)
11
The Basics of counting
(Examples)
12
The Basics of counting
(Examples)
13
The Basics of counting
(Examples)
14
The Basics of counting
(Examples)
15
The Basics of counting
(Examples)
16
The Basics of counting
(Examples)
17
The Basics of counting
(Examples)
18
The Basics of counting
(Examples)
19
The Basics of counting
(Examples)
20
The Basics of counting (Set
version)
If A is the set of ways to do task1, and B the set
of ways to do task2, and if A and B are disjoint,
then:
The ways to do either task1 or task2 are
AB, and |AB|=|A|+|B|
The ways to do both task1 and task2 are
AB, and |AB|=|A|·|B|
K:=0 K:=0
for i1:=1 to n1 for i1:=1 to n1
K:= K +1 for i2:=1 to n2
for i2=1 to n2 for i3:=1 to n3
K:= K +1 K:= K +1
for i3=1 to n3
K:= K +1
22
The Basics of counting (Examples)
P=P6+P7+P8
P6=366-266=1 867 866 560
P7=367-267=70 332 353 920
P8=368-268=2 612 282 842 880
P=P6+P7+P8=2 684 483 063 360
27
The Basics of counting (Examples)
In version 4 of the Internet Protocol (IPv4)
The internet address is a string of 32 bits as
follows:
Class A address [ 0 -netid(7 bits) – hostid (24
bits)]
Class B address [ 10 -netid(14 bits) – hostid (16
bits)]
Class C address [ 110 -netid(21 bits) – hostid (8
bits)]
Class D address [ 1110 –multicast address (28
bits)]
Class E address [ 11110 - address (27 bits)]
Where, Network number(netid) -host
number(hostid)
Restrictions 28
1111111 is unavailable in netid
The Basics of counting (Examples)
How many bit string of length eight either start
with a 1 bit or end with the two bits 00?
1 - - - - - - - 27=128 ways
- - - - - - 0 0 26=64 ways
1 - - - - - 0 0 25=32 ways
29
The Basics of counting (Examples)
A computer company receives 350 applications
from computer graduates for a job.
Suppose that 220 of these people majored in
CS, 147 majored in business, and 51 majored
both in CS and in business. How many of these
applicants majored neither in CS nor in
business?
31
The Pigeonhole principle
The Pigeonhole principle
Suppose there are n pigeons, k pigeonholes,
and n>k.
If these n pigeons fly into these k pigeonholes,
then some pigeonhole must contain at least two
pigeons.
32
The Pigeonhole principle
In terms of the assignment function:
If f:A→B and |A|≥|B|+1, then some element of
B
has ≥2 pre-images under f.( f is not one-to-
one)
33
The Pigeonhole principle (Examples)
The generalized Pigeonhole principle
If N objects are placed into k boxes, then
there is at least one box containing at least N/K
objects.
34
The Pigeonhole principle (Examples)
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?
280/12 = 23.3 = 24
What is the minimum number of students
required in a discrete math 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?
35
Permutations and
Combinations
Permutations
A. In how many ways can we select 3 students
from a group of 5 students to stand in line
for a picture?
B. In how many ways can we arrange all 5 of
these students in a line for a picture?
Note that the order in which we select the
students matters.
5 ways to select the first student
4 ways to select the second student
3 ways to select the third student
2 ways to select the fourth student
1 way to select the fifth student
A. 5.4.3=60 36
Permutations and
Combinations
Permutations
A permutation of a set S of objects is an
ordered arrangement of the elements of S
where each element appears only once:
e.g., 1 2 3, 2 1 3, 3 1 2
39
Permutations and
Combinations
Example
S={1,2,3},
all permutations={(1,2,3),(2,1,3),(1,3,2),
(2,3,1),(3,1,2),(3,2,1)}
all 2-permutations={(1,2),(2,1),(1,3),(3,1),
(2,3),(3,2)}
P(3,3)=3*2*1=6, P(3,2)=3*2=6
40
Permutations and
Combinations
Example
How many ways are there to choose a
committee of size five consisting of three
women and two men from a group of ten
women and seven men?
The number of ways to choose three women
is C(10, 3)
The number of ways to choose two men is
C(7, 2).
Using the product rule to choose three
women and two men, the answer is
C(10, 3) · C(7, 2) = 2, 520.
41
Permutations and
Combinations
Example
A class has 20 women and 16 men. In how many ways
can you
(a) Put all the students in a row?
(b) Put 7 of the students in a row?
(c) Put all the students in a row if all the women are on
the left and all the men are on the right?
Solution:
(a) There are 36 students. They can be put in a row in
36! ways.
(b) You need to have an ordered arrangement of 7 out
of 36 students. The number of such arrangements
is P(36, 7).
(c) You need to have an ordered arrangement of all 20
women AND and ordered arrangement of all 16 men.
By the product rule, this can be done in 20!·16! ways.
42
Permutations and
Combinations
Exercises
PP. 360-362
1
4
5
7
43