Discrete Mathematics -- Chapter 5: Relations and Ch t 5 R l ti d - - PowerPoint PPT Presentation

discrete mathematics
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

Outline

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 F ti C iti d I F ti

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

slide-3
SLIDE 3

Introduction

The same problem!

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

3

slide-4
SLIDE 4

5.1 Cartesian Products and Relations

  • For sets A, B, the Cartesian product (cross product), of A and B is

denoted by

  • E g {a b} × {1 2 3} = {(a 1) (b 1) (a 2) (b 2) (a 3) (b 3)}

}. , | ) , {( B b A a b a B A ∈ ∈ = ×

  • E.g., {a,b} × {1,2,3} = {(a,1),(b,1),(a,2),(b,2),(a,3),(b,3)}
  • Extension of the Cartesian product:

}. 1 , | ) , , , {(

2 1 2 1

n i A a a a a A A A

i i n n

≤ ≤ ∈ ⋅ ⋅ ⋅ = × ⋅ ⋅ ⋅ × ×

  • Ex 5.2 : is recognized as the real plane of

coordinate geometry and two dimensional calculus } , | ) , {( R R R ∈ = × y x y x coordinate geometry and two-dimensional calculus.

  • The subset is the interior of the first quadrant of this plane.
  • R3 represents Euclidean three-space, where the three-dimensional

+ + × 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

slide-5
SLIDE 5

Cartesian Products and Relations

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

  • C = {x, y}
  • |A x B x C| = 12

= 3 * 2 * 2 = |A||B||C|

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

5

slide-6
SLIDE 6

Cartesian Products and Relations

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×

A 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.

  • B

A B A B A to from relations possible 2 6 | | )}, 5 , 3 ( ), 4 , 2 {( ,

6

∴ = × × Q φ

  • B

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

slide-7
SLIDE 7

Cartesian Products and Relations

E 5 7

} | ) {( A t l ti d fi ≤ ℜ

+

Z A

Ex 5.7 :

11 7 7, 7

  • r

, (7,11) (7,7), to". equal

  • r

than less is " relation the is y} x | y) {(x, as A set

  • n

relation a define may we , ℜ ℜ ℜ ∈ ℜ ≤ ℜ =

+

Z A 2 8

  • r

, (8,2) 11 7 7, 7

  • r

, (7,11) (7,7), ℜ / ℜ ∉ ℜ ℜ ℜ ∈

F A

φ φ φ φ A A

  • For any set A,

φ φ φ φ = × = × A A ,

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

7

slide-8
SLIDE 8

Cartesian Products and Relations

Th 5 1 F t h

Theorem 5.1: For any sets

h :

⊆ 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

slide-9
SLIDE 9

5.2: Functions: Plain and One-to-One

D fi iti 5 3 f t t A B f ti ( i )

B A f

  • Definition 5.3: for nonempty sets A, B, , a function (mapping)

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

  • f(a) = b when (a, b) is an ordered pair in the function f.
  • (a, b) ∈ f, b is called the image of a under f, whereas a is a preimage
  • f b
  • f b.
  • f is a method for associating with each a ∈ A the unique element f(a)

= b ∈ B.

  • (a, b), (a, c) ∈ f, implies b = c.

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 ℜ ℜ

slide-10
SLIDE 10

Functions: Plain and One-to-One

D fi iti 5 4 F ti A i ll d th d i f f d B th

B A f

  • Definition 5.4: Function , A is called the domain of f and B the

codomain of f .

  • The subset of B consisting of those elements that appear as second

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 {

  • f

domain the 5.9, Example In f =

  • a
  • f(a)=b

f

} , { ) (

  • f

range the } , , , {

  • f

codomain the x w A f f z y x w f = = =

A B f(A)

  • A C++ compiler can be thought of as a function that transforms a source

program (the input) into its corresponding object program (the output).

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

10

slide-11
SLIDE 11

Functions: Plain and One-to-One

  • Ex 5.10 Many interesting function arise in computer science.
  • (a) Greatest integer function (floor function)

⎣ ⎦

. to equal

  • r

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) .

  • equa
  • a

ess ege g ea es e ) ( , : + = + = ≠ = = + + = + = = = + − = − − = − = = → x x x f f

  • (b) Ceiling function

⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤

3 7 3 01 3 3 3 4 4 7 3 01 3 3 3 1) . to equal

  • r

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) + = + = ≠ = = + + = + = = = + − = − = − − = − = = = =

  • (c) Truncation (trunc) function: delete the fractional part of a real number
  • trunc(3.78) = 3, trunc(5) = 5, trunc(-7.22) = -7

