Chap4 - Functions, Pigeonhole Principle
Chap4 - Functions, Pigeonhole Principle
Chap4 - Functions, Pigeonhole Principle
f( ) =
A B
The important point is that there is only one output for each input.
Note: the input set can be the same as the output set, e.g. both are integers.
Examples of Functions
domain = R
codomain = R>0
domain = R>0
codomain = R
domain = R
codomain = [-1,1]
domain = R>=0
codomain = R>=0
Examples of Functions
not a function,
f(student-name) = student-ID since one input could have
more than one output
|A| ≤ |B|
Surjections
1 arrow in
f( ) =
A B
|A| ≥ |B|
Bijections
f( ) =
A B
|A| = |B|
Exercises
A B
f( ) =
A B
f Y’ g
X Z
Y
Exercises
f:X->Y g:Y->Z
f surjective g injective
f:X->Y g:Y->Z
f surjective g surjective
f:X->Y g:Y->Z
f injective g surjective
f:X->Y g:Y->Z
f bijective g bijective
f:X->Y f-1:Y->X
This Lecture
If more pigeons
than pigeonholes,
Pigeonhole Principle
Pigeonhole principle
A function from a larger set to a smaller set cannot be injective.
(There must be at least two elements in the domain that are
mapped to the same element in the codomain.)
Example 1
Everyone can shake hand with 0 to n-1 people, and there are n people,
and so it does not seem that it must be the case, but think about it carefully:
Case 1: if there is a person who does not shake hand with others,
then any person can shake hands with at most n-2 people,
and so everyone shakes hand with 0 to n-2 people, and so
the answer is “yes” by the pigeonhole principle.
In a group of 367 people, there must be two people having the same birthday.
Suppose n <= 365, what is the probability that in a random set of n people,
some pair of them will have the same birthday?
This is smaller than 50% for 23 people, smaller than 1% for 57 people.
Generalized Pigeonhole Principle
♠ ♥ ♣ ♦
Cannot have < 3 cards in every hole.
Subset Sum
Two different subsets of the 90 25-digit numbers shown above have the same sum.
Subset Sum
We are asking whether two subsets must have the same sum.
We can ask whether the opposite can hold: whether all subsets have different sums.
We will show that it is not possible for all subsets to have different sums.
We will count how many possible different subsets are there, say the answer is X.
And we will also count how many possible different sums are there, say the ans is Y.
If X > Y, then by the pigeonhole principle, there are more inputs than outputs and
thus it is not possible for all subsets to have different sums.
If we could show that |X| > |Y|, then by the pigeonhole principle,
the function f must map two elements in X into the same element in Y.
This means that there are two subsets with the same sum.
Subset Sum
By the pigeonhole principle, there are two different subsets with the same sum.
Club vs Strangers
Let’s agree that given any two people, either they have met or not.
If every people in a group has met, then we’ll call the group a club.
If every people in a group has not met, then we’ll call a group of strangers.
Case 1.1: No pair among those people met each other. OK!
Then there is a group of 3 strangers.
Case 1.2: Some pair among those people have met each other. OK!
Then that pair, together with x, form a club of 3 people.
Club vs Strangers
Case 2.1: Every pair among those people met each other. OK!
Then there is a club of 3 people.
Case 2.2: Some pair among those people have not met each other. OK!
Then that pair, together with x, form a group of 3 strangers.
Club vs Strangers
The idea can be applied to CS, see page 453-454 of the textbook.