0% found this document useful (0 votes)
20 views80 pages

Discrete Chapter 09

Chapter 9 of the Discrete Structures document focuses on relations, specifically binary relations between two sets A and B, and their properties. It covers definitions, examples, and classifications of relations, including reflexive, symmetric, antisymmetric, and transitive relations. The chapter also discusses how functions can be viewed as specific types of relations.

Uploaded by

workairdrop92
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)
20 views80 pages

Discrete Chapter 09

Chapter 9 of the Discrete Structures document focuses on relations, specifically binary relations between two sets A and B, and their properties. It covers definitions, examples, and classifications of relations, including reflexive, symmetric, antisymmetric, and transitive relations. The chapter also discusses how functions can be viewed as specific types of relations.

Uploaded by

workairdrop92
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/ 80

Discrete Structures

Chapter 9
Relations

Prof. Dr. Malik Sikander Hayat Khiyal


Faculty of Computer Science,
Preston University, Islamabad Campus,
85, Street 3, Sector H-8/1,
Islamabad, PAKISTAN.
[email protected]
04/17/2025 Discrete Mathematics Chapter 9 1
Discrete Structures Contents
Chapter 1. The Foundations: Logic and Proofs
Chapter 2. Basic Structures: Sets, Functions, Sequences, and Sums
Chapter 3. The Fundamentals: Algorithms, the Integers, and Matrices
Chapter 4. Number Theory and Cryptography
Chapter 5. Induction and Recursion
Chapter 6. Counting
Chapter 7. Discrete Probability
Chapter 8. Advanced Counting Technique
Chapter 9. Relations
Chapter 10. Graphs
Chapter 11. Trees
Chapter 12. Boolean Algebra

04/17/2025 Discrete Mathematics Chapter 9 2


Relations
If we want to describe a relationship between
elements of two sets A and B, we can use ordered
pairs with their first element taken from A and
their second element taken from B.
Since this is a relation between two sets, it is called
a binary relation.
Definition: Let A and B be sets. A binary relation
from A to B is a subset of AB.
In other words, for a binary relation R we have
R  AB. We use the notation aRb to denote that
(a, b)R and aRb to denote that (a, b)R.
04/17/2025 Discrete Mathematics Chapter 9 3
Relations
When (a, b) belongs to R, a is said to be related to b
by R.
Example: Let P be a set of people, C be a set of cars,
and D be the relation describing which person drives
which car(s).
P = {Carl, Suzanne, Peter, Carla},
C = {Mercedes, BMW, tricycle}
D = {(Carl, Mercedes), (Suzanne, Mercedes),
(Suzanne, BMW), (Peter, tricycle)}
This means that Carl drives a Mercedes, Suzanne
drives a Mercedes and a BMW, Peter drives a tricycle,
and Carla does not drive any of these vehicles.

04/17/2025 Discrete Mathematics Chapter 9 4


Functions as Relations
You might remember that a function f from a set A
to a set B assigns a unique element of B to each
element of A.
The graph of f is the set of ordered pairs (a, b) such
that b = f(a).
Since the graph of f is a subset of AB, it is a
relation from A to B.
Moreover, for each element a of A, there is exactly
one ordered pair in the graph that has a as its first
element.

04/17/2025 Discrete Mathematics Chapter 9 5


Functions as Relations
Conversely, if R is a relation from A to B such that
every element in A is the first element of exactly one
ordered pair of R, then a function can be defined
with R as its graph.

This is done by assigning to an element aA the


unique element bB such that (a, b)R.

04/17/2025 Discrete Mathematics Chapter 9 6


Relations on a Set

Definition: A relation on the set A is a relation from


A to A.
In other words, a relation on the set A is a subset of
AA.

Example: Let A = {1, 2, 3, 4}. Which ordered pairs


are in the relation R = {(a, b) | a < b} ?

04/17/2025 Discrete Mathematics Chapter 9 7


