0% found this document useful (0 votes)
139 views81 pages

Chapter 5 Relations and Functions

Cartesian Products and Relations. Functions: Plain and One-to-One. Onto Functions: Stirling’s Numbers of the Second Kind, Special Functions, The Pigeonhole Principle. Self Learning Exercise: Function Composition and Inverse Functions.

Uploaded by

Nandini Lokanath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views81 pages

Chapter 5 Relations and Functions

Cartesian Products and Relations. Functions: Plain and One-to-One. Onto Functions: Stirling’s Numbers of the Second Kind, Special Functions, The Pigeonhole Principle. Self Learning Exercise: Function Composition and Inverse Functions.

Uploaded by

Nandini Lokanath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 81

Chapter 5 Relations and Functions

Unit 4
Functions:

 Cartesian Products and Relations.


 Functions: Plain and One-to-One.
 Onto Functions: Stirling’s Numbers of the Second Kind,
 Special Functions,
 The Pigeonhole Principle.
 Self Learning Exercise: Function Composition and
Inverse Functions.
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 A1A2…An are ordered n-tuples.
 AB=AB
 Ex 5.1. A={2, 3, 4}, B={4, 5}.
 What are AB, BA, B2 and B3?
But, in general A  B  B  A. And
A1  A2  An  {(a1 , a 2 , , a n )| a i  Ai ,1  i  n}.
Ex 5.1. A={2, 3, 4}, B={4, 5}.
What are AB, BA, B2 and B3?
Tree diagrams for the Cartesian product
Trees are convenient tools for enumeration.
Ex. 5.4 At the Wimbledon Tennis Championships, women play
at most 3 sets in a match. The winner is the first to win two sets.
In how many ways can a match be won?
Problem
Microprocessors are tested individually and are labelled
defective (D) or Good (G). Construct a tree diagram
describing sample space for this testing process which is
continue until either two defective or five microprocessors are
tested in total.
Solution:
16 outcomes
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 2mn
relations from A to B. There are also 2mn relations from B to A.
 For any set A, A=. Likewise,   A =.
Problem
1. Let A = {a,b,c,d} and B ={ w,x,y}
 Give any three relations from A to B
 Give any three relations on A
 |P(A X B)| ?
Theorem 5.1 For any set A, B, C  U :
(a) A  ( B  C )  ( A  B )  ( A  C )
( b) A  ( B  C )  ( A  B )  ( A  C )
(c) ( A  B )  C  ( A  C )  ( B  C )
(d) ( A  B )  C = ( A  C )  ( B  C )

Proof of (a) : For any a, b  U , (a, b)  A  ( B  C )  a  A 


b  ( B  C )  a  A, b  B, b  C  (a, b)  ( A  B),
( a, b)  ( A  C )  ( a, b)  ( A  B )  ( A  C )
5.2. Functions: Plain and one-to-one
 Function is a special kind of relation
 Def. 5.3 For nonempty sets, A,B, a function, or mapping, f from A
to B, denoted f:A  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.
 Definition 5.3. f: AB, A is called domain and B is co domain. 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.
Example
Example
Ex. 5.10 (a ) floor function
f ( x)  x   the greatest integer less than or equal to x
3.8  3,  3.8  4,  3  3
(b) ceiling function
f ( x)  x   the least integer greater th an or equal to x
3.8  4,  3.8  3,  3  3
(c) trunc function
trunc( x)  the integer part of x
trunc(3.8)  3, trunc(3.8)  3, trunc(3)  3
properties
 For finite sets A and B with A=m and B=n, there are nm
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 a1, a2A,
f(a1)=f(a2) a1=a2.
 Ex 5.13. f(x)=3x+7 for xR is one-to-one. But g(x)=x4-x is
not. (Why?)
example
Number of one-to-one functions
 Ex 5.14. A={1, 2, 3}, B={1, 2, 3, 4, 5},
 there are 215 relations from A to B
 and 53 functions from A to B.
 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.
Definition
Example
Example
Example
Theorem 5.2.
 Let f: AB with A1, A2A. Then
(a) f(A1A2)=f(A1)f(A2),
(b) f(A1A2)f(A1)f(A2),
(c) f(A1A2)=f(A1)f(A2) when f is one-to-one.
common notations

(a) Z=the set of integers={0,1,-1,2,-1,3,-3,...}


(b) N=the set of nonnegative integers or natural
numbers
(c) Z+=the set of positive integers
(d) Q=the set of rational numbers={a/b| a,b is
integer, b not zero}
(e) Q+=the set of positive rational numbers
(f) Q*=the set of nonzero rational numbers
(g) R=the set of real numbers
(h) R+=the set of positive real numbers
(i) R*=the set of nonzero real numbers
(j) C=the set of complex numbers
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 5.19. The function f: RR defined by f(x)=x3 is an
onto function. But the function g: RR defined by
f(x)=x2 is not an onto function.
 Ex 5.20. 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.
Example 5.21
The number of onto functions
 Ex 5.22. If A={x, y, z} and B={1,2}, there are 23-2=6 onto
functions. In general, if A=m and B=2, then there are
2m-2 onto functions.
 Ex 5.23. If A={w, x, y, x} and B={1,2, 3}.
 There are C(3, 3)34 functions from A to B.
 Consider subset B of size 2, such as {1, 2}, {1, 3}, {2, 3}, there are
C(3, 2)24 functions from A to B.
 Consider subset B of size 1, such as {1}, {3}, {2}, there are C(3,
1)14 functions from A to B.
 Totally, there are C(3, 3)34- C(3, 2)24+ C(3, 1)14 onto functions
