90
Dr. Eng. Farag Elnagahy [email protected] m Office Phone: 67967 King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222 Discrete Structures I Relations Relations

Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

  • Upload
    maree

  • View
    23

  • Download
    2

Embed Size (px)

DESCRIPTION

King ABDUL AZIZ University Faculty Of Computing and Information Technology. CPCS 222 Discrete Structures I Relations. Dr. Eng. Farag Elnagahy [email protected] Office Phone: 67967. Relations. Functions as Relations Let A and B be nonempty sets. - PowerPoint PPT Presentation

Citation preview

Page 1: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

Dr. Eng. Farag [email protected]

omOffice Phone: 67967

King ABDUL AZIZ University

Faculty Of Computing and Information Technology

CPCS 222Discrete Structures I

RelationsRelations

Page 2: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

22

RelationsRelations

Functions as RelationsFunctions as Relations Let A and B be nonempty sets. A functionfunction ff from A to B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b is the unique element of B assigned by the function f to the element a of A.

If f is a function from A to B, we write f : A → Bf : A → B

Relations are a Relations are a generalizationgeneralization of function of function

Page 3: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

33

RelationsRelations

binary relationbinary relationLet A, B be sets, a Let A, B be sets, a binary relationbinary relation RR from from AA to to BB,,is a subset of is a subset of AA×B×B. . RR AxBAxB

A A binary relationbinary relation from from AA to to B B is a set is a set RR of of ordered pairs where the ordered pairs where the first elementfirst element of each of each ordered pairs comes from ordered pairs comes from AA and the and the second second elementelement comes from comes from BB..

RR::AA×B×B,, or or RR::AA,B,B is a subset of the set Ais a subset of the set A×B. ×B.

The notation The notation aa RR bb means that (a,b) means that (a,b)R.R.The notation The notation aa RR bb means that (a,b) means that (a,b)R.R.

When When (a,b)(a,b) belongs to belongs to RR , , aa is said to be is said to be related related to to bb by relation by relation RR. .

Page 4: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

44

RelationsRelations

binary relationbinary relationExampleExampleLet Let AA be be the set ofthe set of studentsstudents in your school and in your school and let let BB be be set of coursesset of courses, and , and let let RR be be the relationthe relation that consists of those that consists of those pairspairs (a,b), where (a,b), where aa is a is a studentstudent enrolled in enrolled in coursecourse bb..

If If AhmedAhmed, , AliAli, and , and MohamedMohamed are enrolled in are enrolled in CP223CP223 and and AhmedAhmed, , AliAli, and , and OsmanOsman are enrolled in are enrolled in CS313CS313

Then the pairs (Then the pairs (AhmedAhmed,,CP223CP223), (), (AliAli, , CP223CP223), ), ((MohamedMohamed, , CP223CP223), (), (AhmedAhmed, , CS313CS313), (), (AliAli, , CS313CS313 ), and ( ), and (OsmanOsman, , CS313CS313) belong to (are ) belong to (are in) R.in) R.

The pair (The pair (OsmanOsman, , CP223CP223) is not in R. ) is not in R.

Page 5: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

55

RelationsRelations

Representation of relationRepresentation of relation ( (Arrow diagram & Arrow diagram & tabletable))ExampleExampleLet Let AA ={0,1,2} and ={0,1,2} and BB={a,b} and the relation ={a,b} and the relation RR from A to B is {(0,a),(0,b),(1,a),(2,b)}.from A to B is {(0,a),(0,b),(1,a),(2,b)}.

0 0 aa11 bb22

Arrow diagram tableArrow diagram table0 R a 0 R b 1 R a 2 R b0 R a 0 R b 1 R a 2 R b1 R b 2 R a 1 R b 2 R a

RR aa bb

00 xx xx

11 xx

22 xx

Page 6: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

66

RelationsRelations

Representation of relationRepresentation of relation ( (digraphsdigraphs))A A directed graphdirected graph, or , or digraphdigraph consists of a consists of a set set VV of of verticesvertices (or (or nodesnodes) together with a ) together with a set Eset E of ordered pairs of elements of V called of ordered pairs of elements of V called edgesedges (or (or arcsarcs). ).

The The vertexvertex aa is called the is called the initial vertexinitial vertex of the of the edge (a,b), and edge (a,b), and vertexvertex bb is called the is called the terminal terminal vertexvertex of this edge. of this edge. aa bb

An An edgeedge of the form ( of the form (aa,,aa) is represented by an ) is represented by an arcarc from the vertex from the vertex aa back to back to itselfitself and it is and it is called a called a looploop..

a

edgeedge or or arcarc

Page 7: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

77

RelationsRelations

Representation of relationRepresentation of relation ( (digraphsdigraphs))ExampleExample

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

looploop

vertex(node) vertex(node) edge(arc) edge(arc)

A directed graph A directed graph ((digraphdigraph))

12

34

Page 8: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

88

RelationsRelationsRepresentation of relationRepresentation of relation ( (matrixmatrix))A relation between finite sets can be A relation between finite sets can be represented using a represented using a zero-onezero-one matrixmatrix..

Suppose that Suppose that RR is a relation from is a relation from AA={a={a11,a,a22,,…,a…,amm) to ) to BB={b={b11,b,b22,….,b,….,bnn}. This relation can be }. This relation can be represented by the matrix represented by the matrix MMRR=[=[mmijij], where: ], where:

[m[mijij]= ]= 11 if (a if (aii,b,bjj) ) R R

00 if (a if (aii,b,bjj) ) R RExampleExample Let Let AA ={0,1,2} and ={0,1,2} and BB={a,b} and the ={a,b} and the relation relation RR from A to B is {(0,a),(0,b),(1,a), from A to B is {(0,a),(0,b),(1,a),(2,b)}.(2,b)}. 11 11

11 00

00 11

MMRR

==

aa bb

00

11

22

Page 9: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

99

Relations on a SetRelations on a Set

A (binary) A (binary) relationrelation from a set from a set A to itselfA to itself is is called a called a relation on the set Arelation on the set A..

ExampleExample

Let Let AA={1,2,3,4} which ordered pairs are in the ={1,2,3,4} which ordered pairs are in the R={ R={(a,b)(a,b) | | aa dividesdivides bb}.}.

1,2,3,4 are positive integer, max is 41,2,3,4 are positive integer, max is 4

RR= {(1,1),(1,2),(1,3),(1,4),(2,2),(2,4),= {(1,1),(1,2),(1,3),(1,4),(2,2),(2,4),

(3,3),(4,4)}(3,3),(4,4)}

DrawDraw the arrow diagram, digraph, the arrow diagram, digraph,

and matrix?and matrix?

RR 11 22 33 44

11 xx xx xx xx

22 xx xx

33 xx

44 xx

Page 10: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1010

Relations on a SetRelations on a Set

ExampleExample

Consider these relations on the Consider these relations on the setset of of integersintegers

RR11={(a,b) | ={(a,b) | a a b b}}

RR22={(a,b) | ={(a,b) | a a b b}}

RR33={(a,b) | ={(a,b) | a=b or a=-ba=b or a=-b}}

RR44={(a,b) | ={(a,b) | a=ba=b}}

RR55={(a,b) | ={(a,b) | a=b+1a=b+1}}

RR66={(a,b) | ={(a,b) | a+b a+b 3 3}}

Which of these relations contain each of the Which of these relations contain each of the pairs (1,1), (1,2), (2,1), (1,-1), and (2,2) ?pairs (1,1), (1,2), (2,1), (1,-1), and (2,2) ?

The pair (1,1) is in …..The pair (1,1) is in …..

……....

Page 11: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1111

Relations on a SetRelations on a Set

How many How many relations relations are there on a set with are there on a set with nn elements?elements?

A A relationrelation on a set on a set AA is a subset of AxA. is a subset of AxA.

AxA has AxA has nn22 elements when A has elements when A has nn elements, elements, and and

