0% found this document useful (0 votes)
3 views69 pages

Comp106 2 Relations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views69 pages

Comp106 2 Relations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

9.

Relations

Relations are discrete structures that are used to represent relationships between
elements of sets.
• between a business and its telephone number
• between an employee and his or her salary
• between a program and a variable it uses

Relations can be used to solve various problems in computer science such as:
 Determining which pairs of cities are linked by airline flights in a network
 Computing the distance between a pair of registered Facebook users
 Finding an efficient order for different phases of a complicated project
 Producing a useful way to store information in computer databases
9.1 Relations and Their Properties

Definition: Binary relation


Let A, B be sets.
A binary relation R from A to B is a set of ordered pairs, where the first element
of each ordered pair comes from A and the second element comes from B.
Note: A×B is the set of
Hence R is a subset of A×B.
all such ordered pairs.

Notation: Let aA, bB

(a,b)R a is “related to” b by R aRb


means
(a,b)R a is “not related to” b by R aRb
e.g.
A ={a1, a2, a3}
B ={b1, b2}

One can define many relations from A to B:

R1 = {(a1, b1), (a1, b2), (a2, b1), (a3, b2)}


R2 = {(a1, b1), (a2, b2), (a2, b1), (a3, b1), (a3, b2)}
and so on…

a1
b1
a2
b2
a3

A B
R1
Some relations make sense:

e.g.
A: set of cities
B: set of countries
R: (a,b)R if city a is in country b.

(Izmir, Turkey)  R
(Paris, France)  R
(Paris, Turkey)  R

A relation is a set of ordered n-tuples!!


Function is a special case of relation

A function ƒ from A to B can be thought of as the set of ordered pairs (a,b) s.t. b = ƒ(a).

Hence function is a special case of relation with one restriction:


Every element of A is the first element of exactly one ordered pair of the function.


0 a
a b
1 b
0 ×
2
1 ×
A B 2 ×
Relations defined on a single set:
This reads like “R is the set of all pairs
A relation on a set A is a relation from A to A. (a,b) such that a divides b, where a and b
are both elements of A”.
e.g.
A = {1, 2, 3, 4}
R = {(a,b) | a | b, (a,b) A×A}
= {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}

