Menu
Sign up Sign in

AI HL · AHL 1

Graph Theory

AHL 1.4

Counting walks with powers of the adjacency matrix

AHL 1.4

Counting walks with powers of the adjacency matrix

Target: I can write the matrix for counting walks in an undirected or directed graph, entering a loop as 1. (+4 more)

By the end of this section

Key points

Walks, paths and cycles

  • A walk of length k follows k edges, one after another. Edges and vertices may repeat.
  • A path visits no vertex twice. A cycle is a path that returns to its start. You list these by hand.
  • To count walks, do not list them: use the adjacency matrix. In a directed graph, rows are where an arc starts and columns where it ends.

Powers of the adjacency matrix

  • The entry in row i, column j of \(A^k\) is the number of walks of length k from vertex i to vertex j. It works for directed graphs too.
  • Use the calculator for the power. Write the matrix, write \(A^k\), then say which entry you read.
  • The adjacency matrix shows a loop in an undirected graph as 2. To count walks, change that entry to 1: a loop is one way to go from the vertex back to itself.
  • A double edge goes in as 2. Each edge gives a different walk.

Fewer than k steps

  • Walks of length less than 4 are walks of length 1, 2 and 3. Their numbers are the entries of \(A+A^2+A^3\).
  • Read the row for where you start and the column for where you finish. From B to A and from A to B can be different in a directed graph.
  • A graph is Eulerian if it has a circuit using every edge once, and semi-Eulerian if it has such a trail. The next lesson shows how to tell by counting odd vertices.

On the calculator

Powers of a matrix

  • Enter the adjacency matrix in the calculator with rows and columns in the same vertex order.
  • Type the matrix name with the power, for example \(A^5\). Do not multiply by hand.
  • Read the row of the vertex you start from and the column of the vertex you end at.

Screenshot and video to come

Adding powers

  • For walks shorter than 4, calculate \(A+A^2+A^3\) in one line.
  • Read the same entry as before. Check by reading the entry in each separate power.

Screenshot and video to come

Explore: count walks with powers of A

Choose a graph, a start vertex, an end vertex and a length k. The matrix Ak counts the walks. When there are few, they are listed.

Graph
Start
End

Rows are where a walk starts. Columns are where it ends. The highlighted entry is the answer.

    Choose a start and an end vertex.

    1. Set k = 1. Which entries of A are 1? Check them against the edges in the drawing.
    2. Choose the same start and end vertex. Why can there be walks of length 2 from a vertex back to itself?
    3. On the loop graph, find an entry of A2 that is bigger than you expect. Which walks use the double edge?
    4. On One-way links, swap the start and the end. Why can the two answers be different?

    Worked examples

    Problems like the ones in class. Pick one, try it, then open the working.
    Walks of length 3

    The graph has vertices W, X, Y and Z. Find the number of walks of length 3 from W to Z.

    WXYZ
    Working
    1. Adjacency matrix

      Adjacency matrix, rows and columns in the order W, X, Y, Z: \(A=\begin{pmatrix}0 & 1 & 1 & 1 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0\end{pmatrix}\)

      Entry in row i, column j is the number of edges between i and j.

    2. Raise to the power 3

      From the calculator: \(A^3=\begin{pmatrix}4 & 5 & 5 & 5 \\ 5 & 2 & 5 & 2 \\ 5 & 5 & 4 & 5 \\ 5 & 2 & 5 & 2\end{pmatrix}\)

      The entry in row i, column j of \(A^3\) counts walks of length 3 from i to j.

    3. Read the entry

      Row W, column Z: 5

      There are 5 walks of length 3 from W to Z.

    Video walkthrough coming
    A loop and a double edge

    The graph has vertices P, Q, R and S. There is a loop at P, two edges between P and Q, and one edge each for QR, RS and PS. Find the number of walks of length 5 from P to R.

    PQRS
    Working
    1. Adjacency matrix

      Adjacency matrix, rows and columns in the order P, Q, R, S: \(A=\begin{pmatrix}1 & 2 & 0 & 1 \\ 2 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0\end{pmatrix}\)

      The loop at P goes in as 1, not 2: we count connections, not which way round the loop is travelled. The double edge PQ goes in as 2.

    2. Raise to the power 5

      From the calculator: \(A^5=\begin{pmatrix}114 & 124 & 39 & 74 \\ 124 & 56 & 61 & 31 \\ 39 & 61 & 9 & 37 \\ 74 & 31 & 37 & 17\end{pmatrix}\)

      The entry in row i, column j of \(A^5\) counts walks of length 5 from i to j.

    3. Read the entry

      Row P, column R: 39

      There are 39 walks of length 5 from P to R.

    Video walkthrough coming
    Walks in a directed graph

    The directed graph shows one-way links between K, L, M and N. Find the number of walks of length 4 from L to M.

    KLMN
    Working
    1. Adjacency matrix

      Adjacency matrix, rows and columns in the order K, L, M, N: \(A=\begin{pmatrix}0 & 1 & 1 & 0 \\ 1 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0\end{pmatrix}\)

      Entry in row i, column j is the number of edges from i to j.

    2. Raise to the power 4

      From the calculator: \(A^4=\begin{pmatrix}2 & 1 & 2 & 1 \\ 1 & 2 & 2 & 1 \\ 1 & 0 & 1 & 1 \\ 1 & 1 & 1 & 1\end{pmatrix}\)

      The entry in row i, column j of \(A^4\) counts walks of length 4 from i to j.

    3. Read the entry

      Row L, column M: 2

      There are 2 walks of length 4 from L to M.

    Video walkthrough coming
    Walks of length less than 4

    The directed graph shows the one-way links between four vertices. Find the number of walks of length less than 4 from T to S.

    STUV
    Working
    1. Adjacency matrix

      Adjacency matrix, rows and columns in the order S, T, U, V: \(A=\begin{pmatrix}0 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0\end{pmatrix}\)

      Rows are where an arc starts, columns where it ends.

    2. Add the powers

      From the calculator: \(A+A^2+A^3=\begin{pmatrix}2 & 2 & 1 & 1 \\ 4 & 2 & 2 & 1 \\ 3 & 2 & 1 & 1 \\ 2 & 1 & 1 & 0\end{pmatrix}\)

      Walks of length 1, 2 and 3 are all shorter than 4.

    3. Read the entry

      Row T, column S: 1 + 1 + 2 = 4

      Check the split by reading the same entry in A, \(A^2\) and \(A^3\).

    Video walkthrough coming
    Listing the paths

    In the graph, list all the paths of length 3 from H to L. A path does not visit any vertex twice.

    HJKLM
    Working
    1. Go from H

      H is joined to J and M.

      Every path of length 3 starts H-J or H-M.

    2. Take three edges, end at L

      H-J-K-L; H-J-M-L; H-M-J-L

      Check each one: 3 edges, no vertex repeated, finishing at L.

    3. Count

      3 paths

      Write the list. It is the working.

    Video walkthrough coming
    Listing the cycles

    In the same graph, list all the cycles of length 4 that start and end at J. A cycle and its reverse count as the same cycle: write each one once.

    HJKLM
    Working
    1. Four edges, back to J

      J-H-M-L-J; J-K-L-M-J

      A cycle returns to its start and visits no other vertex twice.

    2. Reverse cycles

      2 cycles

      J-K-L-M-J and J-M-L-K-J are the same cycle in two directions. Count it once.

    Video walkthrough coming