Relations on a Set
Solution: R = { (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}

1 1
R 1 2 3 4
1 X X X
2 2
2 X X
3 3
3 X

4 4 4

04/17/2025 Discrete Mathematics Chapter 9 8


Relations on a Set
How many different relations can we define on a
set A with n elements?
A relation on a set A is a subset of AA.
How many elements are in AA ?
There are n2 elements in AA, so how many subsets
(= relations on A) does AA have?
The number of subsets that we can form out of a set
n2
with m elements is 2 . Therefore, 2 subsets can be
m

formed out of AA.


n2
Answer: We can define 2 different relations on A.

04/17/2025 Discrete Mathematics Chapter 9 9


Relations on a Set
Example: Consider these relations on the set of integers:
R1 = {(a, b) ∣ a ≤ b},
R2 = {(a, b) ∣ a > b},
R3 = {(a, b) ∣ a = b or a = −b},
R4 = {(a, b) ∣ a = b},
R5 = {(a, b) ∣ a = b + 1},
R6 = {(a, b) ∣ a + b ≤ 3}.
Which of these relations contain each of the pairs
(1,1), (1,2), (2,1), (1,−1), and (2,2)?
Solution: The pair (1,1) is in R1, R3, R4, and R6; (1,2) is
in R1 and R6; (2,1) is in R2, R5, and R6; (1,−1) is in R2,
R3, and R6; and finally, (2,2) is in R1, R3, and R4.
04/17/2025 Discrete Mathematics Chapter 9 10
Properties of Relations
We will now look at some useful ways to classify
relations.
Definition: A relation R on a set A is called reflexive
if (a, a)R for every element aA.
Are the following relations on {1, 2, 3, 4} reflexive?
R = {(1, 1), (1, 2), (2, 3), (3, 3), (4, 4)} No.
R = {(1, 1), (2, 2), (2, 3), (3, 3), (4, 4)} Yes.
R = {(1, 1), (2, 2), (3, 3)} No.

Definition: A relation on a set A is called irreflexive if (a, a) 


R for every element a  A.

04/17/2025 Discrete Mathematics Chapter 9 11


Properties of Relations
Example: Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(1,1),(1,2),(1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4),
(4,4)},
R6 = {(3,4)}.
Which of these relations are reflexive?
Solution: The relations R3 and R6 are reflexive because they both
contain all pairs of the form (a, a), namely, (1, 1), (2, 2), (3, 3),
and (4, 4). The other relations are not reflexive because they do
not contain all of these ordered pairs. In particular, R1, R2, R4, and
R04/17/2025
6 are not reflexive because (3, 3) is not in any of these relations.
Discrete Mathematics Chapter 9 12
Properties of Relations
Definitions:
A relation R on a set A is called symmetric if (b, a)R
whenever (a, b)R for all a, bA.
A relation R on a set A is called antisymmetric if
a = b whenever (a, b)R and (b, a)R.
A relation R on a set A is called asymmetric if
(a, b)R implies that (b, a)R for all a, bA.

04/17/2025 Discrete Mathematics Chapter 9 13


Properties of Relations
Are the following relations on {1, 2, 3, 4}
symmetric, antisymmetric, or asymmetric?

R = {(1, 1), (1, 2), (2, 1), (3, 3), (4, 4)} symmetric

R = {(1, 1)} sym. and antisym.

R = {(1, 3), (3, 2), (2, 1)} antisym. and asym.


R = {(4, 4), (3, 3), (1, 4)} antisym.

04/17/2025 Discrete Mathematics Chapter 9 14


Properties of Relations
Example: Which of the relations on the set of integers
are symmetric and which are antisymmetric?:
R1 = {(a, b) ∣ a ≤ b},
R2 = {(a, b) ∣ a > b},
R3 = {(a, b) ∣ a = b or a = −b},
R4 = {(a, b) ∣ a = b},
R5 = {(a, b) ∣ a = b + 1},
R6 = {(a, b) ∣ a + b ≤ 3}.
Solution: The relations R3, R4, and R6 are symmetric. R3
is symmetric, for if a=b or a=−b, then b=a or b=−a.
R4 is symmetric because a=b implies that b=a. R6 is
symmetric because
04/17/2025 a+b≤3
Discrete implies
Mathematics Chapter 9 that b+a≤3 15
Properties of Relations

The relations R1, R2, R4, and R5 are


antisymmetric. R1 is antisymmetric because the
inequalities a ≤ b and b ≤ a imply that a = b. R2 is
antisymmetric because it is impossible that a > b
and b > a. R4 is antisymmetric, because two
elements are related with respect to R4 if and
only if they are equal. R5 is antisymmetric
because it is impossible that a = b + 1 and b = a +
1. The reader should verify that none of the other
relations is antisymmetric

04/17/2025 Discrete Mathematics Chapter 9 16


Properties of Relations
Definition: A relation R on a set A is called
transitive if whenever (a, b)R and (b, c)R, then
(a, c)R for a, b, cA.
Are the following relations on {1, 2, 3, 4}
transitive?

R = {(1, 1), (1, 2), (2, 2), (2, 1), (3, 3)} Yes.

R = {(1, 3), (3, 2), (2, 1)} No.


No.
R = {(2, 4), (4, 3), (2, 3), (4, 1)}

04/17/2025 Discrete Mathematics Chapter 9 17


Properties of Relations
Example: Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(1,1),(1,2),(1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4),
(4,4)},
R6 = {(3,4)}.
Which of these relations are transitive?
Solution: R4, R5, and R6 are transitive. For each of these
relations, we can show that it is transitive by verifying that if
(a, b) and (b, c) belong to this relation, then (a, c) also does.
04/17/2025 Discrete Mathematics Chapter 9 18
Properties of Relations
For instance, R4 is transitive, because (3, 2) and
(2,1), (4, 2) and (2, 1), (4, 3) and (3, 1), and (4, 3)
and (3, 2) are the only such sets of pairs, and (3,1),
(4, 1), and (4, 2) belong to R4.
The reader should verify that R5 and R6 are
transitive.
R1 is not transitive because (3, 4) and (4, 1)
belong to R1, but (3, 1) does not. R2 is not
transitive because (2, 1) and (1, 2) belong to R2,
but (2, 2) does not. R3 is not transitive because
(4,1) and (1, 2) belong to R3, but (4, 2) does not.
04/17/2025 Discrete Mathematics Chapter 9 19
Properties of Relations
Example: Which of the relations on the set of integers are
transitive:
R1 = {(a, b) ∣ a ≤ b},
R2 = {(a, b) ∣ a > b},
R3 = {(a, b) ∣ a = b or a = −b},
R4 = {(a, b) ∣ a = b},
R5 = {(a, b) ∣ a = b + 1},
R6 = {(a, b) ∣ a + b ≤ 3}.
Solution: The relations R1, R2, R3, and R4 are transitive. R1 is transitive
because a ≤ b and b ≤ c imply that a ≤ c. R2 is transitive because a > b
and b > c imply that a > c. R3 is transitive because a = ±b and b = ±c
imply that a = ±c. R4 is clearly transitive, as the reader should verify.
R5 is not transitive because (2, 1) and (1, 0) belong to R5, but (2, 0)
does not. R6 is not transitive
04/17/2025
because (2, 1) and (1, 2) belong to R6, but
Discrete Mathematics Chapter 9 20
(2, 2) does not.
Properties of Relations