e.g.
How many relations are there on a set with n elements?
|A×A| = n2
2
 2𝑛 (# of subsets of A×A)
Properties of Relations defined on a set:

A relation R on a set A is called reflexive iff


(a,a)R aA

e.g.
A= {1, 2, 3}

R1 = {(1, 2), (2, 2), (1, 3)} (not reflexive)


R2 = {(1, 1), (1, 3), (2, 2), (3, 1), (3, 3)} (reflexive)
R3 = {(1, 3), (3, 1)} (irreflexive)

e.g.
R: The set of pairs of people having the same eye color (reflexive)
e.g. on integers
R1 = {(a, b) | a ≤ b} ??
R2 = {(a, b) | a > b} ??
R3 = {(a, b) | a = b  a = -b} ??
R4 = {(a, b) | a = b} ??
R5 = {(a, b) | a = b + 1} ??
R6 = {(a, b) | a + b ≤ 3} ??
Definition:
A relation R on a set A is called

symmetric iff the following holds


(b,a)R → (a,b)R a, bA
e.g.
R = {(a,b) | a+b+ab = 12; a,b  Z} symmetric
R = {(1,1), (2,2)} symmetric
R = { } (empty set) symmetric

anti-symmetric iff the following holds


(a,b)R and (b,a)R → a = b a, bA
e.g.
Rt = {(a,b) | a is taller than b} anti-symmetric

asymmetric iff a,bA (a,b)R → (b,a)R


e.g.
Rt = {(a,b) | a is taller than b} is also asymmetric
e.g.
R = {(1,1), (1,2), (3,1)} anti-symmetric but not asymmetric
Definition:
R on set A is called transitive iff
(a,b)R and (b,c)R → (a,c)R a,b,c  A

e.g.
Rt = {(a,b) | a is taller than b} transitive

e.g.
A= {1, 2, 3}

R1 = {(1, 2), (2, 3), (1, 3)} (transitive)


R2 = {(1, 2), (2, 3)} (not transitive)
R3 = {(1, 2)} (transitive)
e.g.
How many reflexive relations are there on a set with n elements?

If R is reflexive, then:
there are n pairs such that (a,a)R (this is a requirement for reflexivity),
and there exist n(n–1) pairs such that a  b;
any combination of these n(n–1) pairs can also be in R.
 # of reflexive relations = 2n(n-1)

e.g.
How many symmetric relations are there on a set with n elements? (Exercise)
Combining relations:

Let A = {a, b} B = {1, 2, 3}

R1 = {(a,1), (b,3)}
R2 = {(a,1), (a,2), (b,1), (b,2)}
R3 = {(b,1), (b,2)}
R4 = {(a,1), (b,2)}

R1  R3 = {(a,1), (b,1), (b,2), (b,3)}


R1  R2 = {(a,1)}
R2 – R3 = {(a,1), (a,2)}
R1  R4 = {(b,2), (b,3)}

 is called “symmetric difference”, acts like XOR


Definition: Let R: A→B and S: B→C.

Then the composite relation of R and S


S○R: A → C is defined s.t.
(a,c)S○R iff (a,b)R and (b,c)S.

Definition:
Let R be a relation on A.
S○R = {(a1, c4), (a2, c3), (a4, c4), (a4, c1)}
The powers Rn, n = 1, 2, 3, …, are defined by
R1 = R, R2 = R○R,… Rn = Rn-1 ○ R.

e.g. R = {(a,b) | b is a parent of a}


 R2 = {(a,c) | c is a grand-parent of a} why?
because (a,b)R means “b is a parent of a”, and (b,c)R means “c is a parent of b”.
Theorem:
R on a set A is transitive iff Rn  R for all n = 1, 2, 3,…

Proof:

If part: (if Rn  R for n = 1, 2, 3,…, then R is transitive)


If Rn  R, in particular R2  R.
Then, a,b,c if (a,b)R and (b,c)R, by definition (a,c)R2.
Since R2  R, (a,c)R.
 R is transitive.

Only if part: (If R is transitive, then n Rn  R) Use induction on n.


Basis step: R1  R; always true for n = 1.

Inductive step: Assume Rn  R and R is transitive. Show Rn+1  R.


Let (a,b)Rn+1 = Rn ○ R.
Then xA s.t. (a, x)R and (x,b)Rn, by definition of composition
Since Rn  R, (x,b)  R.
Then since R is transitive and (a, x)R, we have (a,b)R.
 Rn+1  R
Inverse of R: R-1 = {(b, a) | (a, b)  R}

Complementary of R: R = {(a, b) | (a, b)  R }

e.g.
Let R = {(a, b) | a < b} R: A → B.

Inverse of R: R-1 = {(b, a) | a < b}


Complementary of R: R = {(a, b) | a  b}

Note that if R is a relation representing a function f, then R-1 is a relation representing a


function f-1 assuming the inverse of the function f is defined.
R = {(a, b) | b = f(a)}
R-1 = {(b, a) | a = f-1(b)}
e.g.
R, S are reflexive relations on A.

a) RS is reflexive? Yes since (x, x)  R


b) RS is reflexive?  so does R  S
c) R S is irreflexive? 
d) R-S is irreflexive? 
e) S○R is reflexive? 
f) R-1 is reflexive? 
g) Complementary of R is irreflexive?

 is called “symmetric difference”, acts like XOR


e.g.
Suppose R is irreflexive. Is R2 also irreflexive?
No. Counter-example: Let a  b and R = {(a, b), (b, a)}