a set with m elements has a set with m elements has 22mm subsets, subsets,

there are there are 22nn2 2 subsets of AxA.subsets of AxA.

Thus there are Thus there are 22nn2 2 relationsrelations on a set with on a set with nn

elements.elements.

For exampleFor example there are there are 22332 2 = 2= 299 =512 =512 relationsrelations

on the set {a,b,c} on the set {a,b,c}

Page 12: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1212

Properties of RelationsProperties of Relations

There are There are several propertiesseveral properties that are used to that are used to classifyclassify relations on a set. relations on a set.

In some relations In some relations an element is always relatedan element is always related to itselfto itself. .

For exampleFor example, let , let RR be the relation on the set of be the relation on the set of all peopleall people consisting of pairs consisting of pairs (x,y)(x,y) where where xx and and yy has the has the same fathersame father and the and the same mothersame mother. . Then xRx for every person x.Then xRx for every person x.

Page 13: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1313

Properties of Relations Properties of Relations

A relation A relation RR on a set A is called on a set A is called reflexivereflexive if if

(a,a)(a,a)RR for every element for every element aaAA ( (aaAA)), aRa, aRa..–E.g., the relationE.g., the relation ≥ :≡ {(a,b) | a≥b}≥ :≡ {(a,b) | a≥b} is is reflexivereflexive

A relation A relation RR on the set A is on the set A is reflexivereflexive if if

a(a((a,a)(a,a)R)R) when the universe of discourse is when the universe of discourse is the set of all elements in A.the set of all elements in A.

ReflexiveReflexive means that means that every member is related to every member is related to itselfitself..

A relation A relation RR on a set A is called on a set A is called irreflexiveirreflexive if if (a,a) (a,a) R for every element in A R for every element in A There is no element in A is related to itselfThere is no element in A is related to itself

Page 14: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1414

Properties of RelationsProperties of Relations

ExampleExample

Consider the following relations on the Consider the following relations on the {1,2,3,4}{1,2,3,4}

RR1 1 =={{(1,1)(1,1),(1,2),(2,1),,(1,2),(2,1),(2,2)(2,2),(3,4),(4,1),,(3,4),(4,1),(4,4)(4,4)}}

RR2 2 =={{(1,1)(1,1),(1,2),(2,1),(1,2),(2,1)}}

RR3 3 =={{(1,1)(1,1),(1,2),(1,4),(2,1),,(1,2),(1,4),(2,1),(2,2)(2,2),,(3,3)(3,3),(4,1),,(4,1),(4,4)(4,4)}}

RR4 4 =={{(2,1),(3,1),(3,2),(4,1),(3,4)(2,1),(3,1),(3,2),(4,1),(3,4)}}

RR55 =={{(1,1)(1,1),(1,2),(1,3),(1,4),,(1,2),(1,3),(1,4),(2,2)(2,2),(2,3),(2,4),,(2,3),(2,4),(3,3)(3,3),,

(3,4),(3,4),(4,4)(4,4)}}

RR66 =={{(3,4)(3,4)}}

Which of these relations are Which of these relations are reflexivereflexive??

The relations The relations RR33 and and RR55 are are reflexive reflexive because because they both contain all pairs of the form (a,a). they both contain all pairs of the form (a,a).

irreflexive ?irreflexive ?

Page 15: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1515

Properties of RelationsProperties of Relations

ExampleExample

Consider the following relations on the Consider the following relations on the setset of of integersintegers

RR11={(a,b) | ={(a,b) | a a b b}}

RR22={(a,b) | ={(a,b) | a a b b}}

RR33={(a,b) | ={(a,b) | a=b or a=-ba=b or a=-b}}

RR44={(a,b) | ={(a,b) | a=ba=b}}

RR55={(a,b) | ={(a,b) | a=b+1a=b+1}}

RR66={(a,b) | ={(a,b) | a+b a+b 3 3}}

Which of these relations are Which of these relations are reflexivereflexive??

The relations The relations RR11 , , RR33 and and RR44 are are reflexive reflexive because they both contain all pairs of the form because they both contain all pairs of the form (a,a). (a,a).

irreflexive ?irreflexive ?

Page 16: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1616

Properties of RelationsProperties of Relations

ExampleExample Is the “divides” relation on the set of Is the “divides” relation on the set of positive integerspositive integers reflexivereflexive??

Is the “divides” relation on the set of Is the “divides” relation on the set of integersintegers reflexivereflexive??

NoteNote that 0 does not divide 0. that 0 does not divide 0.

Page 17: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1717

Properties of RelationsProperties of Relations

A relation A relation RR on a set A is called on a set A is called reflexivereflexive if and if and only if there is a only if there is a looploop at at every vertexevery vertex of the of the directed graphdirected graph..

R=R={{((1,11,1),(1,2),(1,3),(1,4),(),(1,2),(1,3),(1,4),(2,22,2),(2,3),(2,4),),(2,3),(2,4),((3,33,3),), (3,4),((3,4),(4,44,4))}}

12

34

irreflexive ?irreflexive ?

Page 18: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1818

Properties of RelationsProperties of Relations

A relation A relation RR on a set A is called on a set A is called reflexivereflexive if and if and only if only if (a(aii,a,aii))RR this means that m this means that miiii=1 for =1 for i=1,2,.,ni=1,2,.,nAll the elements on the All the elements on the main diagonalmain diagonal of of MMRR are equal to are equal to 11

R=R={{((1,11,1),(1,2),(1,3),(1,4),(),(1,2),(1,3),(1,4),(2,22,2),(2,3),(2,4),),(2,3),(2,4),((3,33,3),), (3,4),((3,4),(4,44,4))}} 11 11 11 11

00 11 11 11

00 00 11 11

00 00 00 11

MMRR

==

irreflexive ?irreflexive ?

Page 19: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

1919

Properties of RelationsProperties of Relations

A A relationrelation R on a set A is R on a set A is symmetricsymmetric

if if (b,a)(b,a)R R wheneverwhenever (a,b)(a,b)R R for allfor all a,b a,b A A

aab(b((a,b) (a,b) R R → → (b,a)(b,a)RR ) )

A A relationrelation R on a set A is R on a set A is antisymmetricantisymmetric

if if (a,b)(a,b)R R andand (b,a)(b,a)R R then then a=ba=b for all for all a,b a,b AA

aab(b((a,b) (a,b) R R (b,a)(b,a)RR → → ((a=ba=b)) ))

Note that “Note that “the termthe term symmetricsymmetric andand antisymmetricantisymmetric are not opposites, the relation are not opposites, the relation can have both of these properties or may lack can have both of these properties or may lack both of themboth of them””

Page 20: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2020

Properties of RelationsProperties of Relations

A relation A relation cannot be bothcannot be both symmetricsymmetric and and antisymmetricantisymmetric if it contains some pair of the if it contains some pair of the form (a,b), where form (a,b), where aa≠≠bb

exampleexample

Let Let R R be the following relation defined on the be the following relation defined on the set set

{a, b, c, d}:{a, b, c, d}:

R = R = {{((a, aa, a), (), (a, ca, c), (a, d), (b, a), (), (a, d), (b, a), (b, bb, b), ), (b, c)(b, c), , ((b, db, d), ), (c, b)(c, b), (, (c, cc, c), (), (d, bd, b), (), (d, dd, d))}}..

Determine whether R is:Determine whether R is:

(a)(a) reflexive. reflexive. Yes Yes

(b)(b) symmetric. symmetric. NoNo there is no (c,a) for example there is no (c,a) for example

(c)(c) antisymmetric. antisymmetric. No b No b c b c b d d

Page 21: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2121

Properties of RelationsProperties of Relations

A relation A relation cannot be bothcannot be both symmetricsymmetric and and antisymmetricantisymmetric if it contains some pair of the if it contains some pair of the form (a,b), where form (a,b), where aa≠≠bb

exampleexample

Let Let R R be the following relation defined on the be the following relation defined on the set set

