Graphs and networks
A graph is a set of points (vertices) joined by lines (edges). Graphs model road maps, social networks, circuits and timetables. Graph algorithms find shortest routes, cheapest connecting networks and efficient delivery rounds.
Key facts
- The degree of a vertex is the number of edges meeting it. The degrees always add up to twice the number of edges.
- A tree is connected with no cycles. A tree with n vertices has n − 1 edges. The complete graph Kₙ has (n(n − 1))/2 edges.
- Eulerian (a closed trail using every edge once): every degree is even. Semi-Eulerian: exactly two odd vertices.
- Dijkstra’s algorithm finds shortest paths. Kruskal’s and Prim’s algorithms find a minimum spanning tree.
- Route inspection with two odd vertices: add the shortest path joining them to the total edge weight.
- A connected planar graph satisfies Euler’s formula V − E + F = 2.
Worked examples
Example 1
A graph has vertex degrees 3, 3, 2, 4, 2. How many edges does it have, and is it Eulerian?
- Sum of degrees: 3 + 3 + 2 + 4 + 2 = 14
- Each edge adds 2 to the sum. 14 ÷ 2 = 7 edges
- Exactly two vertices have odd degree, so it is semi-Eulerian. A trail can use every edge once, starting and ending at the odd vertices.
Answer: 7 edges, semi-Eulerian
Example 2
Find a minimum spanning tree for the network shown and its total weight.
- List the edges in order of weight. BC 2, AC 3, DE 3, AB 4, BD 5, CD 6, CE 7
- Take BC, AC and DE.
- Reject AB. A and B are already joined through C, so it would make a cycle.
- Take BD to join the two groups. All five vertices are connected. 2 + 3 + 3 + 5 = 13
Answer: BC, AC, DE, BD: total 13
Example 3
Use Dijkstra’s algorithm to find the shortest route from A to E in the same network.
- From A: C gets 3, B gets 4. Make C permanent (3).
- From C: B stays at 4, since 3 + 2 = 5 is worse. D gets 3 + 6 = 9 and E gets 3 + 7 = 10.
- Make B permanent (4). D via B is 4 + 5 = 9, which is no better.
- Make D permanent (9). E via D is 9 + 3 = 12, which is worse than 10.
- So the shortest route is A → C → E, length 10.
Answer: 10, along A → C → E
Example 4
A graph has 4 vertices with degrees 2, 2, 3 and 3. How many edges does it have?
- Each edge adds 2 to the total of the degrees.
- Halve the total. (2 + 2 + 3 + 3) ÷ 2 = 5
Answer: 5
Example 5
Can a graph have three vertices, each of degree 3?
- The total of the degrees would be 9. 3 + 3 + 3 = 9
- The total must be even, because each edge adds 2, so it is impossible.
Answer: No
Example 6
A tree has 7 vertices. How many edges does it have?
- A tree with n vertices always has n − 1 edges.
- Subtract. 7 − 1 = 6
Answer: 6