We will start this lesson by exploring some situations that can be represented by graphs or networks.
A beach volleyball social competition team can have 3 players on the court at any time. The team has 5 players at the tournament. The table shows 3 combinations that the coach has already used in the first three games.
Games | Players chosen |
---|---|
1 | Ryan, Jimmy, Lucy |
2 | Lucy, Beth, Ellie |
3 | Ellie, Ryan, Jimmy |
Which of the following graphs shows the combinations of players that have already played together?
There is one more game left in the tournament. Who should the coach choose to play so that every team member has played with every other team member at least once?
The following table lists the amount of time it takes to queue up for three rides at an amusement park, and the amount of time it takes to travel between them:
Carousel | Pirate Ship | Haunted House | |
---|---|---|---|
Carousel | 3 | 5 | 4 |
Pirate Ship | 5 | 13 | 6 |
Haunted House | 4 | 6 | 11 |
Represent this information using a network.
Some situations that can be represented by graphs or networks. Vertices can represent objects or places, edges can represent paths or connections, and weights can represent numerical data that connects the vertices like times or distances.
It is sometimes useful to use an adjacency matrix to represent a network. This is a square matrix of numbers, with a row and a column for each vertex, that records how many connections there are between the vertices. For an undirected network, the entry for a particular row and column represents the number of edges connecting the matching vertices.
Now we can create a matrix, with a row and a column for each vertex:
\begin{matrix} & \begin{matrix} A&B&C&D&E\end{matrix}\\ \begin{matrix} A \\ B \\ C \\ D \\ E \end{matrix} & \begin{bmatrix} \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \end{bmatrix} \end{matrix}
Then we put the number edges connecting two vertices as the corresponding table entry. Let’s start by filling out the first row by putting a 1 if it is connected to A, and a 0 if it isn’t.
\begin{matrix} & \begin{matrix} A&B&C&D&E\end{matrix}\\ \begin{matrix} A \\ B \\ C \\ D \\ E \end{matrix} & \begin{bmatrix} \, 0 &\, 1 &\, 1 &\, 1 &\, 1 \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \end{bmatrix} \end{matrix}
0 comes first because A isn’t connected to itself (there’s no loop at A), and A is connected to B, \, C, \, D, and E, so we put a 1 for each other entry in the table.
Since these edges are undirected, we can fill out the first column with the same numbers - if A is connected to B, then B is connected to A, and so on:
\begin{matrix} & \begin{matrix} A&B&C&D&E\end{matrix}\\ \begin{matrix} A \\ B \\ C \\ D \\ E \end{matrix} & \begin{bmatrix} \, 0 &\, 1 &\, 1 &\, 1 &\, 1 \\ \, 1 &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \, 1 &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \, 1 &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \, 1 &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \end{bmatrix} \end{matrix}
Now to fill out the second row, we notice that B is connected to A (already recorded), not itself (no loop), and it is connected to C, \, D, and E:
\begin{matrix} & \begin{matrix} A&B&C&D&E\end{matrix}\\ \begin{matrix} A\\ B\\ C\\D\\E \end{matrix} & \begin{bmatrix} \, 0 &\, 1 &\, 1 &\, 1 &\, 1 \\ \, 1 &\, 0 &\, 1 &\, 1 &\, 1 \\ \, 1 &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \, 1 &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \\ \, 1 &\,\,.\, &\,\,.\, &\,\,.\, &\,.\,\, \end{bmatrix} \end{matrix}
We then record the remaining connections between C, \, D, and E in the same way:
\begin{matrix} & \begin{matrix} A&B&C&D&E\end{matrix}\\ \begin{matrix} A\\ B\\ C\\ D \\E \end{matrix} & \begin{bmatrix} \, 0 &\, 1 &\, 1 &\, 1 &\, 1 \\ \, 1 &\, 0 &\, 1 &\, 1 &\, 1 \\ \, 1 &\, 1 &\, 0 &\, 1 &\, 0 \\ \, 1 &\, 1 &\, 1 &\, 0 &\, 0 \\ \, 1 &\, 1 &\, 0 &\, 0 &\, 0 \end{bmatrix} \end{matrix}
In the completed matrix, notice that:
The diagonal running top-left to bottom-right (called the main diagonal) has only 0's. This indicates that no edge is connected to itself in the network - there are no loops.
The numbers off the main diagonal are only 0's and 1's. This indicates that there are no multiple edges.
All adjacency matrices representing simple networks will have these features.
As an added bonus, for a network with no loops, the sum of all the entries in a row (or column) gives us the degree of the corresponding vertex - we can tell from the table that C and E have degree 2, \, D has degree 3, and A and B have degree 4.
Consider the following network:
Fill in the adjacency matrix for this network:\begin{matrix} & \begin{matrix} P&Q&R&S \end{matrix}\\ \begin{matrix} P \\ Q \\ R \\ S \end{matrix} & \begin{bmatrix} ⬚ &⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ &⬚ \end{bmatrix} \end{matrix}
What is the degree of vertex P?
The degree of a vertex is the number of edges connected to that vertex. Loops are counted twice.
An adjacency matrix is a square array of numbers, a row and a column for each vertex, that records how many connections there are between the vertices.
For undirected networks, the element for a particular row and column represents the number of edges connecting the matching vertices.
Now for a directed network, the entry in a particular row and column indicates the number of edges going from the corresponding row vertex to the corresponding column vertex.
Here’s a directed, non-simple network with 5 vertices and its corresponding adjacency matrix:
This matrix looks a little different from the last one. Notice that:
The matrix is not symmetrical across the main diagonal (an edge from A to B can exist without an edge from B to A),
There is a 1 on the main diagonal because it is not a simple graph as there is a loop at C, and
There’s a 2 in the table because there are two edges from D to E.
While an asymmetrical matrix means the network is directed, there are directed networks that will produce a symmetrical adjacency matrix.
For directed networks, we can add all of the elements in the adjacency matrix to determine the number of edges on the graph.
When a network contains loops, there will be non-zero values on the main diagonal of the adjacency matrix. Each loop is counted as the vertex as having one connection to itself.
When we calculate the degree of a vertex by adding the elements in a row (or column) of the adjacency matrix, numbers on the main diagonal need to be doubled because loops are counted twice.
In the graph above the degree of vertex C is 4, because the loop is considered to be two edges into vertex C. However if we add the numbers in row C of the corresponding adjacency table we only get 3. The 1 on the main diagonal must be counted twice as it represents the loop at C.
Adjacency matrices can be used for weighted graphs where each element in the matrix represents the weight assigned to that edge.
Setting up the matrix template we need, 4 vertices means it will be a 4 \times 4 matrix.
\begin{matrix} & \begin{matrix} A&B&C&D\end{matrix}\\ \begin{matrix} A\\ B\\ C\\ D \end{matrix} & \begin{bmatrix} \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, \end{bmatrix} \end{matrix}
From vertex A, there are 2 edges. The edge connected to B has weight 2, and the edge to 2 has weight 4.
\begin{matrix} & \begin{matrix} A&B&C&D\end{matrix}\\ \begin{matrix} A\\ B\\ C\\ D \end{matrix} & \begin{bmatrix} \, 0 \, &\,2\, &\,4\, &\,0\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, \\ \,\, . \, &\,\,.\, &\,\,.\, &\,\,.\, \end{bmatrix} \end{matrix}
From vertex B there is just one edge. It goes to C with weight 3.33.
\begin{matrix} & \begin{matrix} A&B&C&D\end{matrix}\\ \begin{matrix} A\\ B\\ C\\ D \end{matrix} & \begin{bmatrix} 0 &2 &4 &0 \\ 0 &0 &3.33 &0 \\ \, . &\,\, . &\,\, . &\,\, . \\ \, . &\,\, . &\,\, . &\,\, . \end{bmatrix} \end{matrix}
From vertex C there is just one edge. It goes to D with weight 4.
From vertex D there are two edges. One of them is a loop and this gets written in the D to D position.
\begin{matrix} & \begin{matrix} A&B&C&D\end{matrix}\\ \begin{matrix} A\\ B\\ C\\ D \end{matrix} & \begin{bmatrix} 0 &2 &4 &0 \\ 0 &0 &3.33 &0 \\ 0 &0 &0 &4 \\ 0 &0 &3.5 &2 \end{bmatrix} \end{matrix}
If we know that we have a directed or undirected network, the information in the adjacency matrix is enough for us to draw a graph to represent the network.
Here’s a table with 6 rows and columns (so there are 6 vertices in the network), and we are also told that the network is undirected.
\begin{bmatrix} 1&1&1&0&1&0 \\1&0&2&1&1&1 \\1&2&0&0&0&0 \\0&1&0&1&1&0 \\1&1&0&1&0&1 \\0&1&1&0&1&0 \end{bmatrix}
This is a representation of the network that we get when we draw it out:
start with the first row, and the vertex on the left
draw in the edges connected to that vertex
move on to the next row/next vertex clockwise, ignoring the numbers below the main diagonal - they get drawn into the network when we do earlier rows for undirected networks. If the graph is directed, all the numbers need to be turned into edges.
Select the network with this adjacency matrix:
\begin{matrix} & \begin{matrix} X&Y&Z\end{matrix}\\ \begin{matrix} X\\ Y\\ Z \end{matrix} & \begin{bmatrix}\, 0 &\, 0 &\, 0 \\ \, 2 &\, 0 &\, 0 \\ \, 1 &\, 1 &\, 0 \end{bmatrix} \end{matrix}
For directed networks, the element in a particular row and column indicates the number of edges going from the corresponding row vertex to the corresponding column vertex.
Loops are indicated by elements on the main diagonal with each loop counting as one connection.
Adjacency matrices can be used for weighted graphs where each element in the matrix represents the weight assigned to that edge.
If we know that we have a directed or undirected network, the information in the adjacency matrix is enough for us to draw a graph to represent the network.
The elements in an adjacency matrix for a directed graph represent direct connections from one vertex to another.
Matrix M shows that there are three one-stage connections from vertex C - one each to vertices A, \, B and D.
A two-stage connections is a connections between two nodes that goes via some other node. In the given graph, the path C, \, A, \, B is a two-stage path from C to B. There is also a two-stage path C, \, A, \, D from C to D.
The two-stage connections can be seen in the M^2 matrix, which can be obtained by multiplying the matrix M by itself, either using technology or performing matrix multiplication.
M^{2} = \begin{bmatrix} 0 &0 &0 &0 \\ 0 &0 &0 &0 \\ 0 &1 &0 &1 \\ 0 &0 &0 &0 \end{bmatrix}
This video shows how to evaluate the square of a matrix using a calculator:
Two-stage connections are indicated by the non-zero elements in M^2. The two 1’s in the matrix indicate there are two 2-step paths from C to B \, (CAB) and from C to D \, (CAD). But how does this method actually work?
Let's consider the entry in the third row and second column of the matrix M^2, which indicates that there is a single 2-step path from C to B. To get this value via matrix multiplication, we need to take the product of the third row of matrix M with the second column of matrix M. Since the third row of matrix M counts the number of paths from C to the other vertices, and the second row counts the number of paths to B from other vertices, multiplying them together is the same as counting "how many paths are there from C to B through one other vertex?".
This use of matrix arithmetic can even be extended to use M^{n} to identify n-stage connections.
For this particular graph, we can see that there are no three-stage connections because M^3 is a zero matrix. That means there is no way to get to one vertex to another in three steps.
M^{3} = \begin{bmatrix} 0 &0 &0 &0 \\ 0 &0 &0 &0 \\ 0 &0 &0 &0 \\ 0 &0 &0 &0 \end{bmatrix}
TThis video shows how to evaluate the cube of a matrix using a calculator:
Multi-stage connections can represent numerous practical situations, such as air transport links between cities, the ranking of players in sporting competitions, connections in computer networks and many others.
Consider the given graph.
Create the adjacency matrix, M.\begin{matrix} & \begin{matrix} X&Y&Z \end{matrix}\\ \begin{matrix} X \\ Y \\ Z \end{matrix} & \begin{bmatrix} ⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ \end{bmatrix} \end{matrix}
Find the second-stage adjacency matrix M^2 using technology or otherwise.M^2 \,=\,\begin{matrix} & \begin{matrix} X&Y&Z \end{matrix}\\ \begin{matrix} X \\ Y \\ Z \end{matrix} & \begin{bmatrix} ⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ \end{bmatrix} \end{matrix}
How many two-stage paths are there between Y and X?
There is one two-stage path from Y to X. What is this path?
Find the third-stage adjacency matrix M^3 using technology or otherwise.M^3 \,=\,\begin{matrix} & \begin{matrix} X&Y&Z \end{matrix}\\ \begin{matrix} X \\ Y \\ Z \end{matrix} & \begin{bmatrix} ⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ \\ ⬚ &⬚ &⬚ \end{bmatrix} \end{matrix}
Which vertices are connected by a three-stage path? Write only the start and end vertices.
The elements in an adjacency matrix for a directed graph represent direct (one-step) connections from one vertex to another.
The elements in the adjacency matrix squared, M^2, for a directed graph represent two-step connections from one vertex to another.
The elements in the adjacency matrix cubed, M^3, for a directed graph represent three-step connections from one vertex to another.