0% found this document useful (0 votes)
3 views45 pages

L 24 25 Counting

The document outlines counting techniques in discrete mathematics, focusing on the Product Rule and Sum Rule, which are fundamental for solving counting problems. It provides various examples illustrating how to apply these rules in different scenarios, such as selecting majors, labeling chairs, and generating bit strings. Additionally, it introduces the Inclusion-Exclusion Principle for counting overlapping sets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views45 pages

L 24 25 Counting

The document outlines counting techniques in discrete mathematics, focusing on the Product Rule and Sum Rule, which are fundamental for solving counting problems. It provides various examples illustrating how to apply these rules in different scenarios, such as selecting majors, labeling chairs, and generating bit strings. Additionally, it introduces the Inclusion-Exclusion Principle for counting overlapping sets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

CSC102 - Discrete Structures

(Discrete Mathematics)
Counting Techniques

Lecture 24-25
Lecture Outline

• Counting
– Product Rule
– Sum Rule
– Product and Sum rule mix questions
– Inclusion-Exclusion Principle

06/13/2025 CSC102 - Discrete Structures 3


Counting Applications

• Counting has many applications in computer


science and mathematics.

• 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 sum rule
The product rule

• Also called the multiplication rule


• If there are n1 ways to do task 1, and n2 ways to do
task 2
– Then there are n1n2 ways to do both tasks in sequence
– This applies when doing the “procedure” is made up of
separate tasks
– We must make one choice AND a second choice

6
The Product Rule
• Suppose that a procedure can be broken into a
sequence of two tasks.
• Assume there are ways to do the first task.
• Assume for each of these ways of doing the
first task, there are ways to do the second task.
• So, there are 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
T-1

F-1 T-2

T-3

T-1

F-2 T-2

T-3
Ice cream
T-1

F-3 T-2

T-3

T-1

F-4 T-2

T-3
Example

• There are 18 math majors and 25 CS majors


• How many ways are there to pick one math major and
one CS major? Course

Math CS
• Solution:
• Break the procedure into tasks 18 25
– Task 1: Math major
– Task 2: CS major
– 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:
• Break the procedure into tasks
– Task 1: Choosing a microcomputer
– Task 2: Choosing a port
– By product rule, There are 32*24 = 768 ways to choose a port
to a microcomputer.
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
– 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? Office

• Solution: Employee-1 Employee-2

Break into tasks


– Task 1: assigning an office to employee 1 12 11
– Task 2: assigning an office to employee 2
– There are 12 *11 = 132 ways to assign offices to two employees.
Extended Version of The Product Rule

• A procedure can be broken down into a


sequence of tasks
• Assume each task , can be done in different
ways, regardless of how the previous tasks
were done.
• The procedure can be done in different ways.
Example

• How many different bit strings of length seven are there?


• Solution:
• Break the procedure into tasks b7 b6 b5 b4 b3 b2 b1
– Task 1: assigning bit 1 to 0 or 1 2 2 2 2 2 2 2
– Task 2: assigning bit 2 to 0 or 1
– …
– Task 7: assigning bit 7 to 0 or 1
• Count different ways of doing each task and then use the
product rule
– Each task can be done in 2 different ways.
– By product rule, There are= 128 different bit strings of length seven.
Example

• How many uppercase English letter strings of


length three are there?
L1 L2 L3
263
26 26 26
• Other versions of above question:
L1 L2 L3
(Same letter not repeated)
26 25 24

A L2 L3
(Start with Letter A)
1 26 26

A L2 L3
(Start with Letter A and same letter not repeated)
1 25 24
Example
• The format of telephone numbers in North America is
specified by a numbering plan.
X N Y
– Let X denote a digit between 0 and 9.
– Let N denote a digit between 2 and 9. 10 8 2
– Let Y denote a digit between 0 and 1.
– In the old plan, The format of telephone numbers is NYX-
NNX-XXXX.
– In the new plan, The format of telephone numbers is NXX-
NXX-XXXX.
• How many north American telephone numbers are
possible under the old plan and under the new plan.
Example
In the old plan, the formats of the area code, office code,
and station code are NYX, NNX, and XXXX, respectively,
so that telephone numbers had the form NYX-NNX-XXXX.
X N Y
Solution: 10 8 2

• area codes with format NYX.


• office codes with format NNX.
• station codes with format XXXX.
• Consequently, applying the product rule again, it
follows that under the old plan,
• Under the new plan,
Example

• How many strings of 4 decimal digits, do not


contain the same digit twice?

• Solution:
d 4 d3 d 2 d1
10 9 8 7
Example

• How many different license plates are


available if each plate contains a sequence of
three letters followed by three digits?
L1 L2 L3 D1 D2 D3
26 26 26 10 10 10
Example
• If repetitions of letters is not allowed:
L1 L2 L3 D1 D2 D3
26 25 24 10 10 10 26* 25* 24*10*10*10

• If repetitions of letters and digits are not allowed:


L1 L2 L3 D1 D2 D3
26 25 24 10 9 8 26* 25* 24*10*9*8
• If sequence of letters is LHE and repetitions of
digits are not allowed:
L H E D1 D2 D3
1*1*1*10*9*8
1 1 1 10 9 8
Example
• What is the value of k after the following code
has been executed?
int k 0;
for (int i 1; i 7; i  )
for (int j 1; j 8; j  )
for (int n 1; n 10; n  )
k k  1;
• Solution:
Example
• What is the value of k after the following code has
been executed?

• Solution:
• Task i: traversing the i-th loop. (1im)
• By the product rule, the nested loops traversed times.
• So the final value of k is .
The Sum Rule
The sum rule

