cse 311 foundations of computing
play

CSE 311: Foundations of Computing Fall 2014 Lecture 20: Relations - PowerPoint PPT Presentation

CSE 311: Foundations of Computing Fall 2014 Lecture 20: Relations and Directed Graphs Relations Let A and B be sets, A binary relation from A to B is a subset of A B Let A be a set, A binary relation on A is a subset of A A Relations


  1. CSE 311: Foundations of Computing Fall 2014 Lecture 20: Relations and Directed Graphs

  2. Relations Let A and B be sets, A binary relation from A to B is a subset of A × B Let A be a set, A binary relation on A is a subset of A × A

  3. Relations You Already Know! ≥ on ℕ That%is:%{(x,y)%:%x% ≥ %y%and%x,%y% ∈ % ℕ }% < on ℝ That%is:%{(x,y)%:%x%<%y%and%x,%y% ∈ % ℝ }% = on ∑ * %That%is:%{(x,y)%:%x% = %y%and%x,%y% ∈ % ∑ *}% ⊆ on P(U) for universe U That%is:%{(A,B)%:%A% ⊆ %B%and%A,%B% ∈ %P(U)}%

  4. Relation Examples R 1 = {(a, 1), (a, 2), (b, 1), (b, 3), (c, 3)} R 2 = {(x, y) | x ≡ y (mod 5) } R 3 = {(c 1 , c 2 ) | c 1 is a prerequisite of c 2 } R 4 = {(s, c) | student s had taken course c }

  5. Properties of Relations Let R be a relation on A. R is reflexive iff (a,a) ∈ R for every a ∈ A R is symmetric iff (a,b) ∈ R implies (b, a) ∈ R R is antisymmetric iff (a,b) ∈ R and a ≠ b implies (b,a) ∉ R R is transitive iff (a,b) ∈ R and (b, c) ∈ R implies (a, c) ∈ R

  6. Combining Relations Let R be a relation from A to B. Let S be a relation from B to C. The composition of R and S, S ∘ R is the relation from A to C defined by: S ∘ R = { (a, c) | ∃ b such that (a,b) ∈ R and (b,c) ∈ S } Intuitively, a pair is in the composition if there is a “connection” from the first to the second.

  7. Examples (a,b) ∈ Parent iff b is a parent of a (a,b) ∈ Sister iff b is a sister of a When is (x,y) ∈ Sister Parent? When%there%is%a%person%z,%where%(x,%z)% ∈ %Parent%and%(z,%y)% ∈ %Sister.% That%is,%z%is%a%parent%of%x,%and%y%and%z%are%sisters.%%Or,%y%is%x’s%Aunt.% When is (x,y) ∈ Parent Sister? When%there%is%a%person%z,%where%(x,%z)% ∈ %Sister%and%(z,%y)% ∈ %Parent.% That%is,%z%and%x%are%sisters,%and%y%is%a%parent%of%z.%%Or,%y%is%x’s% parent.% S ∘ R = {(a, c) | ∃ b such that (a,b) ∈ R and (b,c) ∈ S}

  8. Examples Using the relations: Parent, Child, Brother, Sister, Sibling, Father, Mother, Husband, Wife express: Uncle: b is an uncle of a (a,b) ∈ * (Brother ◦ Parent � Husband ◦ Sibling ◦ Parent) Cousin: b is a cousin of a (a,b) ∈ * (Child ◦ Sibling ◦ Parent)

  9. Powers of a Relation Let%R%be%a%relaJon%on%A.% % R 2 %=%R%◦%R%=%{(a,%c)%:% ∃ b%((a,b)% ∈ %R%and%(b,%c)% ∈ %R% % R 0 %=%{(a,%c)%:%a%% ∈ %A}%=%A% % R 1 %=%{(a,%b)%:%(a,%b)% ∈ %R}%=%R% % R n+1 %=%R n %◦%R%

  10. Matrix Representation Let R be a relation on A={a 1 , a 2 , …, a p }. {(1, 1), (1, 2), (1, 4), (2,1), (2,3), (3,2), (3, 3), (4,2), (4,3)} 1" 2" 3" 4" 1" 1% 1% 0% 1% 2" 1% 0% 1% 0% 3" 0% 1% 1% 0% 4" 0% 1% 1% 0%

  11. Directed Graphs G%=%(V,%E)% V%–%verJces% E%–%edges,%ordered%pairs%of%verJces%% Path:%%v 0 ,%v 1 ,%…,%v k ,%with%(v i ,%v i+1 )%in%E% % Simple%Path% Cycle% Simple%Cycle%

  12. Representation of Relations Directed Graph Representation (Digraph) {(a, b), (a, a), (b, a), (c, a), (c, d), (c, e) (d, e) } b c a d e

  13. Relational Composition using Digraphs If ! = {( 2,2 ) ,* ( 2,3 ) ,* ( 3,1 )} and & ={ ( 1,2 ) , ( 2,1 ) , ( 1,3 ) } Compute ! ∘ & (1, 2) ∈* R and (2, 2) ∈* S means (1, 2) % ∈* S %◦% R % (1, 2) ∈* R and (2, 3) ∈* S means (1, 3) % ∈* S %◦% R (2, 1) ∈* R and (2, 2) ∈* S means (2, 2) % ∈* S %◦% R %

  14. Paths in Relations and Graphs A%path%in%a%graph%of%length%n%is%a%list%of%edges%with%verJces% next%to%each%other. % Let%R%be%a%relaJon%on%a%set%A.%%There%is%a%path%of%length%n%from% a%to%b%if%and%only%if%(a,b)% ∈ %R n%

  15. Connectivity In Graphs Two%verJces%in%a%graph%are%connected%iff%there%is%a%path%between% them.% Let%R%be%a%relaJon%on%a%set%A.%%The%connecJvity%relaJon%R*% consists%of%the%pairs%(a,b)%such%that%there%is%a%path%from%a%to%b% in%R.% Note:%%The%text%uses%the%wrong%definiJon%of%this%quanJty.% What%the%text%defines%(ignoring%k=0)%is%usually%called%R +%

  16. Properties of Relations (again) Let R be a relation on A. R is reflexive iff (a,a) ∈ R for every a ∈ A R is symmetric iff (a,b) ∈ R implies (b, a) ∈ R R is transitive iff (a,b) ∈ R and (b, c) ∈ R implies (a, c) ∈ R

  17. Transitive-Reflexive Closure Add%the%minimum%possible%number%of%edges%to%make%the%relaJon%transiJve%and% reflexive.% The%transiJve`reflexive%closure%of%a%relaJon%R%is%the%connecJvity%relaJon%R*%

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend