presentation on binary relations.pdf

14
1 Relations Professor J. F. Baldwin Binary Relation Definition of Binary Relation R Given sets S and T, a binary relation on is a subset of S T × S T × If ρ is a binary relation then x y (x, y) ρ ρ Example: S = {1, 2}, T = {2, 3, 4}, ρ is: x + y is odd, then (1, 2) ε ρ, (1, 4) ε ρ and (2, 3) ε ρ Definition of a Binary Relation, R, on a set S A binary relation on S is a subset of i.e. a set of ordered pairs of members of S S S S × = 2 R S S × R S T ×

Upload: ankitsisodia

Post on 27-Dec-2015

18 views

Category:

Documents


1 download

DESCRIPTION

Presentation on Binary Relation

TRANSCRIPT

Page 1: Presentation on Binary Relations.pdf

1

Relations

Professor J. F. Baldwin

Binary Relation

Definition of Binary Relation RGiven sets S and T, a binary relation on is a subset of

S T× S T×

If ρ is a binary relation then x y (x, y) ρ ρ↔ ∈

Example:S = {1, 2}, T = {2, 3, 4}, ρ is: x + y is odd, then(1, 2) ε ρ, (1, 4) ε ρ and (2, 3) ε ρ

Definition of a Binary Relation, R, on a set SA binary relation on S is a subset of i.e. a set of ordered pairs of members of S

S S S× = 2

R S S⊆ ×

R S T⊆ ×

Page 2: Presentation on Binary Relations.pdf

2

Matrix and Digraphs for BinaryRelations

Consider R = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 2)} defined on S2 where S = {1, 2, 3}

Matrix Representation

1 1 0

1 1 0

0 1 0

element in ith row and jth column = 1 if (ith element of S, jth element of S) is in Rotherwise 0.

Digraph Representation

1

2 3

n-ary Relation

Definition of an n-ary Relation RGive sets S1, S2, …, Sn a relation on is a subset of . i.e. A unary relation is a special case and is a relation on S which is a subset of S.An n-ary relation on S is a relation on

S1 S Sn× × ×2 ...S1 S Sn× × ×2 ... R S1 S Sn⊆ × × ×2 ...

S S S = Sn× × ×...

Databases are relations and are important for storing informationin Computers. Relational databases are used to store and processhuge volumes of data efficiently.

Page 3: Presentation on Binary Relations.pdf

3

Databases

Course Num Section Num Instructor Course TitleCS 105 10 Levy Into. Comp. ScCS 105 20 Khalil Into. Comp. ScCS 105 30 Cassel Into. Comp. ScCS 170 10 Carberry Comp. Sc. 1CS 170 20 Leathrum Comp. Sc. 1CS 240 10 Levy Discrete Str.CS 240 20 Slutzki Discrete Str.

R1

Sets : Course Num, Section Num, Instructor, Course Title - attributesEach row is a member of the set R1The order of the rows is not important

Projection

Let Rn be a n-ary relation, . The projectionof Rn onto is a m-ary relation, obtained fromRn by choosing the i1th, i2th, …, imth components of each element of Rn and is denoted by πRnSi1…Sim

R S1 S Sn⊆ × × ×2 ...Si Si Si

1 m× × ×2

...

πR1course num, course title = R2 =

Course Num Course TitleCS105 Int. Comp. ScCS170 Comp. Sc. 1CS240 Discrete Str

Note: there must not be any repeated rows.

Page 4: Presentation on Binary Relations.pdf

4

Database projection onto the firstthree attributes to give R3

Course Num Section Num InstructorCS 105 10 LevyCS 105 20 KhalilCS 105 30 CasselCS 170 10 CarberryCS 170 20 LeathrumCS 240 10 LevyCS 240 20 Slutzki

R3

We can denote this relation asR(Course Num, Section Num, Instructor)

Composition and Join

Let and then the composition is defined as

R A B⊆ × S B C⊆ × S R•S R={(x,y)| z: xRz zSy}• ∃ ∧

Example:A = {a1, a2}, B = {b1, b2, b3}, C = {c1, c2}R = {(a1, b1), (a2, b3)}, S = { (b1, c2), (b3, c1), (b3, c2)} = {(a1, c2), (a2, c1), (a2, c2)}S R•

Join: If R(A, B, C) and S(C, D, E) then we can formthe join of R and S over C to give a relation T(A, B, C, D, E)in a similar way to composition but we keep all columns.

