Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

CHAPTER 9

Directed Graphs and Partial Orders


(PART 1)
CCC1113 Mathematics for Computer Science

Prepared by : Mdm. Nadiah Arsat


Index
PART 1 ✓Power

▪Definition of relations ▪Representing Relation


✓Functions as Relations ✓Zero-one-matrix
✓Relations on a Set ✓Directed graphs (Digraph)

▪Properties of relations
✓Reflexive, irreflexive
✓Symmetric, antisymmetric
✓Transitive

▪Combining Relations
✓Composite
Definition of Relations
▪Let 𝐴 and 𝐵 be sets. A binary relation from 𝐴 to 𝐵 is a subset of 𝐴 × 𝐵.
𝑅 ⊆ 𝐴×𝐵
▪𝑎𝑅𝑏 to denote that 𝑎, 𝑏 ∈ 𝑅
▪𝑎 ̸R 𝑏 to denote that 𝑎, 𝑏 ∉ 𝑅
▪Example :
𝑃: set of people
𝐶: set of cars
𝐷: relation of which person drives which car(s)
▪𝑃 = {𝐶𝑎𝑟𝑙, 𝑆𝑢𝑧𝑎𝑛𝑛𝑒, 𝑃𝑒𝑡𝑒𝑟, 𝐶𝑎𝑟𝑙𝑎}
▪𝐶 = {𝑇𝑒𝑠𝑙𝑎, 𝐵𝑀𝑊, 𝐻𝑜𝑛𝑑𝑎}
▪𝐷 = {(𝐶𝑎𝑟𝑙, 𝑇𝑒𝑠𝑙𝑎), (𝑆𝑢𝑧𝑎𝑛𝑛𝑒, 𝑇𝑒𝑠𝑙𝑎), (𝑆𝑢𝑧𝑎𝑛𝑛𝑒, 𝐵𝑀𝑊), (𝑃𝑒𝑡𝑒𝑟, 𝐻𝑜𝑛𝑑𝑎)}
Functions as Relations
▪A function 𝑓 from a set 𝐴 to a set 𝐵 assigns exactly one element of 𝐵 to
each element of 𝐴.
▪The graph of 𝑓 is the set of ordered pairs (𝑎, 𝑏) such that 𝑏 = 𝑓 (𝑎).
▪Because the graph of 𝑓 is a subset of 𝐴 × 𝐵, it is a relation from 𝐴 to 𝐵.
▪If 𝑅 is a relation from 𝐴 to 𝐵 such that every element in 𝐴 is the first
element of exactly one ordered pair of 𝑅, then a function can be defined
with 𝑅 as its graph.
▪This can be done by assigning to an element 𝑎 of 𝐴 the unique element 𝑏 ∈
𝐵 such that (𝑎, 𝑏) ∈ 𝑅
Graph of 𝑓: 𝐺 = {(𝑎, 𝑏)| 𝑏 = 𝑓(𝑎), 𝑎 ∈ 𝐴, 𝑏 ∈ 𝐵}
▪𝐺 ⊆ 𝐴 × 𝐵 ⇒ 𝐺 is a relation from 𝐴 to 𝐵
Relations on a Set
▪A relation on a set 𝑨 is a relation from 𝑨 to 𝑨. In
other words, a relation on a set 𝐴 is a subset of 𝐴 × 𝐴.
𝑅 ⊆ 𝐴×𝐴
▪Example :
▪𝐴 = {1,2,3,4}
▪𝑅 = {(𝑎, 𝑏)|𝑎 < 𝑏, 𝑎 ∈ 𝐴, 𝑏 ∈ 𝐴}
▪𝑅 = {(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)}
Relations on a Set
▪𝑅 = {(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)}
▪The pairs in this relation are displayed both graphically and in
tabular form

1 ∙ ∙ 1
𝑅 1 2 3 4
1 X X X
2 ∙ ∙ 2
2 X X
3 ∙ ∙ 3 3 X
4
4 ∙ ∙ 4
Properties of Relations -
Reflexive
▪A relation 𝑅 on a set 𝐴 is called reflexive if (𝑎, 𝑎) ∈ 𝑅 for every element 𝑎 ∈ 𝐴.
∀𝑎 ∈ 𝐴, (𝑎, 𝑎) ∈ 𝑅
▪Example:

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

