Adjacency Matrices - URI Math Department

Adjacency Matrices
MTH 215 Project 1
Due Thursday, April 7
The purpose of this project is to explore how matrices may be used to investigate
graphs. A graph is a set of points (called vertices) and lines connecting some
pairs of vertices (called edges). Two vertices connected by an edge are said to
be adjacent.
Figure 1
As we can see from this example, vertices can be connected by more than one
edge (A and B), some vertices might not be connected to any other vertices
(vertex D), and a vertex may be connected to itself (vertex F ).
Another example of a graph is the route map produced by most transit companies like the ones in Figures 2 and 3. In this case, the vertices are the cities
to which the airlines fly, and an edge represents a direct flight between those
cities.
1
Given a graph, some questions arise naturally. We may want to know if two
vertices are connected by a sequence of two edges, even if they are not connected
by a single edge (this would be equivalent to the availability of a one-stop flight
between two cities in the case of a route map). In the graph in Figure 1, A and
C are connected by a two-edge sequence (actually, there are four distinct ways
to go from A to C in two steps). In our route map, Pittsburgh and Kansas City
are connected by a two-edge sequence, meaning that a passenger would have to
stop in Chicago while flying between those cities on Vanguard. We may want to
know if it is possible to get from a vertex to another vertex. It is impossible, for
example, to get from vertex D in Figure 1 to any other vertex, but a passenger
on Vanguard can get to any city in the network given enough flights. But
how many flights are enough? This is another issue of interest: what is the
minimum number of steps needed to get from one vertex to another? What
is the minimum number of steps needed to get from one vertex to any other?
While these questions are relatively easy to answer for a small graph, as the
number of vertices and edges grows, it becomes much harder to keep track of all
of the ways that the vertices are connected (imagine a computer network with
thousands of nodes and hundreds of thousands of edges). Matrix notation and
computation can help us answer these questions.
The adjacency matrix for a graph with n vertices is an n × n matrix whose
i, j-th entry is 1 if vertex i and vertex j are adjacent, and 0 if they are not. If
we let vertex A be 1, B be vertex 2, etc. in Figure 1, then we find that the
adjacency matrix for this graph is
2




M =



0
1
0
0
0
0
1
0
1
0
1
0
0
1
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
1
0
0
1
0
1
1








Notice that the 4th row and column are all zero since D is not connected to
any vertices, and the only non-zero entry on the diagonal corresponds to the
6,6-th entry since F is the only vertex connected to itself. Also, observe that
the matrix is symmetric about the main diagonal (M T = M ) because if there
is an edge from one vertex to another, then the reverse is also certainly true.
Similarly, if the vertices in the Vanguard graph respectively correspond to
Chicago, Denver, Dallas/Ft. Worth, Minneapolis/St. Paul, Atlanta, Kansas
City, Myrtle Beach, and Pittsburgh, then the adjacency matrix for Vanguard is






M =





0
0
0
1
0
1
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
1
1
0
1
1
1
1
1
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0












We can now use the adjacency matrix to address the questions we raised earlier.
Which vertices are connected by a two-edge sequence? How many different two
edge sequences connect each pair of vertices?
Consider Figure 1. Vertices B and F are connected by two edge sequences
in two different ways: Through vertex E or vertex C. Notice that we do not
distinguish between the two edges from B to C. Let mij be the i, j-th entry in
the adjacency matrix M , and note that
∗ m21 m16 + m22 m26 + m23 m36 + m24 m46 + m25 m56 + m26 m66 =
(1)(0) + (0)(0) + (1)(1) + (0)(0) + (1)(1) + (0)(1) = 2
which is the number of two-step sequences between B and F . This calculation
works because in order for a two-step sequence to occur, B and F must connect
to an intermediate vertex. Since B connects with C and C connects with F ,
3
m23 m36 = 1; since B connects with A but A does not connect with F , m21 m16 =
0. Now, observe that the expression in ∗ is just the 2, 6-th entry in M 2 . By
the same reasoning, in fact, we may say that the number of two-step sequences
between any vertex i and vertex j in a graph with adjacency matrix M is the i, jth entry in M 2 . Inductively, we also have that the number of k-step sequences
between i and j is the i, j-th entry in M k .
If M is the adjacency matrix for Figure 1,




M2 = 



1
0
1
0
1
0
0
3
0
0
0
2
1
0
2
0
2
1
0
0
0
0
0
0
1
0
2
0
2
1
0
2
1
0
1
3








 and M 3 = 






0
3
0
0
0
2
3
0
5
0
5
2
0
5
1
0
1
5
0
0
0
0
0
0
0
5
1
0
1
0
2
2
5
0
5
5








Thus there is a two-step sequence from C to F , and 5 three-step sequences
between C and F .
In your observation of the figures, you might note that some two-step or threestep sequences may not be meaningful. On the Vanguard route map, we see
that Minneapolis is reachable in three steps from Chicago, but in reality we
would not care since there is a direct flight as well. A better question to ask
might be:
What is the least number of edges which must be traversed to go from vertex A
to vertex B?
To answer this question, consider the matrix Sk = M + M 2 + · · · + M k . The
i, j-th entry in this matrix tallies the number of ways to get from vertex i to
vertex j in k steps or less. If such a trip is impossible, the entry will be zero.
Thus to find the shortest number of steps between the vertices, we continue
to compute Sk as k increases; The first k for which the i, j-th entry is nonzero is the shortest number of steps between i and j. Note that this process is
non-constructive; that is, we know the length of the shortest trip, but not the
itinerary. This also gives us a way to answer the following question:
How can we tell if a graph is connected?
This should be easy to see for a small graph, but it is harder to see from the
adjacency graph. However, there is a calculation we can do. If there are n
vertices in the graph, then the largest number of steps it could take to get from
a vertex to any other is n. Hence Sn can help us. If there are any zeroes in
this matrix (say in the i, j-th entry), then it is impossible to get from vertex i
to vertex j, and the graph cannot be connected.
4
Questions
You should use Mathematica or another CAS to do the matrix computations
needed for the questions below. Give full explanations for all of your responses,
giving the appropriate matrix or matrices where appropriate.
List the three-step sequences between C and F in Figure 1, and confirm that
there are indeed 5 of them.
Which Vanguard cities may be reached by one-stop flight from Chicago? Which
cities may be reached by a two-stop flight? 2 In Figure 1, show that the shortest
path between A and F has 3 steps.
Which trips in the Vanguard network take the greatest number of flights?
Figure 3 below shows the May 1999 route map for Reno Air. The adjacency
matrix for this route map is the matrix A which accompanies this project. The
vertices correspond respectively to: Anchorage, Seattle, Portland, San Francisco, San Jose, Los Angeles, Orange County, San Diego, Reno/Tahoe, Las
Vegas, Colorado Springs, Oklahoma City, and Chicago.
What is the smallest number of flights it would take to go from Colorado Springs
to Portland? How many different ways can you make the trip?
What is the largest number of flights you would need to take to get from one
Reno Air city to any other? Which trips take the largest number of flights?
How many ways can you make those trips?
5











A=










0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
1
1
0
0
1
1
0
1
1
0
0
0
0
0
0
1
1
0
0
0
1
1
1
0
0
6
0
1
0
1
1
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
1
0
1
1
1
1
0
1
0
0
1
0
0
0
0
1
1
1
0
1
0
1
1
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0





















