Graph Theory
Graph Theory
Ma/CS 6b
Class 12: Graphs and Matrices
𝑣1
0 1 0 0 1
1 0 1 0 3
𝑣5 𝑣2
0 1 0 1 0
0 0 1 0 1
1 3 0 1 0
𝑣4 𝑣3
By Adam Sheffer
Non-simple Graphs
In this class we allow graphs to be non-
simple.
We allow parallel edges, but not loops.
1
2/1/2015
Incidence Matrix
Consider a graph 𝐺 = 𝑉, 𝐸 .
◦ We order the vertices as 𝑉 = 𝑣1 , 𝑣2 , … , 𝑣𝑛
and the edges as 𝐸 = 𝑒1 , 𝑒2 , … , 𝑒𝑚
◦ The incidence matrix of 𝐺 is an 𝑛 × 𝑚 matrix
𝑀. The cell 𝑀𝑖𝑗 contains 1 if 𝑣𝑖 is an endpoint
of 𝑒𝑗 , and 0 otherwise. 𝑣1
𝑒1
1 0 0 0 0 0 𝑒2
0 1 1 0 0 1 𝑣5 𝑣2
0 0 0 0 1 1 𝑒3
0 0 0 1 1 0 𝑒4 𝑒6
1 1 1 1 0 0 𝑒5
𝑣4 𝑣3
𝑒1 𝑣1
1 0 0 0 0 0
𝑒2
0 1 1 0 0 1 𝑣5 𝑣2
𝑀= 0 0 0 0 1 1 𝑒3
𝑒4 𝑒6
0 0 0 1 1 0 𝑒5
1 1 1 1 0 0 𝑣4 𝑣3
2
2/1/2015
Adjacency Matrix
Consider a graph 𝐺 = 𝑉, 𝐸 .
◦ We order the vertices as 𝑉 = 𝑣1 , 𝑣2 , … , 𝑣𝑛 .
◦ The adjacency matrix of 𝐺 is a symmetric
𝑛 × 𝑛 matrix 𝐴. The cell 𝐴𝑖𝑗 contains the
number of edges between 𝑣𝑖 and 𝑣𝑗 .
𝑣1
0 1 0 0 1
1 0 1 0 3
𝐴= 𝑣5 𝑣2
0 1 0 1 0
0 0 1 0 1
1 3 0 1 0
𝑣4 𝑣3
A Connection
Problem. Let 𝐺 = 𝑉, 𝐸 be a graph with
incidence matrix 𝑀 and adjacency matrix
𝐴. Express 𝑀𝑀𝑇 using 𝐴.
Answer. This is a 𝑉 × 𝑉 matrix.
◦ 𝑀𝑀𝑇 𝑖𝑖 is the degree of 𝑣𝑖 .
◦ 𝑀𝑀𝑇 𝑖𝑗 for 𝑖 ≠ 𝑗 is number of edges
between 𝑣𝑖 and 𝑣𝑗 .
◦ Let 𝐷 be a diagonal matrix with 𝐷𝑖𝑖 being the
degree of 𝑣𝑖 . We have
𝑀𝑀𝑇 = 𝐴 + 𝐷.
3
2/1/2015
2 0 0
Example 𝐷= 0 4 0
0 0 4
0 1 1
𝐴= 1 0 3 𝑣1
1 3 0
1 1 0 0 0
𝑀= 1 0 1 1 1 𝑣3 𝑣2
0 1 1 1 1
2 1 1
𝑇
𝑀𝑀 = 1 4 3 = 𝐴 + 𝐷
1 3 4
Multiplying by 1’s
Let 1𝑛 denote the 𝑛 × 𝑛 matrix with 1 in
each of its cells.
Problem. Let 𝐺 = 𝑉, 𝐸 be a graph with
adjacency matrix 𝐴. Describe the values
in the cells of 𝐵 = 𝐴1 𝑉 .
Answer. It is a 𝑉 × 𝑉 matrix.
◦ The column vectors of 𝐵 are identical.
◦ The 𝑖’th element of each column is the degree
of 𝑣𝑖 .
4
2/1/2015
What about 𝑀3 ?
Let 𝐴 be the adjacency matrix of a simple
graph 𝐺 = 𝑉, 𝐸 . For 𝑖 ≠ 𝑗:
◦ 𝐴𝑖𝑗 tells us if there is an edge 𝑣𝑖 , 𝑣𝑗 ∈ 𝐸.
◦ 𝐴2 𝑖𝑗 tells us how many vertices are adjacent
to both 𝑣𝑖 and 𝑣𝑗 .
◦ What is 𝐴3 𝑖𝑗 ? It is the number of paths of
length three between 𝑣𝑖 and 𝑣𝑗 .
◦ In fact, 𝐴2 𝑖𝑗 is the number of paths of
length two between 𝑣𝑖 and 𝑣𝑗 .
5
2/1/2015
The Meaning of 𝑀𝑘
Theorem. Let 𝐴 be the adjacency matrix
of a (not necessarily simple) graph
𝐺 = 𝑉, 𝐸 . Then 𝐴𝑘 𝑖𝑗 is the number of
(not necessarily simple) paths between 𝑣𝑖
and 𝑣𝑗 .
An Example
𝑎 𝑏 0 1 0 1
𝐴= 1 0 1 0
0 1 0 1
𝑑 𝑐 1 0 1 0
0 1 0 1 0 1 0 1 2 0 2 0
𝐴2 = 𝐴𝐴 = 1 0 1 0 1 0 1 0 = 0 2 0 2
0 1 0 1 0 1 0 1 2 0 2 0
1 0 1 0 1 0 1 0 0 2 0 2
2 0 2 0 0 1 0 1 0 4 0 4
𝐴3 = 𝐴2 𝐴 = 0 2 0 2 1 0 1 0 = 4 0 4 0
2 0 2 0 0 1 0 1 0 4 0 4
0 2 0 2 1 0 1 0 4 0 4 0
6
2/1/2015
The Meaning of 𝑀𝑘
Theorem. Let 𝑀 be the incidence matrix
of a (not necessarily simple) graph
𝐺 = 𝑉, 𝐸 . Then 𝑀𝑘 𝑖𝑗 is the number
of (not necessarily simple) paths between
𝑣𝑖 and 𝑣𝑗 .
Proof. By induction on 𝑘.
◦ Induction basis. Easy to see for 𝑘 = 1 and
𝑘 = 2.
𝐴𝑘 𝑖𝑗
= 𝐴𝑘−1 𝐴
𝑖𝑚 𝑚𝑗
𝑚=1
◦ By the induction hypothesis, 𝐴𝑘−1 𝑖𝑚 is the
number of paths of length 𝑘 − 1 between 𝑣𝑖
and 𝑣𝑚 .
◦ 𝐴𝑚𝑗 is the number of edges between 𝑣𝑚 , 𝑣𝑗 .
7
2/1/2015
𝐴𝑘 𝑖𝑗
= 𝐴𝑘−1 𝐴
𝑖𝑚 𝑚𝑗
𝑚=1
8
2/1/2015
9
2/1/2015
10
2/1/2015
Solution
We define two sets of matrices:
◦ Cell 𝑖𝑗 of the matrix 𝐸 𝑚 contains the
number of paths of length 𝑚 between 𝑣𝑖 an
𝑣𝑗 using an even number of blue edges.
◦ Cell 𝑖𝑗 of the matrix 𝑂 𝑚 contains the
number of paths of length 𝑚 between 𝑣𝑖 an
𝑣𝑗 using an odd number of blue edges.
1
What are 𝐸 and 𝑂(1) ?
◦ 𝐸 1 is the adjacency matrix of 𝐺 after
1
removing the blue edges. Similarly for 𝑂
after removing the red edges.
11
2/1/2015
Solution (cont.)
We wish to compute 𝐸 𝑘 .
◦ We know how to find 𝐸 1 and 𝑂 1 .
◦ How can we compute 𝐸 𝑚 and 𝑂(𝑚) using
𝐸 𝑚−1 and 𝑂(𝑚−1) ?
𝐸 𝑚 = 𝐸 𝑚−1 𝐸 1 + 𝑂(𝑚−1) 𝑂(1) .
𝑚−1 1
◦ 𝐸 𝐸 𝑖𝑗
is the number of paths of
length 𝑚 between 𝑣𝑖 and 𝑣𝑗 with an even
number of blue edges and whose last edge is
red.
𝑚−1 1
◦ Similarly for 𝑂 𝑂 𝑖𝑗
except that the
last edges of the paths is blue.
Solution (cont.)
𝑚
How can we similarly compute 𝑂 using
𝐸 𝑚−1 and 𝑂 𝑚−1 ?
𝑚 𝑚−1 1
𝑂 =𝐸 𝑂 + 𝑂(𝑚−1) 𝐸 (1) .
12
2/1/2015
Identical Graphs?
Are the following two graphs identical?
𝑣1 𝑣2
𝑣3 𝑣2 𝑣3 𝑣1
Possible answers:
◦ No, since in one 𝑣1 has degree 2 and in the
other degree 1.
◦ Yes, because they have exactly the same
structure.
Graph Isomorphism
An isomorphism from a graph 𝐺 = 𝑉, 𝐸
to a graph 𝐺 ′ = 𝑉 ′ , 𝐸 ′ is a bijection
𝑓: 𝑉 → 𝑉 ′ such that for every 𝑢, 𝑣 ∈ 𝑉, 𝐸
has the same number of edges between 𝑢
and 𝑣 as 𝐸 ′ has between 𝑓 𝑢 and 𝑓 𝑣 .
◦ We say that 𝐺 and 𝐺 ′ are isomorphic if there
is an isomorphism from 𝐺 to 𝐺 ′ .
◦ In our example, the graphs are isomorphic
(𝑓 𝑣1 = 𝑢2 , 𝑓 𝑣2 = 𝑢1 , 𝑓 𝑣3 = 𝑢3 ).
𝑣1 𝑢2
𝑣3 𝑣2 𝑢3 𝑢1
13
2/1/2015
Uniqueness?
Question. If two graphs are isomorphic,
can there be more than one isomorphism
from one to the other?
◦ Yes!
◦ 𝑎 → 𝑤, 𝑏 → 𝑧, 𝑐 → 𝑥, 𝑑 → 𝑦.
◦ 𝑎 → 𝑦, 𝑏 → 𝑧, 𝑐 → 𝑥, 𝑑 → 𝑤.
𝑎 𝑏 𝑤 𝑥
𝑐 𝑑 𝑦 𝑧
0 0 0 1 𝑤 𝑥
0 0 1 1
0 1 0 0
1 1 0 0
𝑦 𝑧
14
2/1/2015
Answer
Two graphs 𝐺, 𝐺 ′ are isomorphic if and
only if the adjacency matrix of 𝐺 is
obtained by permuting the rows and
columns of the adjacency matrix of 𝐺 ′ .
◦ (The same permutation should apply both to
the rows and to the column).
◦ 1 → 1, 2 → 4, 4 → 3, 3 → 2:
0 1 0 0 0 0 0 1
1 0 1 0 0 0 1 1
0 1 0 1 0 1 0 0
0 0 1 0 1 1 0 0
15
2/1/2015
Degree in
Biology
Electronics
engineer
Freddie Mercury
16