Properties of Binary Relations
Properties of Binary Relations
R:
a b c
R is reflexive
x R x for all x∈A
Every element is related to itself.
R is symmetric
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A
Example:
i<7 and 7<j implies i<j.
R is irreflexive
(x,x) ∉ R, for all x∈A
Elements aren’t related to themselves.
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A
Example: Reflexive
i<7 and 7<j implies i<j.
R is irreflexive
(x,x) ∉ R, for all x∈A
Elements aren’t related to themselves.
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A Symmetric:
Example:
All edges are 2-way:
i<7 and 7<j implies i<j.
R is irreflexive Might as well use
(x,x) ∉ R, for all x∈A undirected edges!
Elements aren’t related to themselves.
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A Symmetric:
Example:
All edges are 2-way:
i<7 and 7<j implies i<j.
R is irreflexive Might as well use
(x,x) ∉ R, for all x∈A undirected edges!
Elements aren’t related to themselves.
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A Symmetric:
Example:
All edges are 2-way:
i<7 and 7<j implies i<j.
R is irreflexive Might as well use
(x,x) ∉ R, for all x∈A undirected edges!
Elements aren’t related to themselves.
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A Transitive:
Example:
If you can get from
i<7 and 7<j implies i<j.
R is irreflexive x to y, then there
(x,x) ∉ R, for all x∈A is an edge directly
Elements aren’t related to themselves. from x to y!
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A Transitive:
Example:
If you can get from
i<7 and 7<j implies i<j.
R is irreflexive x to y, then there
(x,x) ∉ R, for all x∈A is an edge directly
Elements aren’t related to themselves. from x to y!
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A Irreflexive:
Example:
You won’t see any
i<7 and 7<j implies i<j.
R is irreflexive edges like these!
(x,x) ∉ R, for all x∈A
Elements aren’t related to themselves.
R is antisymmetric
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
R is reflexive
x R x for all x∈A a b
Every element is related to itself.
R is symmetric c d
x R y implies y R x, for all x,y∈A
The relation is reversable.
R is transitive
x R y and y R z implies x R z, for all x,y,z∈A Antisymmetric:
Example:
You won’t see any
i<7 and 7<j implies i<j.
R is irreflexive edges like these!
(x,x) ∉ R, for all x∈A (although xRx is
Elements aren’t related to themselves. okay:
R is antisymmetric x )
x R y and y R x implies that x=y, for all x,y,z∈A
Example: i≤7 and 7≤i implies i=7.
Answers:
Ø
A×A
eq = {(0,0), (1,1)}
less = {(0,1)}
Answers:
Ø symmetric,transitive,irreflexive,antisymmetric
A×A reflexive, symmetric, transitive
eq = {(0,0), (1,1)} reflexive, symmetric, transitive, antisymmetric
less = {(0,1)} transitive, irreflexive, antisymmetric
A A A B
B B B A
C C C C
D
D D D
R S
R S
A A A B
B B B A
C C C C
D
D D D
R S
R S
Examples:
eq ᐤ less = ?
RᐤØ=?
isMotherOf ᐤ isFatherOf = ?
isSonOf ᐤ isSiblingOf = ?
Examples:
eq ᐤ less = less
{ (x,z) | x=y and y<x, for some y}
RᐤØ=Ø
Let R2 = R ᐤ R = ?
R:
a b c
Let R2 = R ᐤ R
Let R3 = R ᐤ R ᐤ R = ?
R: R2:
a b c a b c
Let R2 = R ᐤ R
Let R3 = R ᐤ R ᐤ R = R2 ᐤ R.
R: R2: R3:
a b c a b c a b c
Example:
r(R) = R ∪ Eq = {(a,b),(b,a),(b,c),(a,a),(b,b),(c,c)}
R: r(R):
a b c a b c
Example:
s(R) = R ∪ Rc = {(a,b),(b,a),(b,c),(c,b)}
R: s(R):
a b c a b c
Example:
t(R) = R ∪ R2 ∪ R3 = {(a,b),(b,a),(b,c),(a,a),(b,b),(a,c)}
R: t(R):
a b c a b c
What is t(R)?
What is rt(R)?
What is st(R)?
Let R = {(a,b),(b,c),(c,d)}
a b c d
Let R = {(a,b),(b,c),(c,d)}
a b c d
1 2 3 4
Let R = {(a,b),(b,c),(c,d)}
The matrix M will have a “1” in position Mij if i R j, and “0” otherwise.
M = 0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0 1 2 3 4
We can use this matrix to compute the t(R), the transitive closure of R.
Warshall’s Algorithm
for k := 1 to n
for i := 1 to n
for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
endFor
endFor
endFor
We can use this matrix to compute the t(R), the transitive closure of R.
Warshall’s Algorithm
Consider all ways to bypass node 1.
Then forget about node 1. for k := 1 to n
Consider all ways to bypass node 2. for i := 1 to n
and so on… for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
1 2 endFor
endFor
endFor
We can use this matrix to compute the t(R), the transitive closure of R.
Warshall’s Algorithm
Consider all ways to bypass node 1.
Then forget about node 1. for k := 1 to n
Consider all ways to bypass node 2. for i := 1 to n
and so on… for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
1 2 endFor
endFor
endFor
We can use this matrix to compute the t(R), the transitive closure of R.
Warshall’s Algorithm
Consider all ways to bypass node 1.
Then forget about node 1. for k := 1 to n
Consider all ways to bypass node 2. for i := 1 to n
and so on… for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
1 2 endFor
endFor
endFor
We can use this matrix to compute the t(R), the transitive closure of R.
Warshall’s Algorithm
Consider all ways to bypass node 1.
Then forget about node 1. for k := 1 to n
Consider all ways to bypass node 2. for i := 1 to n
and so on… for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
1 2 endFor
endFor
endFor
We can use this matrix to compute the t(R), the transitive closure of R.
Warshall’s Algorithm
Consider all ways to bypass node 1.
Then forget about node 1. for k := 1 to n
Consider all ways to bypass node 2. for i := 1 to n
and so on… for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
1 2 endFor
endFor
endFor
k=1
1 2 3 4
0 1 0 0
M = 0 0 1 0
0 0 0 1
Warshall’s Algorithm
0 0 0 0
for k := 1 to n
for i := 1 to n
for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
endFor
endFor
endFor
k=2
1 2 3 4
0 1 1 0
M = 0 0 1 0
0 0 0 1
Warshall’s Algorithm
0 0 0 0
for k := 1 to n
for i := 1 to n
for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
endFor
endFor
endFor
k=3
1 2 3 4
0 1 1 1
M = 0 0 1 0
0 0 0 1
Warshall’s Algorithm
0 0 0 0
for k := 1 to n
for i := 1 to n
for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
endFor
endFor
endFor
k=3
1 2 3 4
0 1 1 1
M = 0 0 1 1
0 0 0 1
Warshall’s Algorithm
0 0 0 0
for k := 1 to n
for i := 1 to n
for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
endFor
endFor
endFor
k=4 …Done;
no more changes. 1 2 3 4
0 1 1 1
M = 0 0 1 1
0 0 0 1
Warshall’s Algorithm
0 0 0 0
for k := 1 to n
for i := 1 to n
for j := 1 to n
if Mik = Mkj = 1 then
Mij := 1
endIf
endFor
endFor
endFor
10
1 3
10
10
2
20
30
30
6
5
4
5
Problems: 40
Find the cheapest path from x to y.
Find the shortest path from x to y.
(Just make all weights = 1!)
10
1 3
10
10
2
Idea: 20
30
30
Represent the graph with a matrix. 6
Store the weights. 5
For non-existent edges, use 4
a weight of ∞. 5
Then modify Warshall’s Algorithm. 40
0 10 10 ∞ 20 10
∞ 0 ∞ 30 ∞ ∞
∞ ∞ 0 30 ∞ ∞
M =
∞ ∞ ∞ 0 ∞ ∞
∞ ∞ ∞ 40 0 ∞
∞ ∞ ∞ ∞ 5 0
0 10 10 ∞ 20 10
∞ 0 ∞ 30 ∞ ∞
∞ ∞ 0 30 ∞ ∞
M =
∞ ∞ ∞ 0 ∞ ∞
∞ ∞ ∞ 40 0 ∞
∞ ∞ ∞ ∞ 5 0
0 10 10 40 15 10
∞ 0 ∞ 30 ∞ ∞
∞ ∞ 0 30 ∞ ∞
M =
∞ ∞ ∞ 0 ∞ ∞
∞ ∞ ∞ 40 0 ∞
∞ ∞ ∞ 45 5 0
0 10 10 40 15 10 0 0 0 2 6 0
∞ 0 ∞ 30 ∞ ∞ 0 0 0 0 0 0
∞ ∞ 0 30 ∞ ∞ 0 0 0 0 0 0
M = P =
∞ ∞ ∞ 0 ∞ ∞ 0 0 0 0 0 0
∞ ∞ ∞ 40 0 ∞ 0 0 0 0 0 0
∞ ∞ ∞ 45 5 0 0 0 0 5 0 0