⎦ ⎡ ⎤

3 78 . 3 ) 78 . 3 ( trunc , 3 78 . 3 ) 78 . 3 ( trunc − = − = − = =

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

11

slide-12
SLIDE 12

Functions: Plain and One-to-One

(d) Access function: storing a m×n matrix in a one-dimensional

array

h j i l i

  • Use the row major implementation
  • j

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

slide-13
SLIDE 13

Functions: Plain and One-to-One

Ex 5.11 Division algorithm:

In Example 4.44

⎣ ⎦ ⎣ ⎦b

a r q r qb a

b a b a

− = = ⇒ + = ,

= : squares perfect being divisors positive

  • f

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

  • f

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

  • f

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

slide-14
SLIDE 14

Functions: Plain and One-to-One

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

slide-15
SLIDE 15

Functions: Plain and One-to-One

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|.

  • 2

1 2 1 2 , 1

) ( ) ( , all for if

  • nly

and if

  • ne
  • to
  • ne

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

  • ne.
  • to
  • ne

is so f

slide-16
SLIDE 16

Functions: Plain and One-to-One

Ex 5.13

  • all

for , ) ( where : that Suppose

4

∈ − = → x x x x g g R R R ) 1 but ) 1 ( ) ( (

  • ne
  • to
  • ne

not is so 1 1 ) 1 ( and ) (

4 4

≠ = = − = = − = g g g g g Q

Ex 5.14

  • to

from function

  • ne

to

  • ne

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 ( (

  • ne
  • to
  • ne

not is but , to from function a is )} 3 , 3 ( ), 3 , 2 ( ), 1 , 1 {( to from function

  • ne
  • to
  • ne

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

slide-17
SLIDE 17

Functions: Plain and One-to-One

A B

  • 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

  • ne
  • to
  • ne

) 1 ( ) 2 )( 1 ( ) ( ) , ( c) to from functions b) + − ⋅ ⋅ ⋅ − − = =

  • Definition 5.6:

} some for ), ( | { ) ( then , and : If

1 1 1

A a a f b B b A f A A B A f ∈ = ∈ = ⊆ → . under

  • f

image the called is ) ( and

1 1

f A A f

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

17

slide-18
SLIDE 18

Functions: Plain and One-to-One

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 = =

). , [

  • f

range the ) ( then , ) ( and : If (a)

2

+∞ = = = → R R R g g x x g g } | 3 { ) ( is under

  • f

image the , } { } | ) , {( for is codomain the , is

  • f

domain the , 3 2 ) , ( and : (b) ]. 4 , [ ) ( ] 1 , 2 [ and }, , 16 , 9 , 4 , 1 , { ) ( is under

  • f

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

slide-19
SLIDE 19

Functions: Plain and One-to-One

Th i h L A A A B A f

  • Theorem 5.2:

) ( ) ( ) ( (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

  • ne.
  • to
  • ne

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

  • Definition 5.7:

. 1 1 1 1 1 1

all for ) ( ) ( | if to

  • f

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

∈ = → ⊆ →

  • Definition 5.8:

. , 1 1 1

to

  • f

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

slide-20
SLIDE 20

Functions: Plain and One-to-One

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

  • f

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

slide-21
SLIDE 21

5.3 Onto Functions: Stirling Numbers of g the Second Kind

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∈

A a∈

b.

Ex 5.19 :

function.

  • nto

an is ) ( with :

3

x x f f = → R R function

  • nto

an is ) ( with ) [ :

  • nto.

not is ) ( with : function.

  • nto

an is ) ( with :

2 2

h h x x g g x x f f +∞ → = → → R R R R R

Ex 5.20 :

function.

  • nto

an is ) ( with ) , [ : x x h h = +∞ → R

  • nto

not is 1 3 ) ( with : + = → x x f f Z Z function

  • nto

an is 1 3 ) ( with : . function

  • nto

an is 1 3 ) ( with :

  • nto.

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.

  • nto

an is 1 3 ) ( with : + = → x x h h R R

slide-22
SLIDE 22

Some Functions

The square function f:Z→N, defined by f(x)=x2. f(3)=9, f(0)=0, f–1(4) = {–2,+2}, f–1(3) = ∅. This f is not injective nor surjective This f is not injective, nor surjective. The square function f:[0,2]→[–4,4] is injective, The square function f:[0,2]→[ 4,4] is injective, but not surjective (f–1(–2) =∅) h li f i f d fi d b f( ) 2 The linear function f:Z→Z, defined by f(x)=x+2. f(3)=5, f(0)=2, f–1(4) = 2. This f is injective and surjective: it is a bijection The identity I:A→A is always a bijection. This f is injective and surjective: it is a bijection.

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

22

y y j

slide-23
SLIDE 23

Counting with Functions

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

slide-24
SLIDE 24

How Many Functions?

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

  • a

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

slide-25
SLIDE 25

How Many Onto Functions?

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

slide-26
SLIDE 26

Onto Functions: Stirling Numbers of the g Second Kind

Ex 5.21 :

)} 4 ( ) 3 ( ) 2 ( ) 1 {( )} 4 ( ) 3 ( ) 2 ( ) 1 {( }, { }, 4 3 2 1 { If f f x,y,z B , , , A = = } { ) (

  • nto

not is )} 4 ( ) 3 ( ) 2 ( ) 1 {( .

  • nto

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 :

. } , { ) ( ,

  • nto

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

  • nto

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

  • nto

2 2 are there 2 | | and 2 | | if general, In . to from functions

  • nto

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?

slide-27
SLIDE 27

5.3 Onto Functions: Stirling Numbers of g the Second Kind

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

  • nto

not are that to from functions 2 2 3 {2,3} to from functions 2 {1,2} to from functions 2 : 2 size

  • f
  • f

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

  • nto

3 3 | | , 3 | | If to from functions

  • nto

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

slide-28
SLIDE 28

Onto Functions: Stirling Numbers of the g Second Kind

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

  • nto

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

  • nto

B A

slide-29
SLIDE 29

Onto Functions: Stirling Numbers of the g Second Kind

  • Problem 4: Seven (unrelated) people enter the lobby of a building which

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?

  • Solution

4 3 2

functions

  • f

number total the as same the is number the 384 , 16 4 : space sample (i)

7 =

2 1

4 | | 7 | | where : functions

  • nto
  • f

number total the

  • f

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

  • nto
  • f

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

> = = ∴

slide-30
SLIDE 30

Onto Functions: Stirling Numbers of the g Second Kind

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

  • nto
  • f

number the account expensive most

  • n the
  • nly

woks Teresa (i) : subcases disjoint wo Consider t = = → B A B A f account expensive most just the than more

  • n

woks Teresa (ii) 540 ) 1 (

3 6

) 3 ( 3 3

= ∑ ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ −

=

− −

k k

k k

1560 ) 1 ( 4 | | , 6 | | where : functions

  • nto
  • f

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?

slide-31
SLIDE 31

Onto Functions: Stirling Numbers of the g Second Kind

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

  • nto
  • f

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

  • ns

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 =

slide-32
SLIDE 32

Onto Functions: Stirling Numbers of the g Second Kind

General formulas:

containers numbered into

  • bjects

distinct distribute to ways ) 1 (

) (

n m

n m k

k n n

⎠ ⎞ ⎜ ⎝ ⎛ − . containers identical into

  • bjects

distinct distribute to ways ) 1 ( . containers numbered into

  • bjects

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

  • f

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

  • bjects

distinct distribute to ways possible

  • f

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

slide-33
SLIDE 33

The triangle of Stirling numbers of the second kind

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

33

if m = 4 , n = 3

slide-34
SLIDE 34

More Stirling Numbers of the 2nd Kind More Stirling Numbers of the 2 Kind

The number of ways of partitioning a set of n

l t i t t t d t d S( ) elements into m nonempty sets denoted S(n,m).

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

elements are S(3,1)=1, S(3,2)=3, S(3,3)=1. ( ) ( ) ( )

  • http://mathworld.wolfram.com/StirlingNumberoftheSecondKind.html

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

34

slide-35
SLIDE 35

More Stirling Numbers of the 2nd Kind g

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

slide-36
SLIDE 36

More Stirling Numbers of the 2nd Kind

  • For positive integers m,n with m<n, prove that

⎛ ⎞ − − = ⎜ ⎟ − ⎝ ⎠

( 1) ( )

n k m k

n n k n k

  • For every positive integer n verify that

=

⎝ ⎠

k

n k

  • For every positive integer n, verify that

⎛ ⎞

n k

n

=

⎛ ⎞ = − − ⎜ ⎟ − ⎝ ⎠

! ( 1) ( )

k n k

n n n k n k

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

36

slide-37
SLIDE 37

Onto Functions: Stirling Numbers of the g Second Kind

Theorem 5.3:

  • Proof
  • bjects

he in which t ways

  • f

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

  • bjects

ng distributi

  • f

ways ) 1 , ( (i) (1) empty. left container no with , containers identical among d distribute be can

  • f
  • bjects

he in which t ways

  • f

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

  • bjects

ng distributi

  • f

ways ) , ( (i) (2) ways ) 1 , ( container th) ( empty remaining in the placing

  • f

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

  • f

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 + = ⋅ + = = + ⇒

slide-38
SLIDE 38

Onto Functions: Stirling Numbers of the g Second Kind

1

  • Alternative form:
  • This new form tells something about the number of onto functions.

} { } { 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

  • nto
  • f

number the } : functions

  • nto
  • f

number the : functions

  • nto
  • f

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 ) , (

slide-39
SLIDE 39

5.4 Special Functions

  • Definition 5.10: For any nonempty sets A, B, any function

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).

  • Definition 5.11: A function is called a unary (monary)
  • peration 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

  • n
  • peration

binary a is then , ) , ( here function w the is : If (b) .

  • n
  • peration

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 .

  • n
  • peration

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

slide-40
SLIDE 40

Special Functions

and universe a be Let U A B U ⊆

Ex 5.30 :

.

) (

  • n
  • peration

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 ∪ = → × ⊆

.

) (

  • n
  • peration

unary a is ) ( by defined is ) ( ) ( : function The (b) ) ( p y U P A A g U P U P g f = →

  • Definition 5.12:

, ) , ( all for ) , ( ) , ( if e commutativ be to said is (a) .

  • n
  • peration

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 − =

slide-41
SLIDE 41

Example

f:Z ×

Z Z, by f((x,y))=x+y-3xy Then f(x,y)= x+y-3xy=y+x-3yx=f(y,x) Hence f is commutative

f((x,y),z)=(x+y-3xy)+z-3(x+y-3xy)z

=x+(y+z-3yz)-3x(y+z-3yz) (y y ) (y y ) =f(x,(y,z)) Hence f is associative

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

41

slide-42
SLIDE 42

Special Functions

Ex 5.33 :

: functions 4 16 | | then }, { If (1)

16

A A A f A A a,b,c,d A → × ⇒ = × = } { )} ( ) ( ) ( ) {( (i) .

  • n

) , (

  • perations

binary closed e commutativ

  • f

number the Determine 2) ( .

  • n
  • perations

binary closed 4

16

d b d d b b A y x g A → ⇒ available is pairs 10 6 4 totally } , , , { pairs

  • rdered

two

  • f

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 + ∴ → = = ≠ → =

.

  • n

) , (

  • perations

binary closed e commutativ 4 available is pairs 10 6 4 totally,

10

A y x g ⇒ = + ∴

  • Definition 5.13:

. , ) , ( ) , ( if for identity an called is element An .

  • n
  • peration

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

slide-43
SLIDE 43

Special Functions

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

slide-44
SLIDE 44

Special Functions

  • Theorem 5.4:

P f unique. is identity then that , identity an has If

  • peration.

binary a be : Let f B A A f → ×

  • Proof

2 2 1 1 2 1

) ( ) ( ), , ( ) , ( , let , identity

  • ne

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

slide-45
SLIDE 45

Special Functions

Ex 5.35: If A={x, a, b, c, d}, how many closed

binary operations on A have x as the identity? binary operations on A have x as the identity?

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

slide-46
SLIDE 46

Special Functions

  • Definition 5.14:

coordinate second

  • n the

projection the called is ) ( by defined : . coordinate first

  • n the

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

  • n the

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 , ( } , { ) (

  • nto,

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 { ) (

  • nto,

is 4 ) 4 , ( π π π Q

slide-47
SLIDE 47

Special Functions

Ex 5.37 :

} | ) , {( where , If

2

x y y x D B A D B A = = × ⊆ = = R ) [ ) ( projection The

  • nto

is ) ( projection The

A A

D D π π π ⊂ ∞ ∴ = R R Q Q

  • nto

not is ) , [ ) ( projection The

B B D

π π ∴ ⊂ ∞ = R Q

  • Extension of Projection

: 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

  • f

elements The s coordinate th , th, th,

  • n
  • f

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

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

slide-48
SLIDE 48

Special Functions

  • These projections arise in a natural way in the study of relational data

bases, a standard technique for organizing and describing large quantities

  • f data by modern large-scale computing systems.

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

  • Consider the table (relation),

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

  • P. Z. Chinn
  • V. Larney
  • J. Kinney

A B A

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

48

MA 113 Calculus III

  • A. Schmidt

A

slide-49
SLIDE 49

Special Functions

  • The sets A1, A2 , A3 , A4 are called the domain of relational data base, and

table D is said have degree 4.

  • Each element of D is often called a list (record).
  • Each element of D is often called a list (record).
  • The projections of D on , and is shown in the following

tables.

4 3 1

A A A × ×

2 1

A A ×

Course Number Professor Section Letter MA 111

  • P. Z. Chinn

A Course Number Course Title MA 111 Calculus I MA 111 MA 112 MA 113

  • V. Larney
  • J. Kinney
  • A. Schmidt

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

slide-50
SLIDE 50

5.5 The Pigeonhole Principle

  • The pigeonhole principle: If m pigeons occupy n pigeonholes and m > n,

then at least one pigeonhole has two or more pigeons roosting in it.

  • Proof by contradiction: if the result is not true then each pigeonhole has at
  • Proof by contradiction: if the result is not true, then each pigeonhole has at

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?

  • Solution

tape

  • n the

repeated is word

  • ne

least at 254 , 475 26 26 26 26

2 3 4

∴ = + + +

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

50

tape.

  • n the

repeated is word

  • ne

least at ∴

slide-51
SLIDE 51

The Pigeonhole Principle

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

  • Hint n = 36q + r, 0 ≤ r < 36.

Ex 5.44 : Any subset of size 6 from the set S = {1,2,3,…,9} must

contain two elements whose sum is 10.

  • Hint {1,9},{2,8},{3,7},{4,6},{5}. Pigeon? Pigenhole?

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 ½.

  • Related with Pigeonhole principle ?

C D 1

  • Hint Break up the interior of ACE into 4 regions

A B D F E 2 3 4

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

51

A F E

slide-52
SLIDE 52

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

whose maximum is at most 14. Show that the sums of the elements in all the nonempty subsets of S cannot all be p y distinct. For any nonempty subset A of S the sum of the elements in A For any nonempty subset A of S, the sum of the elements in A, denoted SA, satisfies

1 9 10 14 69 S

d h

1 9 10 14 69 ≤ ≤ + + + = S A L

, and there are 26-1=63 nonempty subsets of S. (too many pigeonholes!) p y ( y p g ) Consider the subset of less than 6 elements. pigeonholes=10+11+...+14=60 pigeons=26-1-1=62=63-1 (only S have 6 elements)

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

52

slide-53
SLIDE 53

The Pigeonhole Principle

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

  • Proof

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(

  • dd

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

slide-54
SLIDE 54

Ex 5.48 28 days to play at most 40 sets of tennis and at y p y least 1 play per day. Prove there is a consecutive span of days during which exactly 15 sets are played. 在28天中至多打40場球,每天至少打一場。 証明必存在有連續數天所打的球賽總和為剛好15場。

≤ ≤ ≤ < < < ≤ 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

  • 55. Of the 56

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

slide-55
SLIDE 55

The Pigeonhole Principle

  • Ex 5.49 : For each , a sequence of n2 + 1 distinct real

numbers contains a decreasing or increasing subsequence of n + 1.

E l

+

∈ Z n

  • Example

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)

  • Proof

n k n a a a 1 1 numbers, real distinct 1

  • f

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

  • f

length maximum the with ends that e subsequenc decreasing a

  • f

length maximum the 1 1 numbers, real distinct 1

  • f

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

slide-56
SLIDE 56

The Pigeonhole Principle

  • Proof

) ( pairs distinct most at . 1 , 1 then 1, length

  • f

e subsequenc increasing

  • r

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

  • f

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

  • r

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

slide-57
SLIDE 57

5.6 Function Composition and Inverse p Functions

  • Definition 5.15: If then f is said to be bijective, or to be a one-to-
  • ne correspondence, if f is one-to-one and onto.

E 5 50 A

{1 2 3 4} B { } f {(1 ) (2 ) (3 ) (4

, : B A f →

  • Ex 5.50 : A = {1, 2, 3, 4}, B = {w, x, y, z} , f = {(1, w), (2, x), (3, y), (4,

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.

  • Definition 5.16:

A all for ) ( 1 by defined : 1 : function Identity ∈ = → a a a A A

  • Definition 5.17:

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

slide-58
SLIDE 58

Function Composition and Inverse p Functions

  • Ex 5.52 :

⎡ ⎤

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

slide-59
SLIDE 59

Function Composition and Inverse p Functions

  • Definition 5.18: The composite function,

, : then , : and : If C A f g C B g B A f → → →

  • .

all for )), ( ( ) )( ( by A a a f g a f g ∈ =

  • g o f is read as "g circle f" or "g composed with f"
  • Ex 5.53 :

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

Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

59

e commutativ not ∴

slide-60
SLIDE 60

Function Composition and Inverse p Functions

d L C B B A f

  • Theorem 5.5:
  • nto

is then

  • nto

are and If b)

  • ne.
  • to
  • ne

is then

  • ne,
  • to
  • ne

are and If a) . : and : Let f g g f f g g f C B g B A f

  • Proof
  • nto.

is then

  • nto,

are and If b) f g g f

  • )

)( ( ) )( ( with , Let a)

2 1 2 1

a f g a f g A a a

  • =

  • ne

to

  • ne

is

  • ne)
  • to
  • ne

is (

  • ne)
  • to
  • ne

is )( ( ) ( ) ) ( ( ) ) ( (

2 1 2 1 2 1

f g f a a g a f a f a f g a f g

  • Q

Q ∴ = ⇒ = ⇒ = ⇒ ) ( with exists

  • nto,

is let , : For b)

  • ne
  • to
  • ne

is z y g B y g C z C A f g f g Q

  • =

∈ ∴ ∈ → ∴ t i ) ( )) ( ( ) ( ) ( with exists

  • nto,

is f x f g x f g y g z y x f A x f

  • Q

= = = ∴ = ∈ ∴

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

60

  • nto

is f g o ∴

slide-61
SLIDE 61

Function Composition and Inverse p Functions

: and : : Let D C h C B g B A f → → →

  • Theorem 5.6:

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

h

A

h

g

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

slide-62
SLIDE 62

Function Composition and Inverse p Functions

  • Definition 5.19:

). ( , for and , define we , : If

1 1 n n

f f f n f f A A f

  • =

∈ = →

+ +

Z

  • Ex 5.56 :

)} 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 = = = = = → =

  • Definition 5.20:

? , 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 ,

  • f

converse then the , to from relation a is if , , sets For ℜ ∈ = ℜ ℜ ℜ ℜ b a a b A B B A B A

c c

  • Ex 5.57 :

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

Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

62

B A

f f f f y x w f 1 , 1 )} 3 , ( ), 2 , ( ), 1 , {( = = ⇒ = ⇒

slide-63
SLIDE 63

Function Composition and Inverse p Functions

  • Definition 5.21:

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 = = → →

  • Ex 5.58 :

) 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 = = →

  • functions

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

= = ∴ = + = = = +

− −

  • Theorem 5.7:

. unique is then , 1 and 1 satisfies : and invertible is : If g g f f g A B g B A f

B A

= = → →

  • Proof

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

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

= = = = = = =

slide-64
SLIDE 64

Function Composition and Inverse p Functions

  • Theorem 5.8:
  • Proof
  • nto.

and

  • ne
  • to
  • ne

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 :

  • ne
  • to
  • ne

(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

  • nto

is )), ( ( ) )( ( ) ( 1 , 1 ) ( let :

  • nto

(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

∴ = = = ∴ = ∈ ⇒ ∈ = ∴ = =

  • Q
  • Q
  • )

( where , ) ( by : define ) ( with each

  • nto,

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

  • ne
  • to
  • ne

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

Q

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

64

invertible is 1 , 1 f g f f g

B A

∴ = = ∴

slide-65
SLIDE 65

Function Composition and Inverse p Functions

  • Ex 5.59 :

invertible not is ) ( by defined :

1 2 2 1 1

x x f f = → R R .

  • f

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

− −

∗ = = +∞ → +∞

  • Theorem 5.9:

)

  • 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

− − − − =

→ → →

  • Ex 5.60 :

invertible is } | ) , {( by defined , : , , , For b mx y y x f f m b m + = = → ≠ ∈ R R R

  • Ex 5.61 :

. ) ( and

  • nto,

and

  • ne
  • to
  • ne

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

slide-66
SLIDE 66

Function Composition and Inverse p Functions

  • Definition 5.22:

} ) ( | { ) ( then , and : If

1 1 1 1 1

B x f A x B f B B B A f

∈ ∈ = ⊆ →

  • Ex 5 62 :

. under

  • f

preimage the called is ) (

1 1 1

f B B f −

(f is not necessary invertible.)

  • Ex 5.62 :
  • btained.

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

slide-67
SLIDE 67

Function Composition and Inverse p Functions

, 5 3 ) ( b d fi d i ⎨ ⎧ > − x x f f R R

  • Ex 5.63 :

? ]) 5 , 5 ([ is What , 1 3 ) ( by defined is :

1 −

⎩ ⎨ ≤ + − = →

f x x x f f R R

  • Solution

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

  • r

3 / 4 | { ]) 5 , 5 ([

1

− = ≤ < ≤ ≤ − = − ∴

x x x f

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

67

slide-68
SLIDE 68

Function Composition and Inverse p Functions

  • Theorem 5.10:

) ( ) ( ( ) ) ( ) ( ) ( (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

− − − − − − − −

∩ = ∩ ⊆ →

  • Proof

) ( ) ( , 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

− − − − −

= ∪ = ∪

) ( ) ( ) (

  • r

) ( ) (

  • r

) ( ) ( ) ( , ( )

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

− − − −

∪ ∈ ⇔ ∈ ∈ ⇔ ∈ ∈ ⇔

  • Theorem 5.11:

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)

  • nto;

is (b)

  • ne;
  • to
  • ne

is (a) : equivalent are statements following Then the f f f

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

68

slide-69
SLIDE 69

Function Composition and Inverse p Functions

  • Problem 6: For every positive integer n, verify that

( )

. ) ( ) 1 ( !

n n k n n k

k n n − ∑ − =

  • Proof

( )

k=

and functions

  • ne

to

  • ne

are there | | | | ∴ n! n B A Q

( ) ( )

functions

  • nto

) ( ) 1 ( and functions,

  • ne
  • to
  • ne

are there | | | | ∑ ∴ = =

= − k n n k k n n k

n-k

  • n!

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

n S n-k

  • n!

! n

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

69

slide-70
SLIDE 70

Reference

  • B

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

  • ne
  • to
  • ne

) 1 ( ) 2 )( 1 ( ) ( c) to from functions b) + − ⋅ ⋅ ⋅ − − =

( ) ( )

. containers numbered into

  • bjects

distinct distribute to ways ) 1 ( : function

  • nto

d)

) (

n m

n k m k

k n k n n

=

− −

( )

. containers identical into

  • bjects

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

slide-71
SLIDE 71

Reference: Counting Principles

  • Discrete Mathematics

Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

71

slide-72
SLIDE 72

5.7 Computational Complexity

  • Properties of a general algorithm

p g g

  • Precision of the individual step-by-step instructions
  • Input provided to the algorithm, and the output the algorithm then

id provides

  • Ability of the algorithm to solve a certain type of problem, not just

specific instances of the problem

  • Uniqueness of the intermediate and final results, based on the input
  • Examining an algorithm
  • Measure how long it takes the algorithm to solve a problem of a large

size

  • Determine whether one algorithm is better than another
  • Determine whether one algorithm is better than another
  • To measure an algorithm means seeking a function f(n), called the

time-complexity function.

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

72

slide-73
SLIDE 73

Computational Complexity

  • Definition 5.23:

. 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

  • f

set the represents ) ( ".

  • f

Oh

  • big

"

  • r

"

  • rder

" read is ) ( where ), ( g O g g g O g O f

+

∈ Z

  • Ex 5 65 :

. by dominated are that R codomain and domain with functions all

  • f

set the represents ) ( g g O Z

  • Ex 5.65 :

, 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 ∈ ∴

slide-74
SLIDE 74

Computational Complexity

  • Ex 5.67 :

| (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

). (

  • r

) ( , 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 ∈ ∈ ≥ ≤ ∴ + + ≤ + + + +

  • Generalization of function dominance

| | | ) ( | ) ( 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 ∈ ≤ ⇒ + + + +

slide-75
SLIDE 75

Computational Complexity

  • Ex 5.68 :

) ( ) ( ) ( ) 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

slide-76
SLIDE 76

Computational Complexity

  • Some important orders:

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

slide-77
SLIDE 77

Ω and Θ

Exercise 5.7, Questions 11 and 14: Let f and g be functions from Z+ to R. Th f ti f i f d l if d l if th The function f is of order at least g if and only if there are M∈R+ and an k∈N+ such that |f(n)| ≥ M |g(n)| for all k≤n. This is denoted by f ∈ Ω(g) This is denoted by f ∈ Ω(g). Say: “f is/has order big-Omega of g” If f∈O(g) and f∈Ω(g), then we can write f ∈ Θ(g) In words: “f has order big-Theta of g” Examples: n2∈Ω(n) and 7n2–8n+10 ∈ Θ(n2) and 2n∈Ω(nc) for every c

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

77

2 ∈Ω(n ) for every c.

slide-78
SLIDE 78

Big-O, Ω and Θ

Definitions: If f is dominated by g: f ∈ O(g) E i l tl Ω(f) Equivalently: g ∈ Ω(f). If f∈O(g) and g∈O(f) then f∈Θ(g) Some examples: For polynomials f and g: f∈O(g) For polynomials f and g: f∈O(g) if and only if deg(f) ≤ deg(g). For all polynomials f and c∈R>1: f ∈ O(cn) p y ( )

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

78

slide-79
SLIDE 79

Examples of O, Ω and Θ

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

slide-80
SLIDE 80

Some More Subtle Cases

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

slide-81
SLIDE 81

Hard versus Easy Problems

Typically we call a problem easy if there is a polynomial time algorithm that solves it in time nO(1). If there is no such poly-time algorithm, then we call the problem hard. Problems for which we only have exponential time algorithms (time complexity 2Θ(n)) are very hard… T k i t f 256 bit d ti l it 2n Take an input of n=256 bits and time complexity 2n. Observe that 2n = 2256 ≈ 1077 steps on a computer with clock speed 1012 operations per second (tera) with clock speed 10

  • perations per second (tera)

still requires 1065 seconds. (about 9 years)

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

81

slide-82
SLIDE 82

Smart Algorithms

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

slide-83
SLIDE 83

5.8 Analysis of Algorithm

  • Ex 5.69 : Procedure

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.

  • Solution

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

slide-84
SLIDE 84

Analysis of Algorithm

  • Ex 5.70 : An array of n integers a1, a2, …, an is to be searched for

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.

  • Solution

Procedure LinearSearch (key, n: integer; a1, a2, …, an: integers )

) 1 ( : complexity case

  • best

) i ( O

n

g ) begin I := 1 while (I < n and key = ai) do I := I + 1

array in not

  • r

being key

  • f

y probabilit the : , : complexity case

  • average

(iii) ) ( : complexity case

  • worst

) 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

slide-85
SLIDE 85

Analysis of Algorithm

  • Ex 5.72 : The following procedures compute the value of an for the

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

slide-86
SLIDE 86

Analysis of Algorithm

  • Solution

⎣ ⎦

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

  • 1)

( [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

slide-87
SLIDE 87

Analysis of Algorithm

Discrete Mathematics Discrete Mathematics – – CH5 CH5 2009 Spring 2009 Spring

87

slide-88
SLIDE 88

Analysis of Algorithm

  • Observations

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

  • ne

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

slide-89
SLIDE 89

Exercise (2009)

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