e.g.
How many relations are there on a set with n elements?
|A×A| = n2
n2
 2 (# of subsets of A×A)

e.g.
How many reflexive relations are there on a set with n elements?
If R is reflexive, then:
there are n pairs such that (a, a)R
and n(n–1) pairs such that (a, b)R where a  b
# of reflexive relations = 2n(n-1)
9.3 Representing Relations
Definition: A relation R can also be represented by a matrix MR = [mij]:
1 if (ai , bj )  R

mij   m11 … mN1
0 if (ai , b j )  R MR = ⋮ ⋮ ⋮
m1K … mNK
K×N
e.g. Let A = {1, 2}, B = {a, b, c} and R: A→B such that
R = {(1,b), (2,a), (2,b), (2,c)}

0 1 0 
MR =  
 1 1 1 

e.g.
Let R be a relation defined on A = {1, 2, 3}: R = {(1,2), (2,2), (1,3)}

0 1 1
MR = 0 1 0 Note that we get a square matrix whenever R: A→ A.
0 0 0
Remark: The matrix representation of a relation assumes a certain ordering of the elements as given in the sets. If
you change the order of the elements, the matrix representation changes.
- Reflexive relation R s.t. i (ai, ai)R
 i mii = 1

i.e. , diagonal with all ones

- Symmetric relation R s.t. (ai, aj)R ↔ (aj, ai)R i, j


 i,j mij = mji
Symmetric matrix
MR = (MR = MTR)
Inverse and Complementary:

If MR = [mij]K×N then

Inverse: MR–1 = MRT = [mji]N×K (transpose)


Complementary: MR = [mij]K×N (negation)

Inverse of R: R-1 = {(b, a) | (a, b)  R}

Complementary of R = {(a, b) | (a, b)  R }

e.g.

Let R = {(a, b) | a < b} R: A → B.

Inverse of R: R-1 = {(b, a) | a < b} R-1: B → A.


Complementary of R = {(a, b) | a  b} A→B
Zero – One Matrices:
The matrix representation of a relation is always a zero-one matrix, a
matrix with entries that are either 0 or 1.

We can define operations on relations using their matrix representations:

Let A = [aij] B = [bij] be m×n zero-one matrices.

Join of A, B: A  B = [aij  bij]


Meet of A, B: A  B = [aij  bij]
e.g.

Remark: Let R1: A→B and R2: A→B


Boolean product:
Let A = [aij]: m×k, B = [bij]: k×n zero-one matrices.

A B = [cij] : m×n, where

cij = (ai1  b1j)  (ai2  b2j)  ….  (aik  bkj)

Hence, to obtain cij , we take the ith row of A and jth column of B and then
compute the dot product:

ith row

jth column

Remark: Let R: A→ B and S: B→ C

MS○R = MR MS (Note the order of matrices)


e.g.

Remark: Let R: A→ B and S: B→ C

MS○R = MR MS
Recall the following example:

S○R = {(a1, c4), (a2, c3), (a4, c4), (a4, c1)}

How would you then compute S○R by using matrices?

MS○R = MR MS
rth Boolean Power:
Let A be a square (M×M) zero-one matrix and r be a positive integer.
Ar = A A … A
r times
A0 = I

Remark: Let R: A→ A

MRn  [MR ]
n
Representing Relations Using Graphs:

Pictorial representation.

Definition:
A directed graph (digraph) consists of a set V of vertices (or nodes) along with a set E
of edges (or arcs) which are ordered pairs of vertices.
Edge(a, b): a is initial vertex (node), b is terminal vertex (node)

e.g.
a
loop
Graph
representation
0 1 0 Matrix
b c
𝑀𝑅 = 0 0 1 representation
Set 0 1 1
R = {(a,b), (b,c), (c,b), (c,c)} representation

Relation R on a set A is defined with


i) elements of A: vertices (nodes)
ii) ordered pairs (a,b)R: edges
Relation R is:
- reflexive iff every node has a loop
- symmetric iff every edge between two nodes has an edge in the opposite
direction.
- transitive iff edge (a,b)  edge (b,c) → edge (a,c) a,b,c
e.g.

a . .b
reflexive

c.
Example to graph representation of a relation:

Connectivity problems:

1) Which nodes are connected?


2) What is the shortest path between two nodes?
9.4 Closures of Relations

e.g. Let R = {(1,1), (1, 2), (3, 2)} on A = {1, 2, 3}

R is not reflexive; what is the smallest possible reflexive relation containing R?

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

S is the reflexive closure of R.


