ECE750 Lecture 6: Binary Relations and Graph Algorithms: Electrical & Computer Engineering University of Waterloo Canada
ECE750 Lecture 6: Binary Relations and Graph Algorithms: Electrical & Computer Engineering University of Waterloo Canada
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
ECE750 Lecture 6: Binary relations and
graph algorithms
Todd Veldhuizen
[email protected]
Electrical & Computer Engineering
University of Waterloo
Canada
Oct. 19, 2007
1 / 1
ECE750 Lecture 6:
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
Binary Relations I
[a]
: a X
X/ is a partition. (Recall that a partition of a set X
is a collection of subsets Y
1
, . . . , Y
k
of X that are
pairwise disjoint and satisfy
Y
i
= X.)
= 1, 6, 11, 16, . . ..
and [b]
,
then using equality.
Interface:
e
a
d
b
b
b
b
b
f
e
a
a
a
a
a
d
e
a
a
a
a
a
c
0 1 1 0
0 0 0 1
0 0 0 1
0 0 0 0
b
d
a
20 / 1
ECE750 Lecture 6:
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
Representation of Graphs III
Note that we can read some properties of the graph
from this matrix:
If A = A
T
, the graph is symmetric.
22 / 1
ECE750 Lecture 6:
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
Depth-First Search I
Example: let V = N
2
(pairs of natural numbers), and
for all i , j , put edges (i , j ) (i + 1, j ) and
(i , j ) (i , j + 1):
.
.
.
.
.
.
.
.
.
Then the transitive reexive closure of this graph is a
partial order _ where (i , j ) _ (i
, j
) if and only if i i
and j j
:
(2, 0) (1, 1) (0, 2)
(1, 0)
s
s
s
s
s
u
u
u
u
u
(0, 1)
u
u
u
u
u
s
s
s
s
s
(0, 0)
s
s
s
s
s
u
u
u
u
u
28 / 1
ECE750 Lecture 6:
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
Topological Sort III
One way to extend _ to a total order is:
.
.
.
f
f
f
f
f
f
f
f
c
c
c
c
c
c
f
f
f
f
c
c
c
(This is one method for what computer scientists call
dovetailing.)
Other examples:
Solving equations
Makeles
with Y Y
, Y = Y
e
q
The connected components are {{a, b, g, q}, {c, d, e}}.
34 / 1
ECE750 Lecture 6:
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
Connected components of undirected graph II
(x
1
z
1
)
2
+ (x
2
z
2
)
2
We can dene distances in graphs in such a way that
they share many of the useful properties of Euclidean
distance.
A distance metric d : V
2
R satises:
1. d(x, y) 0
2. d(x, y) = 0 if and only if x = y
3. d(x, y) = d(y, x) (symmetry)
4. d(x, y) + d(y, z) d(x, z) (triangle inequality)
37 / 1
ECE750 Lecture 6:
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
Distance metric on graphs II
If the symmetry axiom (3) is omitted, d is called a
quasimetric. (For weighted directed graphs, a
quasimetric may be appropriate.)
In R
2
we can dene open and closed discs:
(x, y) :
x
2
+ y
2
< r
(x, y) :
x
2
+ y
2
r
38 / 1
ECE750 Lecture 6:
Binary relations
and graph
algorithms
Todd Veldhuizen
[email protected]
Distance metric on graphs III