Topic 7 - Relation Student should be able to know how

Transcription

Topic 7 - Relation Student should be able to know how
6/4/2015
Learning Outcomes
 Student should be able to know how relation is being
builds.
 Students should be able to apply relation and combine the
knowledge with other topics in this subject.
 Students should be able to use relation in daily lives.
Topic 7 - Relation
2
5. Equivalence relation
1. Basics of relation
 Domain and Range
(Clear / Not Clear)
 Complement and Inverse
2. Relation Representation
 Set representation
 Matrix representation
 Digraph representation
(Clear / Not Clear)
6. Relations Manipulation
 Intersection and union
(Clear / Not Clear)
(Clear / Not Clear)
(Clear / Not Clear)
(Clear / Not Clear)
(Clear / Not Clear)
7. Transitive Closure
 Matrix product
(Clear / Not Clear)
(Clear / Not Clear)
 Warshall Algorithm
3. Concept of degree, path and cycle (Clear / Not Clear)
4. Properties of relations and how to identify it
 Reflexive and Irreflexive
(Clear / Not Clear)
 Symmetric, Asymmetric and Antisymmetric
(Clear / Not Clear)
3
 An ordered pair (a, b) is a listing of object a and b in which a
and b will appear in dedicated order; a appearing first,
followed by b.
 If two sets A and B are nonempty set, its product set (A x B)
or named Cartesian product is a set for ALL (a, b) pairs in
which a  A and b  B.
4
 Example 1:
Let A = {1, 2, 3} and B = {r, s}
So,
A x B = {(1, r), (1, s), (2, r), (2, s), (3, r), (3, s)}
Alternatively, we can arrange the element of A and B in a
tabular array as follows:
 Written as A x B = {(a, b) | a  A and b  B}
B
A
1
r
s
(1,r)
(1,s)
2
(2,r)
(2,s)
3
(3,r)
(3,s)
1
6/4/2015
 Example 2:
Let A = {1, 2, 3} and B = {r, s}
So if
A x B = {(1, r), (1, s), (2, r), (2, s), (3, r), (3, s)}
and
B x A = {(r, 1), (r, 2), (r, 3), (s, 1), (s, 2), (s, 3)}
Example 3:
A marketing research firm classifies a person according to the
following two criteria:
 Gender: male (m); female (f)
 Highest level of education completed: elementary school (e); high
school (h); college (c); graduate school (g)
 Therefore, A x B  B x A
 and |A x B| = |A| x |B|
Find all possible categories that classify a person based on the
gender and highest level of education completed.
Solution to Example 3:
Example 4:
 Let S = {m, f} and L = {e, h, c, g}. The product set S x L
A manufacturer offers the following options for its
refrigerators:
contains all the categories into which the population
classified.
 There are eight categories in this classification scheme.-->
{(m, e), (m, h), (m, c), (m, g), (f, e), (f, h), (f, c), (f, g)}.
 Thus the classification (f, g) represents a female who
completed graduate school.
Doors: side-by-side (s), over-under (o), three (t)
Icemaker: freezer (f), door (d)
Finish: standard (r), metallic (m), custom (c)
Calculate the number of categories that describe refrigerator
options.
Solution: |Doors| x |Icemaker| x |Finish|
= 3 x 2 x 3 = 18 categories.
 A relation between two sets where its value was determined
by a condition. All elements in that relation must fulfill the
condition.
 Let A and B be nonempty set. A relation R from A to B is a
subset of A x B.
 If R  A x B and (a, b)  R, we say that a relates to b through
R and we write as a R b.
Example 6:
Let A = {1, 2, 3, 4, 5}. Define the following relation R (less
than) on A.
Solution:
 R is a relation ‘less than’ on set A.
 Therefore, a R b if and only if a < b
 So R = {(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4),
(3, 5), (4, 5)}
 Example 5:
 Let A = {1, 2, 3} and B = {r, s}.
 Then R = {(1, r), (2, s), (3, r)} is a relation from A to B.
