Graph Theory
undirected grapha
b c
e f
d
node: a, b, c, d, e, fedge: (a, b), (a, c), (b, c), (b, e), (c, d), (c, f), (d, e), (d, f), (e, f)
a
b c
e d
subgraph
adjacency matrix:
A
abcdef
a b c d e f
0 1 1 0 0 01 0 1 0 1 01 1 0 1 0 10 0 1 0 1 10 1 0 1 0 10 0 1 1 1 0
a
b c
e f
d
directed graph ( digraph)
a b
d c
Aabcd
a b c d
0 1 0 00 0 1 10 0 0 01 0 1 0
weighted graph
v0 v1
v4 v2
v3
6
53
8
9
1 4
7
weight matrix
01234
0 1 2 3 40 6 0 8 16 0 5 3 00 5 0 4 78 3 4 0 91 0 7 9 0
a
b c
e f
d
pathcycle
C
1 1 1 11 1 1 10 0 1 01 1 1 1
connectivity matrix CCjk= 1 if there is a path of length 0 or more from vj to vk
0 otherwiseC: reflexive and transitive closure of G.
a b
d c
How to compute the connectivity matrix?Matrix multiplication
﹡ → (AND)+ → (OR)e. g. Z = X‧Y
Zij= (xi1y1j)(xi2y2j)…(xinynj)
the algorithm:matrix B
bjk=ajk for jkbjj=1
that is,
bjk=1 if there is a path of length 0 or 1 from vj to vk vj to vk 0 otherwiseB2 represents paths of length 2 or less.B4
…Bn
B
1 1 0 00 1 1 10 0 1 01 0 1 1
B B2 4
1 1 1 11 1 1 10 0 1 01 1 1 1
complexity: O(logn) matrix multiplications
a b
d c
Aabcd
a b c d
0 1 0 00 0 1 10 0 0 01 0 1 0
Connected components
v5v0
v1
v3
v2
v4
Assign each vertex a component number which is the smallest vertex label in the same component.
Step 1: Compute the connectivity matrix.
1 1 0 0 0 11 1 0 0 0 10 0 1 1 0 00 0 1 1 0 00 0 0 0 1 01 1 0 0 0 1
Step 2: In each row, find the smallest label. component 0: v0, v1, v5 component 2: v2, v3
component 4: v4
complexity: same as that for computing the connectivity matrix.e. g. on hypercubes
time: O(log2n)processor: n3
All pairs shortest path
v0
v2
v1
6
4
2113A
0 4 116 0 23 0
a sequential method — dynamic programming
aijk
for k=0 to n-1 do for i=0 to n-1 do for j=0 to n-1 do
111,min kkj
kik
kij
kij aaaa
: the length of a shortest path from vi to vj going through no vertex of label greater than k.
kjikijij aaaa ,min
A 00 4 116 0 23 7 0
A 10 4 66 0 23 7 0
073205640
2A ←shortest pathstime: O(n3)
v0
v2
v1
6
4
2113 A
0 4 116 0 23 0
a parallel method matrix multiplication an algorithm similar to
that computes the connectivity matrix.
d d dijk
l ilk
ljk min / /2 2
in matrix multiplication:* → + + →min
We can compute D1, D2, D4, D8,…, Dn.complexity: O(log n) matrix multiplicationse.g. on hypercubes
time: O(log2n)processor: n3
Minimum spanning trees
1
3
62
9
1 6
9
1 2
9