Example:Join R2 and R3 over Course Num gives R1

Page 5: Presentation on Binary Relations.pdf

5

Select and Relational Algebra

The select operation creates a new table with those rows ofthe original table satisfying a certain property

Example:Select R3 where Instructor = Levy to give R4

Course Num Section Num InstructorCS 105 10 LevyCS 240 10 Levy

A relational algebra is a theoretical database language in whichselect, project and join operations can be combined.

An example of relational algebraConsider we have databasesPerson(Name, Address, City, State)Pet(Pet-name, Pet-type, Breed)Owns(Name, Pet-name)

Join Pet and Owns over Pet-name = Pet-Owner(Name, Pet-name, Pet-type, Breed)

Query:Give the names of all cats whose owners live in Bristol

Solution = Project(Join(Select Pet-Owner where Pet-type = cat) and (select Person where City = Bristol) over Name) over Pet-name

Page 6: Presentation on Binary Relations.pdf

6

Properties of Binary Relations

Let ρ be a binary relation on set S.ρ is reflexive means ( x)(x S (x,x)∀ ∈ ⊃ ∈ ρ

ρ is symmetric means ( x)( y)(x S y S (x,y) (y,x)∀ ∀ ∈ ∧ ∈ ∧ ∈ ⊃ ∈ ρ ρ

ρ is transitive means ( x)( y)( z)(x S y S z S ((x,y) (y,z) (x,z)∀ ∀ ∀ ∈ ∧ ∈ ∧ ∈ ∧

∈ ∧ ∈ ⊃ ∈

) )ρ ρ ρ

ρ is antisymmetric means ( x)( y)(x S y S (x,y)(y,x) x=y

∀ ∀ ∈ ∧ ∈ ∧ ∈∧ ∈ ⊃

ρρ

ρ is asymmetric means ( x)( y)(x S y S (x,y) (y,x)∀ ∀ ∈ ∧ ∈ ∧ ∈ ⊃ ¬ ∈ ρ ρ

Relations as Predicates.Special Relations

Consider the predicate P, x < y , x, y ε N

Let R ={(x,y) | x < y x y }∧ ∈ ∧ ∈ N N

Predicate P defines relation R

___________ ρ-1 of ρ means{(y,x) | (x,y) ∈ρ }Inverse Relation

Indentity RelationThe identity relation on A is defined asI {(a,a) | a A}A

= ∈

The Universal RelationDefined on A asI {(a,b) | a A, b A}U

= ∈ ∈

Page 7: Presentation on Binary Relations.pdf

7

Domains and Ranges

The Domain and Range of a Binary relation are defied as:R A B⊆ ×

Dom(R)={x|(x,y) R}∈Ran(R)={y|(x,y) R}∈

It is easy to show thatDom(R-1) = Ran(R) Ran(R-1) = Dom(R)

Chess Board ExampleRows labelledR ={a, b, c, d, e, f, g, h}Columns labelledC = {1, 2, 3, 4, 5, 6, 7, 8}

Let S=R C×Rook moves relationdefined by

Rm S S⊆ ×

Rm={((r1,c1)(r2,c2)) | (r1,r2 R) (c1,c2) C ((r1=r2) (c1 c2)) ((r1 r2) (c1=c2))}

∈ ∧ ∈∧ ∧ ≠ ∨ ≠ ∧

Equivalence Relations

An Equivalence relation is one which is:reflexive, symmetric and transitive

Example: a b

d e f

c

A = {a, b, c, d, e, f}R = {(a,b), (b,a), (a,d), (d,a)(a,a) (b,b), (d,d), (b,d), (d,b)(c,c) (e,f), (f,e), (e,e), (f,f)}

reflexive, transitivesymmetric

R partitions A into {{a, b, c}, {c}, {e, f}}

Equivalence relationspartition the set on which it is defined.

Page 8: Presentation on Binary Relations.pdf

8

Equivalence ClassesA = {1, 2, 3, 4, 5, 6}, ρ A A⊆ ×ρ={(x,y)|x A, y A, (x-y) is divisible by 2}∈ ∈

Properties of ρreflexive: (x, x) ε ρsymmetric: (x-y) divisible by 2 ⊃ (y-x) is divisible by 2transitive: if (x-y) and (y-z) are divisible by 2 then there exists integers k and m such that (x-y) = 2k and (y-z) = 2m

But (x-z) = (x-y) + (y-z) = 2(k + m) so that (x-z) is divisible by 2.The Equivalence classes of ρ are:[1] = {x | xεA ∧ (x-1) is divisible by 2} = {1, 3, 5}[2] = {x | xεA ∧ (x-2) is divisible by 2} = {2, 4, 6}

FormsPartition

Equivalence Classes for the Setof all fractions

Let S = {a/b | a, b ε Z, b ≠0} i.e. the set of all fractionsa/b↔c/d iff ad = bc i.e. a/b equivalent to c/d, eg 1/2 ↔2/4

The binary relation ↔ on S isreflexive since ab = ba so that a/b ↔___symmetric since a/b ↔___ then ad= bc so that cb = da so that___ ↔_____________ since if a/b ↔ c/d and c/d ↔ e/f then ad=bc and cf=dso that adf=bcf and bcf=bde. Therefore adf=bde so that af=be.Thus a/b ↔ e/f12

{..., 36, 2

4, 1

2,12,24,36,...}

= −

−−−

−− is an equivalence class for

the set of fractions.

Page 9: Presentation on Binary Relations.pdf

9

Partial OrderingsA binary relation ρ on set S that is reflexive, antisymmetric and transitive is called a partial ordering. The pair (S, ρ) is called a partially ordered set or a posit.We will denote an arbitrary posit by (S, ≤)

Examples:On N, ≤ = {(x, y) | x ≤y}On P(N), ≤ = {(A, B) | }On N, ≤ = {(x, y) | x divides y}

A B⊆If (S, ≤) is a posit and , then (A, ≤) is a posit. A S⊆

{1, 2, 3, 6, 12, 18} , so that x divides y isa partial ordering on {1, 2, 3, 6, 12, 18} andOn {1, 2, 3, 6, 12, 18}, ≤ = {(x, y) | x divides y}

⊆ N

Least upper bound (lub) andGreatest lower bound (glb)Let (S, ≤) be a partially ordered set. If x ≤ y then x < y or x = y.If x < y then we say x is a predecessor of y or y is a successorof x. If x < y but there is no z with x < z< y then x is animmediate predecessor of y.u is an upper bound of x and y iff x ≤ u and y ≤ ul is a lower bound of x and y iff l ≤ x and l ≤ yy ε S is a greatest element of S if x ≤ y for all x ε Sy ε S is a maximal element of S if there is no x ε S with y < xy ε S is a least element of S if y ≤ x for all x ε Sy ε S is a minimal element of S if there is no x ε S with x < yA greatest element is a lub or supremumA least element is a glb or infimumA maximum element is not necessarily a greatest element, aminimum element is not always a least element.

Page 10: Presentation on Binary Relations.pdf

10

Hasse Diagrams

If S is finite and (S, ≤) is a poset we can depict ≤ by a graph called a Hasse diagram. Each element of S is depicted by a node of the graph. If x is an immediate predecessor of y, thennode y is placed above node x and the two nodes are connectedby a straight line.

Example:On P({1, 2}), ≤ = {(A, B) | } = {(Ø, Ø), ({1}, {1}), ({2}, {2}),({1, 2}, {1, 2}), (Ø, {1}), (Ø, {2}), (Ø, {1, 2}), ({1}, {1, 2}), ({2}, {1, 2})}

A B⊆

{1, 2}

{2}{1}

Ø

{1, 2) lubØ glb

Relation x divides yon {1, 2, 3, 6, 12, 18}

1

2 3

6

12 18

12 and 18 are both maximalbut there is no greatest

1 is both minimal and leastglb.

TOTAL ORDERINGA partial ordering in which every element is related to every other element is a total ordering or chain.

.

.

Page 11: Presentation on Binary Relations.pdf

11

Closure of RelationsIf a relation ρ on S fails to have a certain property, we may be able to extend ρ to ρ* on S that does have that property. Byextend we mean ρ* will contain all ordered pairs of ρ + extraordered pairs so that the property is satisfied.

Definition of closure of a relationA binary relation ρ* on a set S is the closure of a relation ρ on Swith respect to property P if∀ ρ * has property P(2)(3) ρ* is a subset of any other relation on S that includes ρ andhas property P

ρ ρ *⊆

Examples: reflexive closure, symmetric closure, transitive closure

An Example of closures

S = {1, 2, 3}, ρ = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3)}

Closure with respect to reflexivity :ρ∗ = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3), (2, 2), (3, 3)}