Definition: Closure
Let R be a relation on A
P: some property, such as symmetry, reflexivity, transitivity
R may or may not have the property P.

The closure S is the smallest possible relation with property P, which contains R.

More formal definition of closure:


If there is a relation S with property P containing R s.t. S is the subset of every relation
with property P containing R, then S is called the closure of R with P.
Reflexive Closure:

Let R = {(1,1), (1, 2), (3, 2)} on A = {1, 2, 3}


The smallest possible reflexive relation containing R:

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

S = Reflexive closure of R = R  ,
where  = {(a, a) | a  A} : diagonal relation

e.g.
R = {(a, b) | a < b}, reflexive closure?

R   = {(a, b) | a < b}  {(a, a) | a  Z}


= {(a, b) | a  b}
Symmetric Closure: The smallest possible symmetric relation containing R

Let R = {(1, 1), (1, 2), (2, 1), (2, 3), (3, 1), (3, 3)} on A = {1, 2, 3}
We should add all ordered pairs (b, a), where (a, b) is in R but (b, a) is not.
Symmetric closure of R = R  {(3, 2), (1, 3)}

Symmetric closure of R = R  R-1 (since R-1 = {(b, a) | (a, b)  R})

e.g.
R = {(a, b) | a < b}

Symmetric closure of R = R  R-1


= {(a, b) | a < b}  {(b, a) | a < b}
= {(a, b) | a  b}
Transitive Closure: The smallest possible transitive relation containing R

Let R = {(1, 3), (1, 4), (2, 1), (3, 2)} on {1, 2, 3, 4}
R is not transitive since there are pairs (a, c)R although (a, b), (b, c)R.

(i) R  {(1, 2), (2, 3), (2, 4), (3, 1)}


Is it transitive? NO!

It has (3, 1),(1, 4), but not (3, 4).


We have a more difficult problem!!!

We might repeat step (i) until reaching a transitive relation. But there are better ways.

Remark: The transitive closure of a transitive relation R is R, itself.

Remark: The transitive closure of R contains all the pairs (a, b) of R, where a is
directly or indirectly linked to b via transitions
e.g. Draw transitive closure of

a. .b

c. .d

How about symmetric closure? Reflexive closure?


Paths in Directed Graphs
We now introduce a new terminology that we will use in the construction of transitive
closures.
Definition:
A path from node x0 to node xn in a directed graph G is a sequence of edges (x0, x1),
(x1, x2), … (xn-1, xn) in G. This path is denoted by x0, x1, …, xn and has a length of n.

If x0 = xn, the path is called a cycle or circuit.


Two vertices are said to be connected if there’s a path between them.

e.g.
a. . b A path:
a, b, d, a, e

c. .d .e a is connected to e, but e is not connected to a.

The term path also applies to relations.


Theorem:
Let R be a relation on A. Then n > 0, there is a path of length n from a to b iff (a, b)Rn.

e.g.
a. . b A path:
a, b, d, e

c. .d .e

(a,e)R3 since there is a path of length 3 between a and e.

But also (a,e)R6 since there is also another path of length 6 between a and e:
a,b,d,a,c,d,e
Theorem:
Let R be a relation on A. Then n > 0, there is a path of length n from a to b iff (a, b)Rn.
Proof: Use induction, where P(n): There is a path of length n from a to b iff (a, b)Rn

Basis step:
By definition there is a path of length 1 from a to b iff (a, b)R. Hence P(n) is T for n = 1.

Inductive step: Assume P(n) is T for some arbitrary fixed n  1. Show P(n+1) is T.
There is a path of length n+1 from a to b iff
cA s. t. there is a path of length 1 from a to c and a path of length n from c to b
that is, cA such that (a,c)R and (c,b)Rn (by inductive hypothesis)
which means (a, b)  Rn+1 = Rn ○ R (by definition of composite relation).

 P(n+1) is T.

 By induction, n > 0 there is a path of length n from a to b iff (a, b)Rn


Connectivity Relation:

Connectivity relation R* consists of all those pairs (a, b) s.t. there is a path between a
and b in R.

