Discrete Mathematics
Ch t 5 R l ti d
- - Chapter 5: Relations and
Functions
Hung-Yu Kao (高宏宇) Department of Computer Science and Information Engineering, N l Ch K U National Cheng Kung University
Discrete Mathematics -- Chapter 5: Relations and Ch t 5 R l ti d - - PowerPoint PPT Presentation
Discrete Mathematics -- Chapter 5: Relations and Ch t 5 R l ti d Functions Hung-Yu Kao ( ) Department of Computer Science and Information Engineering, N National Cheng Kung University l Ch K U Outline 5.1 Cartesian Products
Hung-Yu Kao (高宏宇) Department of Computer Science and Information Engineering, N l Ch K U National Cheng Kung University
5.1 Cartesian Products and Relations 5.2 Functions: Plain and One-to-One 5.3 Onto Functions: Stirling Numbers of the Second Kind 5 4 Special Functions 5.4 Special Functions 5.5 The Pigeonhole Principle
5.6 Function Composition and Inverse Functions 5.7 Computational Complexity 5.8 Analysis of Algorithms
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
2
The same problem!
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
3
denoted by
}. , | ) , {( B b A a b a B A ∈ ∈ = ×
}. 1 , | ) , , , {(
2 1 2 1
n i A a a a a A A A
i i n n
≤ ≤ ∈ ⋅ ⋅ ⋅ = × ⋅ ⋅ ⋅ × ×
coordinate geometry and two dimensional calculus } , | ) , {( R R R ∈ = × y x y x coordinate geometry and two-dimensional calculus.
+ + × R
R
p p , interior of any sphere, and two-dimensional planes, and one- dimensional lines are subsets of importance.
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
4
Ex 5 1 : Let A = {2 3 4} B = {4 5} Then Ex 5.1 : Let A = {2, 3, 4}, B = {4, 5}. Then
(5 4)} (5 3) (5 2) (4 4) (4 3) 2) {(4 b) (4,5)} (4,4), (3,5), (3,4), (2,5), 4), {(2, a) A B B A = ×
3 3 2
(4,5,5) e.g., }; c b, a, | c) b, {(a, d) (5,5)} (5,4), (4,5), 4), {(4, c) (5,4)} (5,3), (5,2), (4,4), (4,3), 2), {(4, b) B B B B B B B B B A B ∈ ∈ = × × = = × = = ×
Ex 5.3: Tree diagram
= 3 * 2 * 2 = |A||B||C|
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
5
Definition 5.2: For sets A, B, any subset of is called a (binary)
relation from A to B. Any subset of is called a (binary) relation on A
B A×
relation on A.
In short, we say “aRb” if and only if (a,b)∈R.
E 5 5 Th f ll
i f h l i f A B
Ex 5.5 : The following are some of the relations from A to B.
A B A B A to from relations possible 2 6 | | )}, 5 , 3 ( ), 4 , 2 {( ,
6
∴ = × × Q φ
A n B m A B A B A
mn
to from relations 2 , | | , | | : formula General to from relations possible 2 , 6 | | = = ∴ = × Q
How many relations from B to A?
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
6
E 5 7
} | ) {( A t l ti d fi ≤ ℜ
+
Z A
Ex 5.7 :
11 7 7, 7
, (7,11) (7,7), to". equal
than less is " relation the is y} x | y) {(x, as A set
relation a define may we , ℜ ℜ ℜ ∈ ℜ ≤ ℜ =
+
Z A 2 8
, (8,2) 11 7 7, 7
, (7,11) (7,7), ℜ / ℜ ∉ ℜ ℜ ℜ ∈
F A
φ φ φ φ A A
φ φ φ φ = × = × A A ,
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
7
Theorem 5.1: For any sets
⊆ C B A , , C) ( ) ( C) ( b) C) ( ) ( C) ( a) × ∪ × = ∪ × × ∩ × = ∩ × A B A B A A B A B A C) ( C) ( C ) ( d) ) ( C) ( C ) ( c) C) ( ) ( C) ( b) × ∪ × = × ∪ × ∩ × = × ∩ × ∪ × = ∪ × B A B A C B A B A A B A B A
Proof
C , and , C and C) ( and C) ( , (a) ∈ ∈ ∈ ∈ ⇔ ∈ ∩ ∈ ∈ ⇔ ∩ ∈ ∈ ⇔ ∩ × ∈ ∀ b A a B b A a b B b A a B b A a B A b a C) ( ) ( ) , ( C ) , ( and ) , ( C , and , C and × ∩ × ∈ ⇔ × ∈ × ∈ ⇔ ∈ ∈ ∈ ∈ ⇔ ∈ ∩ ∈ ∈ ⇔ A B A b a A b a B A b a b A a B b A a b B b A a
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
8
D fi iti 5 3 f t t A B f ti ( i )
B A f
from A to B, is a relation from A to B in which every element of A appears exactly once as the first component of an ordered pair in the relation.
B A f → :
= b ∈ B.
Ex 5.9 : functions. not but relations, are )} , 3 ( ), , 2 ( ), , 2 ( ), , 1 {( )}, , 2 ( ), , 1 {( relation a and function a is )} , 3 ( ), , 2 ( ), , 1 {( } , , , { }, 3 , 2 , 1 {
2 1
z x w w x w x x w f z y x w B A = ℜ = ℜ = = =
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
9
functions. not but relations, are )} , 3 ( ), , 2 ( ), , 2 ( ), , 1 {( )}, , 2 ( ), , 1 {(
2 1
z x w w x w ℜ ℜ
D fi iti 5 4 F ti A i ll d th d i f f d B th
B A f
codomain of f .
B A f → : components in the ordered pairs of f is called the range of f and is also denoted by f(A) because it is the set of images (of the elements of A) under f.
3 , 2 , 1 {
domain the 5.9, Example In f =
f
} , { ) (
range the } , , , {
codomain the x w A f f z y x w f = = =
A B f(A)
program (the input) into its corresponding object program (the output).
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
10
⎣ ⎦
. to equal
than less integer greatest the ) ( , : = = → x x x f f Z R
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
4 . 8 7 . 7 8 7 15 16 1 . 16 4 . 8 7 . 7 3) 2 . 8 1 . 7 8 7 15 3 . 15 2 . 8 1 . 7 2) 3 3 , 4 8 . 3 , 3 3 , 3 8 . 3 1) .
ess ege g ea es e ) ( , : + = + = ≠ = = + + = + = = = + − = − − = − = = → x x x f f
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
3 7 3 01 3 3 3 4 4 7 3 01 3 3 3 1) . to equal
an greater th integer least the ) ( , : = = = = = = = = = → x x x g g Z R
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
)
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
2 . 4 3 . 3 5 4 9 8 5 . 7 4.2 3.3 3) 5 . 4 6 . 3 5 4 9 1 . 8 4.5 3.6 2) 3 7 . 3 01 . 3 , 3 3 , 4 4 7 . 3 01 . 3 , 3 3 1) + = + = ≠ = = + + = + = = = + − = − = − − = − = = = =
⎦ ⎡ ⎤
3 78 . 3 ) 78 . 3 ( trunc , 3 78 . 3 ) 78 . 3 ( trunc − = − = − = =
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
11
(d) Access function: storing a m×n matrix in a one-dimensional
array
h j i l i
n i a f
ij
+ − = ) 1 ( ) ( : formula
a11 a12 … a1n a21 a22 … a2n a31 … aij … amn 1 2 … n n+1 n+2 … 2n 2n+1 … (i-1)n+j … (m-1)n+n=mn
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
12
Ex 5.11 Division algorithm:
In Example 4.44
a r q r qb a
b a b a
− = = ⇒ + = ,
= : squares perfect being divisors positive
number the 11 7 5 3 2 000 , 848 , 338 , 29
3 3 5 8
⎡ ⎤⎡ ⎤⎡ ⎤⎡ ⎤⎡ ⎤
+ + + + +
⋅ ⋅ ⋅ = = ⋅ ⋅ ⋅ ⋅ =
e e e
p p p n
k k
2 1 1 2 1 3 2 1 3 2 1 5 2 1 8
For 1 2 2 3 5 60 : squares perfect being divisors positive
number the
2 2 1 1
⎡ ⎤ ∏
+
+ +
k k k e
r p p p
i k
1
) 1 ( 1 1 hen : form la General : powers th perfect being divisors positive
number the
2 1
⎡ ⎤ ∏
= = =
+ = + =
i i i i i r
e e r
i
1 1 1
) 1 ( 1 , 1 when , : formula General
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
13
Ex 5.12
A sequence of real numbers r1, r2, r3 ,… can be thought of as a
function
all for ) ( where :
+ +
∈ = → Z R Z n r n f f
function
An integer sequence a0, a1, a2 ,… can be defined by means of a
function
. all for , ) ( where : ∈ = → Z R Z n r n f f
n
. all for , ) ( where : N Z N ∈ = → n a n g g
n
Let A, B be nonempty sets with |A| = m, |B| = n, A = {a1, a2 ,…, am}
and B = {b b b } a typical function and B = {b1, b2 ,…, bn}, a typical function can be described by {(a1, x1), (a2, x2), …, (am xm)} . We can select any of n elements of B for x1 and do the same for x2, ti i til S th
m
|B||A| f ti f A t B B A f → : continuing until xm. So, there are nm = |B||A| functions from A to B.
E.g., In Example 5.9, |A| = 3, |B| = 4, there are 43 functions from
A to B, and 34=81 functions from B to A.
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
14
Definition 5.5: A function is called one-to-one (injective),
if each element of B appears at most once as the image of an l t f A
B A f → :
element of A.
If is one-to-one, with A, B finite, we must have
|A| < |B|.
B A f → :
|A| |B|.
1 2 1 2 , 1
) ( ) ( , all for if
and if
is : a a a f a f A a a B A f = ⇒ = ∈ →
Ex 5.13 :
all for , 7 3 ) ( where : function he Consider t x x x f f ∈ + = → R R R t i 3 3 7 3 7 3 ) ( ) ( , all for Then
2 1 2 1 2 1 2 1 2 1
f x x x x x x x f x f x x = ⇒ = ⇒ + = + ⇒ = ∈R
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
15
is so f
Ex 5.13
for , ) ( where : that Suppose
4
∈ − = → x x x x g g R R R ) 1 but ) 1 ( ) ( (
not is so 1 1 ) 1 ( and ) (
4 4
≠ = = − = = − = g g g g g Q
Ex 5.14
from function
to
a is )} 4 3 ( ) 3 2 ( ) 1 1 {( } 5 , 4 , 3 , 2 , 1 { }, 3 2 1 { = = = B A f B , , A ) 3 2 but ) 3 ( ) 2 ( (
not is but , to from function a is )} 3 , 3 ( ), 3 , 2 ( ), 1 , 1 {( to from function
a is )} 4 , 3 ( ), 3 , 2 ( ), 1 , 1 {( ≠ = = = g g B A g B A f Q
215 relations from A to B, 53 functions how many functions are one-to-one?
) 3 2 but ) 3 ( ) 2 ( ( ≠ = g g Q
5*4*3=60
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
16
y
5 4 3 60
A B
A B A n m b , ,b b B a , ,a a A
mn n m
f f i b) to from realtions 2 a) are there , and }, ..., { }, ..., {
2 1 2 1
≤ = = B A m n n n n n,m P A B P B A n
m
to from functions
) 1 ( ) 2 )( 1 ( ) ( ) , ( c) to from functions b) + − ⋅ ⋅ ⋅ − − = =
} some for ), ( | { ) ( then , and : If
1 1 1
A a a f b B b A f A A B A f ∈ = ∈ = ⊆ → . under
image the called is ) ( and
1 1
f A A f
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
17
Ex 5.15 :
} 5 4 3 2 { } 3 2 { } 3 2 1 { } 2 1 { } 1 { )} , 5 ( ), , 4 ( ), , 3 ( ), , 2 ( , ) 1 {( }, , { }, 5 , 4 , 3 2 1 { A A A A A y y x x ,w f z w,x,y B , , A = = = = = = = = } { )} 1 ( { }} 1 { | ) ( { } | ) ( { ) ( under images ing Correspond } 5 , 4 , 3 2 { }, 3 2 { }, 3 2 1 { }, 2 1 { }, 1 {
1 1 5 4 3 2 1
w f a a f A a a f A f f , A , A , , A , A A = = ∈ = ∈ = = = = = = } { ) ( and } { ) ( } , { )} 3 ( ), 2 ( ), 1 ( { }} 3 , 2 , 1 { | ) ( { } | ) ( { ) ( } , { )} 2 ( ), 1 ( { }} 2 , 1 { | ) ( { } | ) ( { ) (
3 3 2 2
y x A f x A f x w f f f a a f A a a f A f x w f f a a f A a a f A f = = ∈ = ∈ = = = ∈ = ∈ =
Ex 5.16 :
} , { ) ( and } { ) (
5 4
y x A f x A f = =
). , [
range the ) ( then , ) ( and : If (a)
2
+∞ = = = → R R R g g x x g g } | 3 { ) ( is under
image the , } { } | ) , {( for is codomain the , is
domain the , 3 2 ) , ( and : (b) ]. 4 , [ ) ( ] 1 , 2 [ and }, , 16 , 9 , 4 , 1 , { ) ( is under
image The
1 1 1
1 1 + + +
∈ = × ⊆ × = ∈ = × + = → × = ⇒ − = ⋅ ⋅ ⋅ = Ζ Z Z Ζ Ζ Z Z Z Z Z Z Z n n A h h A n n A h y x y x h h A g A Z g g
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
18
1 1 1
Th i h L A A A B A f
) ( ) ( ) ( (b) ) ( ) ( ) ( (a) Then . , with , : Let
2 1 2 1 2 1
A f A f A A f A f A f A A f A A A B A f ∩ ⊆ ∩ ∪ = ∪ ⊆ →
Pick up A1∩A2 = φ
D fi iti 5 7
is when ) ( ) ( ) ( (c) ) ( ) ( ) ( (b)
2 1 2 1 2 1 2 1
f A f A f A A f A f A f A A f ∩ = ∩ ∩ ⊆ ∩
i i h ll d i | h d f f
. 1 1 1 1 1 1
all for ) ( ) ( | if to
n restrictio the called is : | then , and , : Let A a a f a f A f B A f A A B A f
A A
∈ = → ⊆ →
. , 1 1 1
to
extension an call then we all for ) ( ) ( and : If . : and Let A f g A a a f a g B A g B A f A A ∈ = → → ⊆
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
19
Ex 5.18 :
: , : } { }, 5 4 3 2 1 { }, { Let
1 1
B A g B A f w,y,z A , , , , B w,x,y,z A → → = = = . to from extend to ways 5 are There . to from
extension an is and |
1 1 1
A A g A A g f f g
A
=
=>
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
20
Definition 5.9: A function is called onto (surjective) if
f(A) = B, i.e., for all there is at least one with f(a) = b
B A f → :
B b∈
b.
Ex 5.19 :
function.
an is ) ( with :
3
x x f f = → R R function
an is ) ( with ) [ :
not is ) ( with : function.
an is ) ( with :
2 2
h h x x g g x x f f +∞ → = → → R R R R R
Ex 5.20 :
function.
an is ) ( with ) , [ : x x h h = +∞ → R
not is 1 3 ) ( with : + = → x x f f Z Z function
an is 1 3 ) ( with : . function
an is 1 3 ) ( with :
not is 1 3 ) ( with : + = → + = → + = → x x h h x x g g x x f f R R Q Q Z Z
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
21
function.
an is 1 3 ) ( with : + = → x x h h R R
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
22
If f:A→B is injective then |B| ≥ |A|. If f:A→B is surjective then |A| ≥ |B|. If f:A→B is bijective then |A| = |B| If f:A→B is bijective then |A| |B|. This still makes sense for infinite sized sets…
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
23
For the finite sets A = {a a } and B = {b b } For the finite sets A = {a1,…,am} and B = {b1,…,bn}, how many functions f:A→B are there? Total number of all functions (trivial): |B||A| = nm. One-to-one functions (easy): |B| options for f(a1), |B|–1 options for f(a2),…, |B|–|A|+1 options for f(am). By the product rule total there are in total y e p oduc u e o a e e a e
n·(n–1)···(n–m+1) = n!/(n–m)! = P(n,m) injective functions. There are P(m,m) = m! bijections if |A|=|B|=m.
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
24
The question how many onto (surjective) functions there are from A =
{a1,…,am} and B = {b1,…,bn} is less easy.
A B
Observe:
If |A|<|B| then the number is 0.
A B
If |A|=|B| then the number is m!
For general m≥n For general m≥n …
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
25
Ex 5.21 :
)} 4 ( ) 3 ( ) 2 ( ) 1 {( )} 4 ( ) 3 ( ) 2 ( ) 1 {( }, { }, 4 3 2 1 { If f f x,y,z B , , , A = = } { ) (
not is )} 4 ( ) 3 ( ) 2 ( ) 1 {( .
from functions both are )} , 4 ( ), , 3 ( ), , 2 ( ), , 1 {( )}, , 4 ( ), , 3 ( ), , 2 ( ), , 1 {(
2 1
B y x A g y y x x g B A z y x x f y x y z f ≠ = = Q
Ex 5.22 :
. } , { ) ( ,
not is )} , 4 ( ), , 3 ( ), , 2 ( ), , 1 {( B y x A g y y x x g ≠ = = Q
f i ll h } { } { f A f A t f f ti t 6 2 2 2 | | th S function) constant the )}( 2 , ( ), 2 , ( ), 2 , {( )}, 1 , ( ), 1 , ( ), 1 , {( except
are : functions all then ,2}, 1 { z}, y, , { If
3 | | 2 1
B A B z y x f z y x f B A f B x A
A
= = → = = . to from functions
2 2 are there 2 | | and 2 | | if general, In . to from functions
6 2 2 2 | | are there So
3 | |
B A B m A B A B
m A
− = ≥ = = − = −
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
26
when m = 1?
Ex 5.23 :
B A B z w,x,y A to from functions 3 ,2,3} 1 { }, , { If
4
⇒ = =
B A A A B
not are that to from functions 2 2 3 {2,3} to from functions 2 {1,2} to from functions 2 : 2 size
subsets three g Considerin
2 3
4 4 4 4
⋅ = ⋅ ⇒ ⎪ ⎪ ⎨ ⎧ ⇒
A A )} 2 ( ) 2 ( ) 2 ( ) 2 ( { f nction constant e ists : {1 2} to from e.g., twice, repeated are functions some are there fact, In {1,3} to from functions 2 { }
2
4
⎧ ⎪ ⎩ ⎨
A z y x w A z y x w A {1,3} {2,3}, {1,2}, to from repeated are functions 1 1 3 )} 2 , ( ), 2 , ( ), 2 , ( ), 2 , ( { function constant exists : {2,3} to from )} 2 , ( ), 2 , ( ), 2 , ( ), 2 , ( { function constant exists : {1,2} to from
1 3
4 4
⋅ = ⋅ ⇒ ⎩ ⎨ ⎧
B A B m A B A
m m m
to from functions
3 3 | | , 3 | | If to from functions
36 3 some are there
1 1 3 2 2 3 3 3 1 1 3 2 2 3 3 3 1
4 4 4
+ − ⇒ = ≥ = = + − ∴
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
27
1 2 3
General formula: |A| = m, |B| = n, there are
) 1 ( ) 1 (
1 2
1 2 ) 2 ( ) 1 (
m n m n m m m
n n n n n n n n
⎞ ⎜ ⎛ − + ⎞ ⎜ ⎛ − + ⋅ ⋅ ⋅ − ⎞ ⎜ ⎛ + ⎞ ⎜ ⎛ − ⎞ ⎜ ⎛
− −
− −
) 1 ( ) 1 ( ) 1 ( ) 1 (
1
) ( ) ( 1 1 2 2 ) 2 ( 2 ) 1 ( 1
n k m k n k m k
k n k n n k n k n n n n n n n n
∑ ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − = ∑ ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − = ⎠ ⎜ ⎝ + ⎠ ⎜ ⎝ + ⎠ ⎜ ⎝ + ⎠ ⎜ ⎝ ⎠ ⎜ ⎝
= − =
− − − − − − Ex 5.24 :
. to from functions
B A ⎠ ⎝ ⎠ ⎝
} { d } 6 4 3 2 1 { A } , , , { and } 7 , 6 , 5 , 4 , 3 , 2 , 1 { Let
7 7 7 7
1 1 4 2 2 4 3 3 4 4 4 4
z y x w B A ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ + ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ = = 8400 ) 1 ( ) 1 (
4 7 3 7
) 4 ( 4 4 ) 4 ( 4 4
k k k k
k k k k
= ∑ ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − = ∑ ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − = ⎠ ⎝ ⎠ ⎝ ⎠ ⎝ ⎠ ⎝
= =
− − − −
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
28
. to from functions
B A
has four additional floors, and they all get on an elevator. What is the probability that the elevator must stop at every floor in order to let probability that the elevator must stop at every floor in order to let passengers off?
4 3 2
functions
number total the as same the is number the 384 , 16 4 : space sample (i)
7 =
2 1
4 | | 7 | | where : functions
number total the
answer the also is floor every at stop must elevator t the number tha the (ii) 4 | | , 7 | | where : → = = → B A B A f B A B A f
5 5127 y probabilit the 8400 4 | | , 7 | | where : functions
number total the
8400 1 1 4 2 2 4 3 3 4 4 4 4
7 7 7 7
> = = ∴ = − + − = = → B A B A f
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
29
5 . 5127 . y probabilit the
16384
> = = ∴
Ex 5.25 : At the CH company, Joan, the supervisor, has a secretary,
Teresa, and three other administrative assistants. If seven accounts must be processed in how many ways can Joan assigns the accounts so that be processed, in how many ways can Joan assigns the accounts so that each assistant works on at least one account and Teresa’s work includes the most expensive account?
Solution
3 | | , 6 | | where : functions
number the account expensive most
woks Teresa (i) : subcases disjoint wo Consider t = = → B A B A f account expensive most just the than more
woks Teresa (ii) 540 ) 1 (
3 6
) 3 ( 3 3
= ∑ ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ −
=
− −
k k
k k
1560 ) 1 ( 4 | | , 6 | | where : functions
number the p j ( )
4 6
) 4 ( 4 4
= ∑ ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − = = →
=
− −
k k
k k
D C D C f
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
30
2100 1560 540 = + ∴ ⎠ ⎝
Difference with 8400?
Ex 5.26 : How many ways to distribute four distinct objects into three
distinguishable containers with no container empty? How many ways to distribute four distinct objects into three identical containers with no to distribute four distinct objects into three identical containers with no container empty?
Solution
f i f b h i bl h k (i) B A f
i di i d h ll i f ll i h C id (ii) 36 ) 1 ( , 3 | | , 4 | | where : functions
number the counting as problem the take (i)
) 3 ( 3 3
3 4 =
∑ − = = →
=
− −
B A B A f
k k
k k
} { } { } { (4) } { } { } { (3) } { } { } { (2) } { } { } { (1) containers distinct under the s collection following he Consider t (ii)
3 2 1 3 2 1 3 2 1 3 2 1
a,b d c d a,b c c d a,b d c a,b same. the are
distributi 3! 6 these identical, are containers the if Now } { } { } { (6) } { } { } { (5) } { } { } { (4) } { } { } { (3)
3 2 1 3 2 1 3 2 1 3 2 1
= a,b c d c a,b d a,b d c d a,b c
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
31
. ways 6 are there
! 3 36 =
∴
General formulas:
containers numbered into
distinct distribute to ways ) 1 (
) (
n m
n m k
k n n
∑
−
⎠ ⎞ ⎜ ⎝ ⎛ − . containers identical into
distinct distribute to ways ) 1 ( . containers numbered into
distinct distribute to ways ) 1 (
) ( ! 1 ) (
n m n m
n k m k k
k n k n n n k n k n
∑ ∑
= =
− − −
⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − ⎠ ⎜ ⎝
Note that for |A|=m ≥ n = |B|, there n!*S(m, n) onto functions from A
to B
kind. second the
number Stirling a called is and ) , ( by donated be will This n m S
to B.
Ex 5.27: Ex 5.27:
allowed. containers empty with containers identical into
distinct distribute to ways possible
number the is ) , ( , For
1
n m i m S n m
n i∑
≥
=
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
32
p y
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
33
if m = 4 , n = 3
The number of ways of partitioning a set of n
Example: The set {1,2,3} can be partitioned
into three subsets in one way(S(3 3)):{{1} {2} {3}} ; into three subsets in one way(S(3,3)):{{1},{2},{3}} ; into two subsets in three ways(S(3,2)): {{1},{2,3}} ,
{{1,3},{2}} , and {{1,2},{3}} ; {{ , },{ }} , {{ , },{ }} ;
into one subset in one way(S(3,1)): {{1,2,3}} .
The Stirling numbers of the second kind for three
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
34
Since a set of n elements can only be partitioned in a
single way into 1 and n subsets single way into 1 and n subsets S(n,1)=S(n,n)=1
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
35
n k m k
=
k
n k
n
=
! ( 1) ( )
k n k
n n n k n k
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
36
Theorem 5.3:
he in which t ways
number the counts ) 1 ( Then } { Let n m S a a a a A + =
) , ( ) 1 , ( ) , 1 ( then , 1 Let n m S n n m S n m S n m ⋅ + − = + > ≥
containers identical 1 among
ng distributi
ways ) 1 , ( (i) (1) empty. left container no with , containers identical among d distribute be can
he in which t ways
number the counts ) , 1 ( Then }. { Let
, , 2 , 1 1 , , , 2 , 1
n a a a n m S n A n m S a a a a A
m m m
− − + =
⋅ ⋅ ⋅ + ⋅ ⋅ ⋅
containers identical among
ng distributi
ways ) , ( (i) (2) ways ) 1 , ( container th) ( empty remaining in the placing
selection 1 (ii)
, , 2 , 1 1
n a a a n m S n m S n a
m m
− ⇒
⋅ ⋅ ⋅ +
) ( ) 1 ( ) 1 ( Totally ways ) , ( containers identical in the placing
selection (ii) g j g y ) , ( ( ) ( )
1 2 1
n m nS n m S n m S n m nS n a n
m m
+ + ∴ ⇒
+
Example:
) , ( ) 1 , ( ) , 1 ( Totally, n m nS n m S n m S + − = + ∴
) 3 7 ( 3 ) 2 7 ( 301 3 63 966 ) 3 1 7 ( 3 , 7 S S S n m + + + ⇒ = =
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
37
) 3 , 7 ( 3 ) 2 , 7 ( 301 3 63 966 ) 3 , 1 7 ( S S S + = ⋅ + = = + ⇒
1
} { } { Let b b b b B a a a a A = =
) , ( ! ) 1 , ( )! 1 ( )] , 1 ( ! [
1
n m S n n m S n n m S n
n
+ − − = +
( )
) { ( }) { { ( ) }. { }, { Let
} : functions
number the } : functions
number the : functions
number the ( 1
1 1 , 1 , , 2 , 1 1 , , , 2 , 1
B A b B A B A b b b b B a a a a A
m n m n n m m
a g a f h n
→ − + − → − = → = =
+ + − ⋅ ⋅ ⋅ + ⋅ ⋅ ⋅
Ex 5.28 :
) { ( }) { { (
1 1 m n m + +
13 11 7 5 3 2 30,030 integer positive he Consider t × × × × × = ) 13 )( 11 7 5 3 2 ( 13 310 2 (iii) ) 13 3 )( 7 5 )( 11 2 ( 39 35 2 2 (v) ) 13 7 3 )( 11 5 2 ( 273 1 1 (ii) ) 13 5 )( 11 3 )( 7 2 ( 65 33 4 1 (iv) ) 13 11 7 )( 5 3 2 ( 1001 30 (i) , g p × × × = × × × × × × = × × × × = × × × × × × = × factors. integer three into 30,030 factor to ways 90 ) 3 , 6 ( . where as 30,030 factor to ways 31 ) 2 , 6 ( ) 13 )( 11 7 5 3 2 ( 13 310 2 (iii) = ∗ ∈ = ∗ × × × × = ×
+
S m,n mn S Z
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
38
g , y ) , (
is called a binary operation on A. If , then the binary operation is said to be closed (on A)
B A A f → × : A B ⊆
said to be closed (on A).
A A g → :
Ex 5.29:
i bi l d i ) ( b d fi d f i Th ( ) Z Z Z Z b b f f 4 7 3 ) 7 3 ( but 3 7 that find we example for closed not is it but
binary a is then , ) , ( here function w the is : If (b) .
binary closed a is , ) , ( by defined , : function The (a)
+ + + + +
∉ = = ∈ − = → × − = → × Z Z Z Z Z Z Z Z Z Z g g b a b a g g b a b a f f .
unary a is ) ( by defined : function The (c) . 4 7 3 ) 7 , 3 ( but , 3,7 that find we example, for closed. not is it but
1 + + +
= → ∉ − = − = ∈ R R R Z Z
a
a h h g
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
39
and universe a be Let U A B U ⊆
Ex 5.30 :
) (
binary closed a is then , ) , ( by defined is ) ( ) ( ) ( : If (a) and universe, a be Let U P f B A B A f U P U P U P f U A,B U ∪ = → × ⊆
) (
unary a is ) ( by defined is ) ( ) ( : function The (b) ) ( p y U P A A g U P U P g f = →
, ) , ( all for ) , ( ) , ( if e commutativ be to said is (a) .
binary a is i.e., , : Let A A b a a b f b a f f A f B A A f × ∈ = → × )). , ( , ( ) ) ( ( , , , all if e associativ be to said is , When (b) c b f a f ,c a,b f f A c b a f A B = ∈ ⊆
Ex 5.31 :
neither 5 29) (Example ) ( (b) . e associativ and e commutativ is 5.30) (Example ) , ( (a) b a a b f B A B A f = ∪ =
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
40
neither. 5.29) (Example ) ( (b) b a a,b f − =
f:Z ×
f((x,y),z)=(x+y-3xy)+z-3(x+y-3xy)z
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
41
Ex 5.33 :
: functions 4 16 | | then }, { If (1)
16
A A A f A A a,b,c,d A → × ⇒ = × = } { )} ( ) ( ) ( ) {( (i) .
) , (
binary closed e commutativ
number the Determine 2) ( .
binary closed 4
16
d b d d b b A y x g A → ⇒ available is pairs 10 6 4 totally } , , , { pairs
two
sets 6 ), , ( ) , ( but , (ii) } , , , { )} , ( ), , ( ), , ( ), , {( , (i)
2 4 16
d c b a x y g y x g y x d c b a d d c c b b a a y x + ∴ → = = ≠ → =
−
.
) , (
binary closed e commutativ 4 available is pairs 10 6 4 totally,
10
A y x g ⇒ = + ∴
. , ) , ( ) , ( if for identity an called is element An .
binary a be : Let A a a a x f x a f f A x A B A A f ∈ ∀ = = ∈ → ×
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
42
Ex 5.34 :
) ( where : (a) b a b a f f + = → × Z Z Z . ) , ( where , : (b) . , ) , ( ) , ( identity, an is . ) , ( where , : (a) b a b a f f a a a f a f b a b a f f − = → × ∀ = = ⇒ + = → × Q Z Z Z Z Z Z }. , min{ ) , ( where }, 7 , 6 , 5 , 4 , 3 , 2 , 1 { , : (c) identity no . ) , ( where , : (b) b a b a g A A A A g b a b a f f = = → × ⇒ → Z Z Z . ), , 7 ( } , 7 min{ } 7 , min{ ) 7 , ( identity, an is 7 } , { ) , ( }, , , , , , , { , ( ) a a g a a a a g g g ∀ = = = = ⇒ Q
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
43
P f unique. is identity then that , identity an has If
binary a be : Let f B A A f → ×
2 2 1 1 2 1
) ( ) ( ), , ( ) , ( , let , identity
than more has If A a a x f a x a f A a a x f a x a f A x x f ∈ ∀ = = ∈ ∀ = = ∈
1 2 1 2 2 2 1 1 2 2
) , ( identity is For ) , ( identity is For ), , ( ) , ( x x x f x x x x f x A a a x f a x a f = ⇒ = ⇒ ∈ ∀
2 1
x x = ∴
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
44
Ex 5.35: If A={x, a, b, c, d}, how many closed
Let f: A x AA with f(x, y)=y=f(y, x) for all y A
516 closed binary operations on A where x is the identity Of these 510 = 54*5(4*4-4)/2 are commutative. Of these 5 5 5 are commutative. 517 closed binary operations on A that have an identity Of these 511 are commutative
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
45
coordinate second
projection the called is ) ( by defined : . coordinate first
projection the called is , ) , ( by defined , : , b b a B D a b a A D B A D
B B A A
= → = → × ⊆ π π π π
Ex 5.36 :
. coordinate second
projection the called is , ) , ( by defined , : b b a B D
B B
= → π π
D B A )} 4 ( ) 1 ( ) 3 ( ) 2 ( ) 1 {( } 4 3 2 1 { } { If y y y x x x x A D y y x x x D B y x w A
A A A A A A
⎩ ⎨ ⎧ = = = = = → = = = ) 4 , ( ) 1 , ( ) 3 , ( ) 2 , ( ) 1 , ( satisfies : projection The )} 4 , ( ), 1 , ( ), 3 , ( ), 2 , ( ), 1 , {( }, 4 , 3 , 2 , 1 { }, , , { If π π π π π π y x A y x D y y y
B B A A A A
⎪ ⎧ = = ≠ = ⎩ 1 ) 1 , ( ) 1 , ( } , { ) (
not is ) 4 , ( ) 1 , ( π π π π π π Q y x x B D
B B B B
⎪ ⎪ ⎩ ⎪ ⎪ ⎨ = = = → 4 ) 4 , ( 3 ) 3 , ( 2 ) 2 , ( satisfies : projection The π π π π
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
46
B D y
B B B
= = ⎪ ⎩ } 4 , 3 , 2 , 1 { ) (
is 4 ) 4 , ( π π π Q
Ex 5.37 :
} | ) , {( where , If
2
x y y x D B A D B A = = × ⊆ = = R ) [ ) ( projection The
is ) ( projection The
A A
D D π π π ⊂ ∞ ∴ = R R Q Q
not is ) , [ ) ( projection The
B B D
π π ∴ ⊂ ∞ = R Q
: then If , with } , , 2 , 1 { } , , , { sets, be , , , Let
2 1 2 1 2 1
A A A D A A A A D n m i i i n i i i A A A
n
m m n
π × × × → = × × × ⊆ < < ⋅ ⋅ ⋅ < < ⋅ ⋅ ⋅ ⊆ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
×
. an is (D) in element an ; called are
elements The s coordinate th , th, th,
projection the is ) ( ) , , , ( : then , If
2 1 2 1 2 1
2 1 2 1
1
m-tuples tuples n D i i i D a a a a a a A A A D A A A A D
i
m m m
i i i n i i i n
π π π ⋅ ⋅ ⋅ × ⋅ ⋅ ⋅ × × = ⋅ ⋅ ⋅ × ⋅ ⋅ ⋅ × × → = × ⋅ ⋅ ⋅ × × ⊆
=
×
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
47
( ) ; p p
bases, a standard technique for organizing and describing large quantities
y g p g y
Ex 5.38 : At a certain university the following sets are related for
purposes of registration: A1 = the set of course numbers for courses offered in mathematics. A1 the set of course numbers for courses offered in mathematics. A2 = the set of course titles offered in mathematics. A3 = the set of mathematics faculty. A4 = the set of letters of the alphabet.
4
p
4 3 2 1
A A A A D × × × ⊆
Course Number Course Title Professor Section Letter MA 111 MA 111 MA 112 Calculus I Calculus I Calculus II
A B A
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
48
MA 113 Calculus III
A
table D is said have degree 4.
tables.
4 3 1
A A A × ×
2 1
A A ×
Course Number Professor Section Letter MA 111
A Course Number Course Title MA 111 Calculus I MA 111 MA 112 MA 113
B A A MA 111 MA 112 MA 113 Calculus I Calculus II Calculus III
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
49
then at least one pigeonhole has two or more pigeons roosting in it.
most one pigeon roosting in it, so a total of at most n (< m) pigeons.
Ex 5.39 : An office employs 13 clerks, so at least two of them must have
birthdays during the same month.
Ex 5.41 : Wilma operates a computer with a magnetic tape drive. One
day she is given a tape that contains 500 000 “word” of four or fewer day she is given a tape that contains 500,000 word of four or fewer lowercase letters. Can it be that the 500,000 words are all distinct?
tape
repeated is word
least at 254 , 475 26 26 26 26
2 3 4
∴ = + + +
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
50
tape.
repeated is word
least at ∴
Ex 5.42 : Let , where |S| = 37. Then S contains two elements that
have the same remainder upon division by 36.
Hi t 36 + 0 ≤ < 36
+
⊂ Z S
Ex 5.44 : Any subset of size 6 from the set S = {1,2,3,…,9} must
contain two elements whose sum is 10.
Ex 5.45 : Triangle ACE is equilateral with AC = 1. If five points are
l t d f th i t i f th t i l th t l t t h selected from the interior of the triangle, there are at least two whose distance apart is less than ½.
C D 1
A B D F E 2 3 4
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
51
A F E
Ex 5 46 Let S be a set of six (distinct) positive integers Ex 5.46 Let S be a set of six (distinct) positive integers
1 9 10 14 69 S
1 9 10 14 69 ≤ ≤ + + + = S A L
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
52
Ex 5.47 : Let with m odd. Prove that there exists a positive integer
n such that m divides 2n - 1
P f
+
∈Z m
1 1 ith i t i i l i h l B th , 1 2 , 1 2 , , 1 2 , 1 2 integers positive 1 he Consider t
1 2 1
≤ ≤ − − ⋅ ⋅ ⋅ − − +
+ + m m
t t m Z by division upon remainder same the have 1 2 and 1 2 where , 1 1 with , , exists principle, pigeonhole By the − − + ≤ < ≤ ∈
+ s t t s t s
m m t s t s Z 1 ) , 2 gcd(
is and ) 1 2 ( 2 2 2 ) ( 2 2 1 2 and 1 2
1 2 2 1
= ∴ − = − − = − ⇒ + = − + = − ∴
− s s t s s t s t t s
m m m q q r m q r m q Q 1 2 | − ∴
−s t
m
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
53
≤ ≤ ≤ < < < ≤ L
1 2 28
For 1 28, let be the total number of sets played from the start to the end of -th day. Then 1 40,
i
i x i x x x + < + < < + ≤ + = L
1 2 28
15 15 15 40 15
integers, since their maximum is 55, two of x x x them must be ≤ ≤ = + the same. Hence there exist 1 < 28 with 15. From day + 1 to the end of day , exactly 15 sets are played.
i j
j i x x j i
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
54
y y , y p y j
numbers contains a decreasing or increasing subsequence of n + 1.
E l
+
∈ Z n
1.
The sequence 6, 5, 8, 3, 7 (length 5, n=2) contains the decreasing subsequence 6, 5, 3 (length 3)
2.
The sequence 11, 8, 7, 1, 9, 6, 5, 10, 3, 12 (length 10, n=3) contains the increasing subsequence 8, 9, 10, 12 (length 4)
n k n a a a 1 1 numbers, real distinct 1
sequence a be , , , Let
2 2 2 1
2
+ ≤ ≤ + ⋅ ⋅ ⋅
k k k k n
a y a x n k n a a a with ends that e subsequenc increasing a
length maximum the with ends that e subsequenc decreasing a
length maximum the 1 1 numbers, real distinct 1
sequence a be , , , Let
1 2 1
2
= = + ≤ ≤ +
+
k 1 2 3 4 5 6 7 8 9 10 ak xk 11 8 7 1 9 6 5 10 3 12 1 2 3 4 2 4 5 2 6 1
Prove one of xk or yk ≥ n+1
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
55 k
yk 1 1 1 1 2 2 2 3 2 4
) ( pairs distinct most at . 1 , 1 then 1, length
e subsequenc increasing
g descreasin no If
2
∴ ≤ ≤ ≤ ≤ + y x n n y n x n
k k
principle) e (pigeonhol let , ), , ( ), , ( pairs identical two numbers) real distinct 1
sequence (a pairs 1 have we But, ) , ( pairs distinct most at
2 2
< ≠ ⇒ + + ∴ j i j i y x y x n n y x n
j j i i k k
) , ( ) , ( pairs two . then if while ; then if fact, In
2
≠ ⇒ > < < < y x y x x x a a y y a a
j j i i i j i j j i j i
. 1 1 some for 1
1 that us ion tells contradict This
2 +
≤ ≤ + + = + = n k n n y n x
k k
k 1 2 3 4 5 6 7 8 9 10
n2+1
k 1 2 3 4 5 6 7 8 9 10 ak xk 11 8 7 1 9 6 5 10 3 12 1 2 3 4 2 4 5 2 6 1 1 1 1 1 2 2 2 3 2 4
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
56
yk 1 1 1 1 2 2 2 3 2 4
E 5 50 A
{1 2 3 4} B { } f {(1 ) (2 ) (3 ) (4
, : B A f →
z)}, g = {(w, 1), (x, 2), (y, 3), (z, 4)} are one-to-one correspondences from A (on)to B / from B (on)to A.
A all for ) ( 1 by defined : 1 : function Identity ∈ = → a a a A A
A all for ) ( 1 by defined , : 1 : function Identity ∈ = → a a a A A
A A
A a a g a f g f g f B A f ∈ = = → all for ) ( ) ( if ) ( equal are , , : g , g f g f g f f ) ( ) ( ) ( q , , g ,
Denoted 1A or idA Identity Matrix In
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
57
y
n
⎡ ⎤
ll f ) ( if , ) ( x x f f ⎨ ⎧ ∈ R Z Z R
⎣ ⎦ ⎡ ⎤
. equal are and that show all for ) ( , if , 1 ) ( , : g , g f x x x g x x x f f ∈ = ⎩ ⎨ − ∈ + = → R Z R Z R
Proof
⎡ ⎤
) ( ) ( then , If q x g x x x f x g f = = = ∈Z
⎣ ⎦ ⎡ ⎤
) ( 1 1 ) ( then , 1 and where write , If x g x n x x f r n r n x x = = + = + = < < ∈ + = − ∈ Z Z R
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
58
, : then , : and : If C A f g C B g B A f → → →
all for )), ( ( ) )( ( by A a a f g a f g ∈ =
5. ) ( , ) ( , : , : Let
2
+ = = → → x x g x x f g f R R R R e commutativ not 5. 2 10 ) 5 ( ) 5 ( )) ( ( ) )( ( whereas 5 ) ( )) ( ( ) )( ( Then
2 2 2 2
∴ + + = + = + = = + = = = x x x x f x g f x g f x x g x f g x f g
Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
59
e commutativ not ∴
d L C B B A f
is then
are and If b)
is then
are and If a) . : and : Let f g g f f g g f C B g B A f
→
is then
are and If b) f g g f
)( ( ) )( ( with , Let a)
2 1 2 1
a f g a f g A a a
∈
to
is
is (
is )( ( ) ( ) ) ( ( ) ) ( (
2 1 2 1 2 1
f g f a a g a f a f a f g a f g
Q ∴ = ⇒ = ⇒ = ⇒ ) ( with exists
is let , : For b)
is z y g B y g C z C A f g f g Q
∈ ∴ ∈ → ∴ t i ) ( )) ( ( ) ( ) ( with exists
is f x f g x f g y g z y x f A x f
= = = ∴ = ∈ ∴
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
60
is f g o ∴
: and : : Let D C h C B g B A f → → →
ve) (associati ). ( ) ( then , : and , : , : Let f g h f g h D C h C B g B A f
→ → →
f g h
( g h o
A
f
A B C D
f g o
) ( f h
f g o
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
61
) ( f g h
). ( , for and , define we , : If
1 1 n n
f f f n f f A A f
∈ = →
+ +
Z
)} 2 , 4 ( ), 2 , 3 ( ), 2 , 2 ( ), 2 , 1 {( )}, 1 , 4 ( ), 2 , 3 ( ), 2 , 2 ( ), 2 , 1 {( )} 3 , 4 ( ), 1 , 3 ( ), 2 , 2 ( ), 2 , 1 {( and , : }, 4 , 3 , 2 , 1 {
2 3 2
f f f f f f f A A f A = = = = = → =
? , are What )} 2 , 4 ( ), 2 , 3 ( ), 2 , 2 ( ), 2 , 1 {( )}, 1 , 4 ( ), 2 , 3 ( ), 2 , 2 ( ), 2 , 1 {(
5 4 f
f f f f f f f
}. ) , ( | ) , {( by denoted to from relation the is , denoted ,
converse then the , to from relation a is if , , sets For ℜ ∈ = ℜ ℜ ℜ ℜ b a a b A B B A B A
c c
c c c
f f f f y x w f y x w f B A f B A 1 1 )} 3 ( ) 2 ( ) 1 {( )} , 3 ( ), , 2 ( ), , 1 {( and , : y}, x, {w, }, 3 , 2 , 1 { = = ⇒ = ⇒ = → = =
Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
62
B A
f f f f y x w f 1 , 1 )} 3 , ( ), 2 , ( ), 1 , {( = = ⇒ = ⇒
1 and 1 such that : function is there if , invertible be to said is then , : If g f f g A B g f B A f = = → →
) 5 2 ( )) ( ( ) )( ( Then ) ( , 5 2 ) ( with : , Let
5 ) 5 2 ( 2 5
x x g x f g x f g x g x x f g f
x x
R R = = + = = = + = →
− + −
1 and 1 such that , :
B A
g f f g A B g = = →
invertible both are and , 1 , 1 5 ) ( 2 ) ( )) ( ( ) )( ( ) 5 2 ( )) ( ( ) )( ( Then
2 5 2 5 2
g f f g g f x f x g f x g f x x g x f g x f g
x x R R
= = ∴ = + = = = +
− −
. unique is then , 1 and 1 satisfies : and invertible is : If g g f f g A B g B A f
B A
= = → →
then 1 and 1 with : function another is e then ther unique, not is If h f f h A B h g = = →
Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
63
. 1 ) ( ) ( 1 then , 1 and 1 g g g f h g f h h h h f f h
A B B A
= = = = = = =
and
is it invertible is : ⇔ → B A f
with : unique exists and , invertible is : that Assuming (1) A B g B A f → → 1 ) )( ( ) )( ( i e )) ( ( )) ( ( ) ( ) ( with , if :
(i) 1 , 1 q , g ( )
2 1 2 1 2 1
a a f g a f g a f g a f g a f g a f a f A a a g f f g g f
B A
∴ = ⇒ = ∈ = = Q
is )), ( ( ) )( ( ) ( 1 , 1 ) ( let :
(ii) , 1 ), )( ( ) )( ( i.e.,
2 1 2 1
f b g f b g f b b g f A b g B b a a f g a f g a f g
B B A
∴ = = = ∴ = ∈ ⇒ ∈ = ∴ = =
( where , ) ( by : define ) ( with each
is bijective is : Suppose (2) b a f a b g A B g b a f B b f B A f = = → = ∈ ∴ → Q 1 1 arise cannot situation this
is )) ( ) ( )( ( ) ( problem possible he consider t ) ( w e e , ) ( by : de e
2 1 2 1
g f f g f a f b a f b g a a b g b a f a b g g ∴ ∴ = = = ≠ = →
Q
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
64
invertible is 1 , 1 f g f f g
B A
∴ = = ∴
invertible not is ) ( by defined :
1 2 2 1 1
x x f f = → R R .
inverse the function the call We ) ( with invertible is ) ( by defined ) [0, ) [0, :
1 1 2 2 2
2
f f x x f x x f f
− −
∗ = = +∞ → +∞
)
inverse the is ( . ) ( and invertible is : then functions, invertible are : , : If
1 1 1 1
f f g f f g C A f g C B g B A f
− − − − =
→ → →
invertible is } | ) , {( by defined , : , , , For b mx y y x f f m b m + = = → ≠ ∈ R R R
. ) ( and
and
is it because
1 m b x
x f
− −
=
x x f e x f f ln ) ( invertible is ) ( by defined :
1 x
= = →
− +
R R
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
65
x x f e x f f ln ) ( , invertible is ) ( by defined : → R R
} ) ( | { ) ( then , and : If
1 1 1 1 1
B x f A x B f B B B A f
−
∈ ∈ = ⊆ →
. under
preimage the called is ) (
1 1 1
f B B f −
(f is not necessary invertible.)
are results following then the )}, 9 , 6 ( ), 9 , 5 ( ), 6 , 4 ( ), 8 , 3 ( ), 7 , 2 ( ), 7 , 1 {( ith : If 0}. {6,7,8,9,1 }, 6 , 5 , 4 , 3 , 2 , 1 { Let f w B A f B A = → = = | | 2 1 | ) ( | , }) 10 ({ , 8 ) 3 ( }( 3 { ) ( }, 10 , 8 { For e) | | 2 | ) ( | }, 4 , 3 { ) ( , } 8 , 6 { For a) g )}, , ( ), , ( ), , ( ), , ( ), , ( ), , {(
5 5 1 1 5 1 5 1 1 1 1 1 1
B B f f f B f B B B f B f B B f = < = = = = = = = = ⊆ =
− − − − −
φ Q
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
66
, 5 3 ) ( b d fi d i ⎨ ⎧ > − x x f f R R
? ]) 5 , 5 ([ is What , 1 3 ) ( by defined is :
1 −
⎩ ⎨ ≤ + − = →
−
f x x x f f R R
: (i) } 5 ) ( 5 | { ]} 5 , 5 [ ) ( | { ]) 5 , 5 ([
1
> ≤ ≤ − = − ∈ = −
−
x x f x x f x f 5 5 3 5 ≤ − ≤ − x : (i) > x 3 / 10 , 3 / 10 10 3 5 5 3 5 ≤ < ∴ ≤ ≤ ≤ ≤ ≤ ≤ x x x x : (ii) ≤ x
4 3 6 5 1 3 5 ≤ − ≤ − ≤ + − ≤ − x x 3 / 4 , 2 3 / 4 ≤ ≤ − ∴ ≤ ≤ − x x ] 3 / 10 , 3 / 4 [ } 3 / 10
3 / 4 | { ]) 5 , 5 ([
1
− = ≤ < ≤ ≤ − = − ∴
−
x x x f
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
67
) ( ) ( ( ) ) ( ) ( ) ( (b) ) ( ) ( ) ( (a) then , , and : If
1 1 1 1 1 2 1 1 1 2 1 1 2 1
B f B f B f B f B B f B f B f B B f B B B B A f
− − − − − − − −
∩ = ∩ ⊆ →
) ( ) ( , If (b)
2 1 2 1 1
B B a f B B f a A a
−
∪ ∈ ⇔ ∪ ∈ ∈
. ) ( ) ( (c) ) ( ) ( ) ( (b)
1 1 1 1 2 1 1 1 2 1 1
B f B f B f B f B B f
− − − − −
= ∪ = ∪
) ( ) ( ) (
) ( ) (
) ( ) ( ) ( , ( )
2 1 1 1 2 1 1 1 2 1 2 1 2 1
B f B f a B f a B f a B a f B a f f f
− − − −
∪ ∈ ⇔ ∈ ∈ ⇔ ∈ ∈ ⇔
i l t t t t f ll i Th th . | | | | where , and sets finite for : Let B A B A B A f = → . invertible is (c)
is (b)
is (a) : equivalent are statements following Then the f f f
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
68
. ) ( ) 1 ( !
n n k n n k
k n n − ∑ − =
−
k=
and functions
to
are there | | | | ∴ n! n B A Q
functions
) ( ) 1 ( and functions,
are there | | | | ∑ ∴ = =
= − k n n k k n n k
n-k
n B A Q
. 1 ) ( ) 1 ( ) , ( Thus, ) ( ) 1 ( (b) and 5.11(a) Theorem Using
! 1
= ∑ = ∑ = ⇒
= − = − n n k k n n k n n n k k n n k
n-k
n S n-k
! n
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
69
A B A n m b , ,b b B a , ,a a A
m mn n m
t f f ti b) to from realtions 2 a) are there , and }, ..., { }, ..., {
2 1 2 1
≤ = = B A m n n n n n,m P B A n
m
to from functions
) 1 ( ) 2 )( 1 ( ) ( c) to from functions b) + − ⋅ ⋅ ⋅ − − =
. containers numbered into
distinct distribute to ways ) 1 ( : function
d)
) (
n m
n k m k
k n k n n
=
− −
−
. containers identical into
distinct distribute to ways ) 1 ( ) , ( : number Stirling e)
) ( ! 1
n m n m S
n k m k
k n k n n n ∑
=
− −
− = j
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
70
Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
71
p g g
id provides
specific instances of the problem
size
time-complexity function.
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
72
. where , all for | ) ( | | ) ( | such that and constants exist there if dominates say that We . : , Let k n k n g m n f k m f g g f ≥ ∈ ≤ ∈ ∈ →
+ + + +
Z Z R R Z
“Big-Oh” notation, we write
and domain with functions all
set the represents ) ( ".
Oh
"
"
" read is ) ( where ), ( g O g g g O g O f
+
∈ Z
. by dominated are that R codomain and domain with functions all
set the represents ) ( g g O Z
, 15 ) 3 ( ; 4 ) 2 ( , 10 ) 2 ( ; 1 ) 1 ( , 5 ) 1 ( : 4 1 (i) . for , ) ( , 5 ) ( by given be : , Let
2
f g f g f n n n n g n n f g f = = = = = ≤ ≤ ∈ = = →
+ +
Z R Z . for | ) ( | | ) ( | , 5 , 1 , 5 : 5 (ii) 16 ) 4 ( , 20 ) 4 ( ; 9 ) 3 (
2
k n n g m n f k m n n n g f f ≥ ≤ = = ∴ ≥ ≥ = = =
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
73
) ( and dominates g O f f g ∈ ∴
| (n) | 9 9 3 5 1 3 5 | 1 3 5 | | ) ( | . ) ( , 1 3 5 ) ( with : , Let
2 2 2 2 2 2 2 2
g n n n n n n n n n f n n g n n n f g f = = + + ≤ + + = + + = = + + = →
+
R Z
li i f f i d i
). (
) ( , 9 any for | ) ( | | ) ( | | (n) | 9 9 3 5 1 3 5 | 1 3 5 | | ) ( |
2
n O f g O f m n g m n f g n n n n n n n n n f ∈ ∈ ≥ ≤ ∴ + + ≤ + + + +
| | | ) ( | ) ( with : , Let
1 1 1 1 1 1 t t t t t t t t
a n a n a n a n f a n a n a n a n f g f + + ⋅ ⋅ ⋅ + + = + + ⋅ ⋅ ⋅ + + = →
− − − − +
R Z | | | | | | | | | | | | | | | | | | | ) ( |
1 1 1 1 1 1 1 1 t t t t t t t t t t t t t t
a n a n a n a a n a n a n a f + ⋅+ ⋅ ⋅ + + = + + ⋅ ⋅ ⋅ + + ≤
− − − −
) ( , 1 |, | | | | | | | Let |) | | | | | | | ( | | | | | | | |
1 1 1 1 1 1 t t t t t t t t t t t t
n n g k a a a a m n a a a a n a n a n a n a = = + + ⋅ ⋅ ⋅ + + = + + ⋅ ⋅ ⋅ + + = + ⋅+ ⋅ ⋅ + + ≤
− −
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
74
) ( |, ) ( | ) ( ) ( , 1 |, | | | | | | | Let
1 1 t t t
n O f n g m n f n n g k a a a a m ∈ ≤ ⇒ + + + +
−
) ( ) ( ) ( ) 1 ( ) ( . 2 1 ) ( by given be : Let (a)
2 1 2 1 1 +
∈ ∴ + + + ⋅ ⋅ ⋅ + + = → n O f n n n n n f n n f f R Z ) ( ) ( ) ( ) ( ) 1 2 )( 1 ( ) ( . 2 1 ) ( with : Let (b) ) ( , ) ( ) ( ) 1 ( ) (
3 1 2 1 3 1 1 2 2 2 2 1 2 1 2 1 +
+ ⋅ ⋅ ⋅ + + = → ∈ ∴ + = + ⋅ ⋅ = O n n g g n O f n n n n n f R Z 2 1 ) ( h . ) ( by defined is : If (c) ) ( , ) ( ) ( ) ( ) 1 2 )( 1 ( ) (
1 1 3 2 1 2 2 1 3 3 1 6 1 + = +
∑ = → ∈ ∴ + + = + + ⋅ ⋅ =
t t t t t t t t n i t
h i n h h n O g n n n n n n n g R Z ) ( , 2 1 ) ( then
1 1 + +
∈ ∴ = = + ⋅ ⋅ ⋅ + + ≤ + ⋅ ⋅ ⋅ + + =
t t t t t t t t t
n O h n nn n n n n n h
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
75
p
Big-Oh Form Name
Li ) ( c Logarithmi ) (log Constant ) 1 (
2
O n O O Quadratic ) ( log ) log ( Linear ) (
2 2 2
n O n n n n O n O Polynomial ) ( Cubic ) ( Quadratic ) (
3
n O n O n O
m
Factorial ) ! ( l Exponentia 1 ), ( y ) ( n O c c O
n
>
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
76
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
77
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
78
n3 ∈ Ω(n2) 2n ∈ Ω(nc) for every finite c∈R (log n)c ∈ O(n) for every finite c∈R n log n ∈ Ω(n) n log n ∈ Ω(n) 5n7 + 6n5 + 4 ∈ Θ(n7) 2log n ∈ Θ(n) 2
∈ Θ(n)
cn = 2(log c)n ∈ 2Θ(n) for every c>1 n log n ∈ O(n1+ε) for every ε>0, but not ε=0
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
79
The set O(n2) contains all functions f that do not grow faster than a quadratic polynomial. For cubic polynomials: O(n3). Hence: O(n) ⊂ O(n2) ⊂ O(n3) ⊂ O(n4) … ⊂ O(2n) How to express the set of all constant degree polynomials? How to express the set of all constant degree polynomials? Answer: nO(1) = O(n) ∪ O(n2) ∪ O(n3) … Similarly for exponential functions: O(2n) ⊂ O(3n) ⊂ O(4n)… Rewrite this as O(2n) ⊂ O(2log(3)·n) ⊂ O(2log(4)·n)… The set of all such exponential functions is thus 2Θ(n).
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
80
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
81
2
Sorting n elements: not Ω(n2) but Θ(n log n) Multiplying two n bit numbers not Ω(n2) not Ω(n1 58 ) Multiplying two n-bit numbers, not Ω(n2), not Ω(n1.58…),
but O(n log n log log n), and maybe even faster
Matrix multiplication: not Ω(n3), but O(n2.41…),
generally believed to be O(n2).
…
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
82
AccountBalance computes the balance in a saving account n
Procedure AccountBalance (n: integer) begin deposit := 50.00
balance in a saving account n months after it has been opened.
I := 1 rate := 0.05 balance := 100.00 while I < n do while I < n do begin balance := deposit + balance + balance * rate I := I + 1
) ( 5 7 1 7 4 ) ( n O n n n f ∈ + + + =
I : I + 1 end end
) ( 5 7 n O n ∈ + =
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
83
the presence of an integer called key. If the integer is found, the value of location indicates its first location in the array; if it is not found the value of location is 0, indicating an unsuccessful search. Analyze the complexity of the algorithm.
Procedure LinearSearch (key, n: integer; a1, a2, …, an: integers )
) 1 ( : complexity case
) i ( O
n
g ) begin I := 1 while (I < n and key = ai) do I := I + 1
array in not
being key
y probabilit the : , : complexity case
(iii) ) ( : complexity case
) ii ( q p n O
I := I + 1 if I < n then location := I else location := 0 end
) ( 2 / ) 1 ( ) ( / 1 If ) 2 1 ( ) (
2 ) 1 (
n O n n f n p q nq q n p n p p n f
n pn
∈ + = ⇒ = = + = ⋅ + ⋅ + ⋅ ⋅ ⋅ + ⋅ + ⋅ =
+
np+q=1
) ( ) 2 / ( 4 / ) 1 ( 2 / 2 / ) 1 ( ) 2 / 1 ( ) ( 2 / 1 , 2 / 1 If ) ( 2 / ) 1 ( ) ( / 1 , If O n n n n n f n p q n O n n f n p q + + = ⇒ = = ∈ + = ⇒ = =
The average-case complexity = the average number of array elements examined
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
84
) ( ) 2 / ( 4 / ) 1 ( n O n n ∈ + + =
number of array elements examined
input a, n, where a is real number and n is a positive integer, analyze the complexity the complexity.
Procedure Power2 (a: real; n: positive integer) begin
i 1.0 : x =
Procedure Power1 (a: real; n: positive integer) begin
⎣ ⎦ h
i/2 2 i if begin do i while n : i > =
begin d
a x : x do n to 1 : i for 1.0 : x ∗ = = =
⎣ ⎦ ⎣ ⎦
h i if i/2 : i a x : x then i/2 2 i if = ∗ = ∗ ≠
end end
end a a : a then i if ∗ = >
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
85
⎣ ⎦
1 7 l 1 7 l 3 times. three executed is loop the , 7 If + < + = n while
⎣ ⎦ ⎣ ⎦
1 8 log 1 8 log 4 . four times executed is loop the , 8 If 1 7 log 1 7 log 3
2 2 2 2
+ < + = = + < + = n while 1 log ) ( , 1 Assume ) ii ( 1 1 log 1 (1) , evaluate , 1 (i) Induction Mathematic by d establishe ), (log 1 log ) (
2 2 2 2
+ ≤ ≤ ≤ + ≤ = = ∈ + ≤ ⇒ n n g k n g a n n O n n g
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ 1
log ) ( 1 to changed pass first , 1 ) iii (
2 1 2 2 1 2 1 2 1
+ ≤ ∴ ≤ ≤ + =
+ + + +
k g k i k n
k k k k
Q
⎣ ⎦
1 1) ( log ] 1 2 log
( [log 1 ] 1 ) 2 1 ( [log 1 ] 1 [log 1 ) 1 (
2 2 2 2 2 1 2
+ + = + + + = + + + ≤ + + ≤ + ⇒
+
k k k k g
k Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
86
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
87
cautious. be must we ), ( ) ( and ) ( ) ( For
2
∈ ∈ n O n g n O n f 1000 d 1000 f lt diff t th ) ( d 1000 ) ( If n. informatio more need But we . complexity quadratic with
than efficient more be to complexity linear with algorithm an expect might We
2
f . 1000 and 1000 for results different are there , ) ( and 1000 ) ( If
2
< > = = n n n n g n n f
Problem size n Order of Complexity
l l
2
2n !
size n
log2n n n log2n n2 2n n!
2 16
1
2 2 4 4 2 4 16 64 256 6.5*104 2.1*1013 64 6 64 384 4096 1.84*1019 >1089
centuries 5845 days 10 14 . 2 ds microsecon 10 84 . 1
8 19
≈ × ≈ ×
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
88
y
5.1: 2 5 2: 6 18 20 5.2: 6, 18, 20 5.3: 2, 12, 18( (d) excluded) 5.4: 6, 8 5 5: 4 10 20 5.5: 4, 10, 20 5.6: 18, 22
Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring
89