Adjacency matrices, spanning trees, Eulerian & Hamiltonian circuits
Math AI HL Topic 3 ExtensionGraph theory is the study of graphs — mathematical structures used to model pairwise relations between objects. A graph $G = (V, E)$ consists of a set of vertices (nodes) $V$ and a set of edges $E$ connecting pairs of vertices.
| Term | Definition | Example |
|---|---|---|
| Vertex (node) | A point in the graph | City in a road network |
| Edge (arc) | A connection between two vertices | Road between two cities |
| Degree of a vertex | Number of edges incident to it | $\deg(v) = 3$ means 3 edges meet at $v$ |
| Simple graph | No loops, no multiple edges | Standard undirected graph |
| Multigraph | Multiple edges allowed between vertices | Two roads between same cities |
| Directed graph (digraph) | Edges have direction (arrows) | One-way streets |
| Weighted graph | Each edge has a numerical weight | Road network with distances |
For any graph $G$, the sum of all vertex degrees equals twice the number of edges:
$$\sum_{v \in V} \deg(v) = 2|E|$$Consequence: The number of vertices with odd degree is always even.
An adjacency matrix $A$ is an $n \times n$ matrix where $a_{ij}$ represents the number of edges from vertex $i$ to vertex $j$.
A graph has vertices $A, B, C, D$ with edges: $AB$, $AC$, $BC$, $BD$, $CD$. Construct the adjacency matrix and find the number of walks of length 2 from $A$ to $D$.
A spanning tree of a connected graph is a subgraph that is a tree containing all $n$ vertices (and exactly $n-1$ edges). A minimum spanning tree (MST) is a spanning tree with the smallest possible total edge weight.
Sort all edges by weight (ascending). Add edges one by one, skipping any edge that would create a cycle. Stop when $n-1$ edges have been added.
Time complexity: $O(E \log E)$ for sorting.
Start from any vertex. Greedily add the cheapest edge connecting a vertex in the current tree to a vertex not yet in the tree. Repeat until all vertices are included.
Key difference from Kruskal: Prim's grows a single connected component; Kruskal's may add isolated edges that eventually merge.
A weighted graph has 5 vertices $\{A,B,C,D,E\}$ with edges and weights: $AB=3$, $AC=5$, $BC=2$, $BD=6$, $BE=4$, $CD=1$, $CE=7$, $DE=5$. Find the MST using Kruskal's algorithm.
An Eulerian path traverses every edge exactly once. An Eulerian circuit is an Eulerian path that starts and ends at the same vertex.
A Hamiltonian path visits every vertex exactly once. A Hamiltonian circuit returns to the starting vertex after visiting every other vertex exactly once.
A graph has 6 vertices with degrees 2, 3, 4, 3, 2, 4. Does an Eulerian circuit exist? Does an Eulerian path exist?
The Chinese Postman Problem (Route Inspection) asks: what is the shortest closed walk that traverses every edge at least once? This models a postman delivering to every street and returning to the depot.
The Travelling Salesman Problem: find the shortest Hamiltonian circuit in a complete weighted graph (visit every city exactly once and return to start).
The TSP is NP-hard — no known polynomial-time exact algorithm. For IB, we use approximation:
Note: This gives a good approximation but not necessarily the optimal solution. The result depends on the starting vertex chosen.
1. A graph has vertices $P, Q, R, S$ with edges $PQ=4$, $PR=7$, $PS=2$, $QR=3$, $QS=6$, $RS=5$. Use Kruskal's algorithm to find the minimum spanning tree and state its total weight.
Sort edges: $PS=2$, $QR=3$, $PQ=4$, $RS=5$, $QS=6$, $PR=7$
Add $PS=2$ ✓, Add $QR=3$ ✓, Add $PQ=4$ ✓ (connects $\{P,S\}$ to $\{Q,R\}$). Now all 4 vertices connected with 3 edges. Stop.
MST edges: $PS, QR, PQ$ | Total weight: $2+3+4 = \mathbf{9}$
2. A connected graph has 8 vertices. Their degrees are: 4, 2, 3, 5, 2, 3, 4, 3. Determine whether an Eulerian circuit exists, and whether an Eulerian path exists.
Odd-degree vertices: 3, 5, 3, 3 — that is 4 vertices with odd degree.
Eulerian circuit: Requires 0 odd-degree vertices. Does NOT exist.
Eulerian path: Requires exactly 2 odd-degree vertices. Does NOT exist (4 odd-degree vertices).
To make an Eulerian circuit, we'd need to add repeated edges to convert all 4 odd-degree vertices to even — this is the Chinese Postman approach.
3. The adjacency matrix of a graph is $A = \begin{pmatrix} 0&1&1&0\\ 1&0&0&1\\ 1&0&0&1\\ 0&1&1&0 \end{pmatrix}$. Find the number of walks of length 2 from vertex 1 to vertex 4, and list all such walks.
$(A^2)_{14}$ = row 1 of $A$ dotted with column 4 of $A$: $(0)(0)+(1)(1)+(1)(1)+(0)(0) = 2$.
Two walks of length 2: $1 \to 2 \to 4$ and $1 \to 3 \to 4$.