{a, b, c, d}:{a, b, c, d}:

R = R = {{((a, aa, a), (), (b, bb, b), (), (c, cc, c), (), (d, dd, d))}}..

Determine whether R is:Determine whether R is:

(a)(a) reflexive. reflexive. Yes Yes

(b)(b) symmetric. symmetric. yesyes

(c)(c) antisymmetric. antisymmetric. yesyes

Page 22: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2222

Properties of RelationsProperties of Relations

ExampleExample

Consider the following relations on the Consider the following relations on the {1,2,3,4}{1,2,3,4}

RR1 1 =={{(1,1),(1,2),(2,1),(2,2),(3,4),(4,1),(4,4)(1,1),(1,2),(2,1),(2,2),(3,4),(4,1),(4,4)}}

RR2 2 =={{(1,1),(1,1),(1,2)(1,2),,(2,1)(2,1)}}

RR3 3 =={{(1,1),(1,1),(1,2)(1,2),,(1,4)(1,4),,(2,1)(2,1),(2,2),(3,3),,(2,2),(3,3),(4,1)(4,1),,(4,4)(4,4)}}

RR4 4 =={{(2,1),(3,1),(3,2),(4,1),(3,4)(2,1),(3,1),(3,2),(4,1),(3,4)}}

RR55 ={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,3),

(3,4),(4,4)}(3,4),(4,4)}

RR66 ={(3,4)}={(3,4)}

Which of these relations are Which of these relations are symmetric symmetric and and which are which are antisymmetricantisymmetric ? ?

RR22 andand RR33 areare symmetric symmetric because in each case because in each case (b,a) belongs to the relation whenever (a,b) (b,a) belongs to the relation whenever (a,b) does.does.

Page 23: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2323

Properties of RelationsProperties of Relations

ExampleExample

Consider the following relations on the Consider the following relations on the setset of of integersintegers

RR11={(a,b) | ={(a,b) | a a b b} }

RR22={(a,b) | ={(a,b) | a a b b} }

RR33={(a,b) | ={(a,b) | a=b or a=-ba=b or a=-b}}

RR44={(a,b) | ={(a,b) | a=ba=b} }

RR55={(a,b) | ={(a,b) | a=b+1a=b+1} }

RR66={(a,b) | ={(a,b) | a+b a+b 3 3} }

Which of these relations are Which of these relations are symmetric symmetric and and which are which are antisymmetricantisymmetric ? ?

RR33 , , RR44 , ,andand RR66 areare symmetric symmetric because in each because in each case (b,a) belongs to the relation whenever case (b,a) belongs to the relation whenever (a,b) does.(a,b) does.

Page 24: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2424

Properties of RelationsProperties of Relations

ExampleExample

Consider the following relations on the Consider the following relations on the setset of of integersintegers

RR11={(a,b) | ={(a,b) | a a b b} } aab b andand b ba a imply thatimply that a=b a=b

RR22={(a,b) | ={(a,b) | a a b b}}

RR33={(a,b) | ={(a,b) | a=b or a=-ba=b or a=-b}}

RR44={(a,b) | ={(a,b) | a=ba=b} }

RR55={(a,b) | ={(a,b) | a=b+1a=b+1}}

RR66={(a,b) | ={(a,b) | a+b a+b 3 3}}

RR11 , , RR2 2 , , RR44 , , RR55 areare antisymmetric antisymmetric

RR2 2 isis antisymmetric antisymmetric it is impossible for a>b and it is impossible for a>b and b>ab>a

RR5 5 isis antisymmetric antisymmetric it is impossible for a=b+1 it is impossible for a=b+1 and b=a+1and b=a+1

Page 25: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2525

Properties of RelationsProperties of Relations

ExampleExample

Is the “divides” relation on the set of Is the “divides” relation on the set of positive positive integersintegers symmetricsymmetric? Is it ? Is it antisymmetricantisymmetric ? ?

This relation is not This relation is not symmetricsymmetric because 1|2, but because 1|2, but 2|1.2|1.

It is It is antisymmetricantisymmetric because a|b, and b|a then because a|b, and b|a then a=b.a=b.

Page 26: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2626

Properties of RelationsProperties of Relations

A relation A relation RR on a set A is called on a set A is called symmetricsymmetric if if and only if for every edge between distinct and only if for every edge between distinct vertices in its vertices in its directed graph directed graph there is an there is an edgeedge in the in the oppositeopposite direction direction..

R=R={{((1,11,1),(1,2),(1,3),(1,4),(),(1,2),(1,3),(1,4),(2,22,2),(2,3),(2,4),),(2,3),(2,4),((3,33,3),), (3,4),((3,4),(4,44,4))}}

1122

33 44

Not Not symmetrisymmetri

cc

Page 27: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2727

Properties of RelationsProperties of Relations

A relation A relation RR on a set A is called on a set A is called antisymmetricantisymmetric if and only if there are never two edges in the if and only if there are never two edges in the opposite direction opposite direction betweenbetween distinct vertices distinct vertices in in its its directed graphdirected graph

1122

33 44

AntisymmetrAntisymmetricic

Not reflexiveNot reflexive

Not Not symmetricsymmetric

Page 28: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2828

Properties of RelationsProperties of Relations

A relation A relation RR on a set A is called on a set A is called symmetricsymmetric if if and only if mand only if mijij=m=mjiji of of MMRR for i=1,2,.,n j=1,2,.,n for i=1,2,.,n j=1,2,.,n

R=R={{((1,11,1),(1,2),(1,3),(1,4),(),(1,2),(1,3),(1,4),(2,22,2),(2,3),(2,4),),(2,3),(2,4),((3,33,3),), (3,4),((3,4),(4,44,4))}}

11 11 11 11

00 11 11 11

00 00 11 11

00 00 00 11

MMRR

==

11 22 33 44

11

22

33

44

((aa,,bb))

AntisymmetAntisymmetricric

Page 29: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

2929

Properties of RelationsProperties of Relations

A relation A relation RR on a set A is called on a set A is called symmetricsymmetric if if and only if mand only if mijij=m=mjiji of of MMRR for i=1,2,.,n j=1,2,.,n for i=1,2,.,n j=1,2,.,n

R=R={{((1,11,1),(1,2),(1,3),(),(1,2),(1,3),(2,22,2),(2,3),(2,4),(),(2,3),(2,4),(3,33,3),), (3,4),((3,4),(4,44,4))}}

11 11 11 00

00 11 11 11

00 00 11 11

00 00 00 11

MMRR

==

11 22 33 44

11

22

33

44

((aa,,bb))

AntisymmetAntisymmetricric

Page 30: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3030

Properties of RelationsProperties of Relations

Suppose that the relation R on a set Suppose that the relation R on a set AA is is represented by the matrixrepresented by the matrix

11 11 00

11 11 11

00 11 11

MMRR

==

A relation R is A relation R is reflexive reflexive iff iff (a(aii,a,aii))RR this means that m this means that miiii=1 =1 for i=1,2,.,nfor i=1,2,.,n

A relation R is A relation R is symmetricsymmetric

if if (a,b)(a,b)R R ↔ (b,a)↔ (b,a)RR

this means that mthis means that mijij=m=mjiji for for i=1,2,.,ni=1,2,.,n

11 11 00

11 11 11

00 11 11

MMRR

==

Page 31: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3131

Properties of RelationsProperties of Relations

Suppose that the relation R on a set Suppose that the relation R on a set AA is is represented by the matrixrepresented by the matrix

11 11 00

00 11 11

00 11 00

MMRR

==

This relation is reflexive This relation is reflexive symmetric symmetric

antisymmetric antisymmetric

This relation is reflexive This relation is reflexive symmetric symmetric

antisymmetricantisymmetric

00 00 00

11 11 11

11 00 11

MMRR

==

Page 32: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3232

Properties of RelationsProperties of Relations