Example: Is the “divides” relation on the set


of positive integers transitive?
Solution: Suppose that a divides b and b
divides c. Then there are positive integers k
and l such that b = ak and c = bl. Hence, c =
a(kl), so a divides c. It follows that this
relation is transitive.

04/17/2025 Discrete Mathematics Chapter 9 21


Properties of Relations
Example: How many different reflexive relations can
be defined on a set A containing n elements?
Solution: Relations on R are subsets of AA, which
contains n2 elements.
Therefore, different relations on A can be generated
by choosing different subsets out of these n 2 elements,
so there are 2n2 relations.
A reflexive relation, however, must contain the n
elements (a, a) for every aA.
Consequently, we can only choose among n2 – n =
n(n – 1) elements to generate reflexive relations, so
there are 2n(n – 1) of them.
04/17/2025 Discrete Mathematics Chapter 9 22
Combining Relations

Relations are sets, and therefore, we can apply the usual


set operations to them.
If we have two relations R1 and R2, and both of them
are from a set A to a set B or subset of A × B, then we
can combine them to R1  R2, R1  R2, or R1 – R2.
In each case, the result will be another relation from A
to B.

04/17/2025 Discrete Mathematics Chapter 9 23


Combining Relations
Example: Let A = {1, 2, 3} and B = {1, 2, 3, 4}. The
relations
R1 = {(1, 1), (2, 2), (3, 3)}
and R2 = {(1, 1), (1, 2), (1, 3), (1, 4)}
can be combined to obtain
R1 ∪ R2 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (3, 3)},
R1 ∩ R2 = {(1, 1)},
R1 − R2 = {(2, 2), (3, 3)},
R2 − R1 = {(1, 2), (1, 3), (1, 4)}.

04/17/2025 Discrete Mathematics Chapter 9 24


Combining Relations
Example: Let R1 be the less than relation on the set of real
numbers and let R2 be the greater than relation on the set of
real numbers, that is, R1={(x, y)∣x<y} and R2={(x, y)∣x>y}.
What are R1 ∪ R2, R1 ∩ R2, R1 − R2, R2 − R1, and R1 ⊕ R2?
Solution: We note that (x, y) ∈ R1 ∪ R2 if and only if (x, y) ∈ R1
or (x, y) ∈ R2. Hence, (x, y) ∈ R1 ∪ R2 if and only if x<y or
x>y. Because the condition x < y or x > y is the same as the
condition x ≠ y, it follows that R1 ∪ R2 = {(x, y) ∣ x ≠ y}. In
other words, the union of the less than relation and the greater
than relation is the not equals relation.
Next, note that it is impossible for a pair (x, y) to belong to
both R1 and R2 because it is impossible that x < y and x > y. It
follows that R1 ∩ R2 = ∅. We also see that R1 − R2 = R1, R2 −
R1 = R2, and R1 ⊕ RDiscrete
04/17/2025
2 = R1 ∪ R2 − R1 ∩ R2 = {(x, y) ∣ x ≠ y}.
Mathematics Chapter 9 25
Combining Relations
There is another important way to combine relations.
Definition: Let R be a relation from a set A to a set B
and S a relation from B to a set C. The composite of R
and S is the relation consisting of ordered pairs (a, c),
where aA, cC, and for which there exists an element
bB such that (a,b)R and (b,c)S. We denote the
composite of R and S by SR.
In other words, if relation R contains a pair (a, b) and
relation S contains a pair (b, c), then S R contains a pair
(a, c).

04/17/2025 Discrete Mathematics Chapter 9 26


Combining Relations
Example: Let D and S be relations on A = {1, 2, 3, 4}.
D = {(a, b) | b = 5 - a} “b equals (5 – a)”
S = {(a, b) | a < b} “a is smaller than b”
D = {(1, 4), (2, 3), (3, 2), (4, 1)}
S = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}
SD = {(2,4), (3,3), (3,4), (4,2), (4,3), (4,4)}

D maps an element a to the element (5 – a), and afterwards


S maps (5 – a) to all elements larger than (5 – a), resulting
in S  D = {(a,b) | b > 5 – a} or S  D = {(a,b) | a + b > 5}.

04/17/2025 Discrete Mathematics Chapter 9 27


