Adjacency matrix

An adjacency matrix is a way to represent a graph using a square matrix.

This is especially useful for representing graphs in computers.

Structure of an adjacency matrix

An adjacency matrix looks like this:

V1V2V3
V1ABC
V2DEF
V3GHI

Where:

Symmetry

In an undirected graph, the adjacency matrix is symmetric along the main diagonal (from the top-left to the bottom-right).

That’s because an edge from vertex V1 to vertex V2 is the same as an edge from V2 to V1 in an undirected graph.

Example 1

For the following undirected graph:

    A
   / \
  B---C

The adjacency matrix for this graph would be:

ABC
A011
B101
C110

Example 2

For this undirected graph:

    A
   / \
  B===C
   \
    D

The adjacency matrix for this graph would be:

ABCD
A0110
B1021
C1200
D0100

flashcards

QuestionAnswer
What is an adjacency matrix used for?A way to represent a graph using a square matrix, especially useful for representing graphs in computers.
How is an adjacency matrix structured?Rows and columns represent vertices; entries in the matrix indicate the number of edges attaching a node to another node.
What property does the adjacency matrix of an undirected graph have?It is symmetric along the main diagonal (top-left to bottom-right).
Why is an undirected graph’s adjacency matrix symmetric?Because an edge from vertex V1 to vertex V2 is the same as an edge from V2 to V1.
For an undirected graph with three vertices A, B, C forming a triangle (A-B, A-C, B-C), what is its adjacency matrix?
For an undirected graph with vertices A, B, C, D where edges are A-B, A-C, B-C (double edge), and B-D, what is its adjacency matrix?