Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5 Relations and Functions Yen-Liang Chen Dept of Information Management National Central University.

Similar presentations


Presentation on theme: "Chapter 5 Relations and Functions Yen-Liang Chen Dept of Information Management National Central University."— Presentation transcript:

1 Chapter 5 Relations and Functions Yen-Liang Chen Dept of Information Management National Central University

2 5.1. Cartesian products and relations  Definition 5.1. The Cartesian product of A and B is denoted by AB and equals {(a, b)aA and bB}. The elements of AB are ordered pairs. The elements of A 1 A 2  … A n are ordered n-tuples.  AB=AB  Ex 5.1. A={2, 3, 4}, B={4, 5}. What are AB, BA, B 2 and B 3 ?  Ex 5.2, What are RR, R + R + and R 3 ?

3 Tree diagrams for the Cartesian product

4 Relations  Definition 5.2. Any subsets of AB is called a relation from A to B. Any subset of AA is called a binary relation on A.  Ex 5.5. The following are some of relations from A={2,3,4} to B={4,5}: (a) , (b) {(2, 4)}, (c) {(2, 4), (2, 5)}, (d) {(2, 4), (3, 4), (4, 4)}, (e) {(2, 4), (3, 4), (4, 5)}, (f) AB.  For finite sets A and B with A=m and B=n, there are 2 mn relations from A to B. There are also 2 mn relations from B to A.

5 Examples  Ex 5.6. R is the subset relation where (C, D)R if and only if C, DB and CD.  Ex 5.7. We may define R on set A as {(x, y)xy}.  Ex 5.8. Let R be the subset of NN where R={(m, n)n=7m}  For any set A, A=. Likewise,   A =.

6 Theorem 5.1.  A(BC)=(AB)(AC)  A(BC)=(AB)(AC)  (AB)C=(AC)(BC)  (AB)C=(AC)(BC)  Why?

7 5.2. Functions: Plain and one-to- one  Definition 5.3. f: AB, A is called domain and B is codomain. f(A) is called the range of f.  For (a, b)f, b is called image of a under f whereas a is a pre-image of b.  Ex Greatest integer function, floor function Ceiling function Truncate function Row-major order mapping function  Ex a sequence of real numbers r 1, r 2, … can be thought of as a function f: Z + R and a sequence of integers can be thought of as f: Z + Z

8 properties  For finite sets A and B with A=m and B=n, there are n m functions from A to B.  Definition 5.5. f: AB, is one-to-one or injective, if each element of B appears at most once as the image of an element of A. If so, we must have AB. Stated in another way, f: AB, is one-to-one if and only if for all a 1, a 2 A, f(a 1 )=f(a 2 ) a 1 =a 2.  Ex f(x)=3x+7 for xR is one-to-one. But g(x)=x 4 -x is not. (Why?)

9 Number of one-to-one functions  Ex A={1, 2, 3}, B={1, 2, 3, 4, 5}, there are 2 15 relations from A to B and 5 3 functions from A to B.  In the above example, we have P(5, 3) one-to-one functions.  Given finite sets A and B with A=m and B=n, there are P(n, m) one-to- one functions from A to B.

10 Theorem 5.2.  Let f: AB with A 1, A 2 A. Then (a) f(A 1 A 2 )=f(A 1 )f(A 2 ), (b) f(A 1 A 2 )f(A 1 )f(A 2 ), (c) f(A 1 A 2 )=f(A 1 )f(A 2 ) when f is one-to- one. A 1 ={2,3,4}, A 2 ={3,4,5} f(2)=b, f(3)=a, f(4)=a, f(5)=b

11 Restriction and Extension  Definition 5.7. If f: AB and A 1 A, then f A1 : AB is called the restriction of f to A 1 if f A1 (a)=f(a) for all aA 1.  Definition 5.8. Let A 1 A and f: A 1 B. If g: AB and g(a)=f(a) for all aA 1, then we call g an extension of f to A.  Ex 5.17.Let f: AR be defined by {(1, 10), (2, 13), (3, 16), (4, 19), (5, 22)}. Let g: QR where g(q)= 3q+7 for all qQ. Let h: RR where h(r)= 3r+7 for all rR. g is an extension of f, f is the restriction of g h is an extension of f, f is the restriction of h h is an extension of g, g is the restriction of h  Ex g and f are shown in Fig 5.5. f is an extension of g.

12

13 5.3. Onto Functions: Stirling numbers of the second kind  Definition 5.9. f: AB, is onto, or surjective, if f(A)=B-that is, for all bB there is at least one aA with f(a)=B. If so, we must have AB.  Ex The function f: RR defined by f(x)=x 3 is an onto function. But the function g: RR defined by f(x)=x 2 is not an onto function.  Ex The function f: ZZ defined by f(x)=3x+1 is not an onto function. But the function g: QQ defined by g(x)=3x+1 is an onto function. The function h: RR defined by h(x)=3x+1 is an onto function.

14 The number of onto functions  Ex If A={x, y, z} and B={1,2}, there are =6 onto functions. In general, if A=m and B=2, then there are 2 m -2 onto functions.  Ex If A={w, x, y, x} and B={1,2, 3}. There are C(3, 3)3 4 functions from A to B. Consider subset B of size 2, such as {1, 2}, {1, 3}, {2, 3}, there are C(3, 2)2 4 functions from A to B. Consider subset B of size 1, such as {1}, {3}, {2}, there are C(3, 1)1 4 functions from A to B. Totally, there are C(3, 3)3 4 - C(3, 2)2 4 + C(3, 1)1 4 onto functions from A to B.

15 The number of onto functions  For finite sets A and B with A=m and B=n, the number of onto functions is:

16 Examples  Ex Let A={1, 2, 3, 4, 5, 6, 7} and B={w, x, y, z}. So, m=7 and n=4. There are 8400 onto functions. C(4, 4)4 7 -C(4, 3)3 7 +C(4, 2)2 7 -C(4, 1)1 7 =8400  Ex Let A={a, b, c, d} and B={1, 2, 3}. So, m=4 and n=3. There are 36 onto functions, or equivalently, 36 ways to distribute four distinct objects into three distinguishable containers, with no container empty.  For mn, the number of ways to distribute m distinct objects into n numbered containers with no container left empty is :

17 Distinguishable and identical  distribute m distinct (identical) objects into n numbered (identical) containers {a, b} in container 1, {c} in container 2, {d} in container 3 {a, b} in one container, {c} in the other container, {d} in another container 2 objects in container 1, 1 object in container 2, 1 object in container 3 2 objects in one container, 1 object in the other container, 1 object in another container

18 Stirling number of the second kind  The stirling number of the second kind is the number of ways to distribute m distinct objects into n identical containers, with no container left empty, denoted S(m,n), which is

19  It is the number of possible ways to distribute m distinct objects into n identical containers with empty containers allowed.

20 Theorem 5.3.  S(m+1, n)=S(m, n-1) + n S(m, n). a m+1 is in a container by itself. Objects a 1, a 2, …, a m will be distributed to the first n-1 containers, with none left empty. a m+1 is in the same container as another object. Objects a 1, a 2, …, a m will be distributed to the n containers, with none left empty.

21 Ex  30030=23571113. How many ways can we factorize the number into two factors? The answer is S(6, 2)=31.  How many ways can we factorize the number into three factors? The answer is S(6, 3)=90.  If we want at least two factors in each of these unordered factorization, then there are 202=

22 5.4. Special functions  Definition f: AAB is called a binary operation. If BA, then it is closed on A.  Definition A function g:AA is called unary, or monary, operation on A.  Ex: the function f: ZZZ, defined by f(a, b)=a-b, is a closed binary operation. The function g: Z + Z + Z, defined by g(a, b)=a- b, is a binary operation on Z +, but it is not closed. The function h: R + R +, defined by h(a)=1/a, is a unary operation.

23 Commutative and associative  Definition f is commutative if f(a, b)= f(b, a) for all a, b.  When BA, f is said to be associative if for all a, b, c we have f(f(a, b), c)=f(a, f(b, c))

24 Commutative and associative  Ex The function f: ZZZ, defined by f(a, b) = a+b-3ab is commutative and associative. The function f: ZZZ, defined by h(a, b) = ab is not commutative but is associative.  Ex Assume A={a, b, c, d} and f: AAA. There are 4 16 closed binary operations on A. Determine the number of commutative and closed operations g. there are four choices for g(a, a), g(b, b), g(c, c) and g(d, d). The other 12 ordered pairs can be classified into 6 groups because of the commutative property. The total number of binary and commutative operations is 4 4 4 6.

25

26 Identity  Definition Let f: AAB be a binary operation on A. An element x in A is called an identity for f if f(a, x)= f(x, a)=a for all a in A.  Ex If f(a, b)=a+b, then 0 is the identity. If f(a, b)=ab, then 1 is the identity. If f(a, b)=a-b, then there is no identity.

27 Identity  Theorem 5.4. Let f: AAB be a binary operation on A. If f has an identity, then that identity is unique.  Ex If A={x, a, b, c, d}, how many closed binary operations on A have x as the identity? Because x is the identity, we have Table 5.2, where there are 16 cells left unfilled. There are 5 16 closed binary operations on A, where x is the identity. Of these, 5 10 =5 4 5 6 are commutative. If every element can be used as the identity, we have 5 11 closed binary operations that are commutative.

28

29 Projection  Definition if DAB, then  A : DA, defined by  A (a, b)=a is called the projection on the first coordinate. The function  B : DB, defined by  B (a, b)=b is called the projection on the second coordinate.  if DA 1  A 2  … A n, then  A : DA i 1  A i 2  A i 3 ,,,, A i m, defined by (a 1, a 2, …, a n )= a i 1, a i 2, a i 3, …, a i m is called the projection on the i 1, i 2, …, i m coordinates.

30 The projection of a database

31 5.5. Pigeonhole principle  The pigeonhole principle: If m pigeons occupy n pigeonholes and m>n, then at least one pigeonhole has two or pigeons roosting in it.  Ex 5.39: among 13 people, at least two of them have birthdays during the same month.  Ex In a laundry bag, there are 12 pairs of socks. Drawing the socks from the bag randomly, we will draw at most 13 of them to get a matched pair.  Ex Let SZ + and S=37. Then S contains two elements that have the same remainder upon division by 36.

32 Examples  Ex If 101 integers are selected from the set S={1, 2, …, 200}, then there are two integers such that one divide the other. For each xS, we may write x=2 k y, with k0 and gcd(2,y)=1. Then yT={1, 3, 5, …, 199}, where T =100. By the principle, there are two distinct integers of the form a=2 m y and b=2 n y for some y in T.  Ex Any subset of size 6 from the set S={1, 2, …, 9} must contain two elements whose sum is 10.

33 Examples  Ex Triangle ACE is equilateral with AC=1. If five points are selected from the interior of the triangle, there are at least two whose distance apart is less than 1/2.  Ex Let S be a set of six positive integers whose maximum is at most 14. The sums of the elements in all the nonempty subsets of S cannot be all distinct. There are =63 subsets of S. 1S A 9+10+ … +14=69 If A=5, then 1S A 10+ … +14=60 There are 62 nonempty subsets A of A with 5A.

34 Ex 5.47  Let m in Z + and m is odd. There exists a positive integer n such that m divides 2 n -1.  Consider the m+1 positive integers , , …, 2 m - 1, 2 m By the principle, we have 1s

35 Ex 5.49  For each nZ +, a sequence of n 2 +1 distinct real numbers contains a decreasing or increasing subsequence of length n+1.  Let the sequence be a 1, a 2, …,a n For 1k n 2 +1  x k = the maximum length of a decreasing subsequence that ends with a k.  y k = the maximum length of an increasing subsequence that ends with a k.  If there is no such sequence, then 1x k n and 1y k n for 1k n  Consequently, there are at most n 2 distinct ordered pairs of x k and y k.  But we have n 2 +1 ordered pairs of x k and y k.  Thus, there are two identical (x i, y i ) and (x j, y j ).  But since every real number is distinct from one another, this is a contradiction.

36 5.6. Function composition and inverse function  For each integer c there is a second integer d where c+d = d+c=0, and we call d the additive inverse of c. Similarly, for each real number c there is a second real number d where cd = dc=1, and we call d the multiplicative inverse of c.  Definition If f: AB, then f is said to be bijective, or to be one-to-one correspondence, if f is both onto and one-to-one.  Definition The function 1 A : AA, defined by 1 A (a)=a for all aA, is called the identity function for A.

37 Equal function  Definition If f, g : AB, we say that f and g are equal and write f = g, if f(a)=g(a) for all aA.  A common pitfall may happen when f and g have a common domain A and f(a)=g(a) for all aA, but they are not equal.  Ex f and g look similar but they are not equal.  Ex f and g look different but they are indeed equal.

