counting rule in descrete structure
counting rule in descrete structure
Lecture - 13
Counting
Counting Applications
• For example,
• Counting the number of operations used by an algorithm to study
its time complexity
• Counting the successful outcomes of experiments
• Counting all the possible outcomes of experiments
• …
Basic Counting Principles
• Two basic counting principles
• The product rule
• The product rule applies when a procedure is made up of separate
tasks.
• The sum rule
The Product Rule
• Also called the multiplicative rule.
• Suppose that a procedure can be broken into a sequence
of two tasks.
• Assume there are n1 ways to do the first task.
• Assume for each of these ways of doing the first task,
there are n2 ways to do the second task.
• So, there are n1n2 ways to do the procedure.
• This applies when doing the “procedure” is made up of separate
tasks
• We must make one choice AND a second choice
The Product Rule
Example
• There are 18 math majors and 25 CS majors
• How many ways are there to pick one math major and
one CS major?
• Solution:
• Break the procedure into tasks
• Task 1: Math major
• Task 2: CS major
• Count different ways of doing each task and then use the
product rule
• Task 1 can be done in 18 different ways and for each of these
ways, Task 2 can be done in 25 different ways.
• By product rule, There are 18 * 25 = 450 ways to pick courses.
Example
• There are 32 microcomputers in a computer center. Each
microcomputer has 24 ports. How many different ports to
a microcomputer in the center are there.
• Solution:
Example
• The chairs of an auditorium are to be labeled with a letter
and a positive integer not exceeding 100. How many
chairs can be labeled differently?
• Solution:
• Break the procedure into tasks
• Task 1: assigning one of the 26 letters
• Task 2: assigning one of the 100 possible integers
• Count different ways of doing each task and then use the
product rule
• Task 1 can be done in 26 different ways and for each of these
ways, Task 2 can be done in 100 different ways.
• By product rule, There are 26*100 = 2600 ways to assign labels to
the chairs.
Example
• A new company with just two employees, rents a floor of a
building with 12 offices. How many ways are there to
assign different offices to these two employees?
• Solution:
• Break the procedure into tasks
• Task 1: assigning an office to employee 1
• Task 2: assigning an office to employee 2
• Count different ways of doing each task and then use the
product rule
• Task 1 can be done in 12 different ways and for each of these
ways, Task 2 can be done in 11 different ways.
• By product rule, There are 12 *11 = 132 ways to assign offices to
two employees.
Extended Version of The Product Rule
• Solution:
• Task i: traversing the i-th loop. (1≤i≤m)
• By the product rule, the nested loops traversed n1n2 … n m
times.
• So the final value of k is n1 n2 … nm .
The Sum Rule
• Also called the addition rule.
• Assume a task can be done either in one of n1 ways or in
one of n2 ways.
• Assume none of the set of n1 ways is the same as any of
the set n2 ways.
• If these tasks can be done at the same time, then there
are n1 + n2 ways to do the task.
• We must make one choice OR a second choice.
The Sum Rule
Example
• There are 18 math majors and 25 CS majors
• How many ways are there to pick one math major or one
CS major?
• Solution:
• Solution:
Example
• What is the value of k after the following code has been
executed?
• Solution:
• Task i: traversing the i-th loop. (1 ≤ 𝑖 ≤ 𝑚 )
• By the sum rule, the final value of k is n1 + n2 + ⋯ + nm .
The Product Rule and The Sum Rule
• Since the hostid cannot consist all 0s and all 1s, the number of
Class A hostids is 224 - 2.
• By the product rule, the number of task 1 is (27 - 1)(224 - 2) =
2,130,706,178.
• K ⊆ 𝐙+
• Assume k+1 or more objects are placed into k boxes.
• So, there is at least one box containing two or more of the
objects.
Example
• Show that among any group of 367 people, there must be
at least two with the same birthday.
• Solution:
• Solution:
• To use pigeonhole principle, first find boxes and objects.
• Suppose that for each letter, we have a box that contains a word
that begins with that letter.
• The number of boxes is 26 and the number of objects is 27.
• By the pigeonhole principle, at least one of these boxes contains
two or more words.
• So, there must be at least two words that begin with the same
letter.
The Generalized Pigeonhole Principle
• Assume 25 pigeons fly into 12 pigeonholes to rest.
• A least one of 12 pigeonholes must have at least three
pigeons in it.
The Generalized Pigeonhole Principle
12/5 = 2.4 2 3
2.7 2 3
−2.7 −3 −2
−2 −2 −2
Example
• Show among 100 people there are at least 9 who were
born in the same month.
• Solution:
• To use pigeonhole principle, first find boxes and objects.
• Suppose that for each month, we have a box that contains persons
who was born in that month.
• The number of boxes is 12 and the number of objects is100.
• By the generalized pigeonhole principle, at least one of these
boxes contains at least 100/12 = 9 persons.
• So, there must be at least 9 persons who were born in the same
month.
Example
• 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:
• To use pigeonhole principle, first find boxes and objects.
• Suppose that for each grade, we have a box that contains students
who got that grade.
• The number of boxes is 5, by the generalized pigeonhole principle,
to have at least 6 (= N/5 ) students at the same box, the total
number of the students must be at least N = 5 . 5 + 1 = 26.
Exercise Questions
Chapter # 5
Topic # 5.1
Q 1,2,3,4,5,6,7,8,9,10,11,26,27,28,29,30,31-a,b
Chapter Reading
Chapter # 5
Topic # 5.1(The Basics of Counting)
Topic # 5.2 (The Pigeonhole Principle)