Since Rn includes all the paths of length n by the previous theorem, There is a path of length n
from a to b iff (a, b)Rn

e.g.
Let R be a relation on the set of people in the world that contains (a,b) if a has met b.

R2: ? if (a, b)  R2 then c s.t. (a, c)R and (c, b)R

R*: ? (a, b)R* if there is a sequence of people, starting with a and ending with b.
Connectivity Relation = Transitive Closure

Finding transitive closure is equivalent to determining all pairs of vertices that are
connected through a path.

Recall that, to find the transitive closure of a relation, we need to iteratively add to
the relation all the missing transitions.
Theorem:
The transitive closure of a relation R equals to the connectivity relation R*.

Proof:
We must show that,
(i) R* is transitive
(ii) R* is the smallest possible transitive relation that contains R
(any transitive relation that contains R also contains R* )

i. R* is transitive?
If (a, b)R*, there is a path from a to b.
If (b, c)R*, there is a path from b to c.
 There is a path from from a to c, which means (a, c)R*, hence R* is transitive.
ii. Let S be any transitive relation that contains R, i.e., R  S. Show R* S.
Since S is transitive, S n  S for all n (by the theorem in Section 9.1) R on a set A is transitive
iff Rn  R for all n
S n  S and 𝑆∗ =  S* S
Also, since R  S (given), R*  S * (by definition of connectivity relation)
 R* S.
Hence, any transitive relation that contains R also contains R*
|A| = 5
Given R, how can we compute the connectivity relation R*?

Lemma:
Let R be a relation in A and |A| = n. If there is a path from a to b in R, then one can
always find a path from a to b with length not exceeding n.

Hence
|A| = 5
Given R, how can we compute the connectivity relation R*?

Lemma:
Let R be a relation in A and |A| = n. If there is a path from a to b in R, then one can
always find a path from a to b with length not exceeding n.

Proof:
Suppose there is a path x0, x1, …, xm from x0 = a to xm = b with length m.
If m  n, then there are at least two vertices on this path, equal to each other xi = xj such
that 0  i  j  m –1. (by the pigeonhole principle)

We can cut this circuit and form a new path


x0, x1, …, xi, xj+1, …, xm
If we do the same for all such two vertices, we get a path of length  n.
Given MR, how can we compute the connectivity relation MR* ?

MR* = MR  M2R M3R  …  MnR

e.g.
Let R = {(a, a), (a, c), (b, a), (c, a), (c, c)}. Find R*.

no need to compute
powers beyond n = 3

MR* = MR  M2R  M3R =


Algorithm for computation of connectivity relation (or transitive closure) :

Transitive closure (MR: zero-one matrix representation of R)


A := MR
B := A
for i := 2 to n
A := A MR
B := B  A
return B

Recall that transitive closure is identical to connectivity relation.


Algorithm for computation of connectivity relation (or transitive closure) :

Transitive closure (MR: zero-one matrix representation of R)


A := MR
B := A
for i := 2 to n
A := A MR
B := B  A
return B

Note: Although in general S○R ≠ R○S, while computing powers of a relation, the order
of compositions does not matter, hence

Rn+1 = Rn ○ R = R○ Rn 
Algorithm for computation of connectivity relation (or transitive closure):

Transitive closure (MR: zero-one matrix representation of R)


A := MR
B := A
for i := 2 to n
MR* = MR  M2R M3R  …  MnR
A := A MR
B := B  A
return B

Complexity:
A MR : T(n) = (n 1) (n2(2n 1) + n2)
(n + (n –1))n2 operations = (n 1)(2n3)
BA:  T(n) is O(n4). (Polynomial complexity)
n2 operations
e.g. Let (a, b)R if there is a non-stop flight from city a to b. When is (a, b) in
R2?
If c s.t. (a, c) R, (c, b)R.
R3?
If c,d s.t. (a, c)  R, (c, d)R, (d, b)R.
R*?
If it is possible to fly from a to b.

R* can be computed using the algorithm of the previous slide given the flight nework.
9.5 Equivalence Relations
e.g. Consider the relation R = {(a, b)  a  b (mod 4)}
R is symmetric, transitive and reflexive.
Hence we say, R is an equivalence relation.