from A to B.
The number of onto functions
 For finite sets A and B with A=m and B=n, the number of
onto functions is:

 n m  n   n  n 1  n  m
 n   (n  1)  
m
(n  2) ...  (1)  1
m

 n  n  1  n  2  1

n
 n 
  (1) k
(n  k ) m
k 0 n  k
Examples
 Ex 5.24. 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)47-C(4, 3)37+C(4, 2)27-C(4, 1)17=8400

n
 n 
 ( 1)k
 
n  k ( n  k ) m

k 0  
Problem 1
Problem 2
Examples
 Ex 5.26. 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 :

n
 n 
 ( 1k
)  
n  k ( n  k ) m

k 0  
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
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

1 n k n 
 ( 1)  
n  k( n  k ) m

n! k 0  
n

 S ( m, i )
i 1

 It is the number of possible ways to distribute m distinct


objects into n identical containers with empty containers
allowed.
Theorem 5.3.
 S(m+1, n)=S(m, n-1) + n S(m, n).
Ex 5.28.
 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= 6
 S (6, i)
i2
5.4. Special functions
 Definition 5.10. f: AAB is called a binary operation. If
BA, then it is closed on A.
 Definition 5.11. 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.
Commutative and associative
 Definition 5.12. 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))
Commutative and associative
 Ex 5.32.
 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 5.33. Assume A={a, b, c, d} and f: AAA. There are 416
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
4446.
Identity
 Definition 5.13. 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 5.34.
 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.
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 5.35. 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 516 closed binary operations on A, where x is the
identity.
 Of these, 510=5456 are commutative.
 If every element can be used as the identity, we have 511 closed
binary operations that are commutative.
Projection
 Definition 5.14. 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A1 A2…An, then A: DAi  Ai  Ai ,,,, Ai ,
1 2 3 m

defined by (a1, a2, …, an)= ai , ai , ai , …, ai is called the


1 2 3 m

projection on the i1, i2, …, im coordinates.


The projection of a database
Digital Signature Standard (DSS)
5.5. 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.
Theorem 1

 If k+1 or more objects are placed into k boxes, then


there is at least one box containing two or more of the
objects
examples
 among 13 people, at least two of them have birthdays
during the same month.

 In a group of 367 people, there must be two people with the


same birthday
 As there are 366 possible birthdays

 In a group of 27 English words, at least two words must start


with the same letter
 As there are only 26 letters
Examples
 In a laundry bag, there are 12 pairs of socks. Drawing
the socks from the bag randomly, we will draw at most
___ of them to get a matched pair.
13

 Let SZ+ and S=37. Then S contains two elements that


have the same remainder upon division by 36.
example
Examples
 Any subset of size 6 from the set S={1, 2, …, 9} must
contain two elements whose sum is 10.
Examples
 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 ½.
Examples
 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 26-1=63 subsets of S.
 1SA 9+10+…+14=69
 If A=5, then 1SA 10+…+14=60
 There are 62 nonempty subsets A of A with 5A.
example
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 5.15. 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 5.16. The function 1A: AA, defined by 1A(a)=a for all aA, is
called the identity function for A.
Equal function
 Definition 5.17. 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 5.51. f and g look similar but they are not equal.
 Ex 5.52. f and g look different but they are indeed equal.
Composite function
 Definition 5.18. 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 5.54.
 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1A = f = 1Bf.
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.
Definitions
 Definition 5.19. If f : AA, we define f1=f and fn+1=ffn.
 Ex 5.56
 Definition 5.20. 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
Invertible function
 Definition 5.21. If f : AB, then f is said to be invertible if
there is a function g: BA such that gf=1A and fg=1B.
(Ex 5.58 )
 Theorem 5.7. If a function f : AB is invertible and a
function g : BA satisfies gf=1A and fg=1B, then this
function g is unique.
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 5.60. 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 5.61. f:RR+ is defined by f(x)=ex, and f-1:R+R is
defined by f-1(x)=ln x.
Preimage
 Definition 5.22. If f: AB and B1B, then f-
1(B )={xAf(x)B }. The set f-1(B ) is called the pre-
1 1 1
image of B1 under f.
 Ex 5.62. If f={(1, 7), (2, 7), (3, 8), (4, 6), (5, 9), (6, 9)},
what are the preimage of B1={6, 8}, B2={7, 8}, B3={8, 9},
B4={8, 9, 10}, B5={8, 10}.
Ex 5.64
 Table 5.9 for f:ZR with f(x)=x2+5
 Table 5.10 for g:RR with g(x)= x2+5
Theorems

 For aA, af-1(B1B2)


f(a) B1B2
f(a) B1 or f(a)B2
af-1(B1) or af-1(B2)
af-1(B1)f-1(B2)
Theorem 5.11.
 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.
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.
Order
 Definition 5.23. 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.
Examples
 Ex 5.65, we observe that fO(g).
 Ex 5.66. we observe that gO(f).
 Ex 5.67. When f(n)=atnt+at-1tt-1 +…+a0, fO(nt).
 Ex 5.68.
 f(n)=1+2+…+nO(n2).
 f(n)=12+22+…+n2O(n3).
 f(n)=1t+2t+…+ntO(nt+1).
 When dealing with the concept of function dominance, we
seek the best ( or tightest) bound.
some order functions that are commonly
seen
5.8. Analysis of algorithms
 Ex 5.69. The time complexity is f(n)=7n+5O(n)
Ex 5.70. 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.
Ex 5.72, Ex 5.73. compute an.

 In Figure 5.14, the time complexity is f(n) O(n).


 In Figure 5.15, the complexity is O(log n).
The growth of complexities

You might also like