discrete mathematics transparency no. 6-1 chapter 6 relations

63
Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Post on 22-Dec-2015

230 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete Mathematics

Transparency No. 6-1

Chapter 6

Relations

Page 2: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-2

Contents

1. Relations and their properties

2. n-ary relations and their applications

3. Representing relations

4. Closure of relations

5. Equivalence relations

6. Partial orderings

Page 3: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-3

6.1 Relations and their properties

Def. 1: A, B: two sets.

A (binary) relation from A to B is a subset of AxB.

(i.e., any subset of {(x,y) | x A and y B} )

Notes: If R AxB, we usually use a R b (or not aRb) to denote th

at (a,b) R (or (a,b) R). Binary relations can be generalized to n-ary ( n > 0) relatio

ns

Ex1: A = the set of all students; B = the set of all courses

let R = {(a,b) | student a is enrolled in course b} AxB

is a binary relation from A to B.

Ex2: A = the set of all cities; B = the set of all nations.

Let R = {(x,y) | city x is located in nation y}.

==> (New York, USA) R and Tokyo R Japan, ...

Page 4: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-4

Relations on a setEx3: A = {1,2,3,4}; B={a,b} ==> {(0,a),(0,b),(1,a),(2,b)} is a relation from A to B. ==> Graphical representation = ? ==> table (or matrix) representation = ?Def. 2: A relation R on (or over) a set A is a subset of AxA (= A2). Ex4: A={1,2,3,4}; Let R = {(a,b) A2 | a divides b} ==> R= ? ; graphical and table representation = ?Ex 5: Let R1,R2,...,R6 be relations on integers Z defined asR1= {(a,b) | a b); R2 = {(a,b) | a > b }; R3 = {(a,b) | a = b or a = -b}; R4={(a,b) | a = b};R5={(a,b) | a = b+1}; R6={(A,B) | A + B < 4} ==> Which relations contain the pairs: (1,1), (1,2),(2,1),(1,-1),(2,2)?

Page 5: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-5

Examples of relations

Ex 6: |A| = n; |B| = m

==> What is the number of relations from A to B ?(i.e., let Rel(A,B)= {R | R is a relation from A to B},

==> |rel(A,B)| = ? )

Sol: 1. |AxB| = ____.

2. Since Rel(A,B) = 2AxB. Hence |rel(A,B)| = ___

Ex6': |Rel(A,A)| = #relations on A = ____

Page 6: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-6

Properties of (binary) relations on a set

Def 3,4,5: R: a binary relation on a set A; R is reflexive if aRa for every a A. R is irrelexive if (a,a) R for each a A. R is symmetric if for every a,b A, (a,b) R => (b,a) R. R is asymmetric if for every a,b A, (a,b) R => (b,a) R. R is antisymmetric if for every a,b A, if (a,b) R and (b,a)

R, then a = b. R is transitive if for every a,b,c A, if aRb and bRc then aRc.

Def: R is a partial ordering(p.o.) iff it is ref. sym. and transitive. R is a strict partial ordering(s.p.o) if it is irref. and trans. R is a preordering iff it is ref. and transitive. R is an equivalence relation iff it is ref. sym. and transitive.

Page 7: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-7

Example:Let B = {1,2,3,4};