What matters?

R divides (or partitions) the set of integers into four disjoint subsets:

{…,-8,-4,0,4,8,…}, {…,-7,-3,1,5,9,…}, {…,-6,-2,2,6,10,…}, {…,-5,-1,3,7,11,…}

where any two integers in a given subset are related with R, hence said to
be “equivalent” to each other.

(4,8)R hence 4 is equivalent to 8, and so is (1,5).

Remark: These subsets are referred to as equivalence classes.


Definition: Equivalence Relation
If a relation is reflexive, symmetric and transitive then it is called an equivalence
relation.
Equivalent elements: Two elements that are related by an equivalence relation.

 R (defined previously) is an equivalence relation, more specifically a “modular”


equivalence relation.
 (4,8)R hence 4 is equivalent to 8, and so is (1,5).
Another relation example that defines an equivalence between strings:

Let R be a relation on the set of strings :


R = {(a, b)  L(a) = L(b)}, where L(x) is the length of string x.

 R is reflexive since a L(a) = L(a) which implies that (a, a)R.


 R is symmetric since a,b (a, b)R  L(a) = L(b)  L(b) = L(a)  (b, a)R
 R is transitive since a,b,c (a, b)R  (b, c)R  L(a) = L(b)  L(b) = L(c)
 L(a) = L(c)  (a, c)R

 R is an equivalence relation.

“discrete” is equivalent to “computer” with respect to R.


Another relation example that defines an equivalence between strings:

Let R be a relation on the set of strings :


R = {(a, b)  L(a) = L(b)}, where L(x) is the length of string x.

 R is reflexive
 R is symmetric
 R is transitive

 R is an equivalence relation.

“discrete” is equivalent to “computer” with respect to R.

 R divides (or partitions) the set of strings into disjoint subsets, where each subset contains all
strings of the same length.

 These subsets are equivalence classes. Any two strings in a given subset are equivalent to each
other (with respect to the relation).
e.g.
Relations on a set of people:
a) {(a, b)  a and b are at the same age}
b) {(a, b)  a and b speak a common language}

Are they equivalence relations?


e.g.
Relations on a set of people:
a) {(a, b)  a and b are at the same age} Yes
b) {(a, b)  a and b speak a common language} No

Are they equivalence relations?


Definition: Equivalence class
Let R be an equivalence relation on A.
The set of all elements that are related to an element a of A is called the equivalence
class of a:
[a]R = { s  (a, s)R}

e.g.
R = {(a, b)  a  b (mod m)}

What is the equivalence class of 1 with respect to R?

1 is equivalent to 1m, 1, 1+m, and so on.

Hence, the equivalence class of 1:


[1]R = {…., 1m, 1, 1+m, 1+2m, ….}
Equivalence Classes and Partitions:

Equivalence classes partition (or divide) a set into disjoint, nonempty subsets.

e.g.
R = {(a, b)  a  b (mod m)}

m equivalence classes:
[0]R , [1]R, ….., [m 1]R
All are disjoint and form a partition.
Equivalence Classes and Partitions:

Equivalence classes partition (or divide) a set into disjoint, nonempty subsets.

e.g. Consider the equivalence relation on the set S of all strings.


R = {(a, b)  L(a) = L(b)}, where L(x) is the length of string x.

Infinitely many equivalence classes:


S1, S2, S3, …
where Sn denotes the set of all strings with n characters.

All are disjoint and form a partition in S.


Equivalence Classes and Partitions:

Equivalence classes partition (or divide) a set into disjoint, nonempty subsets.

e.g.
Relation R on a set of people: {(a, b)  a and b are at the same age}

R partitions the set of people into equivalence classes (hence into nonempty disjoint
subsets).

Each equivalence class is the set of people who are at the same age, for example [a]R is
the set of people who are 18 years old (if a is 18 years old).
Equivalence Classes and Partitioning:

Theorem: Equivalence classes partition (or divide) a set into disjoint,


nonempty subsets.