Combining Relations
Example: What is the composite of the relations R and S,
where R is the relation from {1,2,3} to {1,2,3,4} with R
= {(1,1), (1,4), (2,3), (3,1), (3,4)} and S is the relation
from {1,2,3,4} to {0,1,2} with S = {(1,0), (2,0), (3,1),
(3,2), (4,1)}?
Solution: S ◦R is constructed using all ordered pairs in R
and ordered pairs in S, where the second element of the
ordered pair in R agrees with the first element of the
ordered pair in S. For example, the ordered pairs (2,3)
in R and (3,1) in S produce the ordered pair (2,1) in
S◦R. Computing all the ordered pairs in the composite,
we find S ◦ R = {(1,0), (1,1), (2,1), (2,2), (3,0), (3,1)}.
04/17/2025 Discrete Mathematics Chapter 9 28
Combining Relations
Figure illustrates how this composition is found. In
the figure, we examine all paths that travel via two
directed edges from the leftmost elements to the
rightmost elements via an element in the middle.
R S
1

1→1→0 (1, 0)
1
0
1→4→1 (1, 1)

2 2→3→1 (2, 1)
2

3 1 2→3→2 (2, 2)

3→1→0 (3, 0)
3

4 2 3 → 4→ 1 (3, 1)

04/17/2025 Discrete Mathematics Chapter 9 29


Combining Relations
We already know that functions are just special
cases of relations (namely those that map each
element in the domain onto exactly one element in
the codomain).

If we formally convert two functions into relations,


that is, write them down as sets of ordered pairs, the
composite of these relations will be exactly the same
as the composite of the functions (as defined earlier).

04/17/2025 Discrete Mathematics Chapter 9 30


Combining Relations

Definition: Let R be a relation on the set A. The


powers Rn, n = 1, 2, 3, …, are defined inductively by
R1 = R
Rn+1 = RnR

In other words:
Rn = RR … R (n times the letter R)

04/17/2025 Discrete Mathematics Chapter 9 31


Combining Relations
Example: Let R = {(1, 1), (2, 1), (3, 2), (4, 3)}. Find the
powers Rn, n = 2, 3, 4, … .
Solution: Because R2 = R ◦R, we find that
R2 = {(1, 1), (2, 1), (3, 1), (4, 2)}.
Furthermore, because R3 = R2 ◦R,
R3 = {(1, 1), (2, 1), (3, 1), (4, 1)}.
Additional computation shows that R4 is the same as
R3, so
R4 = {(1, 1), (2, 1), (3, 1), (4, 1)}.
It also follows that Rn = R3 for n = 5, 6, 7, … . And so
on.
04/17/2025 Discrete Mathematics Chapter 9 32
Combining Relations
Theorem: The relation R on a set A is transitive if and
only if Rn  R for all positive integers n.
Remember the definition of transitivity:
Definition: A relation R on a set A is called transitive if
whenever (a, b)R and (b, c)R, then (a, c)R for a, b,
cA.
The composite of R with itself contains exactly these
pairs (a, c).
Therefore, for a transitive relation R, RR does not
contain any pairs that are not in R, so RR  R.
Since RR does not introduce any pairs that are not
already in R, it must also be true that (RR)R  R, and
so on,
04/17/2025
so that R n
 Discrete
R. Mathematics Chapter 9 33
n-ary Relations
In order to study an interesting application of
relations, namely databases, we first need to
generalize the concept of binary relations to n-ary
relations.

Definition: Let A1, A2, …, An be sets. An n-ary


relation on these sets is a subset of A1A2…
An.
The sets A1, A2, …, An are called the domains of the
relation, and n is called its degree.

04/17/2025 Discrete Mathematics Chapter 9 34


n-ary Relations
Example:
Let R = {(a, b, c) | a = 2b  b = 2c with a, b, cN}
What is the degree of R?
The degree of R is 3, so its elements are triples.
What are its domains?
Its domains are all equal to the set of integers.
Is (2, 4, 8) in R?
No.
Is (4, 2, 1) in R?
Yes.

04/17/2025 Discrete Mathematics Chapter 9 35


n-ary Relations
Example: Let R be the relation on N × N × N consisting of
triples (a, b, c), where a, b, and c are integers with a<b<c.
Then (1, 2, 3) ∈ R, but (2, 4, 3) ∉ R. The degree of this
relation is 3. Its domains are all equal to the set of natural
numbers.
Example: Let R be the relation on Z × Z × Z consisting of all
triples of integers (a, b, c) in which a, b, and c form an
arithmetic progression. That is, (a, b, c) ∈ R if and only if
there is an integer k such that b = a + k and c = a + 2k, or
equivalently, such that b−a = k and c−b = k. Note that
(1,3,5) ∈ R because 3 = 1+2 and 5=1+ 2⋅2, but (2, 5, 9) ∉
R because 5 − 2 = 3 while 9 − 5 = 4. This relation has
degree 3 and its domains are all equal to the set of integers.

04/17/2025 Discrete Mathematics Chapter 9 36


Databases and Relations
Let us take a look at a type of database representation
that is based on relations, namely the relational data
model.

A database consists of n-tuples called records, which


are made up of fields.
These fields are the entries of the n-tuples.

The relational data model represents a database as an


n-ary relation, that is, a set of records.

04/17/2025 Discrete Mathematics Chapter 9 37


