You are on page 1of 57

RELATIONS

PreFinal Topic

1
Relations
• Recall the definition of the Cartesian (Cross) Product:
The Cartesian Product of sets A and B, A x B, is the set
A x B = {<x,y> : xA and yB}.

• A relation is just any subset of the CP!!


R  AxB

– Ex: A = students; B = courses.


R = {(a,b) | student a is enrolled in class b}

(#2)
Relations
• Recall the definition of a function:
f = {<a,b> : b = f(a) , aA and bB}

• Is every function a relation?


Yes, a function is
a special kind of
relation.

(#)
Relation
• Abstractly, we define a relation to be a set of ordered pairs.
• Relation of Students to Courses
Student Courses
Bliss Compsci
Sheila IT
Jan Education
Mark HRM
Celestine Criminology
• The relation as a set of ordered pairs.
R={(Bliss, Compsci), (Sheila, IT), (Jan, Education), (Mark,
HRM),(Celestine, Criminology)}

(#)
Digraph
• An informative way to picture a relation on a set
is to draw its digraph.

1
2

3
4

(#)
To Draw a digraph of a relation on a set
X.
1. Draw dots or vertices to represent the elements of X.
2. If the element (x,y) is in the relation, we draw an arrow
(called directed edge) from x to y.
3. Notice that an element of the form (x,x) in a relation
corresponds to a directed edge from x to x. Such an
edge is called a loop.

1
2

3
4

(#)
The relation R to X={a,b,c,d) given by the digraph

• R=(a,a), (b,c), (c,b), (d,d)

(#)
Properties of Relations
• Reflexive:
A relation R on a set X is called reflexive if (x,x)  R for every x  X.

Note:
In words, a relation is reflexive if every element in its domain is
related to itself.
To check whether a relation is reflexive, just check whether (x,x) is
present in R for all x.
Given an arrow diagram, the relation is reflexive if there is a loop at
every vertex.
Ex. The relation R on X={1,2,3,4} R=(1,1)(2,2),(3,3), (4,4)

(#)
Properties of Relations
• Symmetric:
A relation R on a set X is called symmetric
if for al x, y  X, if (x,y)  R then (x,y)  R
.
Note:
In words, a relation is symmetric if whenever x is related to y, then
y is related to x.
To check whether a relation is symmetric, check each member(x,y)
in R to see if (y,x) is also present.
Given an arrow diagram, the relation is symmetric whenever there is
a directed edge from x to y, there is also a directed edge from y to x.

(#)
Properties of Relations
• Transitive:
A relation R on a set X is transitive if for all x,y,z  X, if (x,y) and
(y,z)  R, then (x,z)  R.

Note:
 In words, a relation is transitive if whenever x is related to y and y
is related to z, then x is related to z.
 To check whether a relation is transitive, check all pairs of the
form (x,y), (y,z) with x ≠ y and y ≠ z and then see if (x,z) is also
present.
 Given an arrow diagram, the relation is transitive if whenever there
are directed edges from x to y and from y to z, there is also
directed edge from x to z.
(#)
Properties of Relations
• Anti- symmetric:
A relation R on a set X is anti-symmetric if for all x, y X, if (x,y)  R
and x≠y, then (y,x)  R.

Note:
 In words, a relation is anti-symmetric if whenever x is related to y
and x and y are distinct, then y is not related to x.
 To check whether a relation is anti-symmetric, check each member
(x,y), x≠y, and then see if (y,x) is not present.
 Given an arrow diagram, the relation is anti-symmetric if whenever
there is a diredted edge from x to y, x ≠ y, there is not a directed
edge from y to x.

(#)
Properties of Relations - techniques…
How can we check for transitivity?
Draw a picture of the relation (called a “graph”).
– Vertex for every element of A
– Edge for every element of R

Now, what’s R?
{(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}

1 A “short cut”
2 must be present
for EVERY path
of length 2.
3
4

(#)
Properties of Relations - techniques…
How can we check for the reflexive property?
Draw a picture of the relation (called a “graph”).
– Vertex for every element of A
– Edge for every element of R

Now, what’s R?
{(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}

1 Loops must exist


2 on EVERY vertex.

3
4

(#)
Properties of Relations - techniques…
How can we check for the symmetric property?
Draw a picture of the relation (called a “graph”).
– Vertex for every element of A
– Edge for every element of R

Now, what’s R?
{(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}

1 EVERY edge
2 must have a
return edge.
3
4

(#)
Properties of Relations - techniques…
How can we check for the anti-symmetric
property?
Draw a picture of the relation (called a “graph”).
– Vertex for every element of A
– Edge for every element of R
Now, what’s R?
{(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}

1 No edge can
2 have a return
edge.
3
4

(#)
Properties of Relations - techniques…
Let R be a relation on People,
R={(x,y): x and y have lived in the same country}
?
1 2
?
?
3

Is R transitive? No Is it symmetric? Yes

Is it reflexive? Yes Is it anti-symmetric? No

(#)
Partial Order
• A relation that is reflexive, anti-symmetric and
transitive.

1
2

(#)
More than one relation
Suppose we have 2 relations, R1 and R2,
and recall that relations are just sets!
So we can take unions, intersections,
complements, symmetric differences,
etc.
There are other things we can do as well…

(#)
More than one relation
Let R be a relation from A to B (R  AxB), and let S be a relation
from B to C (S  BxC). The composition of R and S is the relation
from A to C (SR  AxC):
SR = {(a,c):  bB, (a,b)  R, (b,c)  S}
A B C
R S
1 x s
2 y t
3 z u
4 v

SR = {(1,u),(1,v),(2,t),(3,t),(4,u)}

(#)
Inverse of Relations

 Let A = {1, 2, 3, 4} and B = {p, q, r}. Let R = {(1, q), (2, r ), (3, q), (4,
p)}. Then R−1 = {(q, 1), (r , 2), (q, 3), (p, 4)}
 To find R−1, just reverse the directions of the arrows

20
Inverse of Relations

21
Closure
• Consider relation R={(1,2),(2,2),(3,3)} on
the set A = {1,2,3,4}.
• Is R reflexive?
No
What can we add to R to make it reflexive?
(1,1), (4,4)

R’ = {(1,1),(4,4)} is called the


reflexive closure of R.

(#)
Equivalence Relations

a
b

d c
23
Equivalence Relations

24
Equivalence Relations

25
Equivalence Relation
• Ex. List the Equivalence class.

• R={1,1),(1,3),(1,5), (3,1), (3,5), (5,1), (5,3), (5,5),


(2,2), (2,6), (6,2), (6,6), (4,4)} on X={1,2,3,4,5,6} is
an equivalence relation.
• The equivalence class is
[1]=[3]=[5]={1,3,5}, [2]=[6]={2,6}, [4]={4}

26
Equivalence Relation
• Ex. Find the equivalence class of [1].

• R={1,1),(1,3),(1,5), (3,1), (3,5), (5,1), (5,3), (5,5),


(2,2), (2,6), (6,2), (6,6), (4,4)} on X={1,2,3,4,5,6} is
an equivalence relation.
• The equivalence class is
[1]={1,3,5}.

27
Representing relations using digraphs
• A directed graph, or digraph, consists of a set
V of vertices (or nodes) together with a set E
of ordered pairs of elements of V called edges
(or arcs)
• The vertex a is called the initial vertex of the
edge (a,b), and vertex b is called the terminal
vertex of the edge
• An edge of the form (a,a) is called a loop

28
Example
• The directed graph with vertices a, b, c, and d,
and edges (a,b), (a,d), (b,b), (b,d), (c,a), (c,b),
and (d,b) is shown

0 1 0 1
0 1 0 1
MR  
1 1 0 0
 
0 1 0 0

29
Example

0 1 1 1
1 1 0 1 0
M R  0 1 1 M S  
1 0
1 0 0 0
1 1 1  
1 0 0 1

30
Number Theory
• Branch of mathematics concerned with the
integers.

31
Representations of Integers
• Bit- a binary digit, that is 1 or 0. In a digital computer,
data and instructions are encoded as bits.
• Topics to discuss
 Binary Number System-represents integers using
bits.
 Hexadecimal Number System-represents integers
using 16 symbols
 Octal Number System-represents integers using 8
symbols

32
Decimal Number System
• Use 10 symbols 0,1,2,3,4,5,6,7,8 and 9 to
represent integers.
• Representing an integer, the symbol’s position
is significant.
• Reading from the right, the first symbol
represents the number of 1’s, the next symbol
the number of 10’s, the next symbol of 100’s,
and so on.
• Ex. 3854=3·103 + 8·102 +5·101 +4·100
33
Decimal Number System
100’s place(102) 10’s place(101)

1000’s place(103) 1’s place(100)

3854
Symbol 3 Symbol 1

Symbol 2 Symbol 0

• We call the value on which the system is


based(10 in the case of the decimal system) base
of the number system.
34
Binary Number System
• Base 2
• Represent integers need only two symbols the 1 and
0.
• Reading from right, the first symbol represents the
number of 1’s, the next symbol the number of 2’s, the
next symbol the number of 4’s, so on.
• Ex. 1101= 1·23 + 1·22 +0·21 +1·20

35
Decimal Number System
100’s place(22) 10’s place(21)

1000’s place(23) 1’s place(20)

1101
Symbol 3 Symbol 1

Symbol 2 Symbol 0

• We call the value on which the system is


based(10 in the case of the decimal system) base
of the number system.
36
Binary to Decimal
• The binary number 1011012 represents the
number consisting of one 1, one 2, one 4, one 8,
one 16 and one 32. This representation may be
expressed
1011012 = 1·25 + 0·24 + 1·23 + 1·22 +0·21 +1·20
• Computing in decimal
1011012 = 1·32 + 0·16 + 1·8 + 1·4 +0·2 +1·1
= 32+8+4+1=4510

37
Decimal to Binary
• Write the decimal number 130 in binary.
– The computation shows the successive divisions by 2 with the
remainders recorded at the right.
2/130 remainder=0 1’s bit
2/65 remainder=1 2’s bit
2/32 remainder=0 4’s bit
2/16 remainder=0 8’s bit
2/8 remainder=0 16’s bit
2/4 remainder=0 32’s bit
2/2 remainder=0 64’s bit
2/1 remainder=1 128’s bit
0
• We may stop when the quotient is 0. We obtain
13010= 100000102

38
Hexadecimal Number System
• Base 16 or hexadecimal(hex)
• Represent integers we use the symbols
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, and F.
• The symbols A-F are interpreted as decimal
10-15.
• Ex. B4F=11·162 +4·161 +15·160

39
Hexadecimal to Decimal
• Convert the hexadecimal number B4F to
decimal.
• B4F16=11·162 +4·161 +15·160
= 11·256 +4·16 +15
= 2816+64+15
= 289510

40
Decimal to Hexadecimal
• Convert the decimal number 20385 to hexadecimal.
– The computation shows the successive divisions by 16 with the
remainders recorded at the right.
16/20385 remainder=1 1’s place
16/1274 remainder=10 16’s place
16/79 remainder=15 162’s place
16/4 remainder=4 163’s place
0
• We may stop when the quotient is 0. The first remainder
gives the number of 1’s, the second remainder gives the
number of 16’s, and so on; thus we obtain
2038510= 4FA116

41
Binary to Hexadecimal
• Example 3. Consider Binary 11010101
• STEP 1 Break the Byte into 'quartets' -
1101 0101
• STEP 2 Use the table above to covert each
quartet to its Hex equivalent - D5
• Therefore ... 11010101 = D516

42
Hexadecimal to binary
• (1E3)16 = (0001 1110 0011)2
=(111100011)2

43
Binary to Octal
• Starting from the right divide the binary number up in 3
bit sections, then convert each 3 bit section into its
decimal equivalent.
Example: 101001110111012 = 10|100|111|011|101
=247358

44
Octal to Binary
• To convert a given octal number to binary,
write out the octal number in the following
format. We will convert octal 5678:
• Solution: 5678 equals 101 110 1112 Remove
the conversion from the format:
• 1011101112

45
Octal to Decimal
• Convert (765)8 into decimal:

(765)8 = (7 x 82) + (6 x 81) + (5 x 80)

= (7 x 64) + (6 x 8) + (5 x 1)

= 448 + 48 + 5

= 50110

46
Decimal to Octal
• 601 decimal to octal
Divide 600 by 8 = 75 and the remainder is 1
Divide 75 by 8 = 9 and the remainder is 3
Divide 9 by 8 =1 and the remainder is 1
Divide 1 by 8 = 0 and the remainder is 1
Reading from bottom to top 601 decimal is
1131 8.

47
Octal to Hexadecimal
• As an example, converting 12A16 to 4528, follow the steps...
(everything not suffixed is base 16)
12A / 8 is 37 remainder 2
37 / 8 is 4 remainder 5
4 / 8 is 0 remainder 4 - the answer is 4528
Alternatively, since hexadecimal and octal are even multiples of
base 2 or binary, you can convert by writing down the base 16 in
binary, which you can do by inspection, regrouping in groups of 3,
and then converting to base 8.
12A = 0001 0010 1010
000 100 101 010 = 452

48
Hexadecimal to Octal
• Convert the hexadecimal number B4F to
decimal.
• 11216=1·162 +1·81 +2·160
= 1·256 +1·16 +2
= 2816+64+15
= 27410

49
Binary Addition
• Add the binary numbers 10011011 and
1011011.
• We write the problem as
10011011
1011011
11110110

50
Decimal Addition
• Add the binary numbers 155 and 91.
• We write the problem as
155
+ 91
246

51
Hexadecimal Addition
• Add the hexadecimal numbers 84F and 42EA.
• We write the problem as
84F
+ 42EA
4B39

52
Hexadecimal basic concepts:
• Hexadecimal is base 16.
• There are 16 digits in counting (0, 1, 2, 3, 4, 5,
6, 7, 8, 9, A, B, C, D, E, F)
• When you reach 16, you carry a “1” over to
the next column
• The number after F (decimal 15) is 10 in hex
(or 16 in decimal)

53
Use the following steps to perform hexadecimal
addition:
1. Add one column at a time.
2. Convert to decimal and add the numbers.
3a. If the result of step two is 16 or larger
subtract the result from 16 and carry 1 to the
next column.
3b.If the result of step two is less than 16,
convert the number to hexadecimal.

54
Example
The problem:
You are to add these numbers: A C 5 A 9
E D 6 9 4

Carry Over:
1. Add one column at a time A C 5 A 9
2. Convert to decimal & add (9 + 4 = 13) E D 6 9 4
3. Follow less than 16 rule
D
Decimal 13 is hexadecimal D

Carry Over: 1
1. Add next column A C 5 A 9
2. Convert to decimal & add (10 + 9 = 19) E D 6 9 4
3. Follow 16 or larger than 16 rule
3 D
(19 – 16 = 3 carry a 1)

Carry Over: 1
1. Add next column A C 5 A 9
2. Convert to decimal & add (1 + 5 + 6 = 12) E D 6 9 4
3. Follow less than 16 rule, convert to hex
C 3 D
Decimal 12 is hexadecimal C

55
Cont.
Carry Over: 1
1. Add next column A C 5 A 9
2. Convert to decimal & add (12 + 13 = 25) E D 6 9 4
3. Follow 16 or larger than 16 rule
9 C 3 D
(25 – 16 = 9 carry a 1)

Carry Over: 1
1. Add next column A C 5 A 9
2. Convert and add (1 + 10 + 14 = 25) E D 6 9 4
3. Follow 16 or larger than 16 rule
9 9 C 3 D
(25 – 16 = 9 carry a 1)

Carry Over: 1
1. Add next column 0 A C 5 A 9
2. Convert and add (1 + 0 + 0 = 1) 0 E D 6 9 4
3. Follow less than 16 rule
1 9 9 C 3 D

56
Octal Addition
• We write the problem as
11

2347
+ 1251
3620

57

You might also like