Chapter 4 Relations and Digraphs - PowerPoint PPT Presentation

1 / 139
About This Presentation
Title:

Chapter 4 Relations and Digraphs

Description:

Chapter 4 Relations and Digraphs Weiqi Luo ( ) School of Software Sun Yat-Sen University Email weiqi.luo_at_yahoo.com Office A309 Theorem 2 case #2: if mn ... – PowerPoint PPT presentation

Number of Views:412
Avg rating:3.0/5.0
Slides: 140
Provided by: HFJ
Category:

less

Transcript and Presenter's Notes

Title: Chapter 4 Relations and Digraphs


1
Chapter 4 Relations and Digraphs
  • Weiqi Luo (???)
  • School of Software
  • Sun Yat-Sen University
  • Emailweiqi.luo_at_yahoo.com OfficeA309

2
Chapter Four Relations and Digraphs
  • 4.1 Product Sets and Partitions
  • 4.2 Relations and Digraphs
  • 4.3 Paths in Relations and Digraphs
  • 4.4 Properties of Relations
  • 4.5 Equivalence Relations
  • 4.6 Data structures for Relations and Digraphs
  • 4.7 Operations on Relations
  • 4.8 Transitive Closure and Warshalls Algorithm

3
4.1. Product Sets and Partitions
  • Ordered pair
  • An order pair (a, b) is a listing of objects
    a and b in a prescribed order, which a appearing
    first and b appearing second
  • (a,b) (c,d) ltgt ac
    and bd
  • Product set
  • If A and B are two nonempty sets, we define
    the product set or Cartesian product A B as the
    set of all ordered pairs (a, b) with a ? A and b
    ? B. Thus
  • A B (a, b) a ? A and b ? B

4
4.1. Product Sets and Partitions
  • Example 1 2
  • Let A1, 2, 3 and Br, s
  • then
  • A B (1, r), (1, s), (2, r), (2,
    s), (3, r), (3, s)
  • B A (r, 1), (s, 1), (r, 2), (s,
    2), (r, 3), (s, 3)
  • Note A B is not equal to B A

5
4.1. Product Sets and Partitions
  • Theorem 1 For any two finite, nonempty sets A
    and B, AB AB
  • Proof
  • Suppose A m, Bn. To form an ordered
    pair (a, b), a ? A, and b?B, we must perform two
    successive tasks
  • 1) choose a first element from A (m
    ways)
  • 2) choose a second element from B (n ways)
  • By multiplication principle (Section 3.1).
    There are totally mn ways to form an ordered
    pair (a, b), which means that AB AB
    mn

6
4.1. Product Sets and Partitions
  • Example 3
  • If ABR, the set of all real numbers, then
    RR, also denoted by R2, is the set of all points
    in the plane. The ordered pair (a, b) gives the
    coordinates of a point in the plane

Y
(a, b)
O
X
7
4.1. Product Sets and Partitions
  • Cartesian product
  • A1 A2 Am (a1,a2, ,am) ai ?
    Ai
  • where A1, A2 , , Am are non-empty sets.
  • A1 A2 Am A1 A2 Am
  • where A1, A2 , , Am are finite, nonempty
    sets

8
4.1. Product Sets and Partitions
  • Example 5
  • A manufacture offers the following options
    for its refrigerators
  • Doors side-by-side(s)
    over-under(u) , three (t)
  • Icemaker freezer(f), door(d)
  • Finish standard(r), metallic(m),
    custom(c)
  • Let Ds,u,t If,d and Fr, m, c
  • then the Cartesian product D I F contains
    all the categories that describe refigerator
    options. There are 3 2 318 categories.

9
4.1. Product Sets and Partitions
  • Employees
  • Select Dai1required1, ai2required2,,
    aikrequiredk

Employee ID Last Name Department Years with company
8341 Croft Front Office 2
7984 Cottongim Sales 2
2086 King Human Resources 4
0340 Boswell Research 3


3465 Harris Sales 4
10
4.1. Product Sets and Partitions
  • Partition
  • A partition or quotient set of a nonempty set
    A is a collection B of nonempty subsets of A such
    that
  • 1. Each element of A belongs to one of the
    set in B
  • 2. If A1 and A2 are distinct elements of B,
    then
  • A1 n A2
  • A
  • BA1, A2,
    A3, A4, A5, A6

A1
A2
A3
A4
A6
A5
11
4.1. Product Sets and Partitions
  • Example 6
  • Let Aa, b, c, d, e, f, g, h, consider the
    following subsets of A
  • A1 a, b, c, d A2a, c, e, f, g, h
  • A3 a, c, e, g A4b, d A5f, h
  • Then A1, A2 is not a partition, since A1 n
    A2 is not an empty set. Also A1 , A5 is not a
    partition since e is not in A1 and A5 . The
    collection BA3 A4 A5 is a partition of A

12
4.1. Product Sets and Partitions
  • Homework
  • Ex. 2, Ex. 10, Ex. 17, Ex. 32, Ex. 36, Ex. 37

13
4.2 Relations and Digraphs
  • Relation
  • Let A and B be nonempty sets. A relation R
    from A to B is a subset of A B. If R ? A B
    and (a, b) ? R, we say that a is related to b by
    R, write a R b, if a is not related to b by R, we
    write a b.
  • If A and B are equal. We say that If R ? A
    A is a related on A, instead of a relation from A
    to A.

14
4.2 Relations and Digraphs
  • Example 1
  • Let A 1, 2, 3 and Br, s. Then we define
    R(1, r), (2, s), (3, r) is a relation from A
    to B.
  • Example 2
  • Let A and B be sets of real numbers. We
    define the following relation R(equals) from A to
    B

15
4.2 Relations and Digraphs
  • Example 3
  • Let A1, 2, 3, 4. Define the following
    relation R (less than) on A
  • a R b if and only if altb
  • Then R (1,2) (1,3) (1,4) (2, 3) (2,4)
    (3,4)
  • Example 4
  • Let AZ, the set of all positive integers.
    Define the following relation R on A
  • a R b if and only if a
    divides b
  • Then 4 R 12, 6 R 30, but 5 7 .

16
4.2 Relations and Digraphs
  • Example 5
  • Let A be the set of all people in the world.
    We define the following relation R on A a R b if
    any only if there is a sequence a0, a1, a2, ,an
    of people such that a0a, anb and ai-1 knows ai,
    i1,2,,n (n will depend on a and b)

