ma/cs 6bmath.caltech.edu/~2016-17/2term/ma006b/notes/19 graphs and matโฆย ยท 2/21/2017 3 adjacency...
TRANSCRIPT
2/21/2017
1
Ma/CS 6bClass 19: 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/21/2017
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/21/2017
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. ๐๐๐ 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/21/2017
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/21/2017
5
Playing with an Adjacency Matrix
Let ๐ด be the adjacency matrix of a simplegraph ๐บ = ๐, ๐ธ , 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 simplegraph ๐บ = ๐, ๐ธ . 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/21/2017
6
The Meaning of ๐ด๐
Theorem. Let ๐ด be the adjacency matrix
of a graph ๐บ = ๐, ๐ธ . Then ๐ด๐๐๐
is the
number of paths of length ๐ between ๐ฃ๐and ๐ฃ๐.
# of paths
An Example
๐๐
๐๐
๐ด =
0 1 0 11 0 1 001
10
0 11 0
๐ด2 = ๐ด๐ด =
0 1 0 11 0 1 001
10
0 11 0
0 1 0 11 0 1 001
10
0 11 0
=
2 0 2 00 2 0 220
02
2 00 2
๐ด3 = ๐ด2๐ด =
2 0 2 00 2 0 220
02
2 00 2
0 1 0 11 0 1 001
10
0 11 0
=
0 4 0 44 0 4 004
40
0 44 0
2/21/2017
7
The Meaning of ๐ด๐
Theorem. Let ๐ด be the adjacency matrix
of a graph ๐บ = ๐, ๐ธ . Then ๐ด๐๐๐
is the
number of paths of length ๐ 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/21/2017
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.
โฆ Summing over every 1 โค ๐ โค |๐| results in the number of paths from ๐ฃ๐ to ๐ฃ๐ of length ๐.
Which British Classic Rock Band is More Sciency?
2/21/2017
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/21/2017
10
A More Efficient Algorithm
To compute ๐ด๐, we do not need ๐ โ 1matrix 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/21/2017
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 ๐ฃ๐ and ๐ฃ๐ using an even number of blue edges.
โฆ Cell ๐๐ of the matrix ๐ ๐ contains the number of paths of length ๐ between ๐ฃ๐ and ๐ฃ๐ 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/21/2017
12
Solution (cont.)
We wish to compute ๐ธ ๐ .
โฆ We know how to find ๐ธ 1 and ๐ 1 .
โฆ How can we compute ๐ธ ๐ 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/21/2017
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/21/2017
14
Uniqueness?
Question. If two graphs are isomorphic, can there be more than one isomorphismfrom 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 000
10
0 11 0
0 0 0 10 0 1 101
11
0 00 0
2/21/2017
15
Answer
Two graphs ๐บ, ๐บโฒ are isomorphic iff 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 000
10
0 11 0
0 0 0 10 0 1 101
11
0 00 0
The End: Queen
Ph.D. in astrophysics
Freddie Mercury
Electronicsengineer
Degree inBiology