Graphs and Relations Ann
Graphs and Relations Ann
1
Graphs
2
Graphs
A graph consists of vertices (aka nodes) and edges (aka links, arcs)
between vertices.
1 2 1 2
4 3 4 3
3
Graph notation
4
Edge notation
To denote an edge between vertices u and v (where u and v are two, not
necessarily distinct, vertices), we use di↵erent notation depending on the
type of graph:
5
Graph notation examples
Describe these two graphs using the notation from the previous two
slides.
1 2 1 2
4 3 4 3
6
Some more graph terminology
In an undirected graph:
In a directed graph:
• For a directed edge (u, v ), we call u the tail of the edge, and we call
v the head.
• In a digraph, the in-degree (deg (v )) of a vertex v is the number of
edges of which v is the head, and the out-degree (deg+ (v )) of v is
the number of edges of which v is the tail.
7
Degree examples
1 2 1 2
4 3 4 3
8
Edges and degrees
(Note that this applies even if duplicate edges and loops are present.)
9
Edges and degrees
How about for directed graphs? Describe the relation between the
following quantities:
X X
|E | deg (v ) deg+ (v )
v 2V v 2V
10
Graph applications
11
Connectivity
12
More graph terminology: paths and circuits/cycles
From now on, we’ll assume graphs are simple, that is, they do not have
duplicate edges.
1 2 1 2
4 3 4 3
14
Warning
15
Connectivity in social networks
16
Some special graphs
17
Special graphs
There are many special graphs that have many applications in computer
science, such as:
18
Trees
19
Not a tree
20
Bipartite graphs
When this condition holds, we call the pair (V1 , V2 ) a bipartition of the
vertex set V of G .
21
Bipartite graph example
1 2
4 3
22
Some useful facts
23
Some useful facts
24
Binary relations
25
Binary relations
S ⇥ T = {(s, t) : s 2 S, t 2 T }.
• Notation: (s, t) 2 R or s R t
• Example: Let S = {a, b, c}, T = {1, 2} and
R = {(a, 1), (a, 2), (b, 1), (c, 2)}.
• Representation as a bipartite graph and as a matrix:
26
Binary relations and functions
27
Binary relations on a single set
Examples:
• < relation on R
• “is a family member of” relation on people
• relation on the cardinalities of infinite sets
• “bought the same product as” relation on Amazon customers
• ✓ relation on sets
• ...
28
Properties of relations
A relation R on A is
• reflexive if 8x (xRx)
• symmetric if 8x8y (xRy ) yRx).
• transitive if 8x8y 8z (xRy ^ yRz ) xRz).
Examples:
Set A reals Amazon customers
Relation R < “bought same product” “lives on same address’
reflexive
symmetric
transitive
29
Properties of the ⇢ relation
(a) ⇢ is reflexive.
(b) ⇢ is symmetric.
(c) ⇢ is transitive.
30
One more property
Examples:
Set A integers sets
Relation R < “has same parity” ✓
antisymmetric
31
Properties of binary relations
32
Inverting relations
33
Example: inverting a relation
Example: Let A = {1, 2, 3, 4} and R = {(1, 1), (1, 2), (2, 1), (3, 4)}.
1
• Find R .
• Is R anti-symmetric?
34
Exercise 1: revisiting anti-symmetry
35
51
Composition and powers of relations
8x8y ((x, y ) 2 R R, ).
36
Composition and powers of relations
• R 1 = R,
• R n+1 = R n R for n 1.
37
Example: composition and powers of relations
Example: Let A = {1, 2, 3, 4} and R = {(1, 1), (1, 2), (2, 3), (3, 4)}.
• Find R n for n = 1, 2, 3, . . .
• Is R transitive?
38
Exercise 2: revisiting transitivity
Express the definition for R being transitive using only the following
symbols:
• R, R R, R n (for n = 1, 2, 3, . . .)
• [, \, \, ⇢, ✓, =
39
51
Reviewing binary relations using
their graph representation
40
Graph representation of a binary relation
41
Binary relations and their graph representation
Question:
Let R be represented by the graph above. Which of the following
properties does R have?
42
Composing binary relations
(a) (1,3)
(b) (1,2)
(c) (4,3)
43
Composition and powers of relations
44
Transitivity
R R ✓ R.
45
The transitive closure
46
Transitive closure of a binary relation
(i) R ✓ R trans ,
(ii) R trans is transitive,
(iii) For any transitive relation R 0 on A that contains R, it holds that
R trans ✓ R 0 .
Note that that A ⇥ A always satisfies the two properties! But if (iii)
doesn’t hold, then there is a smaller relation that satisfies them.
In other words, we want the smallest relation that contains all of R, and
that is transitive.
47
Example of transitive closure
Question: Suppose A = {1, 2, 3, 4} and R = {(1, 2), (2, 3), (3, 4)}.
What is R trans ?
48
The connectivity relation
49
Transitive closure and the connectivity relation
50
51
Equivalence Relations
52
Equivalence relations
• = on N
• ⇠P on N, where x ⇠P y i↵ x y is even.
• =1 on N ⇥ N, where (x1 , y1 ) =1 (x2 , y2 ) i↵ x1 = x2 .
53
Equivalence class
54
Partition
Examples:
55
Equivalence classes
56
57
Partial orders
58
Partial orders
59
The graph for a partial order
60