Adjacency Matrices

Stage 23 of 23 Strand 2 of 5 3 lessons

3 illustrated lessons, each teaching the why before the how.

Start with The Adjacency Matrix in the app →
Revise Adjacency Matrices with flashcards →

Jump to a lesson

The Adjacency Matrix

A square of ones and zeros for the edges.

An adjacency matrix holds, in row i and column j, the number of edges joining those vertices

Read the full lesson →

ABCD

Every pair of vertices is either joined or not, and that is all a graph records.

ABCDA0110B1010C1101D0010

Write 1 where a pair is joined and 0 where it is not: the adjacency table.

ABCDA0110B1010C1101D0010

Row A, column B holds 1 because the edge from A to B is there.

A0110101011010010

Take the labels off and the numbers stand alone: the adjacency matrix.

A0110101011010010

The matrix is symmetric across the main diagonal, because an edge joins both ways at once.

ABCDA0110B1010C1101D0010

Row C adds to 3, and 3 is the degree of C. A row total is always a degree.

Now you

ABCDA0111B1001C1000D1100

What is the degree of vertex C?

ABCD

What goes in row A, column B of the adjacency matrix?

Counting Walks with Matrix Powers

The nth power counts the walks of length n.

Row i, column j of the nth power of an adjacency matrix counts the walks of length n

Read the full lesson →

ABCD

One walk of length 2 runs from A to D: A to C, then C to D.

A0110101011010010

The adjacency matrix counts the walks of length 1, which are the edges themselves.

A²2111121111301101

Multiply the matrix by itself. Row A, column D holds 1: one walk of length 2.

A²2111121111301101

Row C, column C holds 3, because you can go out to A, B or D and straight back.

A²2111121111301101

Row C, column D holds 0: the only neighbor of D is C, and there is no edge from C to C.

A + A²2221222122311111

Adding the two matrices counts walks of length 2 or less: C to D gives 1.

Now you

A0110101011010010

What does row B, column C of the cube of this matrix count?

A0110101011010010

What does row D, column B of the cube of this matrix count?

The Weighted Adjacency Table

The weight sits where the one used to.

A weighted graph carries a number on each edge, and its table stores that number in place of a 1

Read the full lesson →

42563789ABCDE

Each edge carries a weight: a distance, a cost, or a time.

ABCDEA—42——B4—569C25—83D—68—7E—937—

The table holds the weight where an edge exists, and a dash where none does.

ABCDEA—42——B4—569C25—83D—68—7E—937—

Row B, column D holds 6, so the edge from B to D costs 6.

ABCDEA—42——B4—569C25—83D—68—7E—937—

Row D, column B holds 6 as well: the same edge has the same weight from either end.

42563789ABCDE

A route costs the sum of the weights along it, so A to B to D costs 4 + 6 = 10.

Now you

42563789ABCDE

What does the route A to C to D cost?

42563789ABCDE

Which route from A to E is cheaper?

Continue your journey in the app — save your progress