Suppose that the relation R on a set Suppose that the relation R on a set AA is is represented by the matrixrepresented by the matrix

11 11 00

11 11 11

00 11 00

MMRR

==

This relation is reflexive This relation is reflexive symmetricsymmetric

antisymmetricantisymmetric

This relation is This relation is reflexivereflexive symmetricsymmetric

antisymmetricantisymmetric

11 11 00

11 11 00

00 00 11

MMRR

==

Page 33: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3333

Properties of RelationsProperties of Relations

Let Let RR be the relation consisting of all pairs be the relation consisting of all pairs (x,y)(x,y) of students at your school, where of students at your school, where xx has has taken more creditstaken more credits than than yy..

Suppose that x is related to y and y related to Suppose that x is related to y and y related to z.z.

This means that This means that

xx has taken more credits than has taken more credits than yy and and

yy has taken more credits than has taken more credits than zz

We can We can concludeconclude that that

xx has taken more credits than has taken more credits than zz, so that x is , so that x is related to z. related to z.

The relation R has the The relation R has the transitivetransitive property. property.

Page 34: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3434

Properties of RelationsProperties of Relations

A relation R on a set A is called A relation R on a set A is called transitivetransitive if if whenever whenever (a,b)(a,b)R R andand (b,c) (b,c)R R then then (a,c)(a,c)RR , , for all a, b, c for all a, b, c A A aabbcc((( ( ((a,ba,b))R R ((b,cb,c))RR) ) → → ((a,ca,c))RR))

Page 35: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3535

Properties of RelationsProperties of Relations

Consider the following relations on the Consider the following relations on the {1,2,3,4}{1,2,3,4}

RR11 ={(1,1),(1,2),(2,1),(2,2),(3,4),(4,1),(4,4)}={(1,1),(1,2),(2,1),(2,2),(3,4),(4,1),(4,4)}

RR22 ={(1,1),(1,2),(2,1)}={(1,1),(1,2),(2,1)}

RR33 ={(1,1),(1,2),(1,4),(2,1),(2,2),(3,3),(4,1),={(1,1),(1,2),(1,4),(2,1),(2,2),(3,3),(4,1),(4,4)} (4,4)}

RR44 ={(2,1),(3,1),(3,2),(4,1),(4,2),((4,3)} ={(2,1),(3,1),(3,2),(4,1),(4,2),((4,3)}

RR55 ={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,3),

(3,4),(4,4)}(3,4),(4,4)}

RR66 ={(3,4)} ={(3,4)} Which of these relations are Which of these relations are transitivetransitive ? ? The relation is The relation is transitivetransitive If (a,b) and (b,c) belong to the relation If (a,b) and (b,c) belong to the relation then (a,c) also does. then (a,c) also does. RR4 4 (3,2),(2,1),(3,1) (4,2) (2,1),(4,1) (3,2),(2,1),(3,1) (4,2) (2,1),(4,1) (4,3) (3,1),(4,1) (4,3) (3,2),(4,2) (4,3) (3,1),(4,1) (4,3) (3,2),(4,2)

Page 36: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3636

Properties of RelationsProperties of Relations

Consider the following relations on the Consider the following relations on the setset of of integersintegers

RR11={(a,b) | ={(a,b) | a a b b}}

RR22={(a,b) | ={(a,b) | a a b b}}

RR33={(a,b) | ={(a,b) | a=b or a=-ba=b or a=-b}}

RR44={(a,b) | ={(a,b) | a=ba=b}}

RR55={(a,b) | ={(a,b) | a=b+1a=b+1}}

RR66={(a,b) | ={(a,b) | a+b a+b 3 3}}Which of these relations are Which of these relations are transitivetransitive ? ?

The relation is The relation is transitivetransitive If (a,b) and (b,c) belong to the relation If (a,b) and (b,c) belong to the relation then (a,c) also does.then (a,c) also does.

Page 37: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3737

Properties of RelationsProperties of Relations

Is the “divides” relation on the set of Is the “divides” relation on the set of positive positive integersintegers transitivetransitive? ?

Suppose that a divides b and b divides c.Suppose that a divides b and b divides c.

Then there are positive integers k and l such Then there are positive integers k and l such that b=ak and c=bl.that b=ak and c=bl.

Hence, c=a(kl), so a divides c.Hence, c=a(kl), so a divides c.

It follows that the relation is It follows that the relation is transitivetransitive

Page 38: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3838

Properties of RelationsProperties of Relations

A relation is A relation is transitivetransitive if and only if whenever if and only if whenever there is an edge from a vertex there is an edge from a vertex xx to a vertex to a vertex yy and an edge from a vertex and an edge from a vertex yy to a vertex to a vertex zz, , there is an edge from a vertex there is an edge from a vertex xx to a vertex to a vertex zz completing a completing a triangletriangle where each side is a where each side is a directed edge with the correct direction.directed edge with the correct direction.

1122

33 44

Page 39: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

3939

Properties of RelationsProperties of Relations

ExercisesExercises PP.542-544 PP.542-544

2-32-3

13-1413-14

22-2822-28

3232

Page 40: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4040

Combining RelationsCombining Relations

Let A={1,2,3} and B={1,2,3,4}Let A={1,2,3} and B={1,2,3,4}

The relation The relation

RR11={(1,1),(2,2),(3,3)}={(1,1),(2,2),(3,3)}

RR22={(1,1),(1,2),(1,3),(1,4)}={(1,1),(1,2),(1,3),(1,4)}

RR1 1 RR22 = {(1,1),(1,2),(1,3),(1,4),(2,2),(3,3)} = {(1,1),(1,2),(1,3),(1,4),(2,2),(3,3)}

RR1 1 R R2 2 = {(1,1)}= {(1,1)}

RR1 1 -- R R22 = {(2,2),(3,3)} = {(2,2),(3,3)}

RR2 2 -- R R11 = {(1,2),(1,3),(1,4)} = {(1,2),(1,3),(1,4)}

RR1 1 R R2 2 = R= R2 2 R R1 1 = R= R1 1 RR22 -- R R1 1 R R22

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

ReadRead examples examples 1818,,1919 PP. 525-526 PP. 525-526

Page 41: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4141

Combining RelationsCombining Relations

Let A={1,2,3} and B={1,2,3,4}Let A={1,2,3} and B={1,2,3,4}

The relation The relation

RR11={(1,1),(2,2),(3,3)}={(1,1),(2,2),(3,3)}

RR22={(1,1),(1,2),(1,3),(1,4)}={(1,1),(1,2),(1,3),(1,4)}

ConstructConstruct M MRR1 1 andand

MMRR22

RR1 1 RR22 = = MMRR11RR2 2 = = MMRR1 1

MMRR22

RR1 1 R R2 2 = = MMRR11RR2 2 = = MMRR1 1

MMRR22

Page 42: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4242

Compositions of RelationsCompositions of Relations

Let Let RR be a relation from a set be a relation from a set AA to a set to a set BB and and SS a relation from a relation from BB to a set to a set CC..The The compositecomposite of of RR and and SS is the relation is the relation consisting of ordered pairs consisting of ordered pairs (a,c)(a,c), where a, where aA , A , ccC, and for which there exists an element C, and for which there exists an element bbB such that (a,b)B such that (a,b)R and R and (b,c)(b,c)S. we denote S. we denote the composite of R and S by the composite of R and S by SSRR

ExampleExample R is the relation from {1,2,3} to {1,2,3,4}R is the relation from {1,2,3} to {1,2,3,4}S is the relation from {1,2,3,4} to {0,1,2}S is the relation from {1,2,3,4} to {0,1,2}RR = {(= {(11,,11),(),(11,,44),(2,3),(3,1),(3,4)}),(2,3),(3,1),(3,4)}SS = {(= {(11,,00),(2,0),(3,1),(3,2),(),(2,0),(3,1),(3,2),(44,,11)})}SSR=R={({(11,,00),(),(11,,11),(2,1),(2,2),(3,0),),(2,1),(2,2),(3,0),(3,1)(3,1)}} T/F}} T/F