38 Composite function  Definition If f : AB and g : BC, we define the composition function, which is denoted by gf: AC, (gf) (a)=g(f(a)) for each aA.  Ex 5.53, Ex  Properties The codomain of f = domain of g If range of f  domain of g, this will be enough to yield gf: AC. For any f : AB, f1 A = f = 1 B f.

39 Is function composition associative?  Theorem 5.6. If f : AB and g : BC and h : CD, then (hg)f=h(gf).  Ex 5.55.

40 Definitions  Definition If f : AA, we define f 1 =f and f n+1 =ff n. Ex 5.56  Definition For sets A and B, if  is a relation from A to B, then the converse of , denoted by  c, is the relation from B to A defined by  c ={(b, a) (a, b)}. Ex 5.57

41 Invertible function  Definition If f : AB, then f is said to be invertible if there is a function g: BA such that gf=1 A and fg=1 B. (Ex 5.58 )  Theorem 5.7. If a function f : AB is invertible and a function g : BA satisfies gf=1 A and fg=1 B, then this function g is unique.

42 Invertible function  Theorem 5.8. A function f : AB is invertible if and only if it is one-to-one and onto.  Theorem 5.9. If f : AB and g : BC are invertible functions, then gf: AC is invertible and (gf) -1 =f -1 g -1.  Ex f:RR is defined by f(x)=mx+b, and f -1 :RR is defined by f -1 (x)=(1/m)(x-b).  Ex f:RR + is defined by f(x)=e x, and f -1 :R + R is defined by f -1 (x)=ln x.

43 Preimage  Definition If f: AB and B 1 B, then f -1 (B 1 )={xAf(x)B 1 }. The set f -1 (B 1 ) is called the pre-image of B 1 under f.  Ex If f={(1, 7), (2, 7), (3, 8), (4, 6), (5, 9), (6, 9)}, what are the preimage of B 1 ={6, 8}, B 2 ={7, 8}, B 3 ={8, 9}, B 4 ={8, 9, 10}, B 5 ={8, 10}.

44 Ex 5.64  Table 5.9 for f:ZR with f(x)=x 2 +5  Table 5.10 for g:RR with g(x)= x 2 +5

45 Theorems  For aA, af -1 (B 1 B 2 ) f(a) B 1 B 2 f(a) B 1 or f(a)B 2 af -1 (B 1 ) or af -1 (B 2 ) af -1 (B 1 )f -1 (B 2 )

46 Theorem  If f : AB and A=B. Then the following statements are equivalent: (a) f is one-to-one; (b) f is onto, (c) f is invertible.

47 5.7. Computational complexity  Can we measure how long it takes the algorithm to solve a problem of a certain size? To be independent of compliers used, machines used or other factors that may affect the execution, we want to develop a measure of the function, called time complexity function, of the algorithm. Let n be the input size. Then f(n) denotes the number of basic steps needed by the algorithm for input size n.

48 Order  Definition Let f, g: Z + R. we say that g dominates f (or f is dominated by g) if there exist constants mR + and kZ + such that fmg(n) for all nZ +, where nk.  When f is dominated by g we say that f is of order g and we use what is called “ Big- Oh ” notation to denote this. We write fO(g).  O(g) represents the set of all functions with domain Z + and codomain R that are dominated by g.

49 Examples  Ex 5.65, we observe that fO(g).  Ex we observe that gO(f).  Ex When f(n)=a t n t +a t-1 t t-1 + … +a 0, fO(n t ).  Ex f(n)=1+2+ … +nO(n 2 ). f(n)= … +n 2 O(n 3 ). f(n)=1 t +2 t + … +n t O(n t+1 ).  When dealing with the concept of function dominance, we seek the best ( or tightest) bound.

50 some order functions that are commonly seen

51 5.8. Analysis of algorithms  Ex The time complexity is f(n)=7n+5O(n)

52 Ex Linear search.  The best case is O(1).  The worst case is O(n).  The average case f(n)=pn(n+1)/2+nq, where np+q=1.

53 Ex 5.72, Ex compute a n.  In Figure 5.14, the time complexity is f(n) O(n).  In Figure 5.15, the complexity is O(log n).

54

55 The growth of complexities


Download ppt "Chapter 5 Relations and Functions Yen-Liang Chen Dept of Information Management National Central University."

Similar presentations


Ads by Google