Track progress, take quizzes and save notes on this lesson.

Free forever · no card needed

Start free
Intermediate

Graphs

4.2.4 Graphs: directed, undirected, weighted·adjacency matrix·adjacency list

Aligned to the AQA 7517 specification

Level
Intermediate
Reading time
5 min
Published
13 June 2026
Updated
1 July 2026
On this page
  1. 1.What Is a Graph?
  2. 2.Directed vs Undirected Graphs
  3. 3.Adjacency Matrix
  4. 4.Adjacency List
  5. 5.Choosing a Representation
  6. 6.Common Exam Mistakes

Key takeaways

  • A graph is a set of vertices (nodes) connected by edges (arcs); it is undirected if edges are bidirectional, directed (a digraph) if edges are one-way, and weighted if edges carry a numeric value.
  • An adjacency matrix is a 2D array where matrix[i][j] records whether an edge exists from vertex i to vertex j; for an undirected graph it is symmetric.
  • An adjacency list stores, for each vertex, the list of vertices it connects to and optionally the edge weights.
  • An adjacency matrix uses O(V²) space and checks an edge in O(1), while an adjacency list uses O(V + E) space, so matrices suit dense graphs and lists suit sparse graphs.
  • A tree is a special case of a graph: connected, undirected, and with no cycles, so all graph representations apply to trees.

What Is a Graph?

A graph is a data structure consisting of a set of vertices (nodes) connected by edges (arcs). Graphs model relationships between entities: road networks, social networks, circuit diagrams, dependency trees, and more.

Key terminology:

TermMeaning
Vertex (node)An entity in the graph
Edge (arc)A connection between two vertices
Directed graph (digraph)Edges have a direction (one-way)
Undirected graphEdges have no direction (two-way)
Weighted graphEdges carry a numeric value (cost, distance, time)
Unweighted graphAll edges treated as equal

Example — undirected weighted graph (road network):

Vertices: A, B, C, D. Edge A–B has weight 4; edge C–D has weight 1.

Directed vs Undirected Graphs

Undirected graph — edges are bidirectional; if A connects to B then B connects to A.

Directed graph (digraph) — edges are one-way; A → B does not imply B → A.

Undirected vs directed
Undirected
Directed

Applications:

  • Undirected: friendship networks (mutual), road maps (two-way streets)
  • Directed: Twitter follows (one-way), web page links, task dependencies

(Extra context — not required by AQA 4.2.4) A graph with no cycles is a directed acyclic graph (DAG), used in build systems, spreadsheet dependencies, and scheduling.

Adjacency Matrix

An adjacency matrix represents a graph as a 2D array where matrix[i][j] indicates whether there is an edge from vertex to vertex .

  • Unweighted: 1 if an edge exists, 0 if not
  • Weighted: the edge weight if an edge exists, 0 (or ) if not

Example — the road network from slide 1:

Note: for undirected graphs the matrix is symmetric (value at [i][j] equals value at [j][i]).

Space complexity: — always allocates a array regardless of edge count.

Adjacency List

An adjacency list stores a list of neighbours for each vertex. Each vertex maps to the list of vertices it connects to (and optionally the edge weights).

Example — same graph:

A: [(B, 4), (C, 2)]
B: [(A, 4), (D, 3)]
C: [(A, 2), (D, 1)]
D: [(B, 3), (C, 1)]

Space complexity: — uses space proportional to the number of vertices plus the number of edges.

Comparison:

Adjacency matrixAdjacency list
Space
Check if edge exists
List all neighbours
Best forDense graphs (many edges)Sparse graphs (few edges)

A dense graph has close to edges; a sparse graph has far fewer. Most real-world networks (road maps, social networks) are sparse — adjacency lists are usually more efficient.

Studying this for an exam?

Generate a personalised learning path for this subject. Free to get started.

Create a learning path

Choosing a Representation

The choice of representation depends on the graph's characteristics and the operations required:

Use an adjacency matrix when:

  • The graph is dense (many edges)
  • Frequent edge-existence checks are needed
  • Memory is not a constraint

Use an adjacency list when:

  • The graph is sparse (few edges, as in most real applications)
  • Memory efficiency matters
  • Operations mainly iterate over neighbours (as in BFS and DFS)

Worked example — representing a social network of 1 million users:

  • Matrix would require cells — impractical
  • Each user has on average 200 friends → total edges ≈
  • Adjacency list uses space proportional to — manageable

Common Exam Mistakes

1. Forgetting that undirected adjacency matrices are symmetric

In an undirected graph, if matrix[A][B] = 4 then matrix[B][A] must also be 4. Missing the symmetric entry loses marks in matrix construction questions.

2. Confusing vertices and edges in Big-O analysis

refers to vertices squared; refers to vertices plus edges. Substituting one for the other produces wrong complexity claims.

3. Using an adjacency matrix for a sparse graph

A social network or the Internet is sparse. Claiming a matrix is the better choice is incorrect without justifying that the graph is dense.

4. Stating that a tree is not a graph

A tree is a special case of a graph: connected, undirected, and with no cycles. All the graph representations apply to trees.

Key terms

Graph
A data structure made up of a set of vertices (nodes) connected by edges (arcs).
Vertex (node)
An entity in a graph.
Edge (arc)
A connection between two vertices in a graph.
Directed graph (digraph)
A graph whose edges have a direction, so A to B does not imply B to A.
Undirected graph
A graph whose edges have no direction, so if A connects to B then B connects to A.
Weighted graph
A graph whose edges carry a numeric value such as cost, distance, or time.
Adjacency matrix
A 2D array where entry [i][j] indicates whether (and with what weight) an edge exists from vertex i to vertex j; uses O(V²) space.
Adjacency list
A representation storing a list of neighbours for each vertex, optionally with edge weights; uses O(V + E) space.
Dense graph
A graph with close to V² edges, best represented by an adjacency matrix.
Sparse graph
A graph with far fewer than V² edges, best represented by an adjacency list.

Frequently asked questions

An adjacency matrix is a 2D array marking every possible vertex pair, using O(V²) space and checking an edge in O(1). An adjacency list stores only each vertex's actual neighbours, using O(V + E) space. Matrices suit dense graphs; lists suit sparse graphs.

Use an adjacency list when the graph is sparse (few edges, as in most real applications), when memory efficiency matters, or when operations mainly iterate over neighbours, as in BFS and DFS. Most real-world networks like road maps and social networks are sparse.

In an undirected graph an edge between A and B goes both ways, so if matrix[A][B] = 4 then matrix[B][A] must also be 4. Missing the symmetric entry loses marks in matrix construction questions.

Generate revision on any topic you study

Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.

Lessons on anything

Structured, level-matched lessons on any topic you study

Practice quizzes

Find out what you actually know before the exam does

Flashcard sets

Lock in key concepts with instant revision cards

Ask Aica

Stuck on something? Get a clear explanation, any time

Prev

Stacks and Queues

Next

Binary Search Trees

Related lessons

Top students don’t revise more. They revise what counts.

Start revising free

Free to start. No card needed.