ma/cs 6bmath.caltech.edu/~2014-15/2term/ma006b/12 graphs...ย ยท incidence matrix ๐ and adjacency...
TRANSCRIPT
2/1/2015
1
Ma/CS 6b Class 12: Graphs and Matrices
By Adam Sheffer
๐ฃ1
๐ฃ2
๐ฃ3 ๐ฃ4
๐ฃ5
010
101
0 0 11 0 30 1 0
0 0 1 0 11 3 0 1 0
Non-simple Graphs
In this class we allow graphs to be non-simple.
We allow parallel edges, but not loops.
2/1/2015
2
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
๐ฃ2
๐ฃ3 ๐ฃ4
๐ฃ5 1 0 00 1 10 0 0
0 0 00 0 10 1 1
0 0 01 1 1
1 1 01 0 0
๐1 ๐2
๐3 ๐4 ๐5 ๐6
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
๐ฃ2
๐ฃ3 ๐ฃ4
๐ฃ5 ๐ =
1 0 00 1 10 0 0
0 0 00 0 10 1 1
0 0 01 1 1
1 1 01 0 0
๐1 ๐2
๐3 ๐4 ๐5 ๐6
2/1/2015
3
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
๐ฃ2
๐ฃ3 ๐ฃ4
๐ฃ5 ๐ด =
010
101
0 0 11 0 30 1 0
0 0 1 0 11 3 0 1 0
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
๐๐๐ = ๐ด + ๐ท.
2/1/2015
4
Example
๐ฃ2 ๐ฃ3
๐ฃ1 ๐ด =0 1 11 0 31 3 0
๐ท =2 0 00 4 00 0 4
๐ =1 1 0 0 01 0 1 1 10 1 1 1 1
๐๐๐ =2 1 11 4 31 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 ๐ฃ๐.
2/1/2015
5
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
๐ฃ2
๐ฃ3 ๐ฃ4
๐ฃ5 ๐ด =
010
101
0 0 11 0 10 1 0
0 0 1 0 11 1 0 1 0
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 ๐ฃ๐.
2/1/2015
6
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 11 0 1 001100 11 0
๐ด2 = ๐ด๐ด =
0 1 0 11 0 1 001100 11 0
0 1 0 11 0 1 001100 11 0
=
2 0 2 00 2 0 220022 00 2
๐ด3 = ๐ด2๐ด =
2 0 2 00 2 0 220022 00 2
0 1 0 11 0 1 001100 11 0
=
0 4 0 44 0 4 004400 44 0
2/1/2015
7
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 ๐ฃ๐, ๐ฃ๐.
2/1/2015
8
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?
2/1/2015
9
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.
2/1/2015
10
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 log2 ๐ 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.
2/1/2015
11
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.
What are ๐ธ 1 and ๐(1)?
โฆ ๐ธ 1 is the adjacency matrix of ๐บ after
removing the blue edges. Similarly for ๐ 1 after removing the red edges.
2/1/2015
12
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.
โฆ Similarly for ๐ ๐โ1 ๐ 1๐๐
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.
2/1/2015
13
Identical Graphs?
Are the following two graphs identical?
Possible answers:
โฆ No, since in one ๐ฃ1 has degree 2 and in the other degree 1.
โฆ Yes, because they have exactly the same structure.
๐ฃ1
๐ฃ2 ๐ฃ3
๐ฃ2
๐ฃ1 ๐ฃ3
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
๐ข1 ๐ข3
2/1/2015
14
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 adjacency matrices of isomorphic graphs?
๐ ๐
๐ ๐
๐ค ๐ฅ
๐ฆ ๐ง
0 1 0 01 0 1 000100 11 0
0 0 0 10 0 1 101110 00 0
2/1/2015
15
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 01 0 1 000100 11 0
0 0 0 10 0 1 101110 00 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
๐ฃ2
๐ฃ3 ๐ฃ4
๐ฃ5 โ1 0 00 โ1 โ10 0 0
0 0 00 0 โ10 โ1 1
0 0 01 1 1
โ1 1 01 0 0
๐1 ๐2
๐3 ๐4 ๐5 ๐6
2/1/2015
16
The End: Queen
Ph.D. in astrophysics
Freddie Mercury
Electronics engineer
Degree in Biology