Closure with respect to symmetry:ρ∗ = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3), (2, 1), (3, 2)}

Closure with transivity:ρ = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3)}Add (3, 2) because of (3, 1) and (1, 2), Add (3, 3) from (3, 1) and (1, 3)Add (2, 1) from (2, 3) and (3, 1) to give{(1, 1), (1, 2), (1, 3), (3, 1), (2, 3), (3, 2), (3, 3), (2, 1)}Add (2, 2) because of (2, 3) and (3, 2)ρ∗ = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3), (3, 2), (3, 3), (2, 1), (2, 2)}

must be done iteratively

Page 12: Presentation on Binary Relations.pdf

12

Transitive Closure andComposition

The process of finding the transitive relation we used on previous slide is equivalent to:Let ρ* = ρ ∪ ρ(2) ∪ … ∪ ρ(k)

where k is smallest integer such that P is satisfied.

Example:S = {1, 2, 3}, ρ = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3)}ρ(2) = {(1, 1), (1, 2), (1, 3), (3, 1), (3, 2), (3, 3), (2, 1}ρ∪ ρ(2) = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3), (3, 2), (3, 3), (2, 1)}ρ∪ ρ(2) ∪ ρ(3) = {(1, 1), (1, 2), (1, 3), (3, 1), (2, 3), (3, 2), (3, 3), (2, 1), (2, 2)}

