0% found this document useful (0 votes)
45 views40 pages

Neww Chapter 08-Relations

The document discusses relations and their properties including reflexive, symmetric, transitive, and inverse relations. It also covers representing relations using matrices and sets, as well as operations on relations such as selection, projection, and join.

Uploaded by

Cường Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views40 pages

Neww Chapter 08-Relations

The document discusses relations and their properties including reflexive, symmetric, transitive, and inverse relations. It also covers representing relations using matrices and sets, as well as operations on relations such as selection, projection, and join.

Uploaded by

Cường Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 40

Chapter 8

Relations
Objectives
 8.1-Relations and their Properties.
 8.2-N-ary Relations and their Applications.
 8.3-Representing relations.
 8.5-Equivalence Relations.
8.1 Relations and Their Applications

 Introduction
 Functions as Relations
 Relations on a Set
 Properties of Relations
 Combining Relations
Introduction
 Relations can be used to solve problems such as
determining which pairs of cities are linked by
airline flights in a network, finding a viable order
for the different phases of a complicated project, or
producing a useful way to store information in
computer databases.
8.1- Relations… : Introduction
Definition 1:
Let A and B be sets. A binary relation from A to B is a subset of A🗴B.

Notations
a R b : ( a, b)  R
a R b : ( a, b)  R
Example 1: A: set of students , B: set of courses
A🗴B = { (Hellen, Math1), (Jacob, C Language), ……. }
Example 2: A: set of cities , B: set of states of USA
A🗴B = { (Boulder, Colorado), (Bangore, Maine), ……. }

Example 3:
A = { 0, 1, 2 }
B = { a, b }
R = { (0, a) , (0, b) ,
(1, a), (2, b) } Figure: Displaying the ordered pairs
in the relation R from Example 3.
8.1- Relations… : Functions as Relations
Function: f : A → B
Graph of f : G = { (a, b) | a  A, b  B }
 G  A🗴B
 G is a relation
 Relations are a generalization of functions.
But a relation may not be a function.
 Example:
(R is not a function) 
8.1- Relations… : Relations on a Set
Definition 2:
A relation on a set A is a relation from A to A.
In other words, a relation on a set A is a subset of A × A
EXAMPLE 4 Let A be the set {1, 2, 3, 4}. Which ordered pairs are in the
relation R = {(a, b) ∣ a divides b}?
Solution: Because (a, b) is in R if and only if a and b are positive integers not
exceeding 4 such that a divides b, we see that
R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}.

In-class Examples:
Example 5, page 521
Example 6: page 522
8.1- Relations… : Properties of Relations

 Reflexive / Irreflexive
 Symmetric/ Asymmetric / Antisymmetric
 Transitive
 Inverse relations
 Complementary relations
8.1- Relations… : Properties of Relations
Definition 3:
A relation R on a set A is called reflexive if (a, a) ∈ R for every
element a ∈ A.

R is reflexive  a A, (a, a)  R


Example 7: page 522
Example 9: page 523
Reflexive
R is irreflexive  a A, (a,a)  R and
A= {0,1}. Irreflexive
Some irreflexive relations: properties are
{}, {(0,1)}, {(1,0)}, {(0,1), (1,0)}
Some non-irreflexive relations
boundaries.
{(0,0)}, {(0,1), (1,1)}, {(0,0), (0,1),
(1,0)}
8.1- Relations… : Properties of Relations
Example 16/p.525.
How many reflexive relations are there on a set with n elements?

 Solution. (a, b) belongs to


 Let A be {a1, a2, …, an}. R or not
 A relation on A is a subset of AA, which has (a1, a1)
nn elements. (a2, a2)
 Every relation R on A is reflexive if and only if …
R is a subset of AA and R contains all n (a, b) (an, an)
ordered pairs (ai, ai) for i = 1, 2, …, n. R may (a  b)
have (a, b) or not (where a b).
 There are nn – n ordered pairs (a, b) where
a  b.
 So, there are 2 nn – n reflexive relation on A reflexive
(using product rule to count). relation R
8.1- Relations… : Properties of Relations
Definition 4:
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 such that for all a, b ∈ A, if (a, b) ∈ R and (b, a) ∈
R, then a = b is called antisymmetric.

R is symmetric  (a,b) R  (b,a)  R


Example 10: page 523
Example 12: page 524

R is asymmetric  (a,b) R (b,a)  R


A = { 0,1}
{(0,1)} and {(1,0)} are asymmetric.

R is antisymmetric  a,b A  (a,b)  R ^ (b,a)  R  a=b


A= {0,1}
{}, {(0,1)}, { (0,0), (1,0), (1,1)} are antisymmetric.
{(0,0), (0,1), (1,0), (1,1)} is not antisymmetric ( 0 1).
8.1- Relations… : Properties of Relations

Definition 5:
A relation R on a set A is called transitive if whenever (a, b) ∈ R
and (b, c) ∈ R, then (a, c) ∈ R, for all a, b, c ∈ A.

Example 13: page 524


Example 15: page 524
8.1- Relations… : Properties of Relations

Inverse Relations:
R is a relation from the set A to the set B
Inverse relation R-1 of R is a relation from B to A and
(a,b) R  (b, a) R-1.