Databases and Relations
Example: Consider a database of students, whose
records are represented as 4-tuples with the fields
Student Name, ID Number, Major, and GPA:
R = {(Ackermann, 231455, CS, 3.88),
(Adams, 888323, Physics, 3.45),
(Chou, 102147, CS, 3.79),
(Goodfriend, 453876, Math, 3.45),
(Rao, 678543, Math, 3.90),
(Stevens, 786576, Psych, 2.99)}
Relations that represent databases are also called
tables, since they are often displayed as tables.
04/17/2025 Discrete Mathematics Chapter 9 38
Databases and Relations
Each column of the table corresponds to an attribute
of the database. For instance, the same database of
students is displayed in Table 1. The attributes of
this database are Student Name, ID Number, Major,
and GPA.
TABLE 1 Students.
Student_name ID_ number Major GPA
Ackermann 231455 Computer Science 3.88
Adams 888323 Physics 3.45
Chou 102147 Computer Science 3.49
Goodfriend 453876 Mathematics 3.45
Rao 678543 Mathematics 3.90
Stevens 786576 Psychology 2.99

04/17/2025 Discrete Mathematics Chapter 9 39


Databases and Relations
A domain of an n-ary relation is called a primary
key if the n-tuples are uniquely determined by their
values from this domain.
This means that no two records have the same value
from the same primary key.
In our example, which of the fields Student Name,
ID Number, Major, and GPA are primary keys?
Student Name and ID Number are primary keys,
because no two students have identical values in
these fields.
In a real student database, only ID Number would be
a primary key.
04/17/2025 Discrete Mathematics Chapter 9 40
Databases and Relations
Example: Which domains are primary keys for the n-ary
relation displayed in Table 1, assuming that no
n-tuples will be added in the future?
Solution: Because there is only one 4-tuple in this table
for each student name, the domain of student names is
a primary key. Similarly, the ID numbers in this table
are unique, so the domain of ID numbers is also a
primary key. However, the domain of major fields of
study is not a primary key, because more than one 4-
tuple contains the same major field of study. The
domain of grade point averages is also not a primary
key, because there are two 4-tuples containing the
same GPA.
04/17/2025 Discrete Mathematics Chapter 9 41
Databases and Relations
In a database, a primary key should remain one even if
new records are added.
Therefore, we should use a primary key of the
intension of the database, containing all the n-tuples
that can ever be included in our database.

Combinations of domains can also uniquely identify


n-tuples in an n-ary relation.
When the values of a set of domains determine an n-
tuple in a relation, the Cartesian product of these
domains is called a composite key.
04/17/2025 Discrete Mathematics Chapter 9 42
Operations on n-ary Relations

Definition: Let R be an n-ary relation and C


a condition that elements in R may satisfy.
Then the selection operator sC maps the
n-ary relation R to the n-ary relation of all
n-tuples from R that satisfy the condition
C.

04/17/2025 Discrete Mathematics Chapter 9 43


Operations on n-ary Relations
Example: To find the records of computer science majors in the n-
ary relation R shown in Table 1, we use the operator sC1, where
C1 is the condition Major = “Computer Science.” The result is
the two 4-tuples (Ackermann, 231455, Computer Science, 3.88)
and (Chou, 102147, Computer Science, 3.49). Similarly, to find
the records of students who have a grade point average above
3.5 in this database, we use the operator sC2 , where C2 is the
condition GPA > 3.5. The result is the two 4-tuples (Ackermann,
231455, Computer Science, 3.88) and (Rao, 678543,
Mathematics, 614 9 / Relations 3.90). Finally, to find the records
of computer science majors who have a GPA above 3.5, we use
the operator sC3, where C3 is the condition (Major = “Computer
Science” ∧ GPA > 3.5). The result consists of the single 4-tuple
(Ackermann,231455, Computer Science, 3.88).
04/17/2025 Discrete Mathematics Chapter 9 44
Operations on n-ary Relations
We can apply a variety of operations on n-ary
relations to form new relations.
Definition: The projection Pi1, i2, …, im maps the n-tuple
(a1, a2, …, an) to the m-tuple (ai1, ai2, …, aim), where m
 n.
In other words, a projection Pi1, i2, …, im keeps the m
components ai , ai , …, ai of an n-tuple and deletes its
1 2 m
(n – m) other components.
Example: What is the result when we apply the
projection P2,4 to the student record (Stevens, 786576,
Psych, 2.99) ?
Solution: It is the pair
04/17/2025
(786576, 2.99).
Discrete Mathematics Chapter 9 45
Operations on n-ary Relations
Example: What relation results when the projection P1,4 is
applied to the relation in Table 1?
Solution: When the projection P1,4 is used, the second and
third columns of the table are deleted, and pairs
representing student names and grade point averages are
obtained. Table 2 displays the results of this projection.
TABLE 2 GPAs
Student_nam GPA
e
Ackermann 3.88
Adams 3.45
Chou 3.49
Goodfriend 3.45
04/17/2025 RaoDiscrete Mathematics3.90
Chapter 9 46

Stevens 2.99
Operations on n-ary Relations
In some cases, applying a projection to an entire
table may not only result in fewer columns, but also
in fewer rows.

Why is that?

Some records may only have differed in those fields


that were deleted, so they become identical, and
there is no need to list identical records more than
once.