Page 43: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4343

Compositions of RelationsCompositions of Relations

To find To find the the matrixmatrix representing the relation representing the relation SSRR (composite of R and S) (composite of R and S)

ConstructConstruct M MRR andand

MMss

Then calculate the Boolean product (Then calculate the Boolean product (⊙⊙) of the ) of the matrix matrix MMRR

andand

MMss

MMSSRR= = MMRR ⊙⊙

MMss

Page 44: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4444

Compositions of RelationsCompositions of Relations

•The nThe nthth powerpower RRnn of a relation R on a set A can of a relation R on a set A can be defined recursively by:be defined recursively by:

RR1 =1 =RR RRn+1 n+1 = R= RnnRR for all for all n>0n>0..RR22= R= RR , RR , R33= R= R22RR = (R= (RR)R)RR

ExampleExample RR = {(1,1),(2,1),(3,2),(4,3)}, find the powers = {(1,1),(2,1),(3,2),(4,3)}, find the powers RRnn,n=2,3,4,….,n=2,3,4,….

RR22= R= RR= R= {(1,1),(2,1),(3,1),(4,2)}{(1,1),(2,1),(3,1),(4,2)}RR33= R= R22R= R= {(1,1),(2,1),(3,1),(4,1)}{(1,1),(2,1),(3,1),(4,1)}RR44= R= R33R= R= {(1,1),(2,1),(3,1),(4,1)}= {(1,1),(2,1),(3,1),(4,1)}= RR33

RRnn== RR33

Page 45: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4545

Compositions of RelationsCompositions of Relations

Let Let RR be a relation from a set be a relation from a set AA to a set to a set BB,,

The The inverseinverse relation ( relation (RR-1-1) from B to A is the ) from B to A is the set of ordered pairs set of ordered pairs {{ (b,a) | (a,b) (b,a) | (a,b) R R }}

The The complementcomplement relation relation RR is the set of is the set of ordered ordered pairs pairs {{ (a,b) | (a,b) (a,b) | (a,b) R R }}

ExercisesExercises PP. 527-529 PP. 527-5291-7 , 24-25 , 32 , 541-7 , 24-25 , 32 , 54

Page 46: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4646

Closures of RelationsClosures of Relations

ConsiderConsider relation relation RR=={{(1,2),(2,2),(3,3)(1,2),(2,2),(3,3)}} on the on the

set A = {1,2,3,4}. set A = {1,2,3,4}.

Is R Is R reflexivereflexive? No? No

What can we add to R to make it reflexive?What can we add to R to make it reflexive?

(1,1), (4,4)(1,1), (4,4)

R’ = R U {(1,1),(4,4)} is called the R’ = R U {(1,1),(4,4)} is called the reflexive reflexive closureclosure of R. of R.

Page 47: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4747

Closures of RelationsClosures of Relations

In generalIn general

Let Let RR be a relation on a set be a relation on a set AA

R R may or may not have some may or may not have some property Pproperty P such such as:as:

ReflexivityReflexivity – – SymmetrySymmetry – – TransitivityTransitivity

The The closureclosure of relation of relation RR on set on set AA with respect with respect to to property Pproperty P is the relation is the relation R’R’ with with

R R R’ R’ R’ has R’ has property Pproperty P

R’ R’ is called the is called the closureclosure of of RR with respect to with respect to PP

Page 48: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4848

Closures of RelationsClosures of Relations

Let Let RR be the relation on be the relation on {1, 2, 3, 4}{1, 2, 3, 4} such that such that

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

Find: Find: (a)(a) the the reflexive closurereflexive closure of R. of R.

(b)(b) the the symmetric closuresymmetric closure of R. of R.

(c)(c) the the transitive closuretransitive closure of R. of R.

(a)(a) {(1,1), (1,4), (2,2), (2,3), (3,1), (3,3), {(1,1), (1,4), (2,2), (2,3), (3,1), (3,3), (4,4)}.(4,4)}.

(b)(b) {(1,1), (1,3), (1,4), (2,3), (3,1), (3,2), (3,3), {(1,1), (1,3), (1,4), (2,3), (3,1), (3,2), (3,3), (4,1), (4,4)}.(4,1), (4,4)}.

(c)(c) {(1,1), (1,4), (2,1), (2,3), (2,4), (3,1), (3,3), {(1,1), (1,4), (2,1), (2,3), (2,4), (3,1), (3,3), (3,4), (4,4)}.(3,4), (4,4)}.

Read examplesRead examples 1 and 2 PP. 454 1 and 2 PP. 454

Page 49: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

4949

Equivalence RelationsEquivalence Relations

A relation on a set A is called equivalence relation if it is reflexive, symmetric, and transitive.

Two elements a and b that related by an equivalence relation are called equivalent. a ~ ~ bb

Is Is RR is equivalence relation? is equivalence relation?

RR=={{(a,b) | (a,b) | a=ba=b or or a=-ba=-b} r,s, and t} r,s, and t

Read examplesRead examples 2,4,5,6,7 PP. 556-557 2,4,5,6,7 PP. 556-557

ExercisesExercises PP.553-554 PP.553-554

1,3, 5-71,3, 5-7

ExercisesExercises PP.562-563 PP.562-563

1-21-2

Page 50: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5050

Equivalence RelationsEquivalence Relations

Congruence Modulo mCongruence Modulo mLet m be a positive integer m>1 . Show that Let m be a positive integer m>1 . Show that the following relation is an equivalence the following relation is an equivalence relation on the set of integers.relation on the set of integers.

R={ (a,b) | aR={ (a,b) | ab(mod m) }b(mod m) }Note thatNote that a ab(mod m) b(mod m) MeansMeans mm divides divides a-ba-b a-a=0 and is divisible by m ( a-a=0 and is divisible by m ( RR is is reflexive )reflexive ) aab(mod m) then b(mod m) then a-b=kma-b=km where k is an where k is an integerinteger

It follows that b-a=(-k)m means It follows that b-a=(-k)m means bba(mod a(mod m) m)

( ( RR is is symmetric )symmetric ) suppose that suppose that aab(mod m) and bb(mod m) and bc(mod m) c(mod m) a-b=km and b-c=lma-b=km and b-c=lm add both equations we add both equations we get:get:a-b+ b-c= km+ lm=(k+l)ma-b+ b-c= km+ lm=(k+l)ma-c=(k+l)m I.e a-c=(k+l)m I.e aac(mod m) c(mod m) ( ( RR is is transitive )transitive )

RR is is equivalence relationequivalence relation

Page 51: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5151

Equivalence ClassesEquivalence Classes

Let R be an equivalence relation on S. The set of Let R be an equivalence relation on S. The set of all elements that are related to an element all elements that are related to an element aa of of S is called S is called equivalence classequivalence class of a. of a. thethe equivalence classequivalence class of a with respect to R is of a with respect to R is denoted by [a]denoted by [a]R . R .

a a S, [a] S, [a]RR, is, is

[a][a]RR = {s|(a,s) = {s|(a,s) R} or R} or

[a][a]RR = {s: aRs} = {s: aRs}

If If b b [a] [a]RR b is called a b is called a representativerepresentative of this of this equivalence relation equivalence relation

Any element of a class can be used as a Any element of a class can be used as a representativerepresentative of this class. of this class.

Page 52: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5252

Equivalence ClassesEquivalence Classes

ExampleExample

What is equivalence class of an integer for the What is equivalence class of an integer for the following equivalence relation?following equivalence relation?

RR=={{(a,b) | (a,b) | a=ba=b or or a=-ba=-b}}

In this In this equivalence relationequivalence relation the integer is the integer is related to itself and its negative, so : related to itself and its negative, so :

[a][a]RR={-a,a} or [a]={-a,a} or [a] ={-a,a} ={-a,a}

[7][7] ={-7,7}={-7,7}