Note: We only list down the subsets of A x A that satisfy relation ‘less
than’
2
6/4/2015
 We can also tabulate the elements of A to identify the subsets
 Example 7: An airline services the five cities c1, c2, c3, c4 and
that satisfy the relation R ‘less than’.
c5. Table below gives the cost (in RM)of going from ci to cj.
 R = {(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3,
To
5), (4, 5)}
From
c1
C1
1
1
c2
c3
c4
c5
140
100
150
200
2
3
4
5
C2
190
(1,2)
(1,3)
(1,4)
(1,5)
C3
110
180
(2,4)
(2,5)
C4
190
200
120
(3,4)
(3,5)
C5
200
100
200
2
(2,3)
3
4
(4,5)
200
160
220
190
250
150
150
 We now define the following relation R on the set of cities
A = {c1, c2, c3, c4, c5}: ci R cj if and only if the cost of
going from ci to cj is defined and less than or equal to RM180.
Find R.
5
13
 Solution: The relation R is the subset of A x A consisting of all
cities (ci, cj), where the cost going from ci to cj is less than or
equal to RM180. Hence:
 R = {(c1, c2), (c1, c3), (c1, c4), (c2, c4), (c3, c1), (c3, c2),
(c4, c3), (c4, c5), (c5, c2), (c5, c4)}
To
From
C1
C1
C2
190
C3
110
C2
C3
C4
C5
100
150
200
200
160
220
190
250
C4
190
200
120
C5
200
100
200
domain and range for the relation.
 Domain for R is elements in set A. That is, Dom(R) is a subset
for A, is the set of all first element in the pairs that make up R
140
180
 When there is a relation from A to B, we can find the
 Range for R is elements in set B. That is, Ran(R) is a subset
for B, is the set of element in B that are second elements of
pairs in R.
150
150
Example 8
 A relation can be represented in three ways:
 Consider Example 6. Let A = {1, 2, 3, 4, 5}. Define the
1.
following relation R (less than) on A.
 So R = {(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3,
4), (3, 5), (4, 5)}
Solution
 Dom(R) is {1, 2, 3, 4}
 Ran(R) is {2, 3, 4, 5}
Set
 Example: R = {(1, r), (2, s), (3, r)}
2.
Matrix
 Matrix representation is only for two finite sets.
First element in
the pair
3.
Digraph
 A geometrical/pictorial representation of relations
Second
element in the
pair
3
6/4/2015
Example 9:
Let R be the relation defined in example 5.
 Example 10: Consider the matrix
MR = 1 0 0 1
 Let A = {1, 2, 3} and B = {r, s} and R = {(1, r), (2, s), (3, r)}
is a relation from A to B.
0 1 1 0
 Then the matrix of R is
 MR =
1 0
1 0
1 0 1 0
 1 if (ai, bj)  R
mij =
And since M is a 3 x 4 matrix, let:
 0 if (ai, bj)  R
0 1
B
r
A
1
A = {a1, a2, a3} and B = {b1, b2, b3, b4}.
Question: Find R.
s
 Solution:
(1,r)
2
(2,s)
3
Based on MR:
(3,r)
R = {(a1, b1), (a1, b4), (a2, b2), (a2, b3). (a3, b1), (a3, b3)}
 In example 10, how do we get
 Consider a relation R from a finite set A to a finite set B
where A = {1, 2, 3, 4} and B = {x, y, z} and
R = {(1,y), (1,z), (3,y), (4,x), (4,z)}
R = {(a1, b1), (a1, b4), (a2, b2), (a2, b3). (a3, b1), (a3, b3)}?
 Build the array tabulation of A and B. Then write value 1 to
 Construct MR