ρ ρ ρ ρ ρ ρ ρ .(2) (3)= = etc• • •,

Transivity property satisfied.

Task Scheduling using PartialOrdering and Hasse Diagrams.

Ernie and his brothers run a wood working shop and manufacture rocking chairs with padded seats. The manufacturing process can be broken down into a numberof tasks, some of which have other tasks as prerequisites.

Table of tasks with times to complete each task andprerequisites required are shown on next slide.

We want to calculate critical path for the manufacturingprocess and the total time required for making a rockingchair.

Page 13: Presentation on Binary Relations.pdf

13

Manufacturing Data

1. Selecting wood None 3.02. Carving rockers 1 4.03. Carving seat 1 6.04. Carving back 1 7.05. Carving arms 1 3.06. Selecting fabric None 1.07. Sewing cushion 6 2.08. Assembling back & seat 3, 4 2.09. Attaching arms 5, 8 2.010. Attaching rockers 2, 8 3.011. Varnishing 9, 10 5.012. Adding cushion 7, 11 0.5

TASK Prerequisite TasksHours to Perform

Pert Diagram - Equivalent toHasse Diagramx ≤ y ↔ task x = task y OR task x is prerequisite of task yx < y ↔ task x is prerequisite of task y≤ is reflexive, antisymmetric and transitiveTherefore partial ordering.Draw Hasse Diagram - from left to right rather than bottomto top.2(4.0) 10(3.0)

3(6.0)

4(7.0)

5(3.0)

8(2.0)

9(2.0)

11(5.0)

12(0.5)6(1.0)

7(2.0)

1(3.0)

Page 14: Presentation on Binary Relations.pdf

14

Critical Path Calculation

Task Time from beginning to complete each taskTask 1: 3.0Task 2: 3.0 + 4.0 = 7.0Task 3: 3.0 + 6.0 = 9.0Task 4: 3.0 + 7.0 = 10.0Task 5: 3.0 + 3.0 = 6.0Task 6: 1.0Task 7: 1.0 + 2.0 = 3.0Task 8: max(9.0, 10.0) + 2.0 = 12.0Task 9: max(6.0, 12.0) + 2.0 = 14.0Task 10: max(7.0, 12.0) + 3.0 = 15.0Task 11: max(14.0, 15.0) + 5.0 = 20.0Task 12: max(3.0, 20.0) + 0.5 = 20.5

We can markpath correspondingto max - see next slide

Total time= 20.5

3.0

Critical Path

2(4.0) 10(3.0)3(6.0)

4(7.0)

5(3.0)

8(2.0)

9(2.0)

11(5.0)

12(0.5)6(1.0)7(2.0)

1(3.0)

7.0

9.0

10.0

6.0

15.0

12.0

14.0

20.0

20.5

3.01.0

critical path : 1 -> 4 -> 8 -> 10 -> 11 -> 12

Work forwards for max costsBackwards for critical path