04/17/2025 Discrete Mathematics Chapter 9 47


Operations on n-ary Relations
Example: What is the table obtained when the projection P1,2
is applied to the relation in Table 3?
Solution: Table 4 displays the relation obtained when P1,2 is
applied to Table 3. Note that there are fewer rows after this
projection is applied.
TABLE 3 Enrollments. TABLE 4 Majors
Student Major Course Student Major
Glauser Biology BI 290 Glauser Biology
Glauser Biology MS 475 Marcus Mathematics
Glauser Biology PY 410 Miller Computer
Marcus Mathematics MS 511 Science
Marcus Mathematics MS 603
Marcus Mathematics CS 322
Miller Computer Science MS 575
Miller Computer Science CS 455
04/17/2025 Discrete Mathematics Chapter 9 48
Operations on n-ary Relations
We can use the join operation to combine two tables
into one if they share some identical fields.

Definition: Let R be a relation of degree m and S a


relation of degree n. The join Jp(R, S), where p  m and
p  n, is a relation of degree m + n – p that consists of
all (m + n – p)-tuples (a1, a2, …, am-p, c1, c2, …, cp, b1, b2,
…, bn-p), where the m-tuple (a1, a2, …, am-p, c1, c2, …, cp)
belongs to R and the n-tuple (c1, c2, …, cp, b1, b2, …, bn-
p) belongs to S.

04/17/2025 Discrete Mathematics Chapter 9 49


Operations on n-ary Relations
Example: What relation results when the join operator
J2 is used to combine the relation displayed in
Tables 5 and 6?
TABLE 6 Class schedule.
TABLE 5 Teaching assignments. Department Course Room Time
Professor Department Course number
number Computer Science 518. N521 2:00 P.M
Cruz Zoology 335 Mathematics 575 N502 3:00 P.M.
Cruz Zoology 412
Mathematics 611 N521 4:00 P.M.
Farber Psychology 501
Physics 544 B505 4:00 P.M.
Farber Psychology 617
Psychology 501 A100 3:00 P.M.
Grammer Physics 544
Psychology 617 A110 11:00 A.M.
Grammer Physics 551
Zoology 335 A100 9:00 A.M.
Rosen Computer Science 518
Zoology 412 A100 8:00 A.M.
Rosen Mathematics 575

04/17/2025 Discrete Mathematics Chapter 9 50


Operations on n-ary Relations
Solution: The join J2 produces the relation shown in
Table 7.
TABLE 7 Class schedule.
Professor Department Course number Room Time
Cruz Zoology 335 A100 9:00 A.M.
Cruz Zoology 412 A100 8:00 A.M.
Farber Psychology 501 A100 3:00 P.M.
Farber Psychology 617 A110 11:00 A.M.
Grammer Physics 544 B505 4:00 P.M.
Rosen Computer Science 518 N521 2:00 P.M.
Rosen Mathematics 575 N502 3:00 P.M

04/17/2025 Discrete Mathematics Chapter 9 51


Databases and Relations

In other words, to generate Jp(R, S), we have to find


all the elements in R whose p last components match
the p first components of an element in S.

The new relation contains exactly these matches,


which are combined to tuples that contain each
matching field only once.

04/17/2025 Discrete Mathematics Chapter 9 52


Databases and Relations
Example: What is J1(Y, R), where Y contains the
fields Student Name and Year of Birth,
Y = {(1978, Ackermann),
(1972, Adams),
(1917, Chou),
(1984, Goodfriend),
(1982, Rao),
(1970, Stevens)},
and R contains the student records as defined before ?

04/17/2025 Discrete Mathematics Chapter 9 53


Databases and Relations

Solution: The resulting relation is:


{(1978, Ackermann, 231455, CS, 3.88),
(1972, Adams, 888323, Physics, 3.45),
(1917, Chou, 102147, CS, 3.79),
(1984, Goodfriend, 453876, Math, 3.45),
(1982, Rao, 678543, Math, 3.90),
(1970, Stevens, 786576, Psych, 2.99)}

Since Y has two fields and R has four, the relation


J1(Y, R) has 2 + 4 – 1 = 5 fields.

04/17/2025 Discrete Mathematics Chapter 9 54


Representing Relations
We already know different ways of representing
relations. We will now take a closer look at two ways of
representation: Zero-one matrices and directed
graphs.
If R is a relation from A = {a1, a2, …, am} to B =
{b1, b2, …, bn}, then R can be represented by the zero-
one matrix MR = [mij] with
mij = 1, if (ai, bj)R, and
mij = 0, if (ai, bj)R.
Note that for creating this matrix we first need to list the
elements in A and B in a particular, but arbitrary
order.
04/17/2025 Discrete Mathematics Chapter 9 55
Representing Relations

Example: How can we represent the relation


R = {(2, 1), (3, 1), (3, 2)} as a zero-one matrix?

Solution: The matrix MR is given by

 0 0
M R   1 0
 1 1

04/17/2025 Discrete Mathematics Chapter 9 56


Representing Relations
What do we know about the matrices representing a
relation on a set (a relation from A to A) ?
They are square matrices.
What do we know about matrices representing
reflexive relations?
All the elements on the diagonal of such matrices Mref
must be 1s.
1 
 1 
 
 . 
