This Lecture
We will define what is a function formally, and then
in the next lecture we will use this concept in counting.
We will also study the pigeonhole principle and its applications.
• Examples and definitions (injection, surjection, bijection)
• Pigeonhole principle and applications
Functions
f :AB
function, f, from set A to set B
associates an element f (a ) B , with an element a A.
The domain of f is A.
The codomain of f is B.
Definition: For every input there is exactly one output.
Functions
domain = the set of all sets
f(S) = |S|
codomain = non-negative integers
domain = the set of all strings
f(string) = length(string)
codomain = non-negative integers
not a function,
f(student-name) = student-ID since one input could have
more than one output
[two students may have same name]
f(x) = is-prime(x) domain = positive integers
codomain = {T,F}
Injections (One-to-One)
f : A B is an injection iff no two inputs have the same output.
≤ 1 arrow in
f( ) =
A B
a, a A.
( f (a ) f (a ')) (a a ') |A| ≤ |B|
Surjections (Onto)
f :AB is a surjection iff every output is possible.
≥ 1 arrow in
f( ) =
A B
b B a A. f (a) b |A| ≥ |B|
Bijections
f :AB is a bijection iff it is surjection and injection.
exactly one arrow in
f( ) =
A B
|A| = |B|
Also called One to One Correspondence
Inverse Sets
A B
Given an element y in B, the inverse set of y := f-1(y) = {x in A | f(x) = y}.
Inverse Function
Informally, an inverse function f-1 is to “undo” the operation of function f.
exactly one arrow in
f( ) =
A B
There is an inverse function f-1 for f if and only if f is a bijection.
Composition of Functions
Two functions f:X->Y’, g:Y->Z so that Y’ is a subset of Y,
then the composition of f and g is the function g。f: X->Z, where
g。f(x) = g(f(x)).
f Y’ g
X Z
Y
This Lecture
• Examples and definitions (injection, surjection, bijection)
• Pigeonhole principle and applications
Pigeonhole Principle
If more pigeons
than pigeonholes,
Pigeonhole Principle
then some hole must have at least two pigeons!
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 have
the same image in the codomain.)
Pigeonhole Principle
then some hole must have at least two pigeons!
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 have
the same image in the codomain.)
Example 1
Question: Let A = {1,2,3,4,5,6,7,8}
If five integers are selected from A,
must a pair of integers have a sum of 9?
Consider the pairs {1,8}, {2,7}, {3,6}, {4,5}.
The sum of each pair is equal to 9.
If we choose 5 numbers from this set,
then by the pigeonhole principle,
both elements of some pair will be chosen,
and their sum is equal to 9.
Example 2
Question: In a party of n people, is it always true that there are
two people shaking hands with the same number of people?
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,
0 to n-2 => n-1 possible values (i.e., cardinality of
codomain = n-1)
n n-1
There are n people (i.e., cardinality of domain = n) ... ..
.
so the answer is “yes” by the pigeonhole principle.
Example 2
Question: In a party of n people, is it always true that there are
two people shaking hands with the same number of people?
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 2: if everyone shakes hand with at least one person, then
any person shakes hand with 1 to n-1 people,
1 to n-1 => n-1 possible values (i.e., cardinality of
codomain = n-1)
There are n people (i.e., cardinality of domain = n) n n-1
... ..
so .
the answer is “yes” by the pigeonhole principle.
Birthday Paradox
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?
We can think of it as picking n random numbers from 1 to 365 without repetition.
There are 365n ways of picking n numbers from 1 to 365.
There are 365·364·363·…·(365-n+1) ways of
picking n numbers from 1 to 365 without repetition.
So the probability that no pairs have the same birthday is
equal to 365·364·363·…·(365-n+1) / 365n
Birthday Paradox
Suppose n <= 365, what is the probability that in a random set of n people,
some pair of them will have the same birthday?
We can think of it as picking n random numbers from 1 to 365 without repetition.
There are 365n ways of picking n numbers from 1 to 365.
There are 365·364·363·…·(365-n+1) ways of
picking n numbers from 1 to 365 without repetition.
So the probability that no pairs have the same birthday is
equal to 365·364·363·…·(365-n+1) / 365n
n = 23 => the probability is 0.4927
n = 57 => the probability is 0.0098
This is smaller than 50% for 23 people, smaller than 1% for 57 people.
Birthday Paradox
Suppose n <= 365, what is the probability that in a random set of n people,
some pair of them will have the same birthday?
So the probability that no pairs have So the probability that some pair will
the same birthday is equal to have the same birthday is equal to
365·364·363·…·(365-n+1) / 365n 1 - 365·364·363·…·(365-n+1) / 365n
n = 23 => the probability is 0.492703 n = 23 => the probability is 0.507297
n = 57 => the probability is 0.009878 n = 57 => the probability is 0.990122
n = 75 => the probability is 0.000280 n = 75 => the probability is 0.999720
In a room of just 23 people there’s a 50-50 chance of two people
having the same birthday.
In a room of 57 there’s a 99% chance of two people matching.
In a room of 75 there’s a 99.9% chance of two people matching.
Generalized Pigeonhole Principle
Generalized Pigeonhole Principle
If n pigeons and h holes,
then some hole has at least
n pigeons.
h
♠ ♥
♣ ♦
10 cards; 4 holes (types)
Cannot have < 3 cards in every hole.
At least 3 or more cards of one type
Subset Sum
Two different subsets of the 90 (at most) 25-digit numbers shown above
have the same sum.
Subset Sum
90 numbers, each with at most 25 digits.
So the total sum is < 90x1025
Let A be the set of all subsets of the 90 numbers. (pigeons)
Let B be the set of integers from 0 to 90x1025. (pigeonholes)
By 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.
Theorem: Every collection of 6 people includes a club of 3 people,
or a group of 3 strangers.
Let x be one of the six people.
By the (generalized) pigeonhole principle, we have the following claim.
Met x
Claim: Among the remaining 5 people,
either 3 of them have met x,
or 3 of them have not met x. ~Met x
Club vs Strangers
Theorem: Every collection of 6 people includes a club of 3 people,
or a group of 3 strangers.
Claim: Among the remaining 5 people, either 3 of them have met x,
or 3 of them have not met x.
Met x
Case 1: “3 people have met x”
~Met x
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
Theorem: Every collection of 6 people includes a club of 3 people,
or a group of 3 strangers.
Claim: Among the remaining 5 people, either 3 of them have met x,
or 3 of them have not met x.
Met x
Case 2: “3 people have not met x”
~Met x
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.