• If there are n1 ways to do task 1, and n2 ways to do


task 2
• Also called the addition rule
– If these tasks can be done at the same time, then…
– Then there are n1+n2 ways to do one of the two tasks
– We must make one choice OR a second choice

25
The Sum Rule
• Also called the addition rule.
• Assume a task can be done either in one of
ways or in one of ways.
• Assume none of the set of ways is the same
as any of the set ways.
• If these tasks can be done at the same time,
then there are ways to do the task.
• We must make one choice OR a second choice.

26
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:

– There are 18 ways to pick Math major


– There are 25 ways to pick CS major

• By the sum rule, there are 18 + 25= 43


different ways to pick courses.
Example
• Assume there are 37 members of the
mathematics faculty and 83 mathematics majors.
• Either a member of the mathematics faculty or a
student who is a mathematics major is chosen as
a representative to a university committee.
• How many different ways to choose this
representative? Representative

Solution: Faculty Students

37+83=120
37 83
Extended Version of The Sum Rule

• Suppose a task can be done in one of ways, in


one of ways, …, or in one of ways.
• Assume none of the set of ways of doing the
task is the same as any of the set of ways, for
all pairsand with
• The task can be done in different ways.
Example
• A student can choose a computer project from
one of three lists. The three lists contains 23,
15 and 19 possible projects. No project is on
more than one list.
• How many possible projects are there to
choose from? Project

List-1 List-2 List-3


• Solution:

23 15 19
Example
• What is the value of k after the following code
has been executed?
int k 0;
for (int i 1; i 7; i  )
k k  1;
for (int j 1; j 8; j  )
k k  1;
for (int n 1; n 10; n  )
• Solution: k k  1;
Example
• What is the value of k after the following code
has been executed?

• Solution:

• By the sum rule, the final value of k is .


• Task i: traversing the i-th loop. ()
The Product Rule and The Sum Rule

• Some complicated counting problems can be


solved using both the product rule and the
sum rule.
Example
• In a version of the computer language BASIC, the name
of a variable is a string of one character or two
alphanumeric characters, where uppercase and
lowercase letters are not distinguished. (An
alphanumeric character is either one of the 26 English
letters or one of the 10 digits.) Moreover, a variable
name must begin with a letter. How many different
variable names are there in this version of BASIC?

• V1 (L): variable name with one character. (int a)


• V2 (LA): variable name with two alphanumeric
L D A L  D
characters. (int aa; int a1;) 26 10 26  10 36
Example

• How many license plates can be made using


either three digits followed by three
uppercase English letters or three uppercase
English
D D Dletters
1 L L followed
2 L 3
by three digits?
1 2 3


L1 L2 L3 D1 D2 D3
Example

• How many license plates can be made using either two


uppercase English letters followed by four digits or two
digits followed by four uppercase English letters?

L1 L2 D1 D2 D3 D4

D1 D2 L1 L2 L3 L4
Example
How many three-digit integers are divisible by 5?
Solution:
Integers that are divisible by 5, end either in 5 or in 0.
CASE-I (Integers that end in 0)
There are nine choices for the left-most digit (the digits 1 through 9)
and ten choices for the middle digit.(the digits 0 through 9)
Hence, total number of 3 digit integers that end in 0 is
9 choices (1 to 9) 10 choices (0 to 9) 1 choice (digit 0)

9x10x1= 90
Example
How many three-digit integers are divisible by 5?
Solution:
Integers that are divisible by 5, end either in 5 or in 0.
CASE-II (Integers that end in 5)
There are nine choices for the left-most digit (the digits 1 through 9)
and ten choices for the middle digit.(the digits 0 through 9)
Hence, total number of 3 digit integers that end in 5 is
9 choices (1 to 9) 10 choices (0 to 9) 1 choice (digit 5)

9x10x1= 90
Finally, by sum rule, the number of 3 digit integers that are
divisible by 5 is
90 + 90 = 180
The Inclusion-Exclusion Principle
The Inclusion-Exclusion Principle

• Suppose a task can be done in or in ways.


• However, some of the set of ways are the
same as some of the other ways.
• To count the number of ways to the task, we
add and and subtract the number of ways
that is common in ways and ways.

AB  A  B  AB
Example

• How many bit strings of length eight either start


with a 1 bit or end with two bits 00?
Solution:
b7 b6 b5 b4 b3 b2 b1 b0
Possibilities for Bits 2 2 2 2 2 2 2 1
starting with 1
Possibilities for bits 1 1 2 2 2 2 2 2
ending with 0
Common in both 2 2 2 2 2
Example
• How many bit strings of length eight either start
with a 1 bit or end with two bits 00?
Solution:
• Task 1: bit strings of length eight starts with 1.
• Task 2: bit strings of length eight ends with 00.
– By the product rule, the number of task 1 is .
– By the product rule, the number of task 2 is .
– Common in task 1 and task 2 and the number of them
are .
– By inclusion-exclusion principles, the number of such
strings is
AB  A  B  AB
Example
• How many uppercase English letter strings of length three
either start with letter A or end with letter C?
Solution:
• Task 1: Strings start with letter A.
• Task 2: Strings end with letter C.
– By the product rule, the number of task 1 is .
– By the product rule, the number of task 2 is .
– Common in task 1 and task 2 and the number of them are .
– By inclusion-exclusion principles, the number of such
strings are:

AB  A  B  AB
Exercise Questions

Chapter # 6
Topic # 6.1
Q 1,2,3,4,5,6,7,8,9,10,11,28,29,30,31,32,33-a,b
Chapter Reading
Topic # 6.1(The Basics of Counting)

You might also like