M ref  
 . 
 . 
 
 1

04/17/2025 Discrete Mathematics Chapter 9 57


Representing Relations
What do we know about the matrices representing
symmetric relations?
These matrices are symmetric, that is, MR = (MR)t.

1 0 1 1 1 1 0 0
0 
1 0 0 1 1 0 
0
M R  M R 
1 0 0 1 1 1 0 0
   
1 0 1 1 1 1 0 0
symmetric matrix, non-symmetric matrix,
symmetric relation. non-symmetric relation.

04/17/2025 Discrete Mathematics Chapter 9 58


Representing Relations
The Boolean operations join and meet (you
remember?) can be used to determine the matrices
representing the union and the intersection of two
relations, respectively.

To obtain the join of two zero-one matrices, we apply


the Boolean “or” function to all corresponding
elements in the matrices.

To obtain the meet of two zero-one matrices, we apply


the Boolean “and” function to all corresponding
elements in the matrices.

04/17/2025 Discrete Mathematics Chapter 9 59


Representing Relations
Example: Let the relations R and S be represented by
the matrices
 1 0 1  1 0 1
M R  1 0 0 M S  0 1 1
 0 1 0  1 0 0

What are the matrices representing R  S and R  S?


Solution: These matrices are given by

1 0 1   1 0 1
M R S M R  M S 1 1 1 M R S M R  M S  0 0 0
1 1 0  0 0 0

04/17/2025 Discrete Mathematics Chapter 9 60


Representing Relations Using Matrices

Example: How can we represent the relation


R = {(2, 1), (3, 1), (3, 2)} as a zero-one matrix?

Solution: The matrix MR is given by

 0 0

M R  1 0 
 1 1

04/17/2025 Discrete Mathematics Chapter 9 61


Representing Relations Using Matrices
Example: Let the relations R and S be represented by
the matrices
 1 0 1  1 0 1
M R  1 0 0 M S  0 1 1
 0 1 0  1 0 0

What are the matrices representing R  S and R  S?


Solution: These matrices are given by

1 0 1   1 0 1
M R S M R  M S 1 1 1 M R S M R  M S  0 0 0
1 1 0  0 0 0

04/17/2025 Discrete Mathematics Chapter 9 62


Representing Relations Using Matrices
Do you remember the Boolean product of two zero-one
matrices?
Let A = [aij] be an mk zero-one matrix and
B = [bij] be a k  n zero-one matrix.
Then the Boolean product of A and B, denoted by A○B, is the
m  n matrix with (i, j)th entry [cij], where
cij = (ai1 ˄ b1j) ˅ (ai2 ˄ b2i) ˅ … ˅ (aik ˄ bkj).

cij = 1 if and only if at least one of the terms


(ain ˄ bnj) = 1 for some n; otherwise cij = 0.

04/17/2025 Discrete Mathematics Chapter 9 63


Representing Relations Using Matrices
Let us now assume that the zero-one matrices
MA = [aij], MB = [bij] and MC = [cij] represent relations A, B,
and C, respectively.
Remember: For MC = MA○MB we have:
cij = 1 if and only if at least one of the terms
(ain ˄ bnj) = 1 for some n; otherwise cij = 0.
In terms of the relations, this means that C contains a pair
(xi,zj) if and only if there is an element yn such that (xi, yn) is in
relation A and (yn, zj) is in relation B.
Therefore, C = B○A (composite of A and B).

04/17/2025 Discrete Mathematics Chapter 9 64


Representing Relations Using Matrices
This gives us the following rule:
MB ○A = MA○MB

In other words, the matrix representing the composite of


relations A and B is the Boolean product of the matrices
representing A and B.

Analogously, we can find matrices representing the powers of


relations:
MRn = MR[n] (n-th Boolean power).

04/17/2025 Discrete Mathematics Chapter 9 65


Representing Relations Using Matrices
Example: Find the matrix representing R2, where the
matrix representing R is given by
 0 1 0
M R  0 1 1
 1 0 0

Solution: The matrix for R2 is given by


 0 1 1
 1 1 1
[ 2]
M R 2 M R
 0 1 0

04/17/2025 Discrete Mathematics Chapter 9 66


Representing Relations Using Digraphs

Definition: A directed graph, or digraph, consists of


a set V of vertices (or nodes) together with a set E of
ordered pairs of elements of V called edges (or arcs).
The vertex a is called the initial vertex of the edge (a,
b), and the vertex b is called the terminal vertex of
this edge.

We can use arrows to display graphs.

04/17/2025 Discrete Mathematics Chapter 9 67


Representing Relations Using Digraphs
Example: Display the digraph with V = {a, b, c, d},
E = {(a, b), (a, d), (b, b), (b, d), (c, a), (c, b), (d, b)}.

a
b

d c

An edge of the form (b, b) is called a loop.

04/17/2025 Discrete Mathematics Chapter 9 68


Representing Relations Using Digraphs
Obviously, we can represent any relation R on a set A
by the digraph with A as its vertices and all pairs (a,
b)R as its edges.

Vice versa, any digraph with vertices V and edges E


can be represented by a relation on V containing all
the pairs in E.

This one-to-one correspondence between relations


and digraphs means that any statement about relations
also applies to digraphs, and vice versa.

