Counting Counting Huynh Tuong Nguyen, Tran Vinh Tan 6 1 Chapter 6 Counting Discrete Structures for Computing on 25 April 2011 Huynh Tuong Nguyen, Tran Vinh Tan Faculty of Computer Science and Engineer[.]
Trang 1Huynh Tuong Nguyen, Tran Vinh Tan
Chapter 6
Counting
Discrete Structures for Computing on 25 April 2011
Huynh Tuong Nguyen, Tran Vinh TanFaculty of Computer Science and Engineering
University of Technology - VNUHCM
Trang 2Huynh Tuong Nguyen, Tran Vinh Tan
Contents
Trang 4Huynh Tuong Nguyen, Tran Vinh Tan
Introduction
Example
Trang 5Huynh Tuong Nguyen, Tran Vinh Tan
Trang 6Huynh Tuong Nguyen, Tran Vinh Tan
Problems
brute force attack
Trang 7Huynh Tuong Nguyen, Tran Vinh Tan
Problems
brute force attack
Trang 8Huynh Tuong Nguyen, Tran Vinh Tan
Problems
brute force attack
Trang 9ports How many different ports in the center?
Solution
There are two tasks to choose a port:
Because there are 32 ways to choose the router and 24 ways tochoose the port no matter which router has been selected, thenumber of ports are 32 × 24 = 768 ports
Definition (Product Rule (Luật nhân))
two tasks If there are n1ways to do the first task and for each of
Can be extended to T1, T2, , Tmtasks in sequence
Trang 10ports How many different ports in the center?
Solution
There are two tasks to choose a port:
Because there are 32 ways to choose the router and 24 ways to
choose the port no matter which router has been selected, the
number of ports are 32 × 24 = 768 ports
Definition (Product Rule (Luật nhân))
two tasks If there are n1ways to do the first task and for each of
Can be extended to T1, T2, , Tmtasks in sequence
Trang 11ports How many different ports in the center?
Solution
There are two tasks to choose a port:
Because there are 32 ways to choose the router and 24 ways to
choose the port no matter which router has been selected, the
number of ports are 32 × 24 = 768 ports
Definition (Product Rule (Luật nhân))
two tasks If there are n1ways to do the first task and for each of
Can be extended to T1, T2, , Tmtasks in sequence
Trang 12Huynh Tuong Nguyen, Tran Vinh Tan
Product Rule
Example
ports How many different ports in the center?
Solution
There are two tasks to choose a port:
Because there are 32 ways to choose the router and 24 ways to
choose the port no matter which router has been selected, the
number of ports are 32 × 24 = 768 ports
Definition (Product Rule (Luật nhân))
Trang 13Two new students arrive at the dorm and there are 12 rooms
two students?
Example (2)How many different bit strings of length seven are there?
Example (3)How many one-to-one functions are there from a set with melements to one with n elements?
Trang 14Two new students arrive at the dorm and there are 12 rooms
two students?
Example (2)
How many different bit strings of length seven are there?
Example (3)How many one-to-one functions are there from a set with melements to one with n elements?
Trang 15Huynh Tuong Nguyen, Tran Vinh Tan
More examples
Example (1)
Two new students arrive at the dorm and there are 12 rooms
two students?
Example (2)
How many different bit strings of length seven are there?
Example (3)
How many one-to-one functions are there from a set with m
elements to one with n elements?
Trang 16A student can choose a project from one of three fields:
Information system (32 projects), Software Engineering (12
projects) and Computer Science (15 projects) How many ways are
there for a student to choose?
Solution: 32 + 12 + 15Definition (Sum Rule (Luật cộng))
set of n2 ways, then there aren1+ n2 ways to do the task
Can be extended to n1, n2, , nmdisjoint ways
Trang 17A student can choose a project from one of three fields:
Information system (32 projects), Software Engineering (12
projects) and Computer Science (15 projects) How many ways are
there for a student to choose?
Solution: 32 + 12 + 15
Definition (Sum Rule (Luật cộng))
set of n2 ways, then there aren1+ n2 ways to do the task
Can be extended to n1, n2, , nmdisjoint ways
Trang 18A student can choose a project from one of three fields:
Information system (32 projects), Software Engineering (12
projects) and Computer Science (15 projects) How many ways are
there for a student to choose?
Solution: 32 + 12 + 15
Definition (Sum Rule (Luật cộng))
set of n2 ways, then there aren1+ n2 ways to do the task
Can be extended to n1, n2, , nmdisjoint ways
Trang 19Huynh Tuong Nguyen, Tran Vinh Tan
Sum Rule
Example
A student can choose a project from one of three fields:
Information system (32 projects), Software Engineering (12
projects) and Computer Science (15 projects) How many ways are
there for a student to choose?
Solution: 32 + 12 + 15
Definition (Sum Rule (Luật cộng))
set of n2 ways, then there aren1+ n2 ways to do the task
Can be extended to n1, n2, , nmdisjoint ways
Trang 20or two alphanumeric characters, where uppercase and lowercase
begin with a letter and must bedifferent fromthe five strings of
two characters that are reserved for programming use How many
different variables names are there in this language?
Solution
Let V equal to the number of different variable names
the number of these that are two characters long Then, by sumrule, V = V1+ V2
are 26 · 36 strings of length two that begin with a letter and endwith an alphanumeric character However, five of these are
different names for variables in this language
Trang 21Huynh Tuong Nguyen, Tran Vinh Tan
Using Both Rules
Example
or two alphanumeric characters, where uppercase and lowercase
begin with a letter and must bedifferent fromthe five strings of
two characters that are reserved for programming use How many
different variables names are there in this language?
Solution
Let V equal to the number of different variable names
the number of these that are two characters long Then, by sum
rule, V = V1+ V2
are 26 · 36 strings of length two that begin with a letter and end
with an alphanumeric character However, five of these are
different names for variables in this language
Trang 22ways
Trang 23ways
Trang 24ways
Trang 25ways
Trang 26ways
Trang 27Huynh Tuong Nguyen, Tran Vinh Tan
Inclusion-Exclusion
Example
Solution
ways
Trang 30Huynh Tuong Nguyen, Tran Vinh Tan
Inclusion-Exclusion
|A ∪ B| = |A| + |B| − |A ∩ B|
Trang 34Huynh Tuong Nguyen, Tran Vinh Tan
Inclusion-Exclusion
|A ∪ B ∪ C| =???
Trang 35Huynh Tuong Nguyen, Tran Vinh Tan
Example
onlyArsenal,10liked onlyChelsea,12liked onlyMUand40liked
all three clubs How many of the student surveyed likedboth MU
andChelseabut notArsenal?
Trang 36Huynh Tuong Nguyen, Tran Vinh Tan
Pigeonhole Principle
Trang 37thesame birthday.
Because there are only 366 possible birthdays
Example (2)
Because there are 26 letters in the English alphabet
Trang 38thesame birthday.
Because there are only 366 possible birthdays
Example (2)
Because there are 26 letters in the English alphabet
Trang 39thesame birthday.
Because there are only 366 possible birthdays
Example (2)
Because there are 26 letters in the English alphabet
Trang 40Huynh Tuong Nguyen, Tran Vinh Tan
Examples
Example (1)
thesame birthday
Because there are only 366 possible birthdays
Example (2)
Because there are 26 letters in the English alphabet
Trang 41Huynh Tuong Nguyen, Tran Vinh Tan
Examples
Example (1)
thesame birthday
Because there are only 366 possible birthdays
Example (2)
Because there are 26 letters in the English alphabet
Trang 42Prove that if seven distinct numbers are selected from
{1, 2, , 11}, then some two of these numbers sum to 12
Solution
{3, 9}, {4, 8}, {5, 7}, {6}
pigeonhole corresponding to the set that contains it
placed in six pigeonholes, some pigeonhole contains twonumbers
Trang 43Prove that if seven distinct numbers are selected from
{1, 2, , 11}, then some two of these numbers sum to 12
Solution
{3, 9}, {4, 8}, {5, 7}, {6}
pigeonhole corresponding to the set that contains it
placed in six pigeonholes, some pigeonhole contains twonumbers
Trang 44Prove that if seven distinct numbers are selected from
{1, 2, , 11}, then some two of these numbers sum to 12
Solution
{3, 9}, {4, 8}, {5, 7}, {6}
pigeonhole corresponding to the set that contains it
placed in six pigeonholes, some pigeonhole contains twonumbers
Trang 45Prove that if seven distinct numbers are selected from
{1, 2, , 11}, then some two of these numbers sum to 12
Solution
{3, 9}, {4, 8}, {5, 7}, {6}
pigeonhole corresponding to the set that contains it
placed in six pigeonholes, some pigeonhole contains twonumbers
Trang 46Huynh Tuong Nguyen, Tran Vinh Tan
Exercise
Example
Prove that if seven distinct numbers are selected from
{1, 2, , 11}, then some two of these numbers sum to 12
Solution
{3, 9}, {4, 8}, {5, 7}, {6}
pigeonhole corresponding to the set that contains it
placed in six pigeonholes, some pigeonhole contains two
Trang 49Huynh Tuong Nguyen, Tran Vinh Tan
Examples – Permutations
How many ways can we arrange three students to stand in line for
a picture?
Number of choices: 6 = 3!
Trang 50Apermutation(hoán vị) of a set of distinct objects is anordered
arrangementof these objects
An ordered arrangement of r elements of a set is called an
r-permutation (hoán vị chập r)
(n − r)!
Example
second-prizewinner, and athird-prizewinner from 100 differentpeople who have entered a contest?
P (100, 3) = 100 · 99 · 98 = 970, 200
Trang 51Apermutation(hoán vị) of a set of distinct objects is anordered
arrangementof these objects
An ordered arrangement of r elements of a set is called an
r-permutation (hoán vị chập r)
(n − r)!
Example
second-prizewinner, and athird-prizewinner from 100 different
people who have entered a contest?
P (100, 3) = 100 · 99 · 98 = 970, 200
Trang 52Huynh Tuong Nguyen, Tran Vinh Tan
Permutations
Definition
Apermutation(hoán vị) of a set of distinct objects is anordered
arrangementof these objects
An ordered arrangement of r elements of a set is called an
r-permutation (hoán vị chập r)
(n − r)!
Example
second-prizewinner, and athird-prizewinner from 100 different
people who have entered a contest?
Trang 55Huynh Tuong Nguyen, Tran Vinh Tan
Examples – Combinations
How many ways to choose two students from a group of four to
offer scholarship?
Number of choices: 6
Trang 56Anr-combination(tổ hợp chập r) of elements of a set is an
unordered selectionof r elements from the set Thus, an
r-combination is simply a subset of the set with r elements
Trang 57Anr-combination(tổ hợp chập r) of elements of a set is an
unordered selectionof r elements from the set Thus, an
r-combination is simply a subset of the set with r elements
How many ways are there to select eleven players from a
22-member football team to start up?
Trang 58Huynh Tuong Nguyen, Tran Vinh Tan
Combinations
Definition (Combinations)
Anr-combination(tổ hợp chập r) of elements of a set is an
unordered selectionof r elements from the set Thus, an
r-combination is simply a subset of the set with r elements
How many ways are there to select eleven players from a
22-member football team to start up?
22!
Trang 59Huynh Tuong Nguyen, Tran Vinh Tan
Exercises – Permutations with Repetition
must begin her trip in a specified city, but she can visit the
other seven cities in any order she wishes How many possible
orders can the salesman use when visiting these cities?
and 11 in CE department How many ways are there to select
a defend committee if the committee is to consist of three
faculty members from the CS and four from the CE
department?
Trang 62Huynh Tuong Nguyen, Tran Vinh Tan
Permutations with Repetition
Trang 63Huynh Tuong Nguyen, Tran Vinh Tan
Example
Question: How many ways we can choose3 students fromthe
facultiesof Computer Science, Electrical Engineering and
Mechanical Engineering?
Trang 64Huynh Tuong Nguyen, Tran Vinh Tan
Trang 66Huynh Tuong Nguyen, Tran Vinh Tan
Trang 67There are C(n + r − 1, r) r-combinations from a set with n
elements when repetition of elements is allowed
ExampleHow many solutions does the equation
x1+ x2+ x3= 11have, where x1, x2, and x3are nonnegative integers?
Trang 68Huynh Tuong Nguyen, Tran Vinh Tan
Combinations with Repetition
Theorem
There are C(n + r − 1, r) r-combinations from a set with n
elements when repetition of elements is allowed
Example
How many solutions does the equation
x1+ x2+ x3= 11have, where x1, x2, and x3are nonnegative integers?
Trang 69Huynh Tuong Nguyen, Tran Vinh Tan
Examples
Question: How many permutations are there ofMISSISSIPPI?
Trang 70Huynh Tuong Nguyen, Tran Vinh Tan
Examples
Question: How many permutations are there ofMISSISSIPPI?
Trang 71The number of different permutations of n objects, where there
are n1indistinguishable objects of type 1, n2 indistinguishable
objects of type 2, , and nkindistinguishable objects of type k, is
n!
n1!n2! · · · nk!
ExampleHow many permutations are there of MISSISSIPPI?
Trang 72Huynh Tuong Nguyen, Tran Vinh Tan
Permutations with Indistinguishable Objects
Theorem
The number of different permutations of n objects, where there
are n1indistinguishable objects of type 1, n2 indistinguishable
objects of type 2, , and nkindistinguishable objects of type k, is