DS Presentation
DS Presentation
PRESENTATION
CHAPTER#09
RELATIONS
Eman Nazar 071
Ariba Parvaiz 041
Malaika Shehzadi 027
Ambreen Fatima 089
CARTESIAN PRODUCT
Cartesian product of sets A and B is defined as the set of all ordered pairs (x,y)
Such that ‘x’ belongs to set A and ‘y’ belongs to set B
It is denoted by A(A cross B)
Example
A={1,2} B={ a, b, c}
A {(1,a),(1,b),(1,c),(2,a),(2,b),(2,c)}
RELATIONS
INTRODUCTION:
Let A and B be sets. A binary relation R from A to B is a subset of A cross B(A).
When (a,b) R, we say ‘a’ is related to’b’ by R.
EXAMPLE:
A = {a,b} B = {1, 2, 3}
AxB={(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}
R = {(a,1), (a, 3), (b, 2)}
R₂ = {(a, 2), (b, 1), (b, 2), (b, 3)}
R3 = {(b, 1)}
REPRESENTATION OF RELATION
1. DIRECTED GRAPH
We connect vertex a to vertex b with an edge, going from vertex a to vertex b if and
only if aRb. This type of graph of a relation r is called a directed graph or digraph.
EXAMPLE
A = {a,b} B = {1, 2, 3}
AxB={(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}
a b
1 2 3
R={(a, 1), (a, 2),(b, 3)}
a b
1 2 3
MATRIX REPRESENTATION
MATRIX
A rectangular array of numbers is called matrix
Matrix Representation
Let A = {a1, a2,….. an} B = {b1, b2, ..., bm} Let R be a relation from A to B.
Set A (Number of rows) Set B (numbers of column)
m(i,j) =
for i=1,2,...,n and j=1,2,...,m
EXAMPLE
A= {a,b} B = {1, 2, 3}
AxB={(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)} ; R1 =R={(a, 1), (a, 2),(b, 3)}
M=
PROPERTIES OF RELATIONS
• Reflexive Relation
• Irreflexive Relation
• Symmetric Relation
• Asymmetric Relation
• Antisymmetric Relation
• Transitive relation
REFLEXIVE RELTION
DEFINATION
A relation ‘R’ is said to be reflexive if and only if for all a A,(a,a)
(Each element of a set related to itself)
EXAMPLE
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1 = { (1,1),(2,2),(3,3)}
R2= {(1,1),(2,2),(3,3),(2,1,)
REPRESENTATION OF REFLEXIVE
RELATION
DIGRAPH MATRIX
R1 = { (1,1),(2,2),(3,3)} R1 = { (1,1),(2,2),(3,3)}
M=
1 2 3
1 2 3 M=
IRREFLEXIVE RELATION
DEFINATION
A relation ‘R’ is said to be irreflexive if for all a A,(a,a) ∉
(Each element of a set not related to itself)
EXAMPLE
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1 = { (1,2),(2,1),(3,1)}
R2= {(1,3),(2,1),(3,2)}
REPRESENTATION OF IRREFLEXIVE
RELATION
DIGRAPH MATRIX
R1 = { (1,2),(2,1),(3,1)} R1 = { (1,2),(2,1),(3,1)}
M=
1 2 3
M=
1 2 3
QUESTIONS FOR RR AND IRR
A{(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)}
R1= { (1,1),(2,2),(3,3),(2,1),(3,2)}
R2={(1,2),(2,3),(2,1)}
R3={(1,1),(2,2),(3,3)}
R4={(1,1),(2,2)}
SOLUTION
A{(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)}
R1= { (1,1),(2,2),(3,3),(2,1),(3,2)}
Relation is Reflexive because all element of set are related to itself
R2={(1,1),(2,3),(2,1)}
Relation is Irreflexive because no element of set is related to itself
R3={(1,1),(2,2),(3,3)}
Relation is Reflexive because all element of set are related to itself
R4={(1,1),(2,2)}
Relation is nor reflexive because one element of set is not related to itself
SYMMETRIC RELATION
DEFINATION
A relation is said to be symmetric if (x,y) belongs to R then (y,x) must belongs
to R.
EXAMPLE
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1 = { (1,2),(2,1),(3,3)}
R2= {(1,2),(2,1),(3,1),(1,3)
REPRESENTATION OF SYMMETRIC
RELATION
DIGRAPH MATRIX
R1 = { (1,2),(2,1),(3,3)} R1 = { (1,2),(2,1),(3,3)}
M=
1 2 3
M=
1 2 3
QUESTIONS
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1= {(1,1),(2,2)}
R2={(2,1),(1,3),(3,1)}
R2={(1,2),(2,1),(3,3)}
ASYMMETRIC RELATION
DEFINATION
A relation is said to be asymmetric if (x,y) belongs to R then (y,x) should not
belong to R.
EXAMPLE
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1= { (1,3),(1,2),(2,3)}
R2={(3,1),(2,1),(3,2)}
REPRESENTATION OF ASYMMETRIC
DIGRAPH MATRIX
R1= { (1,3),(1,2),(2,3)} R1= { (1,3),(1,2),(2,3)}
M=
1 2 3
R2={(3,1),(2,1),(3,2)} R2={(3,1),(2,1),(3,2)}
M=
1 2 3
QUESTIONS
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1={(1,2),(3,1),(2,3)}
R2={(1,1),(2,1),(3,1)}
R3= {(1,1),(2,1),(2,2),(3,3)}
ANTISYMMETRIC RELATION
DEFINATION
A relation is said to be antisymmetric if (x,y) belongs to R then (y,x) belongs
to R if x=y
EXAMPLE
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1 = { (1,2),(3,1),(3,3)}
R2= {(1,2),(2,2),(3,2)}
REPRESENTATION OF ANTISYMMETRIC
RELATION
DIGRAPH MATRIX
R1 = { (1,2),(3,1),(3,3)} R1 = { (1,2),(3,1),(3,3)}
M=
1 2 3
M=
1 2 3
QUESTION FOR SYMMETRIC ANTI.S AND
A.S
R1= {(1,1),(2,2),(3,3),(1,2),(3,1)}
R2={(1,1),(1,2),(2,1)}
R3={(1,2),(2,3)}
TRANSITIVE RELATION
DEFINATION
If (x,y) belongs to R and (y,z) belongs to R then (z,x) must be belong to R.
EXMPLE
A={1,2,3} B{1,2,3}
A {(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)
R1 = { (1,2),(2,3),(3,1)}
REPRESENTATION OF TRANSITIVE
RELATION
DIGRAPH MATRIX
R1 = { (1,2),(2,3),(3,1)} R1 = { (1,2),(2,3),(3,1)}
M=
1 2 3
[1knn,