Small-world network http//en.wikipedia.org/wiki/
Small-world_network
17
4.2 Relations and Digraphs
  • Example 6
  • Let AR, the set of real numbers. We define
    the following relation R on A
  • x R y if and only if x and y satisfy the
    equation
  • x2/4y2/91

18
4.2 Relations and Digraphs
  • Example 9
  • Ci R Cj if and only if the cost of going from
    Ci to Cj defined and less than or equal to 180.

C1 C2 C3 C4 C5
C1 140 100 150 200
C2 190 200 160 220
C3 110 180 190 250
C4 190 200 120 150
C5 200 100 200 150
19
4.2 Relations and Digraphs
  • Sets arising from relations
  • Let R ? A B be a relation from A to B.
  • a) The domain of R
  • Denoted by Dom(R), is the set of all first
    elements in the pairs that make up R. (Dom(R)
    ? A )
  • b) The range of R
  • Denoted by Ran(R), is the set of all second
    elements in the pairs that make up R. (Ran(R)
    ? B )

20
4.2 Relations and Digraphs
  • Example 12
  • Let R be the relation of Example 6
  • then
  • Dom(R) -2, 2 Ran(R) -3, 3

21
4.2 Relations and Digraphs
  • R-relative set of x
  • If R is a relation from A to B and x ? A, we
    define R(x), the R-relative set of x, to be the
    set of all y in B with the property that x is
    R-related to y.
  • R(x) y ? B x R y
  • If A1 ?A, then R(A1), the R-relative set of
    A1, is the set of all y in B with the property
    that x is R-related to y for some x in A1.
  • R(A1) y ? B x R y for some x
    in A1

22
4.2 Relations and Digraphs
  • Example 13
  • Let Aa, b, c, d and let R(a,a), (a,b),
    (b,c), (c,a), (d,c), (c,b). Then
  • R(a) a, b R(b)c
  • If A1c, d, Then
  • R(A1) a, b, c

23
4.2 Relations and Digraphs
  • Let R be the relation of Example 6
  • A1-8, -2) U (2, 8, A2-2, 2 then
  • R(A1) ? , R(A2) -3, 3
  • R(-2)0, R(2)0 , R(0)
    -3, 3

24
4.2 Relations and Digraphs
  • Theorem 1
  • Let R be a relation from A to B, and let A1
    and A2 be subsets of A, then
  • (a) If A1 ? A2, then R(A1) ? R(A2)
  • (b) R(A1 U A2 ) R(A1) U R(A2)
  • (c) R (A1 n A2 ) ? R(A1 ) n R(A2)

25
4.2 Relations and Digraphs
  • (a) If A1 ? A2, then R(A1) ? R(A2)
  • Proof
  • If y ? R(A1), then x R y for some x in A1,
    since A1 ? A2, x ?A2, thus y ? R(A2) and
    therefore
  • R(A1) ? R(A2)

26
4.2 Relations and Digraphs
  • (b) R(A1 U A2 ) R(A1) U R(A2)
  • Proof
  • (1) R(A1 U A2 ) ? R(A1) U R(A2)
  • If y ? R(A1 U A2 ), then x R y for some x in
    A1 U A2, then x in A1 or A2. If x in A1 , y ?
    R(A1) if x in A2 . y ? R(A2). In either cases, y
    ? R(A1) U R(A2) , therefore
  • R(A1 U A2 ) ? R(A1) U
    R(A2)
  • (2) R(A1) U R(A2) ? R(A1 U A2 )
  • A1 ? A1 U A2 , then R(A1) ? R(A1 U A2 )
  • A2 ? A1 U A2 , then R(A2) ? R(A1 U A2 )
  • Thus R(A1) U R(A2) ? R(A1 U A2 )
  • Therefore, we obtain R(A1 U A2 ) R(A1)
    U R(A2)

27
4.2 Relations and Digraphs
  • (c) R (A1 n A2) ? R(A1) n R(A2)
  • Proof
  • If y ? R (A1 n A2 ) , then x R y for some x
    in A1 n A2, since x is in both A1 and A2 , it
    follows that y is in both R(A1) and R(A2) that
    is, y ? R(A1 ) n R(A2). Therefore
  • R (A1 n A2) ? R(A1) n R(A2)
  • Note R(A1) n R(A2) ? R (A1 n A2)

28
4.2 Relations and Digraphs
  • Example 15
  • Let AZ, R be A10,1,2 and A29,13.
    Then R(A1) consists of all integers n such that 0
    n, or 1 n, or 2 n, thus R(A1) 0, 1,
    2,.
  • Similarly R(A2)9, 10, 11,, so
  • R(A1) n R(A2) R(A2)9,10,11,
  • On the other hand, A1 n A2 ? , therefore,
  • R (A1 n A2 ) ?
  • This shows that
  • R(A1 ) n R(A2) ? R (A1 n A2 )

29
4.2 Relations and Digraphs
  • Theorem 2
  • Let R and S be relations from A to B, If R(a)
    S(a) for all a in A, then RS
  • Proof
  • If a R b, then b ? R(a). Therefore, b ? S(a)
    and a S b. A completely similar argument shows
    that, if a S b, then a R b. Thus RS.

30
4.2 Relations and Digraphs
  • The matrix of a Relation
  • If Aa1,a2, am and Bb1,b2,bn are
    finite sets containing m and n elements,
    respectively, and R is a relation from A to B, we
    represent R by the mn matrix MR mij, which is
    defined by
  • mij 1 if
    (ai bj) ? R
  • 0
    otherwise
  • The matrix MR is called the matrix of R.

31
4.2 Relations and Digraphs
  • Example 17
  • Let A 1, 2, 3 and Br, s. Then we define
    R(1, r), (2, s), (3, r) is a relation from A
    to B.
  • Then the matrix of R is

32
4.2 Relations and Digraphs
  • Consider the matrix
  • Since M is 34, we let
  • Aa1,a2,a3 and Bb1,b2,b3,b4
  • Then (ai,bj) in R if and only if mij1, thus
  • R(a1,b1),(a1,b4),(a2,b2),(a2,b3),(a3,b1),(a3,b3

33
4.2 Relations and Digraphs
  • The Digraph of a Relation
  • If A is a finite set, R is a relation on A
    (from A to A)
  • 1) Draw a small circle for each element of A
    and label the circle with the corresponding
    element of A (Vertices)
  • 2) Draw an arrow from vertex ai to vertex
    aj if and only if ai R aj (Edge)
  • The resulting pictorial representation of R
    is called a directed graph or digraphy of R.