[5][5] ={-5,5}={-5,5}

[0][0] ={0}={0}

Page 53: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5353

Equivalence ClassesEquivalence Classes

ExampleExample

What is equivalence class of What is equivalence class of 00 and and 11 for the for the Congruence Modulo 4Congruence Modulo 4??

The equivalence class of 0 contains all The equivalence class of 0 contains all integers integers aa such that a such that a0(mod 4) 0(mod 4)

[0] ={…………,-8,-4,0,4,8,……………….}[0] ={…………,-8,-4,0,4,8,……………….}

The equivalence class of 1 contains all The equivalence class of 1 contains all integers integers aa such that a such that a1(mod 4) 1(mod 4)

[1] ={…………,-7,-3,1,5,9,……………….}[1] ={…………,-7,-3,1,5,9,……………….}

Congruence classes modulo mCongruence classes modulo m

[a][a]mm={……………,a-2m,a-m,a,a+m,a+2m,={……………,a-2m,a-m,a,a+m,a+2m,……………..}……………..}

Page 54: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5454

Equivalence ClassesEquivalence Classes

ExampleExample

Let n be a positive integer and S a set of Let n be a positive integer and S a set of strings.strings.

RRnn is the relation on S such that is the relation on S such that sRsRnntt iff iff s=ts=t or or both s and t have at least both s and t have at least nn characters and the characters and the first first nn characters of characters of ss and and tt are the same. are the same.

sRsR33t t 01 R01 R33 01 01 00111 R00111 R33 00101 00101

01 R01 R33 11 11 00111 R00111 R33 01101 01101

What is equivalence class of the string 0111 What is equivalence class of the string 0111 with respect to the with respect to the RR33? ?

[011][011]R3 R3 ={ 011, 0110,0111,01100,01101,01110,={ 011, 0110,0111,01100,01101,01110,

01111,………}01111,………}

Page 55: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5555

Equivalence Classes and Equivalence Classes and PartitionsPartitions

Let n be a positive integer and S a set of Let n be a positive integer and S a set of strings.strings.

RRnn is the relation on S such that is the relation on S such that sRsRnntt iff iff s=ts=t or or both s and t have at least both s and t have at least nn characters and the characters and the first first nn characters of characters of ss and and tt are the same. are the same.

sRsR33tt

[ ][ ]R3 R3 ={ }={ }

[0][0]R3 R3 ={0}={0}

[1][1]R3 R3 ={1}={1}

[00][00]R3 R3 ={00}={00}

[01][01]R3 R3 ={01}={01}

[10][10]R3 R3 ={10}={10}

[11][11]R3 R3 ={11}={11}

Page 56: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5656

Equivalence Classes and Equivalence Classes and PartitionsPartitions

[000][000]R3 R3 ={000,0000,0001,00000,00001,00011,={000,0000,0001,00000,00001,00011,………}………}

[001][001]R3 R3 ={001,0010,0011,00100,00101,00111,={001,0010,0011,00100,00101,00111,………}………}

[010][010]R3 R3 ={010,0100,0101,01000,01001,01011,={010,0100,0101,01000,01001,01011,………}………}

[011][011]R3 R3 ={011,0110,0111,01100,01101,01111,={011,0110,0111,01100,01101,01111,………}………}

[100][100]R3 R3 ={100,1000,1001,10000,10001,10011,={100,1000,1001,10000,10001,10011,………}………}

[101][101]R3 R3 ={101,1010,1011,10100,10101,10111,={101,1010,1011,10100,10101,10111,………}………}

[110][110]R3 R3 ={110,1100,1101,11000,11001,11011,={110,1100,1101,11000,11001,11011,………}………}

[111][111]R3 R3 ={111, 1110,1111,11100,11101,11111,={111, 1110,1111,11100,11101,11111,………}………}

These 15 equivalence classes are disjoint and These 15 equivalence classes are disjoint and every bit string is in exactly one of them. every bit string is in exactly one of them.

These equivalence classes These equivalence classes partitionpartition the set of the set of all bit strings.all bit strings.

Page 57: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5757

Partial Orderings

Let R be a relation on a set S, then R is a Let R be a relation on a set S, then R is a Partially Ordered Set (POSet) if it isPartially Ordered Set (POSet) if it is Reflexive - aRa, Reflexive - aRa, aa Transitive - aRb Transitive - aRb bRc bRc aRc, aRc, a,b,ca,b,c Antisymmetric - aRb Antisymmetric - aRb bRa bRa a=b, a=b, a,ba,b

and denoted by (R,S)and denoted by (R,S)

RR={(a,b) | ={(a,b) | a a b b}}

a a a a Reflexive Reflexive a a b and b b and b a implies a=b a implies a=b Antisymmetric Antisymmetric a a b and b b and b c implies a c implies a c c Transitive Transitive

is is a partial ordering on Z, and (Z,is is a partial ordering on Z, and (Z,) is ) is posetposet

Page 58: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5858

Partial Orderings

ExampleExample

(Z(Z++, , || ), the relation “ ), the relation “dividesdivides” on positive ” on positive integers.integers.

Reflexive?Reflexive? a|a since a=1a (k=1)

Antisymmetric?Antisymmetric?a|b means b=ak,

b|a means a=bj. But b = bjk this means jk=1.

jk=1 means j=k=1, and we have b=a1, or b=a

Transitive?Transitive?a|b means b=ak, b|c means c=bj.

c = bj = akj =am where m=kj then a|c

|| is is a partial ordering on Z is is a partial ordering on Z++, and (Z, and (Z++,|) is ,|) is posetposet

Page 59: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

5959

Partial Orderings

ExampleExample

Show that the inclusion relation Show that the inclusion relation is a partial is a partial ordering on the power set of a set S?ordering on the power set of a set S?

Reflexive?Reflexive? A A A A

Antisymmetric? A Antisymmetric? A B and B B and B A then A=B A then A=B

Transitive? A Transitive? A B and B B and B C then A C then A C C

is is a partial ordering on P(s), and (P(s), is is a partial ordering on P(s), and (P(s), ) ) is is posetposet

Page 60: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6060

Partial Orderings

Different symbols such Different symbols such , , , and | , and | are used for are used for a partial ordering. a partial ordering.

The general symbol The general symbol ≼≼ is used is used for a partial for a partial ordering. ordering.

a ≼ b a ≼ b meansmeans (a,b) (a,b) R in an arbitrary poset R in an arbitrary poset (S,R).(S,R).

The elements The elements aa and and bb of a poset of a poset (S,(S,≼≼)) are are called called comparablecomparable if either if either aa≼b≼b or or b≼ab≼a. . when when aa and and bb are elements of S such that are elements of S such that neither neither aa≼b≼b nor nor b≼ab≼a, , aa and and bb are called are called inincomparablecomparable..

Page 61: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6161

Partial Orderings

ExampleExample

In the poset In the poset (Z(Z++,|),|) , are the integers 3 and 9 , are the integers 3 and 9 comparablecomparable? are the integers 5 and 7 ? are the integers 5 and 7 comparablecomparable? ?

3|9 3|9 comparablecomparable

5|7 7|5 5|7 7|5 incomparableincomparable

The adjective “The adjective “partialpartial” is used to describe ” is used to describe partial orderings because pairs of elements partial orderings because pairs of elements may be incomparable. may be incomparable. When every two elements in the set are When every two elements in the set are comparable, the relation is called comparable, the relation is called total total orderingordering..

Page 62: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6262

Partial Orderings

If If (S,(S,≼≼)) is a poset and every two elements of S is a poset and every two elements of S are are comparablecomparable, S is called a , S is called a totally ordered or totally ordered or linear ordered set (chain). And linear ordered set (chain). And ≼ is called a ≼ is called a total order or a linear order.total order or a linear order.

ExamplesExamples The poset The poset (Z,(Z,)) is is totally ordered totally ordered aab or b or bba.a. The poset (ZThe poset (Z++,|) is ,|) is notnot totally ordered ex. 5,7totally ordered ex. 5,7

