{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

06relations_10

# 06relations_10 - ENGG1007 Foundations of Computer Science...

This preview shows pages 1–7. Sign up to view the full content.

ENGG1007 oundations of Computer Science Foundations of Computer Science Relations Prof. Francis Chin, Dr SM Yiu Sept 24 / 30, 2010 (Chapters 2.1, 2.2, 8) 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
ENGG1007 FCS elations Relations Consider C ={HK, Beijing, Shanghai, Guangzhou, Nanjing} Every city builds roads to its nearest city. This information ( relationship among cities ) can be represented by a set of 2-tuples ( ordered pairs ) R = { (HK, Guangzhou), (Beijing, Nanjing), (Shanghai, Nanjing), (Guangzhou, HK), (Nanjing, Shanghai) } Ordered pairs are used to indicate relationship between 2 objects. . Note that the ordering of the elements are important! 2
ENGG1007 FCS elations nother example Relations Another example A relation can associate objects of one kind with objects of another kind . Example: “Marriage” as a relation. a man in HK; a woman in HK x is a man in HK; y is a woman in HK G is a set of all ordered pairs ( x , y ) where x is a husband of y. John is married to Mary iff (John, Mary) G EG. G = { (John,Mary), (Alex,Cindy), (Joe,Liza) } G is a relation from M (all men in HK) to N (all women in HK) BU CityU CU Eng Sci Med Example: Universities = {BU, CityU, CU, LU, PU, UST, HKU} Programs = {Eng, Sci, Med, Law, Arts, Bus,…} fferings = { ( ityU Eng) (CU Eng) ( olyU Eng) LU PU UST Law Arts Bus 3 Offerings = { (CityU, Eng), (CU, Eng), (PolyU, Eng), (UST, Eng), (HKU, Eng), (CityU, Law), (HKU, Law), (CU, Med), (HKU, Med), …} HKU

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
ENGG1007 FCS artesian Products Cartesian Products The Cartesian product of sets A and B , denoted by A × B , is the set of all ordered pairs ( a , b ) where a A and b B . A × B = { ( a , b ) | a A b B }. xample: Cartesian Products of = 1 2 3}and { Example: Cartesian Products of A = { 1, 2, 3 } and B = { a , b } is A × B = { (1, a ), (1, b ), (2, a ), (2, b ), (3, a ), (3, b ) }. Example: All points in the 2-dimensional space, where A and B are sets of real numbers, R, i.e., R × R or R 2 Relation is a subset of the Cartesian Products Example: Roads Cities × Cities Example: Offerings Universities × Programs 4 Example: A=Students, B=Courses, Enrolment A × B
ENGG1007 FCS otation Notation Given a relation R from A to B, a R b iff ( a , b ) R a is said to be related to b by R A relation on the set A is a relation from A to A. e.g. A = { 1, 2, 3, 4 }. R = { ( a, b ) | a divides b } What are the elements of R ? 1 A x A = { (1,1), (1,2), (1,3), (1,4), (2,1), (2,2), (2,3), (2,4), (3,1), (3,2), (3,3), (3,4), 2 (4,1), (4,2), (4,3), (4,4) } R = { (1,1), (1,2), (1,3), (1,4), 3 4 5 (2,2), (2,4), (3,3), (4,4) } Directed Graph

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
ENGG1007 FCS roperties of Relations eflexive Properties of Relations Reflexive A relation R on a set A is called reflexive if ( a,a ) R for all a A. ( , ) i.e., a A (( a,a ) R ) Example : “same family name” as a relation e.g., (Li Ka Shing, Li Shiu Kee), (Anthony Leung, Leung Oi See) “Best friend” as a relation e.g., (Li Chu Ming, Yeung Shum), (Ma Lik, Choi So Yuk) Everyone is his/her own best friend.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}