the cell which satisfy MR.
MR = 1 0 0 1
0 1 1 0
1 0 1 0
A = {a1, a2, a3}
The number of ‘1’
in the matrix is
equal to the
number of
ordered pair in R
B
A
b1
a1
1
b3
1
1
b4
1
a2
a3
b2
1
1
B = {b1, b2, b3, b4}
R = {(a1, b1), (a1, b4), (a2, b2), (a2, b3). (a3, b1), (a3, b3)}
22
3. Digraph
 It is normally called a directed graph or digraph of R. Each
 How to draw the digraph in example 11?
1. Draw a small circle for each element of A and label the circle with
the corresponding element of A. These circles are called vertices.
2. Draw an arrow, called an edge, from ai to aj, if and only if ai R aj.
 Example 11:
A = {a, b, c, d}
Given A = {a, b, c, d} and
R = {(a, a), (a, b), (b, a), (b, b) (b, c), (b, d), (c, d), (d, a)}
So, the diagraph of R is shown below:
R = {(a, a), (a, b), (b, a), (b, b) (b, c), (b, d), (c, d), (d, a)}
 Digraph is a geometrical/pictorial representation of relations.
 Works on finite set, and is used only for relation on one set.
element is called vertex and the path is called edge.
The diagraph of R:
b
b
a
a
c
d
c
The arrow
represents
‘relation’
d
23
24
4
6/4/2015
 This is an important concept in relation inspired by the visual
form of digraph.
 For diagraph in example 11, its degrees are:
 If R is a relation on set A and a  A, then in-degree for a is
b
the number of b  A where (b, a)  R.
 Out-degree for a is the number of b  A where (a, b)  R.
a
c
 Note:
d
 The in-degree of a vertex is the number of edges terminating
(going in) the vertex.
 The out-degree of a vertex is the number of edges leaving (going
out) the vertex.
visualise
 To read in-degree and out-degree from matrix.
Example 12: Let A = {a, b, c, d} and R is given below:
MR = 1 0 0 0
Vertex
a
b
c
In-degree
3
2
1
2
Out-degree
2
4
1
1
 Get the in degree and out degree for diagraph below.
Then, write the relation into set and matrix. Read the in
degree and out degree from matrix.
a b c d
a 1 0 0 0
0 1 0 0
b 0 1 0 0
1 1 1 0
c 1 1 1 0
0 1 0 1
d 0 1 0 1
2
1
3
 Note: In-degree is in the column, while out-degree is in the
4
row.
 The answer:
d
Element
a
b
c
d
In-degree
2
3
1
1
Out-degree
1
1
3
2
 Let say R is a relation on set A.
 A path with length n in R from a to b is a finite
sequence,  = a, x1, x2,.... xn-1 , b, which start at a and
ends at b in which
a R x1, x1 R x2 , …., xn-1 R b
 Example 13: Consider this digraph:
1
2
3
5
4




1: 1, 2, 5, 4, 3 is a path length 4 from vertex 1 to vertex 3.
2: 1, 2, 5, 1 is a path length 3 from vertex 1 to itself.
3: 2, 2 is a path length 1 from vertex 2 to itself.
4: 2, 5, 1, 2 is a path length 3 from vertex 2 to itself.
 (visualize)
 Also, path length n will involve n + 1 elements of A,
although they are not necessarily distinct.
1
1
2
2
5
4
1
1
2
5
4
3
3
3
5
4
2
4
5
6/4/2015
To calculate the
path, calculate the
number of edges,
not vertex
 Example 13: Consider this digraph:
1
2
5
4
3




1: 1, 2, 5, 4, 3 is a path length 4 from vertex 1 to vertex 3.
2: 1, 2, 5, 1 is a path length 3 from vertex 1 to itself.
3: 2, 2 is a path length 1 from vertex 2 to itself.
4: 2, 5, 1, 2 is a path length 3 from vertex 2 to itself.
 A path that start and ends at the same vertex is called a cycle.
 2, 3 and 4 are all cycles.
 Paths in a relation R can be used to defined new relations that are quite
useful. If n is a fixed positive integer, we defined relation Rn on A as
follows:
x Rn y means that there is a path of length n from x to y in R.
 For example, x R2 y mean there is a path of length 2 from vertex x to