Page 63: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6363

Hasse DiagramsHasse Diagrams

Hasse diagrams are a special kind of graphs used to describe posets.

Ex. In poset ({1,2,3,4}, Ex. In poset ({1,2,3,4}, ), we can draw the following ), we can draw the following

directed graphdirected graph, or , or digraphdigraph to describe the to describe the relation.relation.

11 22 33 44

Page 64: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6464

Hasse DiagramsHasse Diagrams

Hasse diagrams are a special kind of graphs used to describe posets.

1. Draw edge (a,b) if a b

2. Don’t draw self loops

3. Don’t draw transitive edges

4. Don’t draw up arrows

11 22 33 44

Page 65: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6565

Hasse DiagramsHasse Diagrams

Hasse diagrams are a special kind of graphs used to describe posets.

1. Draw edge (a,b) if a b

2. Don’t draw self loops

3. Don’t draw transitive edges

4. Don’t draw up arrows

11 22 33 44

Page 66: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6666

Hasse DiagramsHasse Diagrams

Hasse diagrams are a special kind of graphs used to describe posets.

1. Draw edge (a,b) if a b

2. Don’t draw self loops

3. Don’t draw transitive edges

4. Don’t draw up arrows

11 22 33 44

The poset The poset (Z,(Z,)) is is totally ordered (chain) totally ordered (chain) aab or bb or ba.a.

Page 67: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6767

Hasse DiagramsHasse Diagrams

is is a partial ordering on P(s), and (P(s), is is a partial ordering on P(s), and (P(s), ) ) is is posetposet

The hasse digram of (P({a,b,c}), The hasse digram of (P({a,b,c}), ) )

{a,b,c} or 111

{a,b} or 110 {a,c} or 101 {b,c} or 011

{a} or 100 {b} or 010 {c} or 001

{} or 000

Page 68: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6868

Hasse DiagramsHasse Diagrams

Maximal and Minimal ElementsMaximal and Minimal Elements

o An element in the poset is called An element in the poset is called maximalmaximal if if it is not less than any elements of the it is not less than any elements of the poset.poset.

o An element in the poset is called An element in the poset is called minimalminimal if if it is not greater than any elements of the it is not greater than any elements of the poset.poset. Reds are maximal.

whites are minimal.

Page 69: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

6969

Hasse DiagramsHasse Diagrams

Which elements of the poset Which elements of the poset ({2,4,5,10,12,20,25),|)({2,4,5,10,12,20,25),|)

Are maximal, and which are minimal?Are maximal, and which are minimal?Maximal elements are 12,20,25Maximal elements are 12,20,25minimal elements are 2,5minimal elements are 2,5

22

44

1212

55

1010

2020

2525

Note that:Note that: 25 is the 25 is the greatestgreatest element and 2 is element and 2 is the the leastleast element. element.

Page 70: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7070

Hasse DiagramsHasse Diagrams

Which elements of the poset Which elements of the poset ( {1,2,3,4}, ( {1,2,3,4}, ), ),

Are maximal, and which are minimal?Are maximal, and which are minimal?Maximal element is 4Maximal element is 4minimal element is 1minimal element is 1

11

22

33

44

Note that:Note that: 4 is the 4 is the greatestgreatest element and 1 is the element and 1 is the leastleast element. element.

Page 71: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7171

Page 72: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7272

Page 73: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7373

Page 74: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7474

Page 75: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7575

Page 76: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7676

N-ary Relations and Their N-ary Relations and Their ApplicationsApplications

The The relationshipsrelationships among elementsamong elements from more from more than two sets are called than two sets are called n-aryn-ary relations. relations.

Let ALet A11, A, A22, …., A, …., Ann be sets, an be sets, an n-aryn-ary relations on relations on these sets is a subset of these sets is a subset of AA11xAxA22x…..xAx…..xAnn..The sets The sets AA11, , AA22, …., , …., AAnn are called the are called the domainsdomains of the relation, and of the relation, and nn is called its is called its degreedegree..

ExampleExample Let R be the relation on Let R be the relation on NxNxNNxNxN consisting of consisting of triples (a,b,c)triples (a,b,c), where a, b, and c are integers , where a, b, and c are integers with with a<b<ca<b<c..(1,2,3)(1,2,3)R (2,4,3)R (2,4,3)RRThe The degreedegree of this relation is of this relation is 33Its Its domainsdomains are equal to the are equal to the sets of natural sets of natural numbersnumbers..

Page 77: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7777

N-ary Relations and Their N-ary Relations and Their ApplicationsApplications

ExampleExample Let R be the relation on Let R be the relation on ZxZxZZxZxZ consisting of consisting of triples (a,b,c)triples (a,b,c), where a, b, and c are integers , where a, b, and c are integers with with b-a=kb-a=k and and c-b=kc-b=k, where , where kk ((common common differencedifference)) is an is an integerinteger. This relation is called . This relation is called arithmetic progression (arithmetic progression (a,a+k,a+2ka,a+k,a+2k))..

(1,2,3) , (1,3,5) (1,2,3) , (1,3,5) R , R , (2,4,3) , (2,5,9) (2,4,3) , (2,5,9) RR

The The degreedegree of this relation is of this relation is 33Its Its domainsdomains are equal to the are equal to the sets of integerssets of integers..

Page 78: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7878

N-ary Relations and Their N-ary Relations and Their ApplicationsApplications

ExampleExample Let R be the relation on Let R be the relation on ZxZxZZxZxZ consisting of consisting of triples (a,b,c)triples (a,b,c), where a, b, and c are integers , where a, b, and c are integers with with b/a=kb/a=k and and c/b=kc/b=k, where , where k (k (common ratiocommon ratio)) is an is an integerinteger. This relation is called . This relation is called geometric geometric progression (progression (a,ak,aka,ak,ak22))..

(1,3,9) , (1,4,16) (1,3,9) , (1,4,16) R , R , (2,4,3) , (2,5,9) (2,4,3) , (2,5,9) RR

The The degreedegree of this relation is of this relation is 33Its Its domainsdomains are equal to the are equal to the sets of integerssets of integers..

Page 79: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

7979

N-ary Relations and Their N-ary Relations and Their ApplicationsApplications

ExampleExampleLet R be the relation on Let R be the relation on ZxZxZZxZxZ++ consisting of consisting of triples (a,b,m)triples (a,b,m), where a, b, and m are integers , where a, b, and m are integers with mwith m1 and a1 and ab(mod m).b(mod m).(8,2,3) , (-1,9,5) ,(14,0,7) (8,2,3) , (-1,9,5) ,(14,0,7) R , R , (7,2,3) , (-2,-8,5) , (11,0,6) (7,2,3) , (-2,-8,5) , (11,0,6) RRThe The degreedegree of this relation is of this relation is 33Its first two Its first two domainsdomains are the are the sets sets all all of of integersintegers. And its third . And its third domaindomain is the is the set of all set of all positive integerspositive integers..

Congruence Modulo m m>0Congruence Modulo m m>0aab(mod m). Means b(mod m). Means mm divides divides a-ba-b

Page 80: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8080

N-ary Relations and Their N-ary Relations and Their ApplicationsApplications

ExampleExampleLet R be the relation consisting of 5-tuples Let R be the relation consisting of 5-tuples (A,N,S,D,T) (A,N,S,D,T) representingrepresenting airplane flights airplane flights, , where where AA is the is the airlineairline, , NN is the is the flight numberflight number, , SS is the is the starting pointstarting point, , DD is the is the destinationdestination, and , and TT is the is the departure time.departure time.

(Saudi Arabian (Saudi Arabian Airlines,304,Cairo,Jeddah,15:00) Airlines,304,Cairo,Jeddah,15:00) R R The The degreedegree of this relation is of this relation is 55Its Its domainsdomains are the set of all are the set of all airlinesairlines, the set , the set of of flight numbersflight numbers, , the set of the set of citiescities , the set of , the set of citescites, and the set of , and the set of timestimes..

