This Document has been modified with Flexcil app (Android) https://www.flexcil.com
Supplemental: Matrix Algebra and Graphs
• In discrete mathematics, a graph G = (V, E) consists of
◦ A set V of vertices (also called nodes), and
◦ A set E of edges between pairs of vertices.
• Graphs are said to be directed if every edge has an initial and terminal
vertex. Otherwise, the graph is called undirected.
• The Pokemon Type Super-Effectiveness graph is directed because one
type may be super effective against another, but not vice versa. The
graph on the right is a representation of the Tokyo subway system,
where edges are undirected because subways connect stations in both
directions.
1
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note
This Document has been modified with Flexcil app (Android) https://www.flexcil.com
• In this note, we only discuss undirected graphs. A vertex is allowed to
have an edge with itself, and multiple edges between vertices is allowed.
• Even though graphs are abstract objects, they model real-world phenomena. Graphs are the central structures used in network science,
path finding algorithms, database structures, circuit analysis, etc.
The Seven Bridges of Königsberg
• Graph theory is said to have been invented by Euler in 1735 upon
solution of the so-called “Königsberg bridge problem.”
• The city of Königsberg (now Kaliningrad, Russia) is set on the Pregel
river, which encloses the island of Keniphof and then splits into two.
• Seven bridges connect the city’s landmasses together.
2
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note
This Document has been modified with Flexcil app (Android) https://www.flexcil.com
• Problem: Devise a walk through the city that crosses each bridge once
and only once.
• Euler proved such a walk was impossible by considering (what we now
call) the in-degree and out-degree of a vertex. While the proof itself is
not complicated, the novelty of the problem is Euler’s reformulation of
the problem in abstract terms, laying the foundation of graph theory
and generating several fruitful directions following from this work.
• In particular, Euler discarded extraneous information and simply studied the invariants of the resulting graph:
• Unlike some branches of math such calculus, geometry, probability, etc.,
whose subject evolved over long periods, we can distinctly trace the
origins of graph theory—and thus network science, topology, combinatorics—to this precise moment.
3
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note
This Document has been modified with Flexcil app (Android) https://www.flexcil.com
The Adjacency Matrix
• A graph with n vertices can be represented (or stored in a computer)
by an n × n adjacency matrix A = [aij ] such that
◦ aij = t if there is are t edges connecting vertex vi to vj , and
◦ aij = 0 otherwise.
• When A is undirected, the adjacency matrix is symmetric since the
number of edges connecting vi to vj is the same as the number connecting vj to vi .
Example 1. Construct the adjacency matrix of the Königsberg bridge graph
G.
Solution.
4
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note
This Document has been modified with Flexcil app (Android) https://www.flexcil.com
Example 2. Construct the adjacency matrix of the following graph G. The
degree of each vertex is provided. Explain what it represents and how to
find it from the adjacency matrix.
Solution.
5
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note
This Document has been modified with Flexcil app (Android) https://www.flexcil.com
Walks on graphs
• If vertex vi is connected to vertex vj (i ̸= j), then there is a walk
of length 1 from vi to vj (the edge). This is stored in the adjacency
matrix A.
• What about walks of length 2? These are sequences of vertices connected by edges:
vi → vk → vj
• Similarly, walks of length p from vi to vj is a sequence
vi → v∗ → · · · → v∗ → vj
consisting of p total edges. Vertices and edges may repeat along the
walk. For example, v1 → v2 → v1 is a perfectly valid walk of length 2
occuring whenever there is a walk of length 1 (edge) between v1 and v2 .
Example 3. Count all of walks of paths of length 2 starting at vertex a in
Example 2.
Solution.
6
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note
This Document has been modified with Flexcil app (Android) https://www.flexcil.com
Key observation. Let A be the n × n adjacency matrix of a graph G with
n vertices. The (i, j)-entry of A2 is
n
X
aik akj .
j=1
If aik = t and akj = s, then ts is contributed to the sum. Otherwise, 0 is
added.
But, if aik = t, there are t edges connecting vi to vj , and if akj = s,
there are s edges connecting vj to vk . Hence there are ts total walks
connecting vi → vj through an intermediate vertex vk . By summing over
all such k, we add up all walks from vi to vj . Therefore, the (i, j)-entries of
A2 count the number of walks of length 2 in the graph G.
By the same logic, the powers of the adjacency matrix encode the walks
on the graph G:
Theorem. Let A be an n × n adjacency matrix of an undirected graph G.
The (i, j)-entry of the matrix power Ap is the number of walks of length p
from vertex vi to vertex vj .
7
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note
This Document has been modified with Flexcil app (Android) https://www.flexcil.com
Example 4. How many total walks of length 4 are there in the graph G
shown below? (Apply the theorem, not brute force.)
Solution.
Flexcil - The Smart Study Toolkit & PDF, Annotate, Note