34
4.2 Relations and Digraphs
  • Example 19
  • Let A1, 2, 3, 4
  • R(1,1), (1,2), (2,1), (2,2), (2,3), (2,4),
    (3,4), (4,1)

35
4.2 Relations and Digraphs
  • Example 20
  • Find the relation determined by the following
    Figure.
  • R (1,1), (1,3), (2,3), (3,3),
    (3,2), (4,3)

36
4.2 Relations and Digraphs
  • In-/Out- Degree
  • If R is a relation on a set A, and a in A,
    then
  • The in-degree of a relative to the relation R
    is the number of b in A such that (b,a) in R.
  • The out-degree of a is the number of b in A
    such that (a,b) in R

37
4.2 Relations and Digraphs
  • Example 22
  • Let Aa, b, c, d, and R be the relation on
    A that has the matrix Construct the digraph of
    R, and list the in-degrees and out-degrees of all
    vertices

a b c d
2 3 1 1
1 1 3 2
In-degree
Out-degree
38
4.2 Relations and Digraphs
  • If R is a relation on a set A, and B is a subset
    of A, the restriction of R to B is
  • R n (BB)
  • Example 24
  • Let Aa,b,c,d,e,f, R(a,a), (a,c), (b,c),
    (a,e), (b,e), (c,e).
  • Let Ba,b,c, then BB(a,a), (a,b),
    (a,c), (b,a), (b,b), (b,c), (c,a), (c,b), (c,c)
  • and the restriction of R to B is
  • (a, a), (a, c), (b,
    c)

39
4.2 Relations and Digraphs
  • Homework
  • Ex. 2, Ex. 8, Ex.12, Ex.20
  • Ex.24, Ex. 28, Ex. 32

40
4.3 Paths in Relations and Digraphs
  • Suppose that R is a relation on a set A. A path
    of length n in R from a to b is a finite sequence
  • ? a, x1, x2, , xn-1, b
  • beginning with a and ending with b, such that
  • a R x1, x1 R x2, ,xn-1 R b
  • Note A path of length n involves n1
    elements of A, although they are not necessarily
    distinct.

41
4.3 Paths in Relations and Digraphs
  • Example 1
  • Consider the digraph in the following figure.
    Then
  • ?1 1, 2, 5, 4, 3 is a path of
  • length 4 from vertex 1 to 3
  • ?2 1, 2, 5, 1 is a path of
  • length 3 from vertex 1 to itself
  • ?3 2, 2 is a path of length 1 from
  • vertex 2 to itself
  • Cycle a path that begins and ends at the same
    vertex (?2 ?3 )

42
4.3 Paths in Relations and Digraphs
  • If n is a fixed positive integer, we define a
    relation Rn on A as follows x Rn y means that
    there is a path of length n from x to y in R
  • Define a relation R8 on A, by letting x R y mean
    that there is some path in R from x to y. The
    length of such a path will depend on x and y. The
    relation R8 is sometimes called the connectivity
    relation for R.
  • Rn(x) consists of all verities that can be
    reached form x by means of a path in R of length
    n. The set R8 (x) consists of all vertices that
    can be reached from x by some path in R

43
4.3 Paths in Relations and Digraphs
  • Example 2
  • Let A be the set of all living human beings
  • R be the relation of mutual acquaintance
  • a R b means that a and b know one another
  • a R2 b means that a and b have an acquaintance in
    common
  • a Rn b if a knows someone x1, who knows x2, ,
    who knows xn-1, who knows b.
  • a R8 b means that some chain of acquaintances
    exists that begins at a and ends at b.
  • Q It is interesting (and unknown) whether
    every two Americans, say, are related by R8

44
4.3 Paths in Relations and Digraphs
  • Example 3
  • Let A be a set of cities
  • x R y if there is a direct flight from x
    to y on at least one airline.
  • x Rn y if one can book a flight from x to
    y having exactly n-1 intermediate stops
  • x R8 y if one can get from x to y by plane

45
4.3 Paths in Relations and Digraphs
  • Example 5
  • Let Aa,b,c,d,e and R(a,a), (a,b), (b,c),
    (c,e), (c,d), (d,e) Compute (a) R2 (b) R 8

R
46
4.3 Paths in Relations and Digraphs
  • Compute R2
  • a R2 a since a R a and a R a
  • a R2 b since a R a and a R b
  • a R2 c since a R b and b R c
  • b R2 e since b R c and c R e
  • b R2 d since b R c and c R d
  • c R2 e since c R d and d R e
  • Hence
  • R2 (a,a), (a,b), (a,c), (b,e), (b,d),
    (c,e)

47
4.3 Paths in Relations and Digraphs
  • Compute R 8
  • To compute R 8 , we need all ordered pairs
    of vertices for which there is a path of any
    length from the first vertex to the second. We
    can see that from the figure

R8 (a,a), (a,b), (a,c), (a,d), (a,e),
(b,c),(b,d), (b,e), (c,d), (c,e), (d,e) .
R
Note If R is large, it can be tedious and
perhaps difficult to compute R 8
48
4.3 Paths in Relations and Digraphs
  • Boolean Matrix (p.37)
  • A Boolean Matrix is an mn matrix whose
    entries are either 0 or 1.
  • Let Aaij and Bbij be mn matrix Boolean
    matrix.
  • The Join of A and B A V B C cij
  • cij1 if aij1 or
    bij1
  • cij0 otherwise
  • The meet of A and B A B D dij
  • dij1 if aij and
    bij are both 1
  • dij0 otherwise

49
4.3 Paths in Relations and Digraphs
  • Boolean Product (p.38)
  • A aij is an mp Boolean matrix and
  • B bij is a pn Boolean matrix.
  • The Boolean product of A and B, denoted A?B,
    is the m n Boolean matrix Ccij defined by

50
4.3 Paths in Relations and Digraphs
  • Example
  • Let
  • then

51
4.3 Paths in Relations and Digraphs
  • Theorem 5 (p. 39)
  • 1. (a) A V B B V A (b) A B B A
  • 2. (a) (A V B) V C A V (B V C)
  • (b) (A B) C A (B C)
  • 3. (a) A ( B V C) (A B) V (A C)
  • (b) A V (B C) (A V B) (A V C)
  • 4. (A ? B) ?C A ? (B ?C)

