Basic Electronics - Purdue University =πΌ πΌ=πΆ π π= πΌ π=1πΌπ π=1ππ
Ma/CS 6bmath.caltech.edu/~2014-15/2term/ma006b/12 Graphs...Β Β· incidence matrix π and adjacency...
Transcript of Ma/CS 6bmath.caltech.edu/~2014-15/2term/ma006b/12 Graphs...Β Β· incidence matrix π and adjacency...
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