Proof: See Chapter 9.5 of your textbook.


e.g.
Let R be a relation on the set of positive real-number pairs s.t.
((a, b), (c, d ))  R ↔ ad = bc
Show that R is an equivalence relation.

R is reflexive since a,b ab = ab, which implies that ((a, b), (a, b ))  R
R is symmetric since a,b,c,d ((a, b),(c, d ))  R  ad = bc  da = cb
 ((c, d), (a, b))  R.

R is transitive since
a,b,c,d,e,f ((a, b), (c, d )) R and ((c, d ), (e, f )) R  (ad = bc and cf = de)
 af = be  ((a, b), (e, f )) R

Thus, equivalence classes for this relation partition the set of positive real number pairs
into disjoint nonempty subsets such that

[(a,b)]R = {(x,y) | x/y = a/b = c, c is a positive real number}

Remark: If the relation R were not defined on a set of positive valued number pairs,
(including 0 in particular), then R would not be an equivalence relation. Why?
e.g. a) Let R be the relation on the set of functions from Z+ to Z+ such that (f, g) belongs to R iff f is Θ(g).
Show that R is an equivalence relation. Use the definition of big-O notation whenever necessary.
b) Describe the equivalence class containing f (n) = n2 for the equivalence class of part (a).
a) We need to show that R is reflexive, symmetric and transitive.

- We know that f is Θ(g) iff f is O(g) and g is O( f ).


Thus f, g if f is Θ(g) then g is also Θ( f ). Therefore R is symmetric.

- f f is O( f ) since |ƒ(n)|  C | f (n)| n > k with C = 1 and k = 1.


Then f is also Θ( f ) by definition, R is reflexive.

- Let’s first show that the “big-O’’ relation is transitive.


f, g, h if f is O(g) and g is O(h), then we can write
C1, k1 such that |ƒ(n)|  C1|g(n)| whenever n > k1
 |ƒ(n)|  C1 C2 |h(n)| n > max(k1, k2 )
C2, k2 such that |g(n)|  C2|h(n)| whenever n > k2
Choose C = C1 C2 and k = max(k1, k2 ). Hence f is O(h).

Now consider R, hence the “big-Θ’’ relation.


f, g, h if f is Θ(g) and g is Θ(h), then
 f is O(g) and g is O( f ) and g is O(h) and h is O(g)
 ( f is O(g) and g is O(h)) and (h is O(g) and g is O( f ))
 f is O(h) and h is O( f ) since “big-O’’ relation is transitive
 f is Θ(h) Therefore R is transitive.
e.g. a) Let R be the relation on the set of functions from Z+ to Z+ such that (f, g) belongs to R iff f is Θ(g).
Show that R is an equivalence relation. Use the definition of big-O notation whenever necessary.
b) Describe the equivalence class containing f (n) = n2 for the equivalence class of part (a).

b) Let F denote the set of all functions from Z+ to Z+

[ n2 ]R = { f (n) | f (n) is Θ(n2), f (n)F }


Things to remember about equivalence relations:

• If a relation R is reflexive, symmetric, and transitive, then it is called an


equivalence relation.

• An equivalence relation R divides (or partitions) the set on which it is defined


into non-empty disjoint subsets, each of which is an equivalence class

• Any two elements a and b in an equivalence class are then related, hence
“equivalent” with respect to R
9.6 Partial Order Relations

We can use relations to order/sort elements of a set.


Definition: Partial Order(ing)
A relation R on a set S is called partial order(ing) if it is reflexive, anti-symmetric, and
transitive.
A set S together with a partial ordering R is called a partially-ordered set, or poset, and is
denoted by (S, R).
e.g.
R = {(a, b)  a  b} is a partial order.

e.g.
R = {(a, b) a | b}

‘Less than or equal to’ is a paradigm for partial order.


Poset notation: a ≼b means (a, b)R. (R is a partial order)
a ≺b means (a, b)R, but a  b.
Definition:
The elements a, b of a poset (S, ≼) are called comparable if either a ≼b or b ≼a.
Otherwise they are called incomparable.
e.g.
Poset (Z+, R) with R = {(a, b) a | b}
3, 6 are comparable, thus (3,6)R, thus 3 ≼6 (≼here represents divisibility)
3, 10 are incomparable, thus (3,10)R, thus 3 ≼10