04/17/2025 Discrete Mathematics Chapter 9 69


Equivalence Relations

Equivalence relations are used to relate objects that


are similar in some way.
Definition: A relation on a set A is called an
equivalence relation if it is reflexive, symmetric, and
transitive.
Two elements that are related by an equivalence
relation R are called equivalent.

04/17/2025 Discrete Mathematics Chapter 9 70


Equivalence Relations

Since R is symmetric, a is equivalent to b whenever


b is equivalent to a.
Since R is reflexive, every element is equivalent to
itself.
Since R is transitive, if a and b are equivalent and b
and c are equivalent, then a and c are equivalent.

Obviously, these three properties are necessary for a


reasonable definition of equivalence.

04/17/2025 Discrete Mathematics Chapter 9 71


Equivalence Relations
Example: Suppose that R is the relation on the set of
strings that consist of English letters such that aRb if
and only if l(a) = l(b), where l(x) is the length of the
string x. Is R an equivalence relation?
Solution:
R is reflexive, because l(a) = l(a) and therefore
aRa for any string a.
R is symmetric, because if l(a) = l(b) then l(b) =
l(a), so if aRb then bRa.
R is transitive, because if l(a) = l(b) and l(b) = l(c),
then l(a) = l(c), so aRb and bRc implies aRc.
R is an equivalence relation.
04/17/2025 Discrete Mathematics Chapter 9 72
Equivalence Classes
Definition: Let R be an equivalence relation on a set
A. The set of all elements that are related to an
element a of A is called the equivalence class
of a.
The equivalence class of a with respect to R is
denoted by [a]R.
When only one relation is under consideration, we
will delete the subscript R and write [a] for this
equivalence class.
If b[a]R, b is called a representative of this
equivalence class.
04/17/2025 Discrete Mathematics Chapter 9 73
Equivalence Classes
Example: In the previous example (strings of
identical length), what is the equivalence class of the
word mouse, denoted by [mouse] ?

Solution: [mouse] is the set of all English words


containing five letters.

For example, ‘horse’ would be a representative of


this equivalence class.

04/17/2025 Discrete Mathematics Chapter 9 74


Equivalence Classes
Theorem: Let R be an equivalence relation on a set A.
The following statements are equivalent:
aRb
[a] = [b]
[a]  [b]  
Definition: A partition of a set S is a collection of
disjoint nonempty subsets of S that have S as their
union. In other words, the collection of subsets A i,
iI, forms a partition of S if and only if
(i) Ai   for iI
Ai  Aj = , if i  j
iI Ai = S
04/17/2025 Discrete Mathematics Chapter 9 75
Equivalence Classes
Examples: Let S be the set {u, m, b, r, o, c, k, s}.
Do the following collections of sets partition S ?
{{m, o, c, k}, {r, u, b, s}} yes.

{{c, o, m, b}, {u, s}, {r}} no (k is missing).

{{b, r, o, c, k}, {m, u, s, t}} no (t is not in S).

{{u, m, b, r, o, c, k, s}} yes.

{{b, o, o, k}, {r, u, m}, {c, s}} yes ({b,o,o,k} = {b,o,k}).

{{u, m, b}, {r, o, c, k, s}, } no ( not allowed).


04/17/2025 Discrete Mathematics Chapter 9 76
Equivalence Classes

Theorem: Let R be an equivalence relation on a


set S. Then the equivalence classes of R form a
partition of S. Conversely, given a partition
{Ai | iI} of the set S, there is an equivalence
relation R that has the sets Ai, iI, as its equivalence
classes.

04/17/2025 Discrete Mathematics Chapter 9 77


Equivalence Classes
Example: Let us assume that Frank, Suzanne and
George live in Boston, Stephanie and Max live in
Lübeck, and Jennifer lives in Sydney.
Let R be the equivalence relation {(a, b) | a and b live
in the same city} on the set P = {Frank, Suzanne,
George, Stephanie, Max, Jennifer}.
Then R = {(Frank, Frank), (Frank, Suzanne),
(Frank, George), (Suzanne, Frank), (Suzanne, Suzanne),
(Suzanne, George), (George, Frank),
(George, Suzanne), (George, George), (Stephanie,
Stephanie), (Stephanie, Max), (Max, Stephanie),
(Max, Max), (Jennifer, Jennifer)}.
04/17/2025 Discrete Mathematics Chapter 9 78
Equivalence Classes
Then the equivalence classes of R are:
{{Frank, Suzanne, George}, {Stephanie, Max},
{Jennifer}}.
This is a partition of P.

The equivalence classes of any equivalence relation R


defined on a set S constitute a partition of S, because
every element in S is assigned to exactly one of the
equivalence classes.

04/17/2025 Discrete Mathematics Chapter 9 79


Equivalence Classes
Another example: Let R be the relation
{(a, b) | a  b (mod 3)} on the set of integers.
Is R an equivalence relation?
Yes, R is reflexive, symmetric, and transitive.

What are the equivalence classes of R ?


{{…, -6, -3, 0, 3, 6, …},
{…, -5, -2, 1, 4, 7, …},
{…, -4, -1, 2, 5, 8, …}}

04/17/2025 Discrete Mathematics Chapter 9 80

You might also like