0% found this document useful (0 votes)
54 views

Graph Theory

1) The document discusses graphs and matrices, specifically incidence matrices and adjacency matrices. 2) It shows that the product of the incidence matrix M and its transpose M^T relates to the adjacency matrix and vertex degrees. 3) Powers of the adjacency matrix A count the number of paths between vertices in a graph.

Uploaded by

Teto Schedule
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Graph Theory

1) The document discusses graphs and matrices, specifically incidence matrices and adjacency matrices. 2) It shows that the product of the incidence matrix M and its transpose M^T relates to the adjacency matrix and vertex degrees. 3) Powers of the adjacency matrix A count the number of paths between vertices in a graph.

Uploaded by

Teto Schedule
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

2/1/2015

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

Playing with an Incidence Matrix


 Let 𝑀 be the incidence matrix of a graph
𝐺 = 𝑉, 𝐸 , and let 𝐵 = 𝑀𝑀𝑇 .
◦ What is the value of 𝐵𝑖𝑖 ? The degree of 𝑣𝑖 in 𝐺.
◦ What is the value of 𝐵𝑖𝑗 for 𝑖 ≠ 𝑗? The number
of edges between 𝑣𝑖 and 𝑣𝑗 .

𝑒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

Playing with an Adjacency Matrix


 Let 𝐴 be the adjacency matrix of a simple
graph 𝐺 = 𝑉, 𝐸 , and let 𝑀 = 𝐴2 .
◦ What is the value of 𝑀𝑖𝑖 ? The degree of 𝑣𝑖 in 𝐺.
◦ What is the value of 𝑀𝑖𝑗 for 𝑖 ≠ 𝑗? The number
of vertices that are adjacent to both 𝑣𝑖 and 𝑣𝑗 .
𝑣1
0 1 0 0 1
1 0 1 0 1
𝐴= 𝑣5 𝑣2
0 1 0 1 0
0 0 1 0 1
1 1 0 1 0
𝑣4 𝑣3

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.

The Induction Step


 We have 𝐴𝑘 = 𝐴𝑘−1 𝐴. That is
|𝑉|

𝐴𝑘 𝑖𝑗
= 𝐴𝑘−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

The Induction Step (cont.)


|𝑉|

𝐴𝑘 𝑖𝑗
= 𝐴𝑘−1 𝐴
𝑖𝑚 𝑚𝑗
𝑚=1

 For a fixed 𝑚, 𝐴𝑘−1 𝑖𝑚 𝐴𝑚𝑗 is the


number of paths from 𝑣𝑖 to 𝑣𝑗 of length 𝑘
with 𝑣𝑚 as their penultimate vertex.
◦ Thus, summing over every 1 ≤ 𝑚 ≤ |𝑉|
results in the number of paths from 𝑣𝑖 to 𝑣𝑗 of
length 𝑘.

Which Classic English Rock Band is


More Sciency?

8
2/1/2015

Computing the Number of Paths of


Length 𝑘
 Problem. Consider a graph 𝐺 = 𝑉, 𝐸 ,
two vertices 𝑠, 𝑡 ∈ 𝑉, and an integer
𝑘 > 0. Describe an algorithm for finding
the number of paths of length 𝑘 between
𝑠 and 𝑡.
◦ Let 𝐴 be the adjacency matrix of 𝐺.
◦ We need to compute 𝐴𝑘 , which involves
𝑘 − 1 matrix multiplication.

Matrix Multiplication: A Brief History


 We wish to multiply two 𝑛 × 𝑛 matrices.
◦ Computing one cell requires about 𝑛
multiplications and additions. So computing an
entire matrix takes 𝑐𝑛3 (for some constant 𝑐).
◦ In 1969 Strassen found an improved algorithm
with a running time of 𝑐𝑛2.807 .
◦ In 1987, Coppersmith and Winograd obtained
an improved 𝑐𝑛2.376 .
◦ After over 20 years, in 2010, Stothers obtained
𝑐𝑛2.374 .
◦ Williams immediately improved to 𝑐𝑛2.3728642 .
◦ In 2014, Le Gall improved to 𝑐𝑛2.3728639 .

9
2/1/2015

A More Efficient Algorithm


 To compute 𝐴𝑘 , we do not need 𝑘 − 1
matrix multiplications.
 If 𝑘 is a power of 2:
◦ 𝐴2 = 𝐴𝐴, 𝐴4 = 𝐴2 𝐴2 , …, 𝐴𝑘 = 𝐴𝑘/2 𝐴𝑘/2 .
◦ Only log 2 𝑘 multiplications!
 If 𝑘 is not a power of 2:
◦ We again compute 𝐴, 𝐴2 , 𝐴4 , … , 𝐴 𝑘 .
◦ We can then obtain 𝐴𝑘 by multiplying a
subset of those.
◦ For example, 𝐴57 = 𝐴32 𝐴16 𝐴8 𝐴.
◦ At most 2log 𝑘 − 1 multiplications!

Connectivity and Matrices


 Problem. Let 𝐺 = 𝑉, 𝐸 be a graph with
an adjacency matrix 𝐴. Use 𝑀 = 𝐼 + 𝐴
+ 𝐴2 + 𝐴3 + ⋯ + 𝐴 𝑉 −1 to tell whether
𝐺 is connected.
 Answer.
◦ 𝐺 is connected iff every cell of 𝐴 is positive.
◦ The main diagonal of 𝐴 is positive due to 𝐼.
◦ A cell 𝐴𝑖𝑗 for 𝑖 ≠ 𝑗 contains the number of
paths between 𝑣𝑖 and 𝑣𝑗 of length at most
𝑘 − 1. If the graph is connected, such paths
exist between every two vertices.

10
2/1/2015

And Now with Colors


 Problem. Consider a graph 𝐺 = 𝑉, 𝐸 ,
two vertices 𝑠, 𝑡 ∈ 𝑉, and an integer
𝑘 > 0. Moreover, every edge is colored
either red or blue. Describe an algorithm
for finding the number of paths of length
𝑘 between 𝑠 and 𝑡 that have an even
number of blue edges.

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) .

 Concluding the solution.


◦ We compute about 2𝑘 matrices.
◦ Each computation involves two matrix
multiplications and one addition.

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!
◦ 𝑎 → 𝑤, 𝑏 → 𝑧, 𝑐 → 𝑥, 𝑑 → 𝑦.
◦ 𝑎 → 𝑦, 𝑏 → 𝑧, 𝑐 → 𝑥, 𝑑 → 𝑤.

𝑎 𝑏 𝑤 𝑥

𝑐 𝑑 𝑦 𝑧

Isomorphisms and Adjacency


Matrices
 What can we
say about 𝑎 𝑏
0 1 0 0
adjacency 1 0 1 0
matrices of 0 1 0 1
isomorphic 0 0 1 0
𝑐 𝑑
graphs?

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

Incidence Matrix of a Directed


Graph
 Consider a directed 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 entering 𝑣𝑖 ,
and 1 if 𝑒𝑗 is leaving 𝑣𝑖 . 𝑣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

15
2/1/2015

The End: Queen


Ph.D. in astrophysics

Degree in
Biology
Electronics
engineer

Freddie Mercury

16

You might also like