vertex y.
 3 and 4 are cycle that starts and ends at the same vertex but different
length.
 3 is cycle length 1, respectively. It is clear that paths of length 1 can be
identified with the ordered pairs (x,y) that belong to R. For example
(2,2)
a
Example 14: Consider the following digraph:
b
 We may also defined a relation R on A.
c
d
Compute R2.
 x R y mean that there is some path (of any length) in R
from x to y.
e
Solution:
 The length of the path is depend on x and y.
 List down all path of length 2 (Also remember that path of length n
 The relation R is sometimes called the connectivity relation
involves n + 1 elements of A ):
 a R2 a
 a R2 b
 a R2 c
 b R2 d
 b R2 e
 c R2 e
since
since
since
since
since
since
aRa
aRa
aRb
bRc
bRc
cRd
and
and
and
and
and
and
aRa
aRb
bRc
cRd
cRe
dRe
for R.
(3 elements: a, a, a)
(3 elements: a, a, b)
(3 elements: a, b, c)
(3 elements: b, c, d)
(3 elements: b, c, e)
(3 elements: c, d, e)
 R2 = {(a,a), (a,b), (a,c), (b,d), (b,e), (c,e)}
a
Example 15: Consider the following digraph:
Compute R .
c
d
e
Solution:
 List down all ordered pair of vertices for which there is a path of
any length from the first vertex to the second.
 R = {(a,a), (a,b), (a,c), (a,d), (a,e), (b,c), (b,d), (b,e), (c,d),
(c,e), (d,e)}
a
b
 The set Rn(x) consists of all vertices that can be reached
from x by means of a path in R of length n.
 Find R2(b):
 Solution: R2(b) = {a, d, e}
b
c
d
e
 The set R (x) consists of all vertices that can be reached
from x by some path in R.
 Find R (b):
 Solution: R (b) = {a, c, d, e}
 We can derive the path of length n using set, matrix or
diagraph representation.
6
6/4/2015
 Example 16: Let A = {a, b, c, d, e}
 Example 17: Let A = {a, b, c, d, e}
R = {(a, a), (a, b), (b, c), (c, a), (c, d), (c, e), (d, e)}
R = {(a, a), (a, b), (b, c), (c, a), (c, d), (c, e), (d, e)}
Find all paths with length 2.
Find all paths with length 2.
 Solution:
 Solution:
Using Set:
 Using Matrix: MR =
R2 = {(a, a), (a, b), (a, c), (b, a), (b, d), (b, e), (c, a), (c, b), (c, e)}
1 1 0 0 0
0 0 1 0 0
1 0 0 1 1
a
0 0 0 0 1
b
Advisable to draw
the digraph of R first
before you answer
the question.
c
d
0 0 0 0 0
 Find MR2
e
We can use Boolean product
of MR and MR to get MR2,
where MR2 = MR ⊙ MR.
MR2 = MR ⊙ MR.

MR2
= 1 1 0 0 0
0 0 1 0 0
1 0 0 1 1
1 0 0 1 1
0 0 0 0 1
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
1
0
1
0
0
1
0
0
0
0
0
1
0
0
0
0
1
1
0
0
=
 Reachability is a concept in which there is a relation
between x and y in whatever length possible.
1 1 0 0 0
0 0 1 0 0
= 1
1
1
0
0
R2
⊙
We can use Boolean product
of MR and MR to get MR2,
where MR2 = MR ⊙ MR.
 Written as x R y where x and y have relations.
 Consider Example 13. Identify all x R y.
a
b
c
a
1
1
1
b
1
c
1
1
d
e
1
1
1
d
e
= {(a, a), (a, b), (a, c), (b, a), (b, d), (b, e), (c, a), (c, b), (c, e)}
 List all path length 2 from Exercise 1 using three ways of
representation.
 List all path length 1, 2 and 3 for Example 10 and Example 13.
41
7