Page 81: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8181

Databases and RelationsDatabases and Relations

Relational DatabasesRelational DatabasesA relational database is essentially just an n-ary A relational database is essentially just an n-ary relation R.relation R.

A A databasedatabase consists of consists of recordsrecords, which are , which are n-n-tuplestuples, made up of fields. These , made up of fields. These fieldsfields are the are the entire of the entire of the n-tuples. n-tuples. RelationsRelations used to used to representrepresent databasesdatabases are called are called tablestables..

Each Each columncolumn of the table corresponds to an of the table corresponds to an attributeattribute of the database. of the database.

Page 82: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8282

Databases and RelationsDatabases and Relations

A A domaindomain of an of an n-ary relationn-ary relation is called a is called a primary keyprimary key when the value of the n-tuple when the value of the n-tuple from this domain determines the n-tuple. from this domain determines the n-tuple. ThatThat is,a is,a domaindomain is is primary keyprimary key when when no two n-no two n-tuplestuples in the relation in the relation have the same valuehave the same value from this domain.from this domain.

Student_naStudent_nameme

ID_numbID_numberer

MajorMajor GPAGPA

Ahmed AliAhmed Ali 06123450612345 CSCS 3.83.888

Ashraf SamiAshraf Sami 04123640412364 PhysicsPhysics 3.63.655

Waleed Waleed TarekTarek

05124320512432 MathMath 2.82.888

Tarek MoradTarek Morad 07234650723465 CSCS 3.63.655

Page 83: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8383

Databases and RelationsDatabases and Relations

Records are often Records are often addedadded to or to or deleteddeleted from from databases. Thus, the databases. Thus, the primary keyprimary key should be should be chosen that remains one whenever the chosen that remains one whenever the database is changed.database is changed.

The The current collectioncurrent collection of the n-tuples in a of the n-tuples in a relation is called the relation is called the extension extension of the relation.of the relation.

The more The more permanentpermanent part of a database, part of a database, including the name and attributes of the including the name and attributes of the database is called the database is called the intensionintension..

Selecting the Selecting the primary keyprimary key depends on the depends on the possiblepossible extensionsextensions of the database. of the database.

Page 84: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8484

Databases and RelationsDatabases and Relations

CombinationsCombinations of domains can also uniquely of domains can also uniquely identify identify n-tuplesn-tuples in n-ary database. in n-ary database.

The The Cartesian productCartesian product of these of these domainsdomains is is called a called a composite keycomposite key

A A composite keycomposite key for the database is a set of for the database is a set of domains domains {A{Aii, A, Ajj, …}, …} such that R contains at such that R contains at most most 11 n-tuple n-tuple (…,a(…,aii,…,a,…,ajj,…),…) for each for each composite value composite value

(a(aii, a, ajj,…),…)AAii×A×Ajj×…×…

See student relationSee student relation Is (Is (Major Major x x GPAGPA) a ) a composite key for the n-ary composite key for the n-ary relationrelation ? Assuming that no n-tuples are ever ? Assuming that no n-tuples are ever addedadded

Page 85: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8585

Operations on n-ary RelationsOperations on n-ary Relations

Selection OperatorSelection OperatorLet Let RR be an n-ary relation and be an n-ary relation and C C a condition a condition that elements in R may satisfy. that elements in R may satisfy.

Then the Then the selection operatorselection operator ssCC maps the n-ary maps the n-ary relation R to the n-ary relation of all n-tuples relation R to the n-ary relation of all n-tuples from R that satisfy the condition C. from R that satisfy the condition C.

Page 86: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8686

Operations on n-ary RelationsOperations on n-ary Relations

selection operatorselection operator ssC1 C1 where cwhere c11 is the condition is the condition major=“major=“CSCS“ The result is the two 4-tuples. “ The result is the two 4-tuples. ((Ahmed Ali, 0612345, CSAhmed Ali, 0612345, CS , 3.88, 3.88))((Tarek Morad, 0723465, CSTarek Morad, 0723465, CS , 3.65, 3.65))ssC2 C2 GPA >3.5 GPA >3.5 ssC3 C3 (Major=“(Major=“CSCS“ “ GPA >3.5 ) GPA >3.5 )

Student_naStudent_nameme

ID_numbID_numberer

MajorMajor GPAGPA

Ahmed AliAhmed Ali 06123450612345 CSCS 3.83.888

Ashraf SamiAshraf Sami 04123640412364 PhysicsPhysics 3.63.655

Waleed Waleed TarekTarek

05124320512432 MathMath 2.82.888

Tarek MoradTarek Morad 07234650723465 CSCS 3.63.655

Page 87: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8787

Operations on n-ary RelationsOperations on n-ary Relations

Projection OperatorsProjection Operators

The projection PThe projection Pi1,i2,….imi1,i2,….im where i where i11<i<i22<….i<….imm , maps , maps the the n-tuplen-tuple (a (a11,a,a22,….,a,….,ann) to the ) to the m-tuplem-tuple (a (ai1i1,a,ai2i2,,…a…aimim), where m ), where m ≤≤ n n

The projection PThe projection Pi1,i2,….imi1,i2,….im deletes n-m of the deletes n-m of the components of an n-tuple, leaving the icomponents of an n-tuple, leaving the i11th, th, ii22th,….,ith,….,immth componentsth components

PP1,31,3 is applied to the 4-tuples is applied to the 4-tuples (2,3,0,4) ,(Tarek Morad, 0723465, CS , 3.65)(2,3,0,4) ,(Tarek Morad, 0723465, CS , 3.65)(2,0) , (Tarek Morad, CS)(2,0) , (Tarek Morad, CS)

Page 88: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8888

Operations on n-ary RelationsOperations on n-ary Relations

PP1,41,4 is applied to the relation in the table is applied to the relation in the table

Student_naStudent_nameme

ID_numbeID_numberr

MajorMajor GPAGPA

Ahmed AliAhmed Ali 06123450612345 CSCS 3.883.88

Ashraf SamiAshraf Sami 04123640412364 PhysiPhysicscs

3.653.65

Waleed Waleed TarekTarek

05124320512432 MathMath 2.882.88

Tarek Tarek MoradMorad

07234650723465 CSCS 3.653.65

Student_naStudent_nameme

GPAGPA

Ahmed AliAhmed Ali 3.883.88

Ashraf SamiAshraf Sami 3.653.65

Waleed Waleed TarekTarek

2.882.88

Tarek Tarek MoradMorad

3.653.65

New relationNew relation is is produced using produced using projectionprojection

Page 89: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

8989

Operations on n-ary RelationsOperations on n-ary Relations

Join OperatorJoin Operator•Puts two relations together to form a sort of Puts two relations together to form a sort of combined relation.combined relation.

•If the tuple If the tuple (A,B)(A,B) appears in R appears in R11, and the tuple , and the tuple (B,C)(B,C) appears in R appears in R22, then the tuple , then the tuple (A,B,C)(A,B,C) appears in the join appears in the join J(RJ(R11,R,R22))..

–A, B, and C here can also be sequences of A, B, and C here can also be sequences of elements (across multiple fields), not just elements (across multiple fields), not just single elementssingle elements

Page 90: Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

9090

Operations on n-ary RelationsOperations on n-ary Relations

Join Operator exampleJoin Operator example

Suppose Suppose RR11 is a teaching assignment table, is a teaching assignment table, relating relating ProfessorsProfessors to to CoursesCourses. .

Suppose Suppose RR22 is a room assignment table is a room assignment table relating relating CoursesCourses to to RoomsRooms,,TimesTimes..

Then Then J(RJ(R11,R,R22)) is like your class schedule, listing is like your class schedule, listing (professor,course,room,time)(professor,course,room,time)..

ExercisesExercises PP.536-537 PP.536-5371-171-17