Counting
Counting
CMSC 57
DISCRETE MATHEMATICAL STRUCTURES IN
COMPUTER SCIENCE II
EXAMPLE
Two CMSC 57 students want to sit on the first two rows of CL2. In
how many ways are can we assign the two students these different
seats in the first two rows?
EXAMPLE
Two CMSC 57 students want to sit on the first two rows of CL2. In
how many ways are can we assign the two students these different
seats in the first two rows?
ANSWER: 2 * (number of seats)
EXAMPLE 2
How many different bit strings of length seven are there?
EXAMPLE 2
How many different bit strings of length seven are there?
ANSWER: 27= 128 different bit strings of length seven
EXAMPLE
Suppose that either a student of CMSC 57 section 1 or section 2
sis chosen as the batch representative for Komsai.Org. How many
different choices are there for this representative if there are 15
students in section 1 and 26 students in section 2?
EXAMPLE
Suppose that either a student of CMSC 57 section 1 or section 2
sis chosen as the batch representative for Komsai.Org. How many
different choices are there for this representative if there are 15
students in section 1 and 26 students in section 2?
ANSWER: 15 + 26 = 41 possible ways to pick the batch rep.
EXAMPLE 2
How many different bit strings of length six to eight and 1 is the
leftmost bit that are there?
EXAMPLE 2
How many different bit strings of length six to eight and 1 is the
leftmost bit that are there?
ANSWER: 25 + 27 + 28
INCLUSION-EXCLUSION RULE
The subtraction rule is also known as the Principle of InclusionExclusion, especially when it is used to count the number of
elements in the union of two sets.
| A1 A2 | = | A1 | + | A2 | | A1 A2 |
EXAMPLE 2
I have a total of 350 students. Suppose that 220 of these students
took CMSC 57, 147 took CMSC 22, and 51 took both CMSC 57
and CMSC 22. How many of my students are neither in CMSC 57
nor in CMSC 22?
EXAMPLE 2
I have a total of 350 students. Suppose that 220 of these students
took CMSC 57, 147 took CMSC 22, and 51 took both CMSC 57
and CMSC 22. How many of my students are neither in CMSC 57
nor in CMSC 22?
ANSWER: 220 + 147 51 = 316, 350 316 = 34 students
EXAMPLE
How many different ways are there to sit six people around a
circular table, where two seatings are considered the same when
each person has the same left neighbor and the same right
neighbor?
EXAMPLE
How many different ways are there to sit six people around a
circular table, where two seatings are considered the same when
each person has the same left neighbor and the same right
neighbor?
ANSWER: 5!/2 = 60 ways
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
PIGEONHOLE PRINCIPLE
If k is a positive integer and k + 1 or more objects are placed into k
boxes, then there is at least one box containing two or more of the
objects.
PIGEONHOLE PRINCIPLE
If k is a positive integer and k + 1 or more objects are placed into k
boxes, then there is at least one box containing two or more of the
objects.
PROOF
Suppose that none of the k boxes contains more than one object.
Then the total number of objects would be at most k. This is a
contradiction, because there are at least k + 1 objects.
If YES, then some pigeonhole has to get more than one pigeon.
If YES, then some pigeonhole has to get more than one pigeon.
If YES, then some pigeonhole has to get more than one pigeon.
EXAMPLE 2
At least 2 students in UP Visayas have the same first/last initials.
EXAMPLE 2
At least 2 students in UP Visayas have the same first/last initials.
pigeons
pigeonholes
#(pigeons)
#(pigeonholes)
=
=
=
=
UP Visayas students
possible first/last initials
3,200
676
EXAMPLE 4
How many students must be in a class to guarantee that at least
two students receive the same score on a long exam?
EXAMPLE 4
How many students must be in a class to guarantee that at least
two students receive the same score on a long exam?
ANSWER: At least 102 students, since an exam is graded from 0
to 100 points, that makes it 101 boxes.
Examples
Triangular dartboard
A triangular dartboard
PIGEONHOLE PRINCIPLE
EXAMPLE 5
Dartboard = equilateral triangle with side
length of 2 feet.
CLAIM: If you throw 5 darts (no misses), at
least 2 will be within a foot of each other.
Dartboard = equilateral triangle with side length of 2
T. Goldberg (Cornell)
Examples
Triangular dartboard
A triangular dartboard
PIGEONHOLE PRINCIPLE
EXAMPLE 5
Dartboard = equilateral triangle with side
length of 2 feet.
CLAIM: If you throw 5 darts (no misses), at
least 2 will be within a foot of each other.
REASON:
Dartboard = equilateral triangle with side length of 2
Divide triangle into 4 sub-triangles.
Darts in the same sub-triangle
are w/in 1 foot of each other.
CLAIM: If you throw 5 darts (no misses), at least 2 w
pigeons
= darts
(5)other.
of each
pigeonholes = sub-triangles (4)
T. Goldberg (Cornell)
PROOF
Suppose that none of the boxes contains more than N / k - 1
objects. Then, the total number of objects is at most
EXAMPLE 2
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 13 possible grades from 1.0 5.0, INC, and
DRP?
EXAMPLE 2
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 13 possible grades from 1.0 5.0, INC, and
DRP?
ANSWER: To have at least 6 (=N / 13) students at the same box,
the total number must be at least N = 5 * 13 + 1 = 66.
EXAMPLES
EXAMPLES
EXAMPLE
A combination lock
31 - 5 17
17 31 5
EXAMPLE
A combination lock
31 - 5 17
17 31 5
Though the same numbers are used, the order in which they are
turned to, would mean the difference in the lock opening or not.
EXAMPLE 3
Let S = {a, b, c}. What are the 2-permutations of S?
EXAMPLE 3
Let S = {a, b, c}. What are the 2-permutations of S?
ANSWER: The ordered arrangements a,b a,c b,a b,c c,a
c,b.
Drive-through
Megan, Tricia, Jeff
Sarah, Tricia, Jeff
Sarah, Megan, Jeff
Sarah, Megan, Tricia
Outcomes
SM, ST, SJ
MS, MT, MJ
TS, TM, TJ
JS, JM, JT
COROLLARY
If n and r are integers with 0 < r < n, then P(n, r) =
#!
#%& !
COROLLARY
If n and r are integers with 0 < r < n, then P(n, r) =
PROOF
Because
#!
#%' !
#!
#!
#!
#%& !
= 1 whenever n is a nonnegative
b) What is the probability that the first 3 digits are even numbers?
b) the CS books on the left, and the Math books on the right
b) the CS books on the left, and the Math books on the right
ANSWER: CS books = 3!, Math books = 4!, 3! * 4! = 144
c) the books in the same subject must be kept together
ANSWER: 144 * 2 = 288 ways
EXAMPLE
How many different committees of three students can be formed
from a group of four students?
ANSWER: We need only find the number of subsets with three
elements from the set containing the four subsets. There are 4
such subsets.
#!
&! #%& !
PROOF
The P(n, r) r-permutations of the set can be obtained by forming
the C(n, r) r-combinations of the set, and then ordering the
elements in each r-combinations, w/c can be done in P(r, r) ways.
P(n, r) = C(n, r) * P(n, r)
EXAMPLE 2
How many 2-combinations can we form from the set {a, b, c, d}?
EXAMPLE 2
How many 2-combinations can we form from the set {a, b, c, d}?
ANSWER: There are six subsets {a,b}, {a,c}, {a,d}, {b,c}, {b,d},
and {c,d}. Then C(4, 2) = 6.
COROLLARY
Let n and r be nonnegative integers with r < n. Then,
C(n, r) = C(n, n r)
EXAMPLE 5
A group of 30 people have been trained as astronauts to go on the
first mission to mars. How many ways are there to select a crew of
6 people to go on this mission (assuming they all have same job)?
EXAMPLE 5
A group of 30 people have been trained as astronauts to go on the
first mission to mars. How many ways are there to select a crew of
6 people to go on this mission (assuming they all have same job)?
+'!
ANSWER: C(30, 6) = *! +'%* ! = 593,775
,!
+! ,%+ !
))!
= #34'
#
3
3 #%3 =
#
'
# +
#
)
#%) + ... +
#
#%)
#
#%) + #
= #34'
#
3
3 #%3 =
#
'
# +
EXAMPLE
What is the expansion of (x + y)4?
#
)
#%) + ... +
#
#%)
#
#%) + #
= #34'
#
3
#%3 3 =
#
'
# +
#
)
#%) + ... +
#
#%)
#
#%) + #
EXAMPLE
What is the expansion of (x + y)4?
ANSWER:
+ - = -34' -5 -%3 3= x4 + 4x3y + 6x2y2 +4xy3 + y4.
EXAMPLE 2
What is the coefficient of x12y13 in the expansion of (2x - 3y)25?
EXAMPLE 2
What is the coefficient of x12y13 in the expansion of (x + y)25?
ANSWER: Note that this expression equals (2x + (-3y))25.
25 12
25! 12 13
2 (3)13 =
2 3
13
13! 12!
@
= 2#
34'
@
= 2#
34'
PROOF
Using the binomial theorem with x = 1 and y = 1, we see that
#
#
3 #%3
2 = 1+1 = @
1 1
=@
34'
34'
@ (1)3
34'
=0
@ (1)3
34'
=0
PROOF
Using the binomial theorem with x = -1 and y = 1, we see that
#
#
#
3
#%3
0 = (1) + 1 = @
(1) 1
=@
(1)3
34'
34'
3
@2
= 3#
34'
3
@2
= 3#
34'
PROOF
We recognize that the left-hand side is the expansion of (1 + 2)n
#
#
#%3 3
3
1+2 = @
1
2 =@
2
34'
34'
=
+
=
+
Pascals Triangle
=@
34'
=@
34'
COROLLARY 1
If n is a nonnegative integer, then
#
2
=@
34'
+ 1
=@
+1
34&
+ 1
=@
+1
34&
PROOF
Left-hand side shows that both sides show the ways to count bit
strings of length n+1 with r+1 ones. The right-hand side counts
the same objects, the final one must occur at r+1 or r+2 or or
n+1. Assume that it occurs at the k bit, there must be r ones in the
first k-1 positions.
#G)
@
34&G)
=@
54&
H
3
H!