52
4.3 Paths in Relations and Digraphs
  • Theorem 1
  • If R is a relation on Aa1,a2,an, then
  • Proof
  • Let MRmij and MR2 nij. By
    definition, the i, j-th element of MR ? MR is
    equal to 1 if only if row i of MR and column j of
    MR has a 1 in the same relative position, say
    position k. This means that mik1 and mkj1 for
    some k, 1 k n.
  • By definition of matrix MR, the
    preceding conditions mean that ai R ak, and ak R
    aj. Thus ai R2 aj, and so nij1.
  • Therefore, position i, j of MR ? MR is 1 if
    and only if nij1.

53
4.3 Paths in Relations and Digraphs
  • Example 6
  • Let A and R be as in Example 5. Then

54
4.3 Paths in Relations and Digraphs
  • Theorem 2
  • For n 2 and R is a relation on a finite
    set A, we have
  • Proof by Mathematical Induction
  • (refer to p.138-139 for more details)

55
4.3 Paths in Relations and Digraphs
  • If R and S are relations on A. the relation R U
    S is defined by x (R U S) y if and only if x R y
    or x R y. It is easy to verify that MRUS MR V MS

56
4.3 Paths in Relations and Digraphs
  • The Reachability relation R of a relation on a
    set A that has n elements is defined as follows
  • x R y means that xy or x R8 y

57
4.3 Paths in Relations and Digraphs
  • Composition
  • Let ?1 a, x1, x2, , xn-1,b be a path in
    relation R of length n form a to b,
  • and ?2 b, y1, y2, , ym-1,c be a path in
    relation R of length m form b to c,
  • then the composition of ?1 and ?2 is the
    path
  • a, x1, x2, , xn-1,b y1, y2, , ym-1,c
    of length nm
  • denoted by ?2 O ?1

58
4.3 Paths in Relations and Digraphs
  • Consider the relation whose digraph is given in
    the following figure and the paths
  • ?1 1, 2, 3 and ?2 3, 5, 6, 2,
    4
  • Then the composition of ?1 and ?2 is the
    path
  • ?2 O ?1 1, 2, 3, 5, 6, 2, 4 from 1 to 4 of
    length 6

59
4.3 Paths in Relations and Digraphs
  • Homework
  • Ex. 2, Ex. 6, Ex. 12, Ex. 18, Ex. 20, Ex. 26

60
4.4 Properties of Relations
  • Reflexive Irreflexive
  • A relation R on a set A is reflexive if (a,
    a)? R for all a ?A. A relation R on a set A is
    irreflexive if a R a for all a? A

Dom(R) Ran(R) A
61
4.4 Properties of Relations
  • Example 1
  • (a) ? (a,a) a ?A
  • Reflexive
  • (b) R (a,b)?AA a ? b
  • Irreflexive
  • (c) A1,2,3 and R(1,1), (1,2)
  • not Reflexive ((2,2) not in R), not Irreflexive
    ((1,1) in R)
  • (d) A is a nonempty set. RØ ? AA, the
    empty relation.
  • not Reflexive, Irreflexive

62
4.4 Properties of Relations
  • Symmetric, Asymmetric Antisymmetric
  • Symmetric if a R b, then b R a
  • Asymmetric if a R b, then b R a (must be
    irreflexive)
  • Antisymmetric if a ? b, a R b or b R a
  • ( if a R b and b R
    a, then ab )
  • not Symmetric some a and b with a R b, but b R
    a
  • not Asymmetric some a and b with a R b, but b R
    a
  • not Antisymmetric
  • some a and b with a ? b, but both a R b and
    b R a

63
4.4 Properties of Relations
  • Example 2
  • Let AZ, the set of integers, and let
  • R (a,b) ?AA a lt b
  • Is R symmetric, asymmetric, or
    antisymmetric?
  • Solution
  • not symmetric if altb then blta is not true.
  • asymmetric if altb, then blta must be true
  • Antisymmetric if a ? b, then altb or blta must be
    true

64
4.4 Properties of Relations
  • Example 4
  • Let A1,2,3,4 and let
  • R(1,2), (2,2), (3,4), (4,1)
  • R is not symmetric, since (1,2) ? R, but (2,1)
    ? R.
  • R is not asymmetric, since (2,2) ? R
  • R is antisymmeric, since if a ? b, either (a,
    b) ? R or (b,a) ? R

65
4.4 Properties of Relations
  • Example 5
  • Let AZ, the set of positive integers, and
    let
  • R(a,b) ?AA a divides b
  • Is R symmetric, asymmetric, or antisymmetric?
  • Solution
  • not symmetric 3 9 but 9 3
  • not asymmetric 2 2
  • antisymmetric if a b and b a, then ab
    (Section 1.4)

66
4.4 Properties of Relations
  • The properties of symmetric matrix
  • The matrix MRmij of a symmetric relation
    on a finite set A a1,a2, ,an satisfies the
    following property
  • if mij1 (ai R aj) then mji1
    (aj R ai)
  • Moreover,
  • if mij0 (ai R aj) then mji0
    (ai R aj)
  • Therefore, we have

67
4.4 Properties of Relations
  • The properties of asymmetric matrix
  • The matrix MRmij of an asymmetric relation
    on a finite set A a1,a2, ,an satisfies the
    following property
  • if mij1 (ai R aj) then
    mji0 (aj R ai)
  • Moreover,
  • if mii0 (ai R ai) for all
    i1,2, ,n

68
4.4 Properties of Relations
  • The properties of antisymmetric matrix
  • The matrix MRmij of an antisymmetric
    relation on a finite set A a1,a2, ,an
    satisfies the following property
  • if i ? j, ( ai ? aj )
  • then mij0 (ai R aj ) or mji0 (aj
    R ai )

69
4.4 Properties of Relations
  • Example 6

Symmetric Not Asymmetic Not Antisymmetric
Symmetric Not Asymmetic Not Antisymmetric
Not Symmetric Not Asymmetic Antisymmetric
70
4.4 Properties of Relations
  • Example 6

Not Symmetric Asymmetic Antisymmetric
Not Symmetric Not Asymmetic Not Antisymmetric
Not Symmetric Not Asymmetic Antisymmetric
71
4.4 Properties of Relations
  • The digraphs of asymmetric relation
  • The digraphs cannot simultaneously have an
    edge from vertex i to vertex j and an edge from
    vertex j to vertex i. This is true even i equals
    j (no cycles). All edges are one-way streets
  • The digraphs of antisymmetric relation
  • For different vertices i and j, there cannot
    be an edge from vertex i to vertex j and edge
    from vertex j to vertex i. When ij, no condition
    is imposed. Thus there may be cycles of length 1,
    but again all edges are one way.

72
4.4 Properties of Relations
  • The digraphs of symmetric relation
  • If there is an edge from vertex i to vertex
    j, then there is an edge from vertex j to vertex
    i. Thus, if two vertex are connected by an edge,
    they must always be connected in both directions.
  • We keep the vertices as they appear in the
    digraph, but if two vertices a and b are
    connected by edges in each direction, we replace
    these two edges with one undirected edge,
    two-way street (Graph of the symmetric
    relation)

73
4.4 Properties of Relations
  • Example 7
  • Let Aa,b,c,d,e and R be the symmetric
    relation given by R(a,b), (b,a), (a,c), (c,a),
    (b,c), (c,b), (b,e), (e,b), (e,d), (d,e), (c,d),
    (d,c)

74
4.4 Properties of Relations
  • Transitive Relations
  • A relation R on a set A is transitive if
    whenever a R b and b R c, then a R c.
  • For instance (Ex. 8)
  • the relation lt on the set of integers
  • If a lt b and b lt c, then we have a lt c
  • Note not Transitive if there exist a, b and c
    in A so that a R b and b R c, but a R c.

75
4.4 Properties of Relations
  • Example 9
  • Let AZ, and R(a,b) ?AA a divides b
  • Is R transitive?
  • Solution
  • Suppose that a R b and b R c, so that a b
    and b c. It then does follow that a c (See
    Theorem 2 of Section 1.4). Thus R is transitive.

76
4.4 Properties of Relations
  • Example 10
  • Let A 1,2,3,4 and let R(1,2),(1,3),(4,2)
  • Is R transitive?
  • Solution
  • Since there are no elements a, b and c in A
    such that a R b and b R c, but a R c, R is
    transitive.

77
4.4 Properties of Relations
  • A sufficient condition of transitive
  • A relation R is transitive if and only if its
    matrix MRmij has the property
  • if mij1 and mjk1, then mik1.
  • the left-hand side means that has
    a 1 in position (i,k). Thus the transitivity of R
    means that if has a 1 in any
    position, then MR must have a 1 in the same
    position.
  • Thus, in particular, if
    , then R is transitive.

78
4.4 Properties of Relations
  • Example 11
  • Let A1,2,3 and let R be the relation on A
    whose matrix is
  • Show that R is transitive.
  • Solution
  • By direct computation,
    , therefore, R is transitive.

79
4.4 Properties of Relations
  • If R is transitive, may not equal to
    MR (Verify the Example 10)

80
4.4 Properties of Relations
  • If R is a transitive relation, and a R b and b R
    c mean that there is a path of length 2 in R from
    a to c, namely a R2 c. Therefore, we may rephrase
    the definition of transitivity as follows
  • If a R2 c, then a R c, that is R2 ?
    R

81
4.4 Properties of Relations
  • Theorem 1
  • A relation R is transitive if and only if it
    satisfies the following property
  • If there is a path of length greater than 1
    from vertex a to vertex b, there is a path of
    length 1 from a to b (that is, a is related to
    b).
  • Algebraically stated, R is transitive if and
    only if Rn ? R for all n gt1
  • How to Proof the Theorem?

82
4.4 Properties of Relations
  • Theorem 2
  • Let R be a relation on a set A, then
  • (a) Reflexivity of R means that a?R(a) for
    all a in A.
  • (b) Symmetry of R means that a?R(b) iff
    b?R(a).
  • (c) Transitivity of R means that if b?R(a)
    and c?R(b), then c?R(a).

83
4.4 Properties of Relations
  • Homework
  • Ex. 2, Ex. 14, Ex. 18, Ex. 26, Ex. 32, Ex. 38

84
4.5 Equivalence Relations
  • Equivalence Relation
  • A relation R on a set A is called an
    equivalence relation if it is reflexive,
    symmetric, and transitive.
  • Example 1
  • Let A be the set of all triangles in the
    plane, and let R be the relation on A defined as
    follow
  • R (a, b) ?AA a is congruent to
    b
  • Therefore, R is an equivalence relation.
  • Q R (a, b) ?AA a is similar to
    b ?

85
4.5 Equivalence Relations
  • Example 2
  • Let A1,2,3,4 and let
  • R(1,1),(1,2), (2,1), (2,2), (3,4), (4,3),
    (3,3), (4,4)
  • R is an equivalence relation.

86
4.5 Equivalence Relations
  • Example 3
  • Let AZ, the set of integers, and let R be
    defined by a R b if and only if altb, is R an
    equivalence relation?
  • Reflexive? Yes, since alta for all a in
    A
  • Symmetric? No, (1, 2) in R but (2,1) is
    not in R
  • Transitive?
  • Yes, since altb and bltc, then we have
    altc
  • Therefore, R is not an equivalence relation.

87
4.5 Equivalence Relations
  • Example 4
  • Let AZ and let R (a, b) ?AA a and b
    yield the same remainder when divided by 2.
  • In this case, we call 2 the modulus and write
  • read a is
    congruent to b mod 2
  • Reflexive
  • Symmetric if , then
    a and b yield the same remainder when divided by
    2, thus
  • Transitive if
    , then a, b and c yield the
    same remainder when divided by 2. Thus

88
4.5 Equivalence Relations
  • Theorem 1
  • Let P be a partition on a set A. Recall that
    the sets in P are called the blocks of P. Define
    the relation A as follows
  • a R b if and only if a and b are member of
    the same block
  • Then R is an equivalence relation on A .
    Proof
  • (a) If a in A, then a is in the same block as
    itself, so a R a
  • (b) If a R b, then a and b are in the same
    block, so b R a
  • (c) If a R b, and b R c, then a , b and c must
    all lie in the same block of P, thus a R c.
  • Note If P is a partition of a set A, then P
    can be used to construct an equivalence on A

89
4.5 Equivalence Relations
  • Example 6
  • Let A1,2,3,4 and consider the partition
    P1,2,3,4 of A. Find the equivalence
    relation R on A determined by P.
  • Solution
  • Based on the Theorem 1, each element in a
    block is related to every other element in the
    same block and only to those elements. Thus,
  • R(1,1), (1,2), (1,3), (2,1), (2,2), (2,3),
    (3,1), (3,2), (3,3), (4,4)

90
4.5 Equivalence Relations
  • P is a partition of A and R is the equivalence
    relation determined by P

  • If a in Ai, i1,26

  • then AiR(a)

  • Lemma 1

  • a R b iff R(a)R(b)

91
4.5 Equivalence Relations
  • Lemma 1 (Note Lemma is a theorem whose main
    purpose is to aid in proving some other theorem)
  • Let R be an equivalence relation on a set A,
    and let a ? A , b ? A. Then
  • a R b if and only if
    R(a)R(b)
  • Proof
  • First, suppose that R(a)R(b).
  • Since R is reflexive, b ? R(b)
  • therefore, b in R(a), so a R b

92
4.5 Equivalence Relations
  • Conversely, suppose that a R b, then
  • (1) b in R(a) by definition. Therefore, since R
    is symmetric
  • (2) a in R(b) by theorem 2 (b) of Section 4.4.
  • To prove R(a)R(b)
  • First, we choose x in R(b), since R is
    transitive, the fact x in R(b) with b in R(a) (1)
    , implies by Theorem 2(c) of Section 4.4 that x
    in R(a). Thus, R(b) ? R(a)
  • Second, support y in R(a). This fact and a in
    R(b) (2) imply. As before, that y in R(b). Thus
    R(a) ? R(b)
  • Therefore, we have R(a) R(b)
  • The Lemma proved.

93
4.5 Equivalence Relations
  • Theorem 2
  • Let R be an equivalence relation on A, and
    let P be the collection of all distinct relative
    sets R(a) for a in A. Then P is a partition of A,
    and R is the equivalence relation determined by
    P.
  • Proof
  • According to the definition of a partition,
    we should show the two following properties
  • (a) Every element of A belongs to some relative
    set
  • (b) If R(a) and R(b) are not identical, then
    R(a) n R(b) ?

94
4.5 Equivalence Relations
  • Property (a) is true, since a ? R(a)
    (reflexivity)
  • Property (b) is equivalent to the following
    statement
  • If R(a) n R(b) ? ?, then R(a) R(b) (p59
    Theorem 2 b)
  • Assume c? R(a) n R(b), then a R c, b R c.
  • then we have c R b (symmetric)
  • a R c, c R b ? a R b (transitivity)
  • Therefore, R(a) R(b) (by lemma 1)

95
4.5 Equivalence Relations
  • Equivalence classes
  • If R is an equivalence relation on A, then
    the sets R(a) (or a) are traditionally called
    equivalence classes of R.
  • The partition P constructed in Theorem 2
    consists of all equivalence classes of R, and
    this partition will be denoted by A/R. (the
    quotients set of A)

96
4.5 Equivalence Relations
  • Example 7
  • Let A1,2,3,4 and let
  • R(1,1),(1,2), (2,1), (2,2), (3,4), (4,3),
    (3,3), (4,4)
  • Determine A/R
  • Solution
  • R(1) 1, 2 R(2) ,
  • R(3) 3, 4 R(4)
  • Hence
  • A/R 1,2 , 3,4

97
4.5 Equivalence Relations
  • Example 8
  • Let AZ and let R (a, b) ?AA a and b
    yield the same remainder when divided by 2.
  • Solution
  • First R(0),-4,-2,0,2,4,, the set of
    even integers, since the remainder is zero when
    each of these numbers is divided by 2.
  • R(1) , -3,-1,0,1,3, , the set of odd
    integers, since the remainder is 1 when divided
    by 2. Hence,
  • A/R consists of the even integers and the set
    of odd integers.

98
4.5 Equivalence Relations
  • The procedure of determining A/R is as follows
  • Support Aa1,a2, (finite or
    countable)
  • Step 1 i0 j0
  • Step 2 ii1
  • Step 3 if ai ? A, then jj1 bjai
  • and compute the equivalence class R(bj ),
    A A- R(bj)
  • Step 4 if A become an empty set, then we
    obtain the equivalence classes R(b1), R(b2),
    R(bj) (Note j may be finite or infinite)
  • otherwise repeat step 2 4

99
4.5 Equivalence Relations
  • Homework
  • Ex. 4, Ex. 12, Ex. 14, Ex. 20, Ex. 23, Ex. 28

100
4.7 Operations on Relations
  • Let R and S be relations from a set A to a set B
  • R and S are subsets of AB. We can use set
    operations on the relations R and S
  • Relations (three representations)
  • 1. the set of ordered pairs (finite or
    infinite)
  • 2. digraph (finite)
  • 3. matrix (finite)

101
4.7 Operations on Relations
  • Complementary relation
  • if and only if a R
    b
  • The intersection R n S
  • a (R n S) b means that a R b and a S b
  • The union R U S
  • a (R U S) b means that a R b or a S b

102
4.7 Operations on Relations
  • Inverse
  • Let R be a relation from A to B, the relation
    R-1 is a relation from B to A (reverse order from
    R) denoted by
  • b R-1 a if and only if a R b
  • Note (R-1) -1R
  • Dom(R-1) Ran (R)
  • Ran(R-1) Dom(R)

103
4.7 Operations on Relations
  • Example 1
  • Let A1,2,3,4 and B a,b,c. We Let
  • R(1,a), (1,b), (2,b),(2,c),(3,b),(4,a)
  • and S (1,b),(2,c),(3,b),(4,b)
  • Compute (a) (b) R n S (c) R U S (d) R-1
  • Solution
  • AB (1,a), (1,b), (1,c), (2,a), (2,b), (2,c),
    (3,a), (3,b),
  • (3,c), (4,a), (4,b), (4,c)

104
4.7 Operations on Relations
  • Example 1
  • RnS (1,b), (3,b), (2,c)
  • R?S (1,a), (1,b), (2,b), (2,c), (3,b),
    (4,a), (4,b)
  • R-1 (a,1), (b,1), (b,2), (c,2), (b,3),
    (a,4)

105
4.7 Operations on Relations
  • Example 2
  • Let AR. Let R be the relation on A and let
    S be
  • Then the complement of R is the relation gt,
    since a b means agtb
  • Similarly, the complement of S is the
    relation lt.
  • On the other hand, R-1S, since for any
    number a and b
  • a R-1 b if and only if b R a if and only
    if b a
  • if and only if a b if and
    only if a S b
  • R n S
  • R U S AA

106
4.7 Operations on Relations
  • Example 3
  • R (a,a), (b,b), (a,c), (b,a), (c,b), (c,d),
    (c,e), (c,a), (b,d), (d,a), (d,e), (e,b), (e,a),
    (e,d), (e,c)
  • R-1 (b,a), (e,b), (c,c), (c,d), (d,d),
    (d,b), (c,b), (d,a), (e,e), (e,a)
  • RnS (a b), (b e) (c c)

107
4.7 Operations on Relations
  • Example 4

108
4.7 Operations on Relations
  • Operations on Boolean Matrix

109
4.7 Operations on Relations
  • Theorem 1
  • Suppose that R and S are relations from A to B
  • (a) If R ? S, then R-1 ? S-1.
  • (b) If R ? S, then S ? R
  • (c) (RnS) -1 R -1 n S -1 and (R U S) -1
    R -1 U S -1
  • (d) (RnS) R U S and R U S R n S

110
4.7 Operations on Relations
  • Theorem 2
  • Let R and S be relations on a set A
  • (a) If R is reflexive, so is R-1
  • (b) If R and S are reflexive, then so are RnS
    and R U S
  • (c) R is reflexive if and only if R is
    irrflexive

111
4.7 Operations on Relations
  • Example 5
  • Let A1,2,3 and consider the two reflexive
    relations
  • R (1,1), (1,2), (1,3), (2,2),
    (3,3)
  • S (1,1), (1,2), (2,2), (3,2),
    (3,3)
  • then R-1 (1,1), (2,1), (3,1), (2,2),
    (3,3) . R and R-1
  • are both reflexive.
  • R (2,1), (2,3), (3,1), (3,2) is
    irreflexive while R is
  • reflexive.
  • RnS (1,1), (1,2), (2,2), (3,3) (reflexive)
  • R?S (1,1), (1,2), (1,3), (2,2), (3,2), (3,3)
    (reflexive)

112
4.7 Operations on Relations
  • Theorem 3 (Homework Ex. 37)
  • Let R be a relation on a set A. Then
  • (a) R is symmetric if and only if RR-1
  • (b) R is antisymmetric if and only if R n R -1
    ? ?
  • (c) R is asymmetric if and only if R n R -1
    Ø

113
4.7 Operations on Relations
  • Theorem 4
  • Let R and S be relations on A
  • (a) If R is symmetric, so are R-1 and R
  • (b) If R and S are symmetric, So R n S and R
    U S

114
4.7 Operations on Relations
  • Example 6
  • Let A1,2,3 and consider the symmetric
    relations
  • R (1,1), (1,2), (2,1), (1,3),
    (3,1)
  • S (1,1), (1,2), (2,1), (2,2),
    (3,3)
  • then
  • (a) R-1 (1,1), (2,1), (1,2), (3,1), (1,3)
    (symmetric)
  • R (2,2), (2,3), (3,2), (3,3)
    (symmetric)
  • (b) RnS (1,1), (1,2), (2,1) (symmetric)
  • R?S (1,1), (1,2), (1,3), (2,1),
    (2,2), (3,1), (3,3)
  • (symmetric)

115
4.7 Operations on Relations
  • Theorem 5
  • Let R and S be relations on A
  • (a) (R n S )2 ? R2 n S2
  • (b) If R and S are transitive, so is R n S
  • (c) If R and S are equivalence relations, so
    is R n S

116
4.7 Operations on Relations
  • Closure
  • If R is a relation on a set A, and R lacks
    some relational properties (e.g. reflexivity,
    symmetry and transitivity) .
  • We try to add as few new pairs as possible to
    R, so that the resulting relation R1 has the
    property we desired.
  • If R1 exists, we call it the closure of R
    with the respect to the property in question.

117
4.7 Operations on Relations
  • Example 8
  • Support that R is a relation on A, and R is
    not reflexive.
  • R1R?? is the smallest reflexive relation on
    A containing R. The reflexive closure of R is
    R??.
  • Example 9
  • Support that R is a relation on A, and R is
    not symmetric.
  • R1 R?R-1 is the smallest symmetric relation
    containing R.
  • (Note (R?R-1)-1 R-1?R )

118
4.7 Operations on Relations
  • The symmetric closure of R
  • R (a,b), (b,c), (a,c), (c,d)
  • R?R-1 (a,b), (b,a) ,(b,c), (c,b), (a,c),
    (c,a), (c,d), (d,c)

119
4.7 Operations on Relations
  • Composition
  • Support A, B and C are sets, R is a relation
    from A to B, and S is a relation from B to C, the
    composition of R and S, written SoR is a relation
    from A to C
  • If a is in A and c is in C, then a SoR c if
    and only if for some b in B, we have a R b, and b
    S c.

120
4.7 Operations on Relations
  • Example 10
  • Let A 1,2,3,4 and R(1,2), (1,1), (1,3),
    (2,4),(3,2) and S(1,4), (1,3), (2,3),(3,1),
    (4,1).
  • Since (1,2) in R, (2,3) in S, we must have
    (1,3) in SoR
  • Similarly, we have
  • SoR (1,4), (1,3), (1,1),(2,1),
    (3,3)

121
4.7 Operations on Relations
  • Theorem 6
  • Let R be a relation from A to B and let S be
    a relation from B to C. Then if A1 is any subset
    of A, we have
  • (SoR)(A1) S(R(A1) )
  • Proof by the definition of composition and
    relative set

122
4.7 Operations on Relations
  • Theorem 7
  • Let A, B, C and D be sets, R a relation from
    A to B, S a relation from B to C and T a relation
    from C to D. Then
  • T o (S o R) (T o S)
    o R
  • Proof by the definition of composition

123
4.7 Operations on Relations
  • Example 13
  • Let Aa, b, R(a, a), (b, a), (b,b) and
    S (a, b), (b, a), (b, b). Then
  • So R(a,b), (b,a), (b,b)
  • Ro S(a,a), (a,b),
    (b,a),(b,b)
  • In general, So R does not equal to Ro S

124
4.7 Operations on Relations
  • Theorem 8
  • Let A, B and C be sets, R a relation from A
    to B, and S a relation from B to C. Then
  • (S o R) -1 R-1 o
    S-1
  • Proof by the definition of composition and
    inverse

125
4.7 Operations on Relations
  • Homework
  • Ex. 5, Ex. 12, Ex. 16, Ex. 22 Ex. 25, Ex. 29,
    Ex. 37

