Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Structures Li Tak Sing( 李德成 ) Lectures 7-8 1.

Similar presentations


Presentation on theme: "Discrete Structures Li Tak Sing( 李德成 ) Lectures 7-8 1."— Presentation transcript:

1 Discrete Structures Li Tak Sing( 李德成 ) Lectures 7-8 1

2 Minimum depth of a binary tree A full binary tree of depth n should have 2 n+1 -1nodes. So if we have 2 n+1 -1 nodes, the minimum depth of the tree is n. if the number of nodes is x with depth n, 2 n -1 <x  2 n+1 -1. This becomes 2 n  x< 2 n+1 then we have n  log 2 x<n+1 and therefore the minimum depth is  log 2 x  2

3 Problems in functions Let f: A  B be a function, and let E and F be subsets of A. Prove each of the following facts about images. 1.f(E  F)=f(E)  f(F) 2.f(E  F)=f(E)  f(F) 3

4 Solution 1. y  f(E  F)  there exists x  E  F s.t. f(x)=y  x  E or x  F s.t. f(x)=y  y  f(E) or y  F(F)  y  f(E)  f(F) 4

5 Solution 2. y  f(E  F)  there exists x  E  F s.t. f(x)=y  x  E and x  F s.t. f(x)=y  y  f(E) and y  F(F)  y  f(E)  f(F) 5

6 Constructing Functions Composition of Functions. The composition of two functions f and g is the function denoted by f  g and is defined by (f  g)(x)=f(g(x)) This definition would only make sense if f:A  B and g:C  D and D  A. 6

7 7

8 Examples 1.f:R  R and f(x)=3x+2 2.g:R  R and g(x)=x 2 +x Find f  g and g  f 8

9 Solution 1. f  g (x)=f(g(x)) =f(x 2 +x) =3(x 2 +x)+2 = 3x 2 +3x+2 2. g  f(x)=g(f(x)) =g(3x+2) =(3x+2) 2 +(3x+2) =9x 2 +15x+6 9

10 The Sequence, Distribute, and Pairs Functions seq: N  lists(N) seq(n)= For example seq(3)= dist:A  lists(B)  lists(A  B) dist(x, )= pairs:lists(A)  lists(B)  lists(A  B) pairs(, )= 10

11 Composing functions with different arities Composition can also occur between functions with different arities. f(X)=h(g 1 (X), g 2 (X),...,g n (X)). Example: f(x,y)=dist(x,seq(y)) 11

12 A list of pairs f(n)= =pairs(seq(n),seq(n)) 12

13 The Map Function Let f be a function with domain A and let be a list of elements from A. Then map(f, )= map: (A  B)  lists(A)  lists(B) Example, map(f, )= map(+, )= = 13

14 Examples 1.For each function, find the image of the set {1,2,3,4,5,6,7,8,9,10} a)f(x)=ceiling(log 2 (x)). b)f(x)=floor(log 2 (x)). 2.Describe the set of natural numbers x such that floor(log 2 (x))=15 3.Describe the set of natural numbers x such that ceiling(log 2 (x))=15 14

15 Solution 1(a) {0,1,2,3,4} (b) {0,1,2,3} 2. floor(log 2 (x))=15  15  log 2 (x)<16  2 15  x<2 16 3. ceiling(log 2 (x))=15  14<log 2 (x)  15  2 14 <x  2 15 15

16 Examples Let f be defined informally by f(n)=. Express f as a composition of known function from the set {seq, dist, pairs, map, -, *}. 16

17 Solution f(n)=map( , ) =map( ,dist(2, )) =map( ,dist(2,map(-, ))) =map( ,dist(2,map(-,dist(n, )))) =map( ,dist(2,map(-,dist(n,seq(n))))) 17

18 Properties of Functions Injections  A function f: A  B is called injective (or called one-to-one) if it maps distinct elements of A to distinct elements of B.  If f: A  B is called injective, then x,y  A, f(x)=f(y)  x=y 18

19 19

20 Injective or not? 1.f:R  R, f(x)=sin(x) 2.f:R  R, f(x)=x 2 3.f:R +  R, f(x)=log e x 20

21 Solution 1. Not injective 2. Not injective 3. Injective 21

22 Surjective Functions A function f:A  B is called surjective (also onto) if the range of f is the codomain B. f:A  B is surjective iff for each element in B, there is an x in A such that f(x)=y. 22

23 23

24 Surjective or not? 1.f:R  R, f(x)=x 2 2.f:R  R, f(x)=sin(x) 3.f:R +  R, f(x)=log e x 24

25 Solution 1. Not surjective 2. No surjective 3. surjective 25

26 Bijections A function is called bijective if it is both injective and surjective. 26

27 27

28 Bijective or not 1.f:R  R, f(x)=x 2 2.f:R  R, f(x)=sin(x) 3.f:R +  R, f(x)=log e x 28

29 Solution 1.not bijective 2.not bijective 3.bijective 29

30 Inverse functions Bijections always come in pairs. If f: A  B is a bijection, then there is a function g: B  A, called the inverse of f, defined by g(b)=a if f(a)=b. The inverse of f is also a bijection. There is only one inverse of f. 30

31 Problems For each property below, define a function that satisfies the property. Choose the domain and codomain for each function from the three sets. A={a,b,c,d}, B={1,2,3,4}, C={x,y} 1.Injective but not surjective. 2.Surjective but not injective. 3.Bijective but not the identity function. 4.neither injective nor surjective. 31

32 Solution 1. f:C  A, f(x)=a, f(y)=b 2. g:A  C, g(a)=x,g(b)=x, g(c)=x, g(d)=y 3. h:A  B, h(a)=1, h(b)=2, h(c)=3, h(d)=4 4. j:C  C, h(x)=x, h(y)=x 32

33 Problems In each case, find an example of a function f:N  N satisfying the given condition. 1.Injective but not surjective. 2.Surjective but not injective. 3.Bijective but not the identity function. 33

34 Solution 1. f:N  N, f(x)=2x 2. g:N  N, g(x)=floor(x/2) 3. h:N  N, h(x)=x-1 if x is odd, otherwise x+1. 34

35 Problem Left f:R +  R + be defined by f(x)=x/(x+5). 1.Show that f is injective. 2.Show that if is not surjective. 35

36 Solution 1. f(x)=f(y)  x/(x+5)=y/(y+5)  xy+5x=xy+5y  x=y Therefore, f is injective. 2. There is no x in R + so that f(x)=2. Therefore f is not surjective. 36

37 Injective and surjective relationships If f and g are injective, then f  g is injective. If f and g are surjective, then f  g is surjective. If f and g are bijective, then f  g is bijective. There is an injection from A to B iff there is a surjection from B to A. 37


Download ppt "Discrete Structures Li Tak Sing( 李德成 ) Lectures 7-8 1."

Similar presentations


Ads by Google