▪𝑅1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}, The relations 𝑅3and 𝑅5 are
reflexive because they both
▪𝑅2 = {(1, 1), (1, 2), (2, 1)}, contain all pairs of the form
(𝑎, 𝑎), namely,
▪𝑅3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}, (1, 1), (2, 2), (3, 3), and (4, 4).

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

▪𝑅5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},

▪𝑅6 = {(3, 4)}.


▪Which of these relations are reflexive?
Properties of Relations -
Irreflexive
A relation 𝑅 on a set 𝐴 is called irreflexive if ∀𝑎 ∈ 𝐴, 𝑎, 𝑎 ∉ 𝑅

Example :

𝐴 = {1,2,3,4}

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


Properties of Relations –
Symmetric, Antisymmetric, Asymmetric
➢A relation 𝑅 on a set 𝐴 is symmetric if
𝑎, 𝑏 ∈ 𝑅, 𝑎 ∈ 𝐴, 𝑏 ∈ 𝐴 → 𝑏, 𝑎 ∈ 𝑅
➢A relation R on a set A is antisymmetric if
𝑎 ∈ 𝐴, 𝑏 ∈ 𝐴, 𝑎, 𝑏 ∈ 𝑅, 𝑏, 𝑎 ∈ 𝑅 → 𝑎 = 𝑏
➢A relation R on a set A is asymmetric if
𝑎 ∈ 𝐴, 𝑏 ∈ 𝐴, 𝑎, 𝑏 ∈ 𝑅 → 𝑏, 𝑎 ∉ 𝑅

Property Symmetric Antisymmetric Asymmetric

Can be Can be Cannot be


Reflexivity
reflexive reflexive reflexive

Can be Can be Can be


Transitivity
transitive transitive transitive
Properties of Relations –
Symmetric & Antisymmetric
Example :

Are the following relations on {1,2,3,4} symmetric,


antisymmetric, or asymmetric?
Symmetric :
▪𝑅1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}, 𝑅2 and 𝑅3
Symmetric : if have Antisymmetric :
▪𝑅2 = {(1, 1), (1, 2), (2, 1)}, (a,b) MUST have (𝑏, 𝑎)
𝑅4, 𝑅5 and 𝑅6
▪𝑅3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
▪𝑅4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
▪𝑅5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},
Antisymmetric : if have
▪𝑅6 = {(3, 4)}. (a,b) CANNOT have (𝑏, 𝑎)
Properties of Relations –
Symmetric, Antisymmetric, Asymmetric
Example :

Are the following relations on {1,2,3,4} symmetric,


antisymmetric, or asymmetric?
Symmetric :
➢𝑅1 = {(1, 1), (1, 2), (2, 1), (3, 3), (4, 4)} 𝑅1 and 𝑅2
Antisymmetric :
➢𝑅2 = {(1,1)} 𝑅2, 𝑅3 and 𝑅4

➢𝑅3 = {(1, 3), (3, 2), (2, 1)} Asymmetric : Asymmetric :


CANNOT have (𝑎, 𝑎)
𝑅3
➢𝑅4 = {(4, 4), (3, 3), (1, 4)}
Properties of Relations -
Transitive
➢A relation 𝑅 on a set 𝐴 is transitive if
𝑎, 𝑏, 𝑐 ∈ 𝐴, 𝑎, 𝑏 ∈ 𝐴, 𝑏, 𝑐 ∈ 𝐴 → (𝑎, 𝑐) ∈ 𝐴
➢Example :
➢Are the following relations on {1,2,3,4} transitive?