Complementary Relations:
R is a relation from the set A to the set B.
Complementary relation ~R of R is a relation from A
to B and and ~R contains ordered pairs { (a, b) | (a, b)
 R }.
Properties of Relations
Consider the set A = {1, 2, 3, 4} and some relations.

R1 1 2 3 4 R2 1 2 3 4 R3 1 2 3 4
1 X X 1 X X 1 X X X
2 X X 2 X X 2 X X X
3 X X 3 X X 3 X X
4 x X 4 X X 4

Reflexive Transitive
Symmetric (1,2) (2,1)  (1,1)
Main diagonal
(1,3) (3,2)  (1,2)
(2,1) (1,2)  (2,2)
(2,1) (1,3)  (2,3)
(2,3) (3,2)  (2,2)
(3,2) (2,3)  (3,3)
8.1- Relations… : Combining Relations
Unions, Intersections and Differences of two relations:

EXAMPLE 17:
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)}.
8.1- Relations… : Combining Relations
Definition 6:
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.

R S S◦R
Example 20:
R is the relation from {1, 2, 3} to {1, 2, 3, 4} (1,1) (1,0) (1,0)
R = {(1, 1), (1, 4), (2, 3), (3, 1), (3, 4)}
S is the relation from {1, 2, 3, 4} to {0, 1, 2} (1,4) (4,1) (1,1)
S = {(1, 0), (2, 0), (3, 1), (3, 2), (4, 1)} (3,1) (2,1)
⇰ S ◦ R = {(1, 0), (1, 1), (2, 1), (2, 2), (3, 0), (3, 1)}. (2,3)
(3,2) (2,2)
(3,1) (1,0) (3,0)
(3,4) (4,1) (3,1)
8.1- Relations… : Combining Relations
Definition 7:
Let R be a relation on the set A. The powers n , n = 1, 2, 3, …, are
defined recursively by
R1 = R and Rn+1 = Rn ◦ R.
The definition shows that R2 = R ◦ R, R3 = R2 ◦ R = (R ◦ R)◦ R, and so on.

EXAMPLE 22:
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)}.
R3 = {(1, 1), (2, 1), (3, 1), (4, 1)}.
R4 = {(1, 1), (2, 1), (3, 1), (4, 1)}
………
8.1- Relations… : Combining Relations
THEOREM 1.
The relation R on a set A is transitive if and only if Rn ⊆ R for n = 1, 2, 3, ….

Proof: Page 527


8.2- n-ary Relations and Their Applications
 Theory of Relational Databases
Definition 1:
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.

Primary key
column
Degree of
Primary
4
domain

Extension: collection
of current records.
Record
Intension: current
( n-tuple )
records.
N-ary Relations ….

Which domains are primary keys? Suppose that no record can


be added.
 Student_name or ID_number because these columns
contain different values.
 Student_name x ID_number may be used as primary
domain ( composite key ).
8.2- n-ary Relations…: Operations
 Selection
 Projection
 Join
8.2…. Selection Operation

SMajor=‘Computer Science’ PStudent_name,GPA


8.2…: Projection Operation

P1,4
8.2… : Projection
8.2… : Join Operation

J2 , 2 common columns
 Result table haves 3+4-2=5 columns
8.3- Representing Relations

 Using matrices
 Using Directed Graphs (Digraphs)
8.3…. : Representing Relations Using Matrices
8.3… : Matrices of Special Relations
8.3…. Matrices for Unions, Intersections
8.3- ……Matrix for SoR

(1.0)+(0.0)+(1.1)=1
(1.1)+(0.0)+(1.0)=1
(1^0)+(0.1)+(1.1)=1
8.3…. : Representing Relations Using Digraphs
8.3…. Digraphs
8.3….. Digraphs

- It is reflexive (loops)
- It is not symmetric -It is not reflexive (no loop)
- It is symmetric
(a,b)  R but (b,a)  R
-It is not antisymmetric: -It is not antisymmetric:
(b,c), (c,b)  R but b  c (a,c), (c,a)  R but a  c
-It is not transitive
- It is not transitive:
(a,b), (b,c)  R but (a,c)  R (c,a), (a,b)  R but (c,b)  R
8.5- Equivalence Relations

Steps to show that a relation is a equivalence:


Step 1: Show that it is reflexive : aRa
Step 2: Show that it is symmetric : aRb  bRa
Step 3: Show that it is transitive: aRb, bRc  aRc
Equivalence Relations….
Page 556, 557
Equivalence Classes
Equivalence Classes and Partitions
Proof: page 560

Consider the relation on the set N:


R = { (a,b) | a = b (mod 4) }

Equivalence classes:
a mod (4)=0
{ 4,8,12,16,20,24,28,32,…}
{ 1,5,9,13,17, …}
{ 2,6,10,14,18,…}
{ 3,7,11,15,19,…. }
 N is partitioned into 4 different parts
Figure 1: A Partition of a Set
Equivalence Classes and Partitions
Summary
 8.1-Relations and their Properties
 8.2-N-ary Relations and their Applications
 8.3-Representing relations
 8.5-Equivalence Relations
Thanks

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy