1. Trang chủ
  2. » Tất cả

17 representing relations quan hệ đại diện

28 4 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 28
Dung lượng 868,5 KB

Nội dung

PowerPoint Presentation Representing Relations Epp section ??? CS 202 Aaron Bloomfield In this slide set Matrix review Two ways to represent relations Via matrices Via directed graphs Matrix review We[.]

Representing Relations Epp section ??? CS 202 Aaron Bloomfield In this slide set… • Matrix review • Two ways to represent relations – Via matrices – Via directed graphs Matrix review • We will only be dealing with zero-one matrices – Each element in the matrix is either a or a 1 0  1  1 0 0 1 0 0 0  0 • These matrices will be used for Boolean operations – is true, is false Matrix transposition • Given a matrix M, the transposition of M, denoted Mt, is the matrix obtained by switching the columns and rows of M  3 M      4 M t  5  6 • In a “square” matrix, the main diagonal stays unchanged  4  8  M   10 11 12   13 14 15 16 1 2 M t  3  4 13 10 14 11 15  12 16 Matrix join • A join of two matrices performs a Boolean OR on each relative entry of the matrices – Matrices must be the same size – Denoted by the or symbol:  1 0  1  1 0 0 1 0 0  0  0 0 0  0  1 1 1 1 0  1 0   1    0  1 1 1 0 0 1  0 Matrix meet • A meet of two matrices performs a Boolean AND on each relative entry of the matrices – Matrices must be the same size – Denoted by the or symbol:  1 0  1  1 0 0 1 0 0  0  0 0 0  0  1 1 1 1 0  0   1    0  1 0 0 0 0 0  0 Matrix Boolean product • A Boolean product of two matrices is similar to matrix multiplication c1,1 a1,1 * b1,1  a1, * b2,1  a1,3 * b3,1  a1, * b4,1 – Instead of the sum of the products, it’s the conjunction (and) of the disjunctions (ors) c1,1 a1,1  b1,1  a1,  b2,1  a1,3  b3,1  a1,  b4,1 – Denoted by the or symbol:  1 0  1  1 0 0 1 0 0 0  0 0 0  0  1 1 1 1 0  0   1    0  1 1 0 0 1  1 Relations using matrices • List the elements of sets A and B in a particular order – Order doesn’t matter, but we’ll generally use ascending order • Create a matrix M R [mij ] 1 if (ai , b j )  R mij  0 if (ai , b j )  R Relations using matrices • Consider the relation of who is enrolled in which class – Let A = { Alice, Bob, Claire, Dan } – Let B = { CS101, CS201, CS202 } – R = { (a,b) | person a is enrolled in course b } CS101 CS201 CS202 Alice Bob X X X X X Claire Dan 1 0 M R  0  0 1 0 1 0  1 Relations using matrices • What is it good for? – It is how computers view relations • A 2-dimensional array – Very easy to view relationship properties • We will generally consider relations on a single set – In other words, the domain and co-domain are the same set – And the matrix is square 10 Asymmetry • Consider an asymmetric relation: < – One which if a is related to b then b is not related to a for all (a,b) • If, for every value and the – Let A = { 1, 2, 3, 4, } 0 0  M    0  0 1 0 1 1 1 1  1 0 0 value in its transposed position, if they are not both 1, then the relation is asymmetric • An asymmetric relation must also be irreflexive • Thus, the main diagonal must be all 0’s 14 Antisymmetry • Consider an antisymmetric relation: ≤ – One which if a is related to b then b is not related to a unless a=b for all (a,b) • If, for every value – Let A = { 1, 2, 3, 4, } and the value in its transposed position,  1 1 1 if they are not both 1,  1 1   then the relation is M   0 1 1 antisymmetric   0 1 • The center diagonal    0 0 1 can have both 1’s and 0’s 15 Transitivity • Consider an transitive relation: ≤ – One which if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) – Let A = { 1, 2, 3, 4, } • If, for every spot (a,b) and (b,c) that each  1 1 1  1 1 have a 1, there is a   at (a,c), then the M   0 1 1 relation is transitive    0 1  0 0 1 • Matrices don’t show this property easily 16 Combining relations: via Boolean operators • Let:  1 M R  0  0 • Join: M R S • Meet: M R S  1 M S  1  0 1 M R  M S 1 1 1 M R  M S   0 1 1 0 1 0 0 17 Combining relations: via relation composition d • Let: e f  1 M R b  0 c  0 a g h i  1 M S e  1 f  0 d g h i  1 M R  M S  b  1 c  0 a M S R • But why is this the case? 18 Representing relations using directed graphs • A directed graph consists of: – A set V of vertices (or nodes) – A set E of edges (or arcs) – If (a, b) is in the relation, then there is an arrow from a to b • Will generally use relations on a single set • Consider our relation R = { (a,b) | a divides b } • Old way: 1 2 3 4 19 Reflexivity • Consider a reflexive relation: ≤ – One which every element is related to itself – Let A = { 1, 2, 3, 4, } If every node has a loop, a relation is reflexive 20

Ngày đăng: 02/04/2023, 06:08

w