Neww Chapter 08-Relations
Neww Chapter 08-Relations
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.
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.
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, ….
Primary key
column
Degree of
Primary
4
domain
Extension: collection
of current records.
Record
Intension: current
( n-tuple )
records.
N-ary Relations ….
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
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