126
4.8 Transitive Closure and Warshalls Algorithm
  • Theorem 1
  • Let R be a relation on a set A. Then R 8 is
    the transitive closure of R
  • Proof
  • R 8 is transitive. a R 8 b , b R 8 c, then a R 8
    c
  • R 8 is the smallest transitive relation
    containing R.
  • Support S is any transitive relation on A,
    and R ? S ,
  • S is transitive ? Sn ? S, for all n (P.146
    Theorem 1)
  • then S 8 S1 U S2 ? S
  • R 8 ? S 8 ? S
    (why?)
  • This means that R 8 is the smallest one.

127
4.8 Transitive Closure and Warshalls Algorithm
  • Example 1
  • Let A1,2,3,4 and let R (1,2), (2,3),
    (3,4), (2,1). Find the transitive closure of R
  • Method 1
  • 1 ? 1, 2, 3, 4
  • 2 ? 1, 2, 3, 4
  • 3 ? 4
  • 4 ? ?
  • R 8 (1,1) , (1,2), (1,3), (1,4), (2,1) ,
    (2,2), (2,3), (2,4), (3,4)

128
4.8 Transitive Closure and Warshalls Algorithm
  • Example 1
  • Method 2

129
4.8 Transitive Closure and Warshalls Algorithm
  • Theorem 2
  • Let A be a set with An, and let R be a
    relation on A. Then
  • Proof
  • If x0 R 8 xm, then there is a path from x0 to
    xm with length m
  • x0, x1, x2,
    , xm
  • case 1 if 1 m n, then x0 Rm xm

130
4.8 Transitive Closure and Warshalls Algorithm
  • Theorem 2
  • case 2 if mgtn, there must have some
    vertex appearing two times in the path (why?),
    saying xi xj, where iltj
  • x0, x1, , xi, , xj, xj1
    xm
  • there must exists another path from x0 to xm
    with length less than m (why?),
  • x0, x1, , xi,
    xj1 xm
  • Therefore, if x0 R 8 xm , we can find the
    shortest path from x0 to xm with length less than
    or equal to n (why?) , namely x0 R k xm 1 k n
  • Therefore, the theorem has been proofed.

131
4.8 Transitive Closure and Warshalls Algorithm
  • Let R be a relation on a set Aa1,a2,,an.
  • Interior vertices
  • If x1,x2,xm is a path in R, then any
    vertices other than x1 and xm are called interior
    vertices of the path.
  • Boolean matrix Wk (n matrices with size
    n-by-n)
  • For 1 k n, Wk has a 1 in position i , j if
    and only if there is a path from ai to aj in R
    whose interior vertices, if any, come from the
    set a1,a2, , ak
  • WnM R 8
  • Since any vertex must come from the set
    a1,a2,,an, it follows that the matrix Wn has a
    1 in position i , j if some path in R connects ai
    with aj

132
4.8 Transitive Closure and Warshalls Algorithm
  • How to compute Wk k1,2,n
  • Let W0MR
  • Support Wk-1sij is known, let Wktij
    then
  • if tij 1, then there must be a path from
    ai to aj whose interior vertices come from the
    set a1,a2, ,ak.
  • Case 1 If ak is not an interior vertex of
    this path, then all interior vertices must
    actually come from the set a1,a2,ak-1, so
    sij1.
  • Case 2 If ak is an interior vertex of this
    path, then sik1 and skj1 (refer to the proof
    of Theorem 2)

P1, P2 are subpaths with all interior
vertices from a1,a2, , ak-1
133
4.8 Transitive Closure and Warshalls Algorithm
  • Warshalls Algorithm
  • Warshalls Algorithm is a more efficient
    algorithm for computing transitive closure, the
    procedure of the algorithm is as follows
  • Step1 First transfer Wk all 1s in Wk-1
  • Step 2 List the locations p1,p2, in column k
    of Wk-1, where the entry is 1 and the locations
    q1,q2, in row k of Wk-1, where the entry is 1
  • Step 3 Put 1s in all the positions pi, qj of
    Wk

134
4.8 Transitive Closure and Warshalls Algorithm
  • Example 2
  • Consider the relation R defined in Example 1.
    Then

pi 2 qj 2
pi 1, 2 qj 1, 2, 3
pi 1, 2 qj 4
pi 1, 2 qj ?
135
4.8 Transitive Closure and Warshalls Algorithm
  • Algorithm WARSHALL
  • 1. CLOSURE ? MAT
  • 2. FOR K1 THRU N
  • a. FOR I1 THRU N
  • 1. FOR J1 THRU N
  • a. CLOSUREI,J ? CLOSUREI,J
  • V (CLOSUREI,K
    CLOSUREK,J )
  • Warshalls Algorithm O(N3)
  • Boolean Matrix operations O(N4)

136
4.8 Transitive Closure and Warshalls Algorithm
  • Theorem 3
  • If R and S are equivalence relations on a set
    A, then the smallest equivalence relation
    containing both R and S is (R U S) 8
  • Proof
  • Reflexive. ? ? R, ? ? S, ? ? R U S ? (R U S) 8
  • Symmetric. RR-1, SS-1, (RUS)-1R-1 U S-1R U S
  • all paths in RUS are two-way streets, and
    it follows from the definitions that (R U S) 8
    must be symmetric (why?)
  • Transitive. (R U S) 8 is the transitive closure
    of R U S (Theorem 1). (the smallest)

137
4.8 Transitive Closure and Warshalls Algorithm
  • Example 3
  • Let A1,2,3,4,5, R(1,1), (1,2), (2,1),
    (2,2), (3,3), (3,4), (4,3), (4,4), (5,5), and S
    (1,1), (2,2), (3,3), (4,4), (4,5), (5,4), (5,5)
    .
  • Find the smallest equivalence relation
    containing R and S, and compute the partition of
    A that it produces

138
4.8 Transitive Closure and Warshalls Algorithm
(R?S)8 (1,1), (1,2), (2,1), (2,2), (3,3),
(3,4), (3,5), (4,3), (4,4), (4,5), (5,3), (5,4),
(5,5
139
4.8 Transitive Closure and Warshalls Algorithm
  • Homework
  • Ex. 1, Ex. 2, Ex. 7, Ex. 13, Ex. 18, Ex. 25
Write a Comment
User Comments (0)
About PowerShow.com