▪𝑅1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
▪𝑅2 = {(1, 1), (1, 2), (2, 1)},
▪𝑅3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
▪𝑅4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
▪𝑅5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},
▪𝑅6 = {(3, 4)}
Properties of Relations - Summary
➢Summary
Property Descriptions
Reflexive Must contain same pairs (a,a)
e.g. (1,1), (2,2), (3,3), (4,4)
Irreflexive NO same pairs (a,b), (b,c)
Symmetric • If (a,b) MUST have (b,a).
• (a,a) is part of symmetric
Antisymmetric • If (a,b) CANNOT have (b,a).
• (a,a) is part of antisymmetric
Asymmetric CANNOT have (a,a)
Transitive If (a,b), (b,c) MUST have (a,c)
Combining Relations
➢Because relations from 𝐴 to 𝐵 are subsets of 𝐴 × 𝐵, two
relations from 𝐴 to 𝐵 can be combined in any way two sets can
be combined.
➢Let 𝐴 = {1, 2, 3} and 𝐵 = {1, 2, 3, 4}. The relations 𝑅1 =
{(1, 1), (2, 2), (3, 3)} and 𝑅2 = {(1, 1), (1, 2), (1, 3), (1, 4)} can be
combined to obtain
➢𝑅1 ∪ 𝑅2 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (3, 3)},
➢𝑅1 ∩ 𝑅2 = {(1, 1)},
➢𝑅1 − 𝑅2 = {(2, 2), (3, 3)},
➢𝑅2 − 𝑅1 = {(1, 2), (1, 3), (1, 4)}.
Combining Relations - Composite
➢There is another way that relations are combined that analogous to the
composition of functions.
➢Let 𝑅 be a relation from a set 𝐴 to a set 𝐵 and 𝑆 a relation from 𝐵 to a set 𝐶.
➢The composite of 𝑅 and 𝑆 is the relation consisting of ordered pairs
(𝑎, 𝑐), where 𝑎 ∈ 𝐴, 𝑐 ∈ 𝐶, and for which there exists an element 𝑏 ∈ 𝐵 such
that (𝑎, 𝑏) ∈ 𝑅 and (𝑏, 𝑐) ∈ 𝑆.
➢We denote the composite of 𝑅 and 𝑆 by 𝑆 ∘ 𝑅
➢𝑆 ∘ 𝑅 is constructed using all ordered pairs in 𝑅 and ordered pairs in 𝑆, where
the second element of the ordered pair in 𝑅 agrees with the first element of
the ordered pair in 𝑆
Combining Relations - Composite
Example :
➢What is the composite of the relations 𝑅 and 𝑆, where

𝑅 is the relation from {1, 2, 3} to {1, 2, 3, 4} with 𝑅 =


{(𝟏, 𝟏), (𝟏, 𝟒), (𝟐, 𝟑), (3,1), (𝟑, 𝟒)}
𝑆 is the relation from {1, 2, 3, 4} to {0, 1, 2} with 𝑆 =
{(𝟏, 𝟎), (2, 0), (𝟑, 𝟏), (𝟑, 𝟐), (𝟒, 𝟏)}?
Solution :
➢The ordered pairs (2, 3) in 𝑅 and (3, 1) in 𝑆 produce the ordered pair
(2, 1) in 𝑆 ∘ 𝑅 .
➢Computing all the ordered pairs in the composite, we find
𝑆 ∘ 𝑅 = {(𝟏, 𝟎), (𝟏, 𝟏), (𝟐, 𝟏), (𝟐, 𝟐), (3, 0), (𝟑, 𝟏)}
Combining Relations - Power
➢The powers of a relation 𝑅 can be recursively defined from the
definition of a composite of two relations.
➢Let 𝑅 be a relation on the set 𝐴. The powers 𝑅𝑛 , 𝑛 = 1, 2, 3, … , are
defined recursively by
𝑅1 = 𝑅 and 𝑅𝑛_1 = 𝑅 𝑛 ◦ 𝑅
The definition shows that
𝑅2 = 𝑅 ∘ 𝑅,
𝑅 3 = 𝑅2 ∘ 𝑅 = (𝑅 ◦ 𝑅) ◦ 𝑅,

and so on.
Combining Relations - Power
Example :
➢Let 𝑅 = {(1, 1), (2, 1), (3, 2), (4, 3)}. Find the powers 𝑅𝑛 , 𝑛 = 2, 3, … .

Solution :
➢𝑅2 = 𝑅 ◦ 𝑅 = 𝑅 2
𝑅 = {(1, 1), (2, 1), (3, 2), (4, 3)}.
𝑅 = {(1, 1), (2, 1), (3, 2), (4, 3)}.
Hence, 𝑅2 = {(1, 1), (2, 1), (3, 1), (4, 2)}.
➢𝑅3 = 𝑅2 ◦ 𝑅
𝑅 2 = {(1, 1), (2, 1), (3, 1), (4, 2)}.
𝑅 = {(1, 1), (2, 1), (3, 2), (4, 3)}.

➢𝑅3 = {(1, 1), (2, 1), (3, 1), (4, 1)}.


Representing Relations Using
Zero – One Matrix
▪𝑅 is a relation from 𝐴 to 𝐵

▪𝐴 = {𝑎1 , 𝑎2 , … , 𝑎𝑚 }

▪𝐵 = {𝑏1 , 𝑏2 , … , 𝑏𝑛 }

▪The relation 𝑅 can be represented by the matrix 𝑀𝑅 = [𝑚𝑖𝑗 ], where

1 𝑖𝑓 𝑎𝑖 , 𝑏𝑗 ∈ 𝑅
𝑚𝑖𝑗 ቐ
0 𝑖𝑓 𝑎𝑖 , 𝑏𝑗 ∉ 𝑅
Representing Relations Using
Zero – One Matrix
Example :

▪Suppose that 𝐴 = {1, 2, 3} and 𝐵 = {1, 2}. Let 𝑅 be the relation from 𝐴 to 𝐵
containing (𝑎, 𝑏) if 𝑎 ∈ 𝐴, 𝑏 ∈ 𝐵, 𝑎𝑛𝑑 𝑎 > 𝑏 . What is the matrix
representing 𝑅 if 𝑎1 = 1, 𝑎2 = 2, and𝑎3 = 3, and 𝑏1 = 1 𝑎𝑛𝑑 𝑏2 = 2?

▪Solution: Because 𝑅 = {(2, 1), (3, 1), (3, 2)}, the matrix for 𝑅 is
0 0
𝑀𝑅 = 1 0
1 1

▪The 1s in 𝑀𝑅 show that the pairs (2, 1), (3, 1), and (3, 2) belong to 𝑅.

▪The 0s show that no other pairs belong to 𝑅.


Representing Relations Using
Zero – One Matrix
▪𝑅 is reflexive if and only if 𝑚𝑖𝑖 = 1, 𝑓𝑜𝑟 𝑖 = 1, 2, … , 𝑛.
In other words, 𝑅 is reflexive if all the elements on the
main diagonal of 𝑀𝑅 are equal to 1. Note that the
elements off the main diagonal can be either 0 or 1.
▪𝑅 is symmetric if and only if 𝑚𝑗𝑖 = 1 whenever 𝑚𝑖𝑗 = 1.
This also means 𝑚𝑗𝑖 = 0 whenever 𝑚𝑖𝑗 = 0 .
Consequently, 𝑅 is symmetric if and only if𝑚𝑖𝑗 = 𝑚𝑗𝑖 , for
all pairs of integers 𝑖 and 𝑗 with 𝑖 = 1, 2, … , 𝑛 and 𝑗 =
1, 2, … , 𝑛
▪ The matrix of an antisymmetric relation has the
property that if 𝑚𝑖𝑗 = 1 with 𝑖 ≠ 𝑗, then 𝑚𝑗𝑖 = 0. Or,
in other words, either𝑚𝑖𝑗 = 0 or 𝑚𝑗𝑖 = 0 when 𝑖 ≠ 𝑗
Representing Relations Using Zero –
One Matrix (Boolean Operations)
▪The Boolean operations join (or) and meet (and) can be used to find
the matrices representing the union and the intersection of two
relations.

▪Suppose that 𝑅1 and 𝑅2 are relations on a set A represented by the


matrices 𝑀𝑅1 and 𝑀𝑅2 respectively
Representing Relations Using Zero –
One Matrix (Boolean Operations)
Example
▪Suppose that the relations 𝑅1 and 𝑅2 on a set 𝐴 are represented by
the matrices

▪What are the matrices representing 𝑅1 ∪ 𝑅2 and 𝑅1 ∩ 𝑅2?


Representing Relations Using
Diagraph
A directed graph, or digraph, consists of :

▪A set V of vertices (or nodes)

▪A set E of edges: ordered pairs of elements of V

▪For edge (a,b)


▪ a: initial vertex

▪ b: terminal vertex

▪Use arrows to display graphs


Representing Relations Using
Diagraph
➢The directed graph with Vertices, V 𝑎, 𝑏, 𝑐, 𝑎𝑛𝑑 𝑑, and
➢Edges, E (𝑎, 𝑏), (𝑎, 𝑑), (𝑏, 𝑏), (𝑏, 𝑑), (𝑐, 𝑎), (𝑐, 𝑏), 𝑎𝑛𝑑 𝑑, 𝑏 .
➢An edge of the form (𝑏, 𝑏) is called a loop
Representing Relations Using
Diagraph
➢Any relation 𝑅 on a set 𝐴 can be represented by the digraph with 𝐴

as its vertices and all pairs (𝑎, 𝑏) ∈ 𝑅 as its edges

➢Any digraph with vertices 𝑉 and edges 𝐸 can be represented by a

relation on 𝑉 containing all the pairs in 𝐸.

You might also like