Chapter 1
Chapter 1
Counting
1
Introduction
Suppose that a password
on a computer system
consists of six, seven, or
eight characters. Each of
these characters must be
a digit or a letter of the
alphabet. Each password
must contain at least one
digit. How many such
passwords are there?
2
Contents
1. The Rules of Sum and Product
2. Permutations
3. Combinations: The Binomial Theorem
4. Combinations with Repetition
5. Summary
3
1. The Rules of Sum and
Product
4
What is enumeration or counting?
It just starts from counting your fingers.
Enumeration does not end with arithmetic.
5
The Rules of Sum and Product
Two basic principles of counting: the rules
of sum and product.
6
The Rule of Sum
If a first task can be performed in m ways,
while a second task can be performed in n
ways, and the two tasks cannot be performed
simultaneously, then performing either task
can be accomplished in any one of m+n ways.
Tasks
A m P(A or B) = P(A) + P(B)
B n
7
Example 1.1
A college library has 40 textbooks on
sociology and 50 textbooks dealing with
anthropology. By the rule of sum, a student at
this college can select among 40+50=90
textbooks in order to learn more about one or
the other of these two subjects.
Tasks Textbook
S s P(S or A) = P(S) + P(A)
A m = 40 + 50
n = 90
8
The Rule of Product: principle of choice
If a procedure can be broken down into first
and second stages, and if there are m
possible outcomes for the first stage and if,
for each of these outcomes, there are n
possible outcomes for the second stage, then
the total procedure can be carried out, in the
designated order, in m.n ways.
P(A and B) = m x n
9
Example 1.5
The drama club of Central University is
holding tryouts for a spring play. With six men
and eight women auditioning for the leading
male and female roles, by the rule of product
the director can cast his leading couple 6x8 =
48 ways. M
F
F
M–6 M F
P(M and F) = 6 x 8
F-8 M F
M F
M F
M F
F
10
Example 1.6
Considering the manufacture of license plates consisting of
2 letters followed by 4 digits.
a) If no letter or digit can be repeated, there are 26 × 25 ×
10 × 9 × 8 × 7 = 3,276,000 different possible plates.
b) With repetitions of letters and digits allowed, 26 × 26 ×
10 × 10 × 10 × 10 = 6,760,000 different license plates
are possible.
L L D D D D 26 – letter (alphabet)
10 - digits
a) 26 x 25 x 10 x 9 x 8 x 7
P(L and D) = 26 x 25 x 10 x 9 x 8 x
7
11
Example 1.8
At the AWL corporation Mrs. Foster operates the
Quick Snake Coffee Shop. The menu at her shop is
limited: 6 kinds of muffins, 8 kinds of sandwiches, and
5 beverages (hot coffee, hot tea, iced tea, cola, and
orange juice). Ms. Dodd, an editor at AWL, sends her
assistant Carl to the shop to get her lunch – either a
muffin and a hot beverage or a sandwich and a
cold beverage. How many ways in which Carl can
purchase Ms. Dodd’s lunch?
Carl has an order as follows:
A muffin AND a hot beverage OR a sandwich AND a cold
beverage
6P(M
× 2and
+ 8B × 3 =or
(hot)) 12P(S
+ and
24 =
B 36
(cold)) 12
Example
A student can choose a computer project
from one of three lists. The three lists contain
23, 15, and 19 possible projects, respectively.
No project is on more than one list. How
many possible projects are there to choose
from?
Solution: The rule of sum?
The rule of product?
13
Example
What is the value of x after the following
a) codes?
b
)
14
More complex counting problems
L L L L L L
26 x 26 x 26 x 26 x 26
x 26
L – 26
D - 10
15
2. Permutations
16
Permutations
Linear arrangements of objects – called
permutations; how do we count the
number of these arrangements?
Note: We consider the order of objects
while counting the number of
permutations.
A, B, C ≠ B, C, A ≠ C, B, A etc.
17
Example 1.9
In a class of 10 students, 5 are to be chosen
and seated in a row for a picture. How many
such linear arrangements are possible?
10 × 9 × 8 × 7 × 6 = 30,240
18
Definition 1.1
19
Example 1.9
In a class of 10 students, 5 are to be chosen
and seated in a row for a picture. How many
such linear arrangements are possible?
20
Definition 1.2
21
Formula 1
22
Example 1.10 & 1.11
The number of permutations of the letters in
the word COMPUTER is 8!.
But the number of arrangements of the four
letters in BALL is 12, not 4!, because we do
not have four distinct letters to arrange.
R O U T C P E M
8 x 7 x 6 x 5 x 4 x 3 x
2 x 1
23
= 12
Example 1.11
A B L L A B L 1 L2 A B L2 L1
A L B L A L 1 B L2 A L2 B L1
A L L B A L 1 L2 B A L2 L1 B
B A L L B A L1 L2 B A L2 L1
B L A L B L 1 A L2 B L2 A L1
B L L A B L 1 L2 A B L2 L1 A
L A B L L 1 A B L2 L2 A B L1
L A L B L 1 A L2 B L2 A L1 B
L B A L L 1 B A L2 L2 B A L1
L B L A L 1 B L2 A L2 B L1 A
L L A B L1 L 2 A B L2 L1 A B
L L B A L 1 L2 B A L2 L1 B A
24
Example
How many ways are there to select a first-
25
Example
How many permutations of the letters
ABCDEFGH contain the string ABC ?
6! = 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 720
26
Example 1.12
Consider the arrangements of all 9 letters in
DATABASES.
(2!)(3!)(Number of arrangements of the
letters in DATABASES) = (Number of
permutations of the symbols D, A1, T, A2, B,
A3, S1, E, S2) 9!/(2!3!) = 30,240
27
Formula 2
28
Example 1.13
Arranging all of the letters in MASSASAUGA,
we find that there are
10!/(4!3!1!1!1!)=25,200
29
Example 1.14
Determine the number of (staircase) paths in the
xy-plane from (2, 1) to (7, 4), where each such
path is made up of individual steps going one unit
to the right (R) or one unit upward (U).
Solution:
8!/(5!3!) = 56 30
Example 1.16
If 6 people, designated as A, B, …, F, are seated about a
round table, how many different circular arrangements
are possible, if arrangements are considered the same
when one can be obtained from the other by rotation?
ABEFCD
BEFCDA
EFCDAB
FCDABE
CDABEF
DABEFC
31
Example
a) Write a java code that find all the
permutations of string "ABCDEF"
b) Write a java code that find all the
permutations of string "ABACBC"
32
3. Combinations
The Binomial Theorem
33
Combinations:
The Binomial Theorem
Suppose we draw three cards from a standard
deck of playing cards (52 cards) in succession and
without replacement, then by the rule of product
there are 52×51×50=52!/49!=P(52,3).
If instead we simply select 3 cards at one time
from the deck so that the order of selection of the
cards is no longer important, then the six
permutations (3!) correspond to just one
(unordered) selection.
Consequently, three cards can be drawn, without
replacement, from a standard deck in 52!/(3!49!) =
22100 ways.
34
Formula 3
35
Example 1.19
A hostess is having a dinner party for some
members of her charity committee. Because
of the size of her home, she can invite only 11
of the 20 committee members. She can invite
“the lucky 11” in
=20!/(11!9!)=167,960
ways.
36
Example 1.20
a) A student taking a history examination is
directed to answer any 7 of 10 essay
questions.
b) The student must answer 3 questions from
the first 5 and 4 questions from the last 5.
c) The student must answer 7 of 10 questions
where at least 3 are selected from the first 5.
i. C(10, 7) = 120 ways
ii. C(5, 3)C(5,4) = 10 × 5 = 50 ways
iii. C(5, 3)C(5, 4) + C(5, 4)C(5, 3) + C(5, 5)C(5, 2)
= 110 ways
37
Notes
38
T L L H S S E
E
39
Example 1.25
Suppose that Ellen draws 5 cards from a
standard deck of 52 cards. In how many ways
can her selection result in a hand with no
clubs?
C(39, 5)
Now suppose we want to count the number of
Ellen’s 5-card selections that contain at least
one club.
C(52, 5) – C(39, 5) = 2,023,303 vs.
40
Example 1.25 (cont.)
41
Theorem 1.1
()
( 𝑥+ 𝑦 ) =∑ 4 𝑥
4
𝑗 =0 𝑗
4− 𝑗
() ()
0 1
3
()2
2 2
()
3
3
()
𝑦 = 4 𝑥 + 4 𝑥 𝑦+ 4 𝑥 𝑦 + 4 𝑥 𝑦 + 4 𝑦
𝑗 4
4
4
42
Theorem 1.2
43
Example 1.26
44
Example 1.27
45
4. Combinations with
Repetition
46
Example
How many ways can I select 15 cans of soda from a cooler
containing large quantities of Coke, Pepsi, Diet Coke, Diet
Pepsi and Sprite?
We have to model this problem using the chart:
Coke Pepsi Diet Diet Sprite
Coke Pepsi
A 111 111 111 111 111
B 11 11111 11111 1
1 1
C 1111 11111 1111
11
48
n n2 n3 … n3
Examples
1 0
A 2 25 25 … 25
5
B 5 30 20 … 0
0
How many ways Ccan
1 I 1fill 1 … holding
a box 1 100 pieces
of candy from 30 different types of candy?
#slots = 100, #transitions = 30 - 1, so there are
C(100+29,100) = 129!/(100!29!) different ways to fill
the box.
How many ways if I must have at least 1 piece of
each type?
Now, we are reducing the #slots to choose over to
(100 - 30) slots, so there are
C(70+29,70) = 99!/70!29!
49
Example 1.28
50
Formula 4
51
Example 1.29
A donut shop offers 20 kinds of donuts.
Assuming that there are at least a dozen of
each kind when we enter the shop, how many
ways can we select a dozen donuts?
C(20 + 12 – 1, 12) = C(31, 12) = 141,120,525
ways.
n n n n20
1 2 3
A 11
11
11
11
11
11
B 11 11 11 11
1 1 1 1
52
C
Example 1.31
B B B B
Child 1 Child 2 Child 3 Child 4 53
Example 1.37
1+1 7
+5
1+5 6+1
+1 1+6
5+1 2+5
+1 5+2
2+1 3+4
+4 4+3
4+2
+1
2+4
+1
3+3 54
Example 1.39: Computer Science
Application
55
Homework 1
Exercises 1.1 and 1.2
11, 31, 34, 38
Exercises 1.3
20,26
Exercises 1.4
18
56
Exercise 1.1 and 1.2
Exercise 1.1 and 1.2
58
Exercise 1.3
Exercise 1.3
60
Exercise 1.4