Relations
Still for the quizzzzz... next week...
- Discrete mathematics
- Relations
- Closures
Definition of Relations
Let
and be sets. A binary relation from to is a subset of .
Properties of Relations
Reflexive
A relation
on a set is called reflexive if for every element .
Symmetric
A relation
on a set is called symmetric if whenever , for all .
Antisymmetric
A relation
on a set such that for all , if and , then is called antisymmetric.
- Notice that antisymmetric is NOT asymmetric
Transitive
A relation
on a set is called transitive if whenever and , then , for all .
- Following is the definitions pick from the exercises
Irreflexive
A relation
on the set is irreflexive if for every
Asymmetric
A relation
is called asymmetric if implies that .
Combining Relations
Definition
Let
be a relation from a set to a set and a relation from to a set .
The composite ofand is the relation consisting of ordered pairs , where , and for which there exists an element such that and .
We denote the composite ofand by .
Powers
Let
be a relation on the set . The powers are defined recursively by
Theorem of transitive 1
The relation
on a set is transitive if and only if for .
n-ary Relations
Definition
Let
be sets. An -ary relation on these sets is a subset of .
The setsare called the domains of the relation, and is called its degree.
Operations on n-ary Relations
Selection
Let
be an -ary relation and a condition that elements in may satisfy.
Then the selection operatormaps the -ary relation to the -ary relation of all -tuples from that satisfy the condition .
Projection
- Projections are used to form new
-ary relations by deleting the same fields in every record of the relation.
The projection
where , maps the -tuple to the m-tuple , where .
In other words, the projection
deletes of the components of an -tuple, leaving the and components. Fewer rows may result when a projection is applied to the table for a relation. This happens when some of the
-tuples in the relation have identical values in each of the m components of the projection, and only disagree in components deleted by the projection.
Join
- The join operation is used to combine two tables into one when these tables share some identical fields.
Let
be a relation of degree and a relation of degree . The join , where and , is a relation of degree that consists of all -tuples , where the -tuple belongs to and the -tuple belongs to .
- In other words, the join operator
produces a new relation from two relations by combining all -tuples of the first relation with all -tuples of the second relation, where the last components of the -tuples agree with the first components of the -tuples.
Closures of Relations
Different Types of Closures
If
is a relation on a set , it may or may not have some property , such as reflexivity, symmetry, or transitivity. When does not enjoy property , we would like to find the smallest relation on with property that contains .
Definition
If
is a relation on a set , then the closure of with respect to , if it exists, is the relation on with property that contains and is a subset of every subset of containing with property .
Transitive Closures
Let
be a relation on a set . The connectivity relation consists of the pairs such that there is a path of length at least one from to in .
Theorem of transitive 2
The transitive closure of a relation
equals the connectivity relation .
Zero–one matrix of the transitive closure of the relation R
Let
be the zero–one matrix of the relation R on a set with n elements. Then the zero–one matrix of the transitive closure is
It's implement
ALGORITHM 1 A Procedure for Computing the Transitive Closure.
procedure transitive closure (: zero–one matrix)
forto
return{ is the zero–one matrix for }
Warshall’s Algorithm
ALGORITHM 2 Warshall Algorithm.
procedure Warshall (: zero–one matrix)
forto
forto
forto
return{ is }
Cpp implement
- This is the implement of the relation matrix class
1 | class RelationMatrix { |
- This is the naive algorithm
1 | RelationMatrix naiveAlgo(RelationMatrix M) { |
- And this is warshall's algorithm
1 | RelationMatrix warshall(RelationMatrix M) { |