2.3 Representing a network: adjacency matrices — Learn
Prerequisites: Section 2.1 — degree; Section 2.2 — directed networks.
Objectives: write a network as an adjacency matrix; read a network back out of one; use row sums for degree and out-degree, and column sums for in-degree.
By the end of this section you can turn any network into a table of numbers and back again, so that a computer can work on it.
A picture is not a list of numbers
A drawing of a network is quick for you to read and hard for a computer. A table of numbers is the opposite. The adjacency matrix is the table, and it holds exactly the same information as the drawing.
Number the vertices, in a fixed order, . Then build an table. The entry in row , column is:
- if there is an edge joining vertex and vertex ;
- if there is not.
That is all. The matrix is adjacent vertices that are joined, which is where the name comes from.
Example 1. A network has vertices and edges , , , . Write its adjacency matrix, in the order .
Go through the rows one at a time.
- Row : joined to and to , not to or →
- Row : joined to and to →
- Row : joined to , and →
- Row : joined to only →
The order of the vertices matters. Write it down before you start, because a different order gives a different matrix for the same network.
Reading the network back out
Every entry tells you about a pair of vertices, so the matrix contains the whole network.
- The sum of a row is the degree of that vertex. Row is , which adds to , and . This is the handshake lemma appearing in the matrix: the total of all the entries is .
- The matrix of an undirected network is symmetric. The entry in row , column equals the entry in row , column , because the edge is the same edge seen from either end. If a matrix is not symmetric, the network is directed.
- The diagonal is all zeros unless there is a loop.
Example 2. Use the matrix above to find the number of edges.
Each row sums to the degree, so the degrees are , adding to . The sum of all the entries is , so
where is the number of edges. That matches the four edges listed.
Directed networks
For a directed network the entry in row , column is when there is an arrow from to . The matrix need not be symmetric, because an arrow one way does not imply an arrow the other way.
- The sum of a row is the out-degree of that vertex — the arrows leaving it.
- The sum of a column is the in-degree — the arrows arriving at it.
Example 3. A directed network has arrows , , and , with the vertices in the order .
Row is , so the out-degree of is . Column is , so the in-degree of is . Notice the matrix is not symmetric: the entry in row , column is , but the entry in row , column is also here — check the other pair. The entry in row , column is while row , column is , and that pair is what breaks the symmetry.
Weighted networks
If the edges carry weights, put the weight in the matrix instead of . A still means there is no edge.
Example 4. A weighted network has km, km and km. With the order the matrix is
This is called the weighted adjacency matrix. In a weighted network the row sum is the sum of the weights of the edges at that vertex, not the degree — the degree still counts edges, which is a different question.
Progress check
Back to the chapter problem. Take your seven-room network and number the rooms to in some fixed order. Write down its adjacency matrix, then use it to answer two questions without looking at the drawing.
What is the degree of each room? Read the row sums. How many possible cable runs are there in total? Halve the sum of all the entries. Both answers came out of the numbers alone, which is the point of the matrix: Section 2.4 multiplies it, and Section 2.8 searches it.
You should now be able to
- write the adjacency matrix of an undirected, directed or weighted network;
- read a network's edges and degrees back out of its matrix;
- use symmetry to tell a directed network from an undirected one;
- use row sums for degree and out-degree, and column sums for in-degree;
- say why the row sum is not the degree when the network has a loop.