R1= {(1,1),(1,2),(2,1),(2,2),(3,4),(4,1),(4,4)} R2={(1,1),(1,2),(2,1)} R3={(1,1),(1,2),(1,4),(2,1),(2,2),(3,3),(4,1),(4,4)} R4={(2,1),(3,1),(3,2),(4,1),(4,2),(4,3)} R5={((1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} R6={(3,4)}

Ex 7: Which of these relations are ref. ?

Ex 7': Which of these relations are irref. ?

Note: 1. using graphical representations may help determining properties of relations.

2. There are relations which is neither ref. nor irref.

Ex 8: Is the "divides" relation on integers reflexive ?

Ex 9: which of the relations on Ex5 are ref. ?

Page 8: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-8

Examples

Ex10. Which of these relations are symmetric, antisymmetric ?

Ex10': Which are asymmetric ? What is the graphical characteristic of sym., asym. and antis

ym. relations ? What is the relation among symmetric, antisymmetric and a

symmetric properties ?

Ex 12: Is the "divides" relation on integers sym. ? Is it antisym. or asym. ?

Ex13: Which of these relations in Ex 7 are transitive. ?

Ex13': Which of the relations inEx 7 are preordering, p.o., s.p.o.

or equivalence?

Ex15: is the "divides" relation transitive ?

Page 9: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-9

Counting the number of relations

|A| = n.

1. # relations on A = ? (2^(n^2))

2. # reflexive relations on A = ? (2 ^ (n^2 - n))

3. # irreflexive relation on A = ? (= sol of 2, why?)

4. #irref and symmetric relation on A = ? (2^(n(n-1)/2) )

5. #symmetric relation on A = ? (2^(n(n+1)/2))

6. #asymmetric relations on A = ? (3^(n(n-1)/2))

7. #antisymmetric relations on A = ? (3^(n(n-1)/2) x 2^n)

8. #transitive relations on A = ? (hard!)

9. #equivalence relations on A = ? (hard!)

10. #strict partial ordering on A = ? (hard!)

11. #preordering on A = ? (hard!)

12. #partial ordering on A = ? (hard!)

Page 10: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-10

Combining relations

Relations are sets:

==> All set operations can be applied to relations

Ex: R1; R2: relations on A;

==> R1 U R2; R1 ⋂ R2; R1 \ R2 and ~R are defined as usual.

[Binary ] relation compositions:

R AxB ; S BxC;

==> R·S (the composition of R and S) AXC is the set:

{(x,z) | y B s.t. xRy /\ ySz}

Note: The textbook use S·R (less popular) instead of R·S to denote the composition.

Page 11: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-11

Examples of relation compositions

Ex19: A={1,2,3}; B={1,2,3,4}; C={0,1,2}

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

S BXC = {(1,0),(2,0),(3,1),(3,2),(4,1)} => R·S= ?

Fact: Relation composition is associative (i.e., R·(S·T) = (R·S)·T )

Hence we can write RST w/t parentheses.

A B CR S

1

2

3

1

2

3

4

0

1

2

Page 12: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-12

The power of relations

Def.7 : R: a relation on A (i.e., a subset of AxA); n : nonnegative integers. The relation Rn is defined inductively as follows: 1. R0 = IA =def {(x,x) | x A}.

2. Rk+1 = RRk = {(x,z) | y R s.t. (x,y) R /\ (y,z) Rk }.Hence R2 = RR; R3=RR2 = R(RR) = (RR)R = R2 R = RRR . in general we have Rn = RRRR...R. (n R’s)

Ex: show that If a, b 0 then RaRb = Ra+b.

Pf : by induction on a. basis: a = 0: => RaRb = IARb =

{(x,z) | y (x,y) IA /\ (y,z) Rb } =

{(x,x) | (x,x) IA /\ (x,z) Rb} = {(x,z) | (x,z) Rb } = Rb.

Ind. step : assume RaRb= Ra+b => Ra+1Rb = (RRa)Rb = R(RaRb) = RRa+b = Ra+1+b.

Corollary: RRk = Rk R.

Page 13: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-13

Example

Ex20: A= {1,2,3,4}; R={(1,1),(2,1),(3,2),(4,3)} is relation on A.=> R0, R1, R2, R3, R4,R5, ...= ____? (use graphical representation)Lemma: If Rn = Rn+1 then Rk = Rk-1 for all k > n.Ex: If R5 = R6 => R10 = R6R4 = R5R4 = R9

Pf: left as an exercise.Corollary: If Rn = Rn+1 ==> Rk = Rn for all k > n. Pf: Rk = Rk-1 = R(k-1)-1 = Rk-2 = ...Rn+1 = Rn.Theorem 1: Relation R on a set A is transitive iff Rn R for all n > 0.Pf: (=>) : trivial (by induction on n). Basis: n = 1 (ok). Ind. step: for any (x,z) Rn+1 => z s.t. (x,y)

Rn /\ (y,z) R. By ind. hyp. both (x,y) and (y,z) R. By tran. of R, (x,z) R.

(<=) : for any x,y,z, (x,y) R /\ (y,z) R => (x,z) R2 => (x,y) R. QED

Corollary: R is transitive iff R2 R. (why ?)

Page 14: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-14

6.2 n-ary relations

Def. 1: A1,A2,...,An : n sets.

1. An n-ary relation R on A1,A2,...,An is any subset of A1xA2x...xAn = {(x1,...,xn) | x1 A1,...,xn An }.

2. A1,..., An are the domains of R

3. n: the degree (or arity) of R.

4. 1-ary (0-ary, 2-ary, 3-ary) relations are called unary (nullary, binary, ternary) relations.

Ex: If R Z3 (= ZxZxZ) =def {(x,y,z) | x < y < z, x,y,z Z}.

Then (1,2,3) R but (2,4,3) R.

Page 15: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-15

Relations and databases

Database: In a database, lots of information about the real world are

extracted and stored. Since the database is a "representation" of the world, if

the real world changes, the database should change over time accordingly

Issues in database theory (data model): How to represent various information (or data) in a

database? (i.e., can we have a unifying method by which we can

always (or in most cases) easily organize or arrange all data to be stored in the database ).

Any such method is called a data model.

Page 16: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-16

The relational data model

A database DB (at a time instant, say, time t) consists of a pair <Dom,Rel> where Dom = {A1,...,An} is a set of sets, each Ai is called a domai

n of the database. Rel = {R1,...,Rm} where each Ri Aj1xAj2x...xAjki is a ki-ary r

elations on domain Aj1,Aj2,...,Ajki.

Each Ki-tuple (a1,a2,...,aki) Ri is called a record (or row) of Ri.

Each Ajs ( 1 <= s < = ki) is called a field (or a column) of the relation Ri (and the record).

Each relation Ri can be represented by a table (w/t duplicate rows) with |Ri| rows and Ki columns.

Page 17: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-17

Example relations

Ex: Student records S in a school may be represented by 4-tuples of the form: (student-name, register-id, major, GPA )

Let A = the set of all student [names]

B = the set of all student identifier numbers.

C = the set of all departments [names]

D = the set of all possible GPA numbers ([0,5]).

=> DB = <{A,B,C,D}, {S}> where S must be a subset of AxBxCxD.

A possible value of S may be represented by the table: NAME ID MAJOR GPA------------------------------------------------------- Allen 23 CS 3 Bob 15 math 4.1 Chen 34 CS 4.0 ...

Page 18: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-18

Operations on n-ary relationsA domain Bj of an n-ary relation R (in database) is called a prim

ary key iff it can be used to uniquely identify records in R at all time. (in other words, If R is an n-ary relation on domain B1,B2,...,

Bn, then for any time t, R(t) must be a subset of B1xB2...xBn. Bj is a primary key iff for any time t and for any (a1,a2,...,an)

and (b1,..,bn) R(t), if aj = bj then (a1,...an) = (b1,...,bn). Note: R(t) changes over time.

Operations on n-ary relations Selection (or restriction) --- find subset of R with a certain property. Projections. Joins --- generalization of binary composition and other usual set operations (U, /, intersection,...)

Page 19: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-19

relation operations

Restriction (selection):

P(x1,...,xn): a statement (or property) on n-tuples

(x1,...,xn).

R: a relation on A1xA2...,xAn.

==> R|P ( find tuples of R with property P) is the set

{(a1,...,an) | (a1,...,an) R and P(a1,...,an) is true }.

Ex: Let P(x1,x2,x3) = " x1 < x2 < x3 or x3 = 2 " and R = { (1,2,3), (1,3,2),

(2,1,3), ==> R|p = {(1,2,3), (1,3,2), (3,1,2) }. (2,3,1), (3,1,2), (3,2,1) }

Page 20: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-20

Projections

R : a relation on A1,A2,...,An

= j1j2...jm is a sequence with 0< js< n+1 for all s = 1,..,m.

==> P(R) : the projection of R on Aj1Aj2...Ajm is a m-ary relation on Aj1Aj2...Ajm with value:

{(xj1,...,xjm) | (x1,...,xn) R }.

Ex: R= {(1,2,3), (1,3,3), (2,3,1), (2,2,2)}

=> P1(R) = {1,1,2,2} = {1,2}

P2(R) = {2,3}

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

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

Page 21: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-21

Joins (combining two relations into one)

R : A1xA2x...xAm-pxAm-p+1x...xAm;

S : B1 xB2x..Bpx Bp+1x ..xBm;

p ≤ min(m,n).

==> Jp(R,S) = {(a1,...,am-p, c1,c2,...,cp, bp+1,..., bn) |

(a1,...,am-p, c1,c2,...,cp ) R /\

(c1,c2,...,cp, bp+1,..., bn) S }

Ex: R={(1,2,3), (2,2,3), (3,3,3) (6,1,2)}; S={(2,3,4), (3,3,3), (2,2,2)}

==> J2(R,S) = ?

J1(R,S) = ?

J3(S,R) = ?

Page 22: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-22

6.3 Relation representation

Three possible ways to represent a finite relation a list (or array) of ordered pairs. (0-1) matrix digraph (directed graph)

Ex: A={1,2,3}, B={a,b},

R = {(2,a),(3,a),(3,b)}.

1. list representation:

((2,1),(3,1),(3,2)) possibly ordered by fields.

2. Matrix (table): 3. Digraph:

A\B a b

1 0 0 or

2 1 0

3 1 1

A B

a

b

A->B1

2

3

a

b

Page 23: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-23

Formalization of relation representationA={a1,a2,..,am}; B = {b1,...,bn}; R: a binary relation from A to B.

MR (the matrix representation of R) = (mij) mxn where

mij = 1 if (ai,bj) R and = 0 if (ai,bj) ∉ R.Ex: A={a1,a2,a3}; B = {b1,b2,...,b5} If R1={(a1,b1),(a1,b2),(a3,b2),(a3,b5)}

==> MR1 = ? 01000

If MR2= 10110 ==> R2 = ? 10101

Note: 1. If R AxA with |A| = n, ==> MR is a nxn 0-1 matrix.

2. R is ref. (resp. irref. ) iff mii = 1 (0) for every 0<i < n+1.

3. R is symmetric (asym) iff for all i, j mij = mji (mij ≠ mji)

4. R is tansitive iff for all i,j,k if mij=mjk=1 => mik = 1.

Page 24: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-24

0-1 matrix operation

Boolean operation on {0,1} x \/ y = max(x,y) x /\ y = min(x,y) ~x = 1-x

Boolean operation on 0-1 matrices: (M1 \/ M2) ij = M1ij \/ M2ij for all i,j. --- pairwise or

(M1 /\ M2) ij = M1ij /\ M2ij for all i,j. --- pairwise and

(~M1) ij = 1- M1ij for all i,j. -- complement.

(M1x M2)ij = \/k=1,n M1ik /\ M2kj. --- product

M0 = I; Mn+1 = Mn x M. --- power of 0-1 matrix.

Page 25: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-25

Matrix representation for relation operations

R1, R2: two relations from A to B.

1. MR1 UR2 = MR1 \/ MR2.

2. MR1R2 = MR1 /\ MR2

3. M~R1 = ~MR1.

R: AXB; S: BxC with

A = {a1,...,am}, B = {b1,...,bn} and C= {c1,..,cp}.

==> RS = {(ai,ck) | bj B s.t. (ai,bj) R and (bj,ck) S }

Hence (MRS)ik = 1 iff

there is 1 j n s.t. (aj,bj) R and (bj,ck) S iff

there is 1 j n s.t. (MR)ij = 1 /\ (MS)jk = 1 iff

\/j=1,n (MR)ij /\ (MS)jk = 1

Hence MRS = MR x MS. ==> MRk = (MR)k for any k 0.

Page 26: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-26

Examples:

Ex3: MR = [110; 111; 011]

==> Is R ref, symmetric or antisymmetric ?

Ex4: R1,R2: two relation on A.

MR1= [101;100;010]; MR2 = [101;011;100].

==> MR1UR2 = ? MR1 R2 = ? M~R1 = ?

Ex5: MR = [101;110;000]; MS = [010; 001;101]

=> MRS = ?

Ex6: MR = [010;011;100]

==> MR2 = (MR)2 = ?

Page 27: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-27

Representing relations using digraphs

Def 1. A diagraph (or directed graph) is a pair (V,E) where V is a set, each member is called a node or a vertex. E is a set of ordered pairs of nodes. (i.e. E V2), each

member of which is called an edge. If (a,b) E is an edge, we say a is the initial (or starting)

vertex and b the terminal (or ending) vertex of the edge. If (a,a) is an edge, we say it is a loop.

Ex7: In Fig 3, we have G=(V,E) where

V= {a,b,c,d} and

E={ (a,b),(a,d),(b,b)(b,d),

(c,a),(c,b),(d,b)}.

Note: E in fact is a relation on V.

a b

cd

Fig 3: (p 377)

Page 28: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-28

Representing relations by digraphs (cont'd)

A = {a1,...,am}, B = {b1,...,bn}

R: a binary relation from A to B

==> we can use the digraph G=(V,E) to represent R, where V= A U B. E = R.

Ex: A = {1,2,3} ; B = {2, 3,4}

R = {(x,y) | x > y} AXB.

==> R = ?

The digraph GR for R = ({1,2,3,4}, R).

==> What is its graphical representation ?

Page 29: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-29

6.4 closure of relationsR: a relation on AP(-): a property (or statement or predicate) about relations. eg: 1. P(R) = " R is reflexive" or 2. P(R) = " R is symmetric and transitive" or 3. P(R) = " |R| is not finite" etc.Def: P: a property about relations on A;

The operation CLp: 2AxA -> 2AxA is defined to be the function s.t. for each each relation R on A, CLP(R) is the smallest of all relations on A which includes R and satisfies the property P. (i.e., CL

p(R) is the relation on A s.t. 1. R CLP(R) --- including R 2. P(CLP(R)) is true --- satisfying P 3. For any relation S on A, if it satisfies (1) and (2), then CLP(R) S. --- smallest

CLp(R) is called the P closure of R.

Page 30: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-30

Properties about closureEx: A = {1,2,3}; R={(1,1),(1,2),(2,1),(3,2)} Let P(S) means " S is reflexive"

==> CLp(R) (reflexive closure of R) = ? (exist ? unique ?)

1. Let TT = { T | T A2 /\ T is ref. and R T}. Note: by def. every T TT satisfies item (1) and(2) of the def.

of P-closure. ==> TT = ?

2. Which is the smallest in TT ? (= R U IA !)Theorem: CLP(R), if existing, is unique.pf: Let S and T be any two P-closures of R. ==> By (3) S T and T S, hence S = T.

3. Problem: Does CLP(R) always exist ? (no!) Does the irreflexive closure of R exist in the example ?

Page 31: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-31

closure properties

Def: P: a property about relations

P is said to be increasing if for each relation R, there exists a relation S satisfying P and including R.

P is said to be closed under intersection(or conjunctive) if for any set TT of relations, if all R TT satisfies P, then so is their intersection TT.

Ex: The following properties are increasing and closed under intersection: 1. reflexivity; 2. symmetry; 3. transitivity. Since A2 (the largest relation on A) includes R and satisfies 1,2,3.

Theorem: If P is increasing and closed under intersection, then CLp(R) always exist for all relations R (on a universe set A).

Page 32: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-32

Example:

Ex: property increasing closed under intersection ref. yes yes symmetric yes yes transitivity yes yes irref. no(why?) yes(why?) asymmetric ? ? antisymmetric ? ? equivalence ? ? partial order ? ? total ordering ? ? ref or symmetric yes no (why?)

Fact: If P is not increasing, then CLp may not exist.

If P is not conjunctive,then CLp may not exist.

Page 33: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-33

reflexive and symmetric closures of relations

Theorem 1': R: a binary relation on A, then

1. reflexive closure of R (Rref) = R U IA.

2. symmetric closure of R (Rsym) = R U R-1.

Ex: if MR = [100,101,000], then

1. IA = ?

2. MRref = ?

3. MR-1 = ?

4. MRsym = ?.

pf: Let Tref = {SR | S is a relation on A and is ref.}

==> 1. (1) RUIA Tref (2) S Tref ==> S R U IA.

Hence R U IA = CLref(R).

2. Similar to 1.

Page 34: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-34

Transitive closure of relationsR: a binary relation on A

==> What is the transitive closure of R (i.e., the smallest transitive relation S on A including R (i.e., if (a,b) and (b,c) S, then (a,c) is also S)).

Ex: If R = {(1,2)(2,6)(6,1)(1,3)(3,4)(4,5)}

==> GR = Fig 1.

==> MR = ?

==> GS = ?

==> MS = ?

==> S = ?The reflexive and transitive closure

of R is the smallest reflexive and transitive relation on A including R.

1 2

6

3

4

5

Page 35: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-35

Path

Def. 1: G = (A,R): a digraph; a, b : two vertices in A.

1. A path of length n (n 0) from a to b is a sequence

x0,x1,...,xn of vertices s.t.

x0 = a (starting point) and xn = b (ending point) and

(xi, xi+1) R for all i = 0,..,n-1.

2. If x0 = xn and n > 0 ==> the path is called a cycle ( or circuit).

Ex: If R = {(1,2),(2,1),(2,3)(3,4)(4,2)}

==> "1,2,3,4,5" is a path of length ? from ? to ?.

Page 36: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-36

Correspondence b/t relation and digraph

Theorem 1: |A|= m; R is binary relation on A;

(Hence G=(A,R) is a digraph)

==> for all n (x,y) Rn iff a path of length n from x to y.

pf: by induction on n.

Basis: n = 0 (and R0 = IA = {(x,x) | x A})

path of length 0 from x to y iff

x=y iff (x,y) IA.

Ind. case: n = k+1.

a path of length n from x to y <=> (by def)

a path of length k from x to z and

a path of length 1 from z to y for some z A <=>

(by ind. hyp.) z A s.t. (x,z) Rk /\ (z,y) R <=> (by def)

(x,y) Rn. QED

Page 37: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-37

correspondence b/t relation and digrqph

Def. 2: R: a binary relation on A (hence (A,R) is a digraph).

R+ =def {(x,y) a path of length > 0 from x to y in (A,R)}

(i.e., R+ = Uk=1, Rk)

R* =def {(x,y) | there is a path of length 0 from x to y}

=Uk=0, Rk = R+ U {(x,x) | x in A} = R+ U IA.Theorem 2: 1. R+ is the transitive closure of R. 2. R* is the reflexive and transitive closure of R.

Note: If R encodes the property that " (a,b) R iff b can be reached from a by 1 step" then

1. (a,b) Rk means "b can be reached from a by n steps." 2. (a,b) R* means " b is reachable from a" or means " b is connected to a".

Page 38: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-38

Proof of Theorem 2:

pf: (1) left to the students.(2). 1. R R* ; 2. R* is ref. and transitive. 3. If T is another relation with property 1 & 2, then R* T.

1. R R* and R* is ref.: trivial, since R* = IA U R U R2 U ... 2. R* is transitive: (x,y) R* and (y,z) R* => m and n s.t. (x,y) Rm and

(y,z) Rn => (x,z) Rm+n => (x,z) R*. 3. Let T be any ref. and tran. relation including R. we show by induction on n that RnT for all n 0. Hence R* = R0 U R UR2U... T.

case 1: n = 0 : R0 = IA T (since T is reflexive). case 2 : n = 1 : R T (since T includes R) case 3: n = k+1 > 1: by ind.hyp., RJ T for all J < n. ==> if (x,y) Rn => z s.t. (x,z) Rk and (z,y) R => (by ind. hyp.) (x,z)T and (z,y)T => (by tran. of T) (x,y)T.

Page 39: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-39

Some lemmas

Lem 1: |A|= n > 0, R: a relation on A. 1. If there is a path of length m > n from a to b, then there is a pat

h of length 0 < p < m from a to b. 2. If there is a path of length > 0 from a to b then there is a path

of length 0 < p n from a to b. pf: 1. Let a=x0, x1,x2,..., xm-1,xm=b be the path of length m from a t

o b. Since m > n, by pigeonhole principle, there is 1 i<j m s.t. xi = xj. ==> The path x0,x1,..,xi, xj+1,...,xm is a path from a to b with length

m + (j-i) < m. 2. Let 0 be any path from a to b. if | 0 | ≤ n, we are done. O/w, by 1. we can construct a path 1 with length | 1 | <| 0 |. if | 1| ≤ n, then we are done. O/w, repeat the same process, we can obtain a sequence of pat

h 0, 1, 2,... from a to b with | 0 | > | 1 | > ... But since | 0 | is finite, we will eventually find a path k with leng

th n . QED

Page 40: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-40

Corollaries

lemma: If a b and there is a path of length m n, then there is a path of length 0 < p < n from a to b.

pf: similar to the previous one.Corollary: |A| = n.

1. R+ = Uk= 1, n Rk. 2. R* = Uk=0,n Rk.Pf: (1.) Since m > n, Rm RUR2U...URn. (x,y) Rm <=> a path from x to y of length m > n => a path from x to y of length 0 < p n <=> (x,y) Rp <=> (x,y) RUR2U...URn. (2.) Similar to 1.

Corollary: R* = Uk=0,n-1 Rk.

Pf: Left as an exercise. Hint: Rn IA U Uk=1,n-1 Rk.

(x,y) Rn ==> (x=y /\ (x,y) IA) or (xy /\ (x,y) Uk=1,n-1 Rk).

Theorem: 1. MR+ = MR \/ MR2 \/...\/MRn.

2. MR* = MR0 \/ MR \/ MR2 \/...\/MRn-1.

Page 41: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-41

Algorithm for transitive closure

TR(MR: a 0-1 nxn matrix)

1. A := MR;

2. B := A 3. for i = 2 to n do 3.1 A := A x MR // A = MRi.

3.2 B := B \/ A // B = Uk=1,i MRk.

4. return(B) // B = MR+.

Exercise: Give an alg. for finding MR*.

Complexity: each execution of step 3.1 takes time O(n3) Total execution time = O(n4). ==> more efficient algorithm ( O(n3) ) is possible!!

Page 42: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-42

Warshall's algorithm

Applying dynamic programming technique running time O(n3).R: a relation on A = {v1,v2,...,vn}.

note: (MR)ij = 1 iff (vi,vj) R.

W0,W1,...,Wn: a sequence of nxn 0-1 matrices, where

(WK)ij = 1 ( 0 k n ) iff there is a path of length >0 from vi to vj s.t. all interior vertices of this path are in the set {v1,...,vk}.

(i.e., a path vi,u1,u2,...,us,vj (s 0) s.t.{u1,...,us} {v1,...,vk}.

Facts:

1. W0 = MR. [ since (vi,vj) R <=> a path of length 1 from vi to vj

(w/o interior vertex) <=> (i,j) W0. ]

2. Wn = MR+. [ Since (vi,vj) R+ <=> a path of length > 0 from vi

to vj <=> a path of length > 0 from vi to vj with interior vertices among the set {v1,v2,...,vn} <=> (i,j) Wn. ]

Page 43: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-43

Warshall's algorithm (cont'd)

Fafct 3: Wk+1 can be defined in terms of Wk.

Lem 2: (Wk+1)ij = (Wk)ij \/ ((Wk)i(k+1) /\ (Wk)(k+1)j )

pf: (Wk+1)ij = 1 <=> (by def.)

a path =vi,u1,...,us, vj from vi to vj

with {u1,...,us} {v1,...,vk+1}.

<=> two possible cases:

case 1: no ui (i= 1,..,s) is vk+1 (i.e., vk+1 {u1,...,us}).

==> is also a path from vi to vj with interior vertices from {v1, ...,vk} ==> (Wk)ij = 1.

Page 44: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-44

Warshall's algorithm (cont'd)

case 2: a path = vi,u1,...,us, vj from vi to vj

with some ui = vk+1. (i.e., vk+1 {u1,...,us}).

Now let IDX = {i | ui = vk+1} and let

p = min(IDX); q = max(IDX).

Note that p will equal to q iff |IDX| = 1. Now the path

= v1,u1,...,up-1,up,uq+1,...,us,vj

is a path from vi to vj containing only one vk+1 = up.

==> v1,u1,..,up ia a path from v1 to vk+1 and

up,u q+1,..,vj is a path from vk+1 to vj

==> (Wk)i(k+1) = (Wk)(k+1)j = 1.

<=> (Wk)ij \/ ((Wk)i(k+1) /\ (Wk)(k+1)j = 1. QED

Page 45: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-45

Warshall's algorithm (cont'd)

EX: Let MR = [0001,1010,1001,0010]. find W0,W1,W2,W3,W4.

The Warshall's algorithm:

Procedure WS1(MR: nxn 0-1 matrix)

1. W0 := MR;

2. for k := 1 to n do // compute Wk

3. for i := 1 to n do

4. for j = 1 to n do // compute (Wk)ij

5. Wk[i,j] := Wk-1[i,j] \/ (Wk-1[i,k]/\Wk-1[k,j] );

6. Return(Wn) // Wn = MR+.

analysis: 1. The algorithm takes time O(n3).

2. The algorithm require memory space O(n3).

==> can be improved to O(n2) by collapsing all Wk into one W. (and become the final Warshall's algorithm shown in the book).

(why? since Wk[i,k]=Wk-1[i,k] /\ Wk[k,j]=Wk-1[k,j] )

Page 46: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-46

6.5 Equivalence relations

Def. 1: R: a relation on a set A. R is an equivalence relation on A iff it is ref. symmetric an

d transitive. x and y in A are said to be equivalent (or R-equivalent) if

(x,y) R.

Ex1: R: a relation on the set of all bit strings {0,1}* defined by

xRy iff |x| = |y|.

==> 1. R is an equivalence relation on {0,1}* ?.

2. 00110 and 11100 are R-equivalent since both have the

same length.

Ex 2: R: a relation on integers s.t. xRy iff x=y or x = -y.

==> R is an equivalence relation ?

Ex3: R: a relation on real numbers s.t. xRy iff x-y is an integer.

==> R is an equivalence relation ?

Page 47: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-47

More equivalence relations

Ex5: [congruence modulo m](共餘 )

m: a positive integer > 1.

m: a binary relation on Z s.t. x m y iff m divides (x-y).

==> m is an equivalence relation on Z.

pf:

Equivalence classes:

Def 2: R: an equivalence relation on A;

a : any element of A.

==> the equivalence class of a w.r.t. R, denoted

[a]R, is the set of all elements of A equivalent to a, i.e.,

[a]R = { b | aRb /\ b A}.

If b [a]R, then say b is a representative of the class [a]R.

Page 48: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-48

Equivalence classesEx 5: R: a binary relation on Z s.t. xRy iff x = y or x = -y. => 1. R is an equivalence relation.

2. For each x in Z, [x]R = {x, -x}.

3. e.g., [3]R = { y Z | 3 = y or 3 = -y} = {3, -3}.Ex6: R Z2 s.t. xRy iff x y (mod 4).

=> [0]R = {y Z: 4 | (0-y) } = {..., -8, -4, 0, 4, 8 ,...}

[1]R = {y Z: 4 | (1-y) } = {..., -7, -3, 1, 5, 9 ,...},

[2]R = {y Z: 4 | (2-y) } = {..., -6, -2, 2, 6, 10 ,...},

[3]R ={y Z: 4 | (3-y) } = {..., -5, -1, 3, 7,11,...}

[4]R = {y Z: 4 | (0-4) } = {..., -8, -4, 0, 4, 8 ,...}= [0]R.

[5]R = [1]R, [6]R = [2]R,...

=> 1. [i]R = [i+4k]R, where i and k are any integers. 2. There are only 4 equivalence classes w.r.t. R. i.e.,

{[a]R | a Z} = {[0]R, [1]R, [2]R, [3]R}= { {...,-4,0,4,..}, {...,-3,1,5,..}, {...,-2,2,6,...}, {...,-1,3,7,...}}.

Page 49: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-49

Congruence relation

3. the class [a]R is called a congruence class (modulo m).

4. For any integer x, x[y]R iff xRy.

Quotient set:

A: a set; R: an equivalence relation on A.

The quotient of A w.r.t R, denoted A/R, is the set of all R-equivalence classes of A. (i.e., A/R = {[x]R | x A} ).

Ex: The set Z/4 = {[0]4,[1]4,[2]4,[3]4}.

in general we have Z/n = {[0]n,[1]n,...,[n-1]n}.

Ex: |A| = n; R: an equivalence relation on A s.t. |[a]R| = k for all

a A. ==> | A/R | = ___

Page 50: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-50

Lemma 1: R: an equivalence relation on A. Then for any x,y A,

1. x R y iff [x]R = [y]R iff [x]R [y]R .

2. not x R y iff [x]R [y]R iff [x]R [y]R = . 3. Every class [x] is not empty and every x belongs to exactly

one class.pf: 1. (=>:) x R y => [x] = {b | xRb} = {b | yRb} = [y]=> since [x]=[y] and x [x],

[x]R [y]R .

1. (<=:) let z in [x]R [y]R . => [x] = {b | xRb} = {b | zRb} = {b |yRb} = [z]. => y [x] => xRy. 2,3: direct from 1.

Equivalence classes and partitions

x

y

x1

y1

A

xRy not xRy

Page 51: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-51

Partitions

A: a set. P 2A : a set of subsets of A.

P is said to be a partition of A iff

1. Every Ai in P is not empty.

2. For all Ai, Aj P, if Ai Aj then Ai Aj = {}.

3. U{Ai | Ai P} (i.e., the union of all members of P) = A.

Note: Every member of P is called a block.

Ex: Let A = N be the set of all nonnegative integers.

P={ODD, EVEN}, where ODD = {1,3,5,7,9,..}

EVEN = {0,2,4,6,...}

==> P is a partition of A.

Note: Every element of A

belongs to exactly one member

Aj in P.

A1 A2

A3

A4

A5

A6

Page 52: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-52

Equivalence of partition and quotient set

A: a set.

For each partition P of A, define a relation P as follows:

for all x, y A, x P y iff x and y belong to the same

block of P (i.e., Aj P s.t. {x,y} Aj).

Lem 1: p is an equivalence relation. P is called the equivalence relation induced by P.

pf: left to you.

Theorem: R: an equivalence relation on A; P: a partition on A. Then

1. A/R is a partition of A Ex: P = {ODD,EVEN}

2. A/R = R. ==> P = {(x,y) | x y mod 2}

3. A/ p = P. ==> N /p = { {1,3,5,...}, {0,2,4,...}} = P

Page 53: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-53

Proof

1. A/R is a partition: Note: A/R = {[x] | x A}.

1. A/R contains no empty set since every [x] is not empty.

2. for any Ai=[x], Aj=[y] A/R, if Ai Aj => [x] [y]

=> [x][y] = {}.

3. U{ B | B in A/R} = U {[x] | x A} = A.

2. xRy <=> [x] = [y]

<=> x and y are in the same block [class] of A/R

<=> x A/R y.

3. For any B, B P => B=[x]p for any x B=> B A/P.

For any C, C A/P => C=[x]p for some x => C P.

Page 54: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-54

6.6 partial orderings (偏序 )

Def 1: R: a binary relation on a set S.

1. R is a partial ordering (or called partial order, (po)) iff it is reflexive, antisymmetric and transitive.

2. If R is a po on S ==> (S,R) is called a partial ordered set (poset).

Ex1: (Z, ) is a poset.

Ex2: (Z+, |) is a poset.

pf: ref: x | x; trans: x | y /\ y | z => x | z;

antisym: x | y /\ y | x ==> x = y.

Ex3: (2S, ) is a poset.

pf: ref: A A ; trans: A B and BC ==> A C;

antisym: A B and B A => A = B. QED

Page 55: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-55

Strict partial ordering

Def: R: a binary relation on A.

If R is irreflexive and transitive, then we say R is a strict partial ordering (spo) on A.

EX: The less than relation < on Z is a spo.

pf: irref: for all x, not x < x.

trans: x < y and y < z ==> x < z.

Lemma: Every strict partial ordering is asymmetric.

pf: Proof by contradiction. Assume there are x, y s.t.

xRy and yRx. Then by transitivity of R, we must have xRx, a

contradiction!. QED

Page 56: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-56

Relationship between po and spo:S: a set; R: a relation on S

1. Define a new relation <·R as follows:

x, y S, x <·R y iff xRy /\ x y.

2. Define a new relation ·R as follows: x,y S, x ·R y iff xRy \/ x = y. Theorem:

1. If R is a po => <· R is a spo.

2. If R is a spo => ·R is a po.

3. If R is a po => ·(<·R) = R.

4. If R is a spo ==> <·(·R) = R.

pf: 1. irref: x<·R x => xRx and x x => contrdiction!

trans: 1. x <·R y /\ y <·R z => x R z.

2. x <·R y /\ y<·R z /\ x = z => x=y=z, a contradiction!

==> (xRz and x z ) and x <·R z.

Page 57: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-57

Notations

(S,R) is a poset ==> use the symbol (less than or equal to) to stand for the

relation R,

[and its "less than" version <·R are written by <. ] If (S,R) is a sposet, ==> use the symbol < (less than) to stand for the relation R a

nd use to stand for its "less than or equal to" version ·R.Note:

By previous theorem, < and can be uniquely defined by each other. Hence we can choose either one as the basic definition; once one ordering is defined, the other can be obtained too.

Mathematicians usually use as official definition of ordering while most computer scientists choose < as official definition.

Page 58: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-58

Total ordering

Def 2: (S, ): a poset; x, y in S; x and y are said to be comparable iff either x y or y x. If x and y are not comparable, they are said to be incompar

able.Def 3: (S, ): a poset;

If every two elements of S are comparable, S is said to be a totally ordered set or linearly ordered set and is called a total order or linear order.

A total ordered set is also called a chain.Def 4: (S, ): a totally ordered set; (S,) is called a well-ordered set if every nonempty subset of S

has a least element.Ex5: (Z, ) is a totally ordered set but not well-ordered.Ex6: (N, |) is not a chain, Since neither 5 | 7 nor 7 | 5.Ex7: (N, ) is well-ordered ; (N, is totally ordered but not wel

l-ordered.

Page 59: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-59

Lexicographical ordering

Let ( , )be a poset and * be the set of all finite strings over . Define a relation on * as follows:

For any string x, y :

x y iff

1. x is a prefix of y or 2. there are strings z, u, v and symbol a, b in S s.t.

x = z a u and y = z b v with a < b.

Def: If (S, ) : a poset, then (S,) is well founded if there is no infinite descending sequence.

Theorem:

1. If (,) is a poset then so is (*,).

2. If (,) is a total ordered set, then so is (*,).

3. If (,) is well-ordered, then so is (*,).

4. if (,) is well-founded then so is (*,).

Page 60: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-60

Maximal and minimal elements: (S, ) : a poset; X: a subset of S;

1. x X is the least (smallest, minimum) element of X iff ?

y X x y.

2. x X is the greatest (largest, maximum) element of X iff ?

y X y x.

3. x X is a minimal element of X iff ?

~ y X y< x (or equivalently, y X y x=>y=x)

4. x X is a maximal element of X iff ?

~ y X x < y (or equivalently, y X x y=>y=x)

5. x is a lower bound of X iff ? y X x y.

6. x is an upper bound of X iff ? y X y x.

7. x is the greatest lower bound of X (glb(X)) iff ?

8. x is the least upper bound of X (lub(X) iff ?

x is an upper bound of X and x y for all upper bounds y of X.

Page 61: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-61

Lattices

Def: (S,) is a lattice if

1. (S,) is a poset

2. Every pair (x,y) of elements of S has both lub and glb.

where lub(x,y) = x \/ y = the join of x and y

glb(x,y) = x /\ y = the meet of x and y.

Ex: 1. (N, |) is a lattice

with x\/y = lcm(x,y) and x /\ y = gcd(x,y).

2. (2S, ) is a lattice

with x \/ y = x U y and x /\ y = x y.

Def: (S,): a lattice

==> (S, ) is bounded iff it has a least and a greatest element.

(S,) is a complete lattice iff every subset(including empty set) of S has both lub and glb.

Page 62: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-62

Topological sorting

(S,R): a poset.a total ordering on S is said to be compatible with R if a

b implies aRb (i.e., ≤ is an extension of R; R ).Topological sorting:

Given a finite poset, construct a total ordering compatible with it.

Lem 1: Every finite nonempty poset has a minimal element.

pf: choose a0 from S, if a0 is not minimal

=> a1 < a0, if a1 is not minimal

=> a2 < a1,...

...

=> The process must end with a minimal element an (since S is finite). QED

Page 63: Discrete Mathematics Transparency No. 6-1 Chapter 6 Relations

Discrete MathematicsCh 6 Relations

Transparency No. 6-63

Topological sorting (cont'd)

The algorithm:

procedure topological-sort(S: a poset)

1. { k = 1;

2. while( S {} ){

3. a[k] = any minimal element of S;

4. S = S - {a[k]};

5. k = k + 1}

6. } /* a[1],a[2],...a[n] is a compatible total ordering. */

Ex: The poset is ({1,2,4,5,12,20}, |)

==> 1. Draw a graphical representation for (S, |).

==> 2. find a total ordering compatible with |.