3. Basic Relations and Functions
3. Basic Relations and Functions
M. O. Odim (Ph.D.)
Department of Computer Science
Redeemer’s University
1
Relation in Math
The concept of relation in math refers to an association of two objects or two variables based
some property possessed by them.
For Example:
1. Rachel is the daughter of Noah.
This statement shows the relation between two persons.
The relation (R) being ‘is daughter of’.
2. 5 is less than 9.
This statement shows the relation between two numbers.
The relation (R) being ‘is less than’.
If A and B are two non-empty sets, then the relation R from A to B is a subset of A x B, i.e., R
⊆ A x B.
If (a, b) ∈ R, then we write a R b and is read as 'a' related to 'b'.
2
Definition
Given sets A and B, a relation between A and B is a subset of A × B.
By this definition, a relation R is simply a specification of which
pairs are related by R, that is, which pairs the relation R is true
for.
For Example:
1. If A = {p, q, r} B = {3, 4, 5}
Hence, R ⊆ A × B 5
2. Given A = {3, 4, 7, 10} B = {5, 2, 8, 1} then the relation R from A to B is
defined as ‘is less than’ and can be represented in the roster form as R =
{(3, 5) (3, 8) (4, 5), (4, 8), (7, 8)}
6
Set builder form:
For Example:
Let A = {2, 4, 5, 6, 8} and B = {4, 6, 8, 9}
Let R = {(2, 4), (4, 6), (6, 8), (8, 10) then R in the set builder form, it
can be written as
R = {a, b} : a ∈ A, b ∈ B, a is 2 less than b}
7
Arrow diagram:
Draw two circle (oval shape) representing Set A and Set
B.
Write their elements in the corresponding sets, i.e.,
elements of Set A in circle A and elements of Set B in
circle B.
● Draw arrows from A to B which satisfy the relation and
indicate the ordered pairs.
For Example:
1. If A = {3, 4, 5} B = {2, 4, 6, 9, 15, 16, 25}, then
relation R from A to B is defined as ‘is a positive
square root of’ and can be represented by the arrow
diagram as shown (upper right).
Here R = {(3, 9); (4, 16); (5, 25)}
2. If A = {2, 3, 4, 5} and B = {1, 3, 5} and R be the relation
'is less than' from A to B, as shown (lower right)
then R = {(2, 3), (2, 5), (3, 5), (4, 5)} 8
Domain and Range of a Relation
Suppose R be a relation from set A to set B, then
• The set of all first components of the ordered pairs belonging to R is called the
domain of R.
Thus, Dom(R) = {a ∈ A: (a, b) ∈ R for some b ∈ B}.
Let R be the relation ‘is less than’ from A to B. Find Domain (R) and Range (R).
Solution:
Under this relation (R), we have
R = {(4, 5); (4, 7); (4, 9); (6, 7); (6, 9), (8, 9) (2, 5) (2, 7) (2, 9)}
10
Solved examples on domain and range of a
relation:
1. In the given ordered pair (4, 6); (8, 4); (4, 4); (9, 11); (6, 3); (3, 0); (2,
3) find the following relations. Also, find the domain and range.
(a) Is two less than
(d) Is equal to
11
Solution:
(a) R₁ is the set of all ordered pairs whose 1ˢᵗ component is two less than the 2ⁿᵈ
component. Therefore, R₁ = {(4, 6); (9, 11)}
Also, Domain (R₁) = Set of all first components of R₁ = {4, 9} and Range (R₂) = Set of all
second components of R₂ = {6, 11}
(b) R₂ is the set of all ordered pairs whose 1ˢᵗ component is less than the second
component.
Therefore, R₂ = {(4, 6); (9, 11); (2, 3)}.
Also, Domain (R₂) = {4, 9, 2} and Range (R₂) = {6, 11, 3}
(c) R₃ is the set of all ordered pairs whose 1ˢᵗ component is greater than the second
component.
Therefore, R₃ = {(8, 4); (6, 3); (3, 0)}
Also, Domain (R₃) = {8, 6, 3} and Range (R₃) = {4, 3, 0}
(d) R₄ is the set of all ordered pairs whose 1ˢᵗ component is equal to the second component.
Therefore, R₄ = {(4, 4)}
Also, Domain (R) = {4} and Range (R) = {4} 12
2. Let A = {2, 3, 4, 5} and B = {8, 9, 10, 11}. b.
Let R be the relation ‘is factor of’ from A to B.
(b) Draw an arrow diagram to represent the 3. The arrow diagram below shows the relation
relation. (R) from set A to set B. Write this relation in
the roster form.
Solution: Solution:
(a) Clearly, R consists of elements (a, b) where Clearly, R consists of elements (a, b), such that
a is a factor of b. ‘a’ is square of ‘b’
i.e., a = b².
So, in roster form R = {(9, 3); (9, -3); (4, 2); (4, -
Therefore, Relation (R) in the roster form is R 2); (16, 4); (16, -4)}
= {(2, 8); (2, 10); (3, 9); (4, 8), (5, 10)}
16
Mapping or Functions:
● Different elements of A can have the same image ● It is necessary that every f image is
in B. Adjoining figure represents a mapping. in B but there may be some
elements in B which are not f
images of any element of A.
18
Domain,Co-domain and Range of Function
Therefore, the given arrow diagram (b) does not represent a mapping.
(c) The element ‘b’ of set A is not associated with any element of set B. So b ∈
A does not have any image. For a mapping from A to B, every element of set
A must have a unique image in set B which is not represented by this arrow
diagram. So, the given arrow diagram (c) does not represent a mapping.
(d) a has a unique image p. b has a unique image q. c has a unique image r. Thus,
each element in set A has a unique image in set B.
20
2. Find out if R is a mapping from A to B. 3. Let A = {1, 2, 3, 4} and B = {0, 3, 6, 8, 12, 15}
(i) Let A = {3, 4, 5} and B= {6, 7, 8, 9} and Consider a rule f (x) = x² - 1, x∈A, then
R = {(3, 6) (4, 7) (5, 8)}
(a) show that f is a mapping from A to B.
Solution:
(b) draw the arrow diagram to represent the
Since, R = {(3, 6); (4, 7); (5, 8)} then Domain mapping.
(R) = {3, 4, 5} = A
(c) represent the mapping in the roster form.
We observe that no two ordered pairs in R
have the same first component. (d) write the domain and range of the
Therefore, R is a mapping from A to B. mapping.
(ii) Let A = {1, 2, 3} and B= {7, 11} and R = {(1, Solution:
7); (1, 11); (2, 11); (3, 11)} (a)
Solution: Using f (x) = x² - 1, x ∈ A we have
Since, R = {(1, 7); (1, 11); (2, 11); (3, 11)} f(1) = 0,
then Domain (R) = {1, 2, 3} = A f(2) = 3,
But the ordered pairs (1, 7) (1, 11) have the f(3) = 8,
same first component. f(4) = 15
We observe that every element in set A has
Therefore, R is not a mapping from A to B. unique image in set B.
Therefore, f is a mapping from A to B.
21
(b) Arrow diagram which represents the
mapping is given below.
Representation of a function by an arrow
diagram:
22
Some examples of functions:
Note:
• Observe in figure (i) and figure (ii), there are some elements in B which are not f-
images of any elements of A. In figure (iii), figure (iv), two elements of A have the
same image in B. 23
Ordered pairs
• The definition of a set explicitly disregards the order of the set elements, all that matters is who’s in, not
who’s in first
• However, sometimes the order is important leading to the notion of an ordered pair of two elements x and y,
denoted (x, y).
• The crucial property is:
• (x, y) = (u, v) if and only if x = u and y = v.
• This notion can be extended naturally to define an ordered n-tuple as the ordered counterpart of a set with n
elements.
• Given two sets A and B, their cartesian product A×B is the set of all ordered pairs (x, y), such that x ∈ A and y
∈ B:
A x B = {(x, y) : x ∈ A, y ∈ B}.
useful special case:
A2 = A × A = {(x, y) : x, y ∈ A}.
a general definition: A1 = A, and for n ≥ 2,
An = {(x1, x2, . . . , xn) : x1, x2, . . . , xn ∈ A}
24
.
DEFINITION
26
Solving a Recurrence
To solve a given recurrence subject to a given initial condition implies to find an explicit formula for
the generic term of the sequence that satisfies both the recurrence equation and the initial condition
or to prove that such a sequence does not exist. For example, the solution to recurrence (1) subject
to initial condition (2) is
𝑛 𝑛+1
𝑥(𝑛) = for n≥0. (3)
2
by substituting this formula into (1) to check that the equality holds for every n > 0, i.e., that
𝑛 𝑛+1 𝑛−1 𝑛−1+1
= +n
2 2
and into (2) to check that 𝑥 0 =0 i.e., that
0 0+1
=0
2
27
General Solution to a Recurrence Equation
Sometimes it is convenient to distinguish between a general solution and a particular solution to a
recurrence. Recurrence equations typically have an infinite number of sequences that satisfy them.
A general solution to a recurrence equation is a formula that specifies all such sequences.
Typically, a general solution involves one or more arbitrary constants. For example, for recurrence
(1), the general solution can be specified by the formula
𝑛 𝑛+1
𝑥 𝑛 =𝑐+ (4)
2
Where c is such an arbitrary constant. By assigning different values to c,
we can get all the solutions to equation (1) and only these solutions.
A particular solution is a specific sequence that satisfies a given recurrence
equation.
Usually we are interested in a particular solution that satisfies a given initial
condition. For example, sequence (3) is a particular solution to (1)– (2).
28
Methods for Solving Recurrence Relations
No universal method exists that would enable us to solve every recurrence relation.
There are several techniques, however, some more powerful than others, that
can solve a variety of recurrences. We consider 2.
29
Method of Forward Substitutions
Starting with the initial term (or terms) of the sequence given by the initial condition(s), we can use the recurrence
equation to generate the few first terms of its solution in the hope of seeing a pattern that can be expressed by a
closed-end formula.
If such a formula is found, its validity should be either checked by direct substitution into the recurrence equation
and the initial condition (as we did for (1)–(2)) or proved by mathematical induction.
31
Method of Backward Substitutions
• works exactly as its name implies: using the recurrence relation in question, we
express x(n − 1) as a function of x(n − 2) and substitute the result into the original
equation to get x(n) as a function of x(n − 2).
• Repeating this step for x(n −2) yields an expression of x(n) as a function of x(n −
3).
• For many recurrence relations, we will then be able to see a pattern and express
x(n) as a function of
x(n − i) for an arbitrary i = 1, 2, . . . . Selecting i to make n − i reach the initial
condition and using one of the standard summation formulas often leads to a
closed-end formula for the solution to the recurrence.
32
As an example, let us apply the method of backward substitutions to recurrence (1)–(2).
Thus, we have the recurrence equation
x(n) = x(n − 1) + n.
Replacing n by n − 1 in the equation yields x(n − 1) = x(n − 2) + n − 1; after substituting this
expression for x(n − 1) in the initial equation, we obtain
x(n) = [x(n − 2) + n − 1]+ n = x(n − 2) + (n − 1) + n.
Replacing n by n − 2 in the initial equation yields x(n − 2) = x(n − 3) + n − 2; after
substituting this expression for x(n − 2), we obtain
x(n) = [x(n − 3) + n − 2]+ (n − 1) + n = x(n − 3) + (n − 2) + (n − 1) + n.
Comparing the three formulas for x(n), we can see the pattern arising after i such
substitutions:
x(n) = x(n − i) + (n − i + 1) + (n − i + 2) + . . . + n.
Since initial condition (2) is specified for n = 0, we need n − i = 0, i.e., i = n, to reach it:
x(n) = x(0) + 1+ 2 + . . . + n = 0 + 1+ 2 + . . . + n = n(n + 1)/2.
33
The method of backward substitutions works well for a
wide variety of simple recurrence relations.
There are many examples of its successful applications
of this method in computing
e.g. Mathematical Analysis of Recursive Algorithms
(in CMP 452)
34