e.g.
Let R = {(1, 1), (2,2), (3, 3), (2, 1), (2, 3), (3, 1)} on S = {1, 2, 3}.
R is reflexive, anti-symmetric and transitive  R is a partial order  (S, R) is a poset.
1 ≼1 2 ≼2 3 ≼3 2 ≼1 2 ≼3 3 ≼1

e.g.
Poset (Z+, R) with R = {(a, b) b | a}.
1 ≼1 4 ≼2 10 ≼5

e.g. Poset (P(Z) -power set-, R) with R = {(a, b) a  b}.


Definition:
If (S, ≼) is a poset and every two elements of S are comparable, S is called a totally-ordered set
and ≼is called a total order(ing).

e.g. Poset (Z+, R ) with R = {(a, b) a | b}.


R is not a total ordering since there are elements incomparable such as 5 and 6.

e.g. R = {(1, 1), (2,2), (3, 3), (2, 1), (2, 3), (3, 1) } on S = {1, 2, 3}.
R is a total ordering; every two elements are comparable.

e.g. R = {(a, b)  a  b} on the set of integers.


R is a total ordering; every two elements are comparable.

e.g. R = {(a, b)  b  a} on the set of integers.


R is a total ordering; every two elements are comparable, for instance 10 ≼5.

e.g. Rt = {(a,b) | a is taller than b or a = b} on the set of people.


R is a total ordering; every two elements are comparable.

e.g. Poset (P(Z) -power set-, R) with R = {(a, b) a  b} ??


Lexicographic (Alphabetic) Order

We can define the lexicographic order on the Cartesian product of n posets:


(A1, ≼1), (A2, ≼2), …., (An, ≼n)

(a1, a2, …, an) ≺ (b1, b2, …., bn)


if
a1 ≺b1 or i, 1 i n, such that
a1 = b1, ...., ai = bi, and ai+1 ≺ bi+1
where the ordering ≺= {(a,b) | a is alphabetically before b, a and b are letters}.

e.g. Comparing strings...


“that” ≺ “this”
Topological Sorting
A compatible total ordering can be constructed with a partial ordering R.

Topo-sort (S,R: finite poset)


k=1
while S   {
ak = minimal element of S
S = S – {ak}
k = k +1
}

{a1 ,a2 ,…,an} is a compatible total ordering of S (compatible with relation R).

You will learn this in COMP 202 in 2nd year.


Maximal and Minimal Elements:

Definition:
An element a is maximal in poset (S, ≼) if there is no bS s.t. a ≺b.
An element a is minimal in poset (S, ≼) if there is no bS s.t. b ≺a.

An element a is the greatest element in poset (S, ≼) if bS b ≼a.


An element a is the least element in poset (S, ≼) if bS a ≼b.

An element aS is an upper bound of A  S in poset (S, ≼) if bA b ≼a.


An element aS is a lower bound of A  S in poset (S, ≼) if bA a ≼b.
(bound is not necessarily in the set)

An element aS is the least upper bound of A  S in poset (S, ≼) if bA b ≼a


and also for all upper bounds c of A, a ≼c
An element aS is the greatest lower bound of A  S in poset (S, ≼) if bA a ≼b.
and also for all lower bounds c of A, c ≼a
Lattices:

A poset in which every pair of elements has both the least upper bound and the greatest lower
bound is called a lattice.

Lattice-based cryptography: Lattices have many special properties useful in various


applications. One new trend in cryptography is to create cryptosystems based on lattice
problems (e.g., finding the element in a lattice closest to a given point in the lattice-space)

e.g. Is the poset (Z+, | ) a lattice?


Yes. The greatest lower bound of a,b is gcd(a,b)
The least upper bound of a,b is lcm(a,b)

e.g. Is the poset (P(S),  ) a lattice?


The greatest lower bound of a,b is ??
The least upper bound of a,b is ??

You might also like