Skip to main content
← AT CS Study Guide

Unit 8 · Heavy

Graphs and Graph Theory

The most general structure in the course, and the one where the choice of representation changes the complexity of everything built on top of it.

What a strong answer looks like

A strong Unit 8 answer names the representation, states complexity in terms of both vertices and edges, and says which traversal discipline the algorithm relies on.

Topics in this unit

1

Representation

Know

An adjacency list uses space proportional to vertices plus edges; an adjacency matrix uses the square of the vertices regardless of how few edges exist.

Apply

Choose the list for sparse graphs and the matrix when edge lookup between two named vertices must be constant.

Watch out

Quoting a traversal cost without saying which representation it assumes. The answer differs.

Study move

State the space and the traversal cost for one graph under both representations.

2

Breadth-First Search

Know

BFS uses a queue and expands in layers, so the first time it reaches a vertex it has used the fewest edges. That is why it solves unweighted shortest paths.

Apply

Use BFS when the fewest steps matters and edges carry no weight.

Watch out

Expecting BFS to handle weighted shortest paths. Layer order is not weight order.

Study move

Run BFS on a small graph and record the layer each vertex is discovered in.

3

Depth-First Search

Know

DFS uses a stack, explicitly or through recursion, and goes deep before backtracking. It underpins cycle detection and topological ordering.

Apply

Detect a cycle in a directed graph by finding an edge back to a vertex still on the recursion stack.

Watch out

Calling any edge to a visited vertex a cycle. An edge to a finished vertex is legal in an acyclic graph.

Study move

Trace DFS on a directed graph and classify each edge as tree, back, or cross.

4

Shortest Paths and Spanning Trees

Know

Dijkstra settles vertices in increasing distance and therefore cannot tolerate negative edges. Kruskal and Prim build minimum spanning trees by different strategies.

Apply

Choose Bellman-Ford over Dijkstra when negative weights are possible.

Watch out

Running Dijkstra on a graph with negative edges, which finalises a vertex a later edge could still improve.

Study move

Construct a small graph with a negative edge where Dijkstra returns a wrong distance.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Naming the representation before quoting a cost
  • Matching the traversal discipline to the question
  • Knowing which algorithms tolerate negative weights

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Network flow. An extension topic in some sections.
  • Union-find. Introduced with Kruskal in some courses and omitted in others.

Mastery checklist

  • Compare adjacency list and matrix on space and lookup.
  • Explain why BFS solves unweighted shortest paths.
  • Detect a cycle correctly with DFS.
  • Say when Dijkstra is invalid and what to use instead.

Check yourself

  • Why does the representation change traversal complexity?
  • What exactly distinguishes a back edge from a cross edge?
  • Why does a negative edge break Dijkstra?

Modeling drill

Model a campus as a graph where edges carry walking times, choose an algorithm for the fastest route, and justify it against one alternative.

VertexEdgeAdjacency listAdjacency matrixBFSDFSBack edgeSpanning tree