Study and Productivity

Graph Theory for Students: Euler Paths, Spanning Trees and Graph Colouring

Learn the core graph algorithms of decision and discrete maths: Euler paths, Hamilton cycles, Kruskal and Prim spanning trees and graph colouring.

Saizul Amin
Saizul Amin3 Nov 2026 · 5 min read
Graph Theory for Students: Euler Paths, Spanning Trees and Graph Colouring

Graph Theory for Students: Euler Paths, Spanning Trees and Graph Colouring

A graph, in this sense, is not a chart. It is a set of points called vertices joined by lines called edges. With that tiny definition you can model road networks, computer networks, friendships, timetables and molecules. This guide covers the algorithms that appear most in decision maths and discrete maths courses and shows how to try them with the free graph theory explorer, where you draw a graph and watch each algorithm work on it.

Vocabulary you need

  • Degree: the number of edge ends at a vertex. A loop counts twice.
  • Walk, path, cycle: a walk follows edges; a path repeats no vertex; a cycle is a path that returns to its start.
  • Connected: every vertex can be reached from every other.
  • Weighted graph: each edge has a number, such as a distance or cost.

The handshake lemma. Adding up all the degrees counts every edge twice, so the total is always even. It follows that every graph has an even number of odd-degree vertices. The explorer's first algorithm option shows the degree of each vertex and checks this.

Euler paths and circuits

In 1736 Leonhard Euler was asked whether you could walk round the city of Königsberg crossing each of its seven bridges exactly once. He turned the map into a graph, with land areas as vertices and bridges as edges, and proved it was impossible. His reasoning gives a rule you can apply to any connected graph:

  • If every vertex has even degree, there is an Euler circuit: a route using every edge once and finishing where it started.
  • If exactly two vertices have odd degree, there is an Euler path that starts at one odd vertex and ends at the other.
  • With more than two odd vertices, neither exists.

Königsberg has four odd vertices, so no such walk exists. Load it in the explorer to see the degrees. Then load the "envelope" example, a house shape with two odd vertices at the bottom, and the tool draws an Euler path starting from one of them using Hierholzer's algorithm.

In practice this matters for route inspection: a road gritter or postal worker wants to cover every street with as little repetition as possible.

Hamilton cycles

A Hamilton cycle visits every vertex exactly once and returns home. It sounds similar to an Euler circuit, but there is no simple degree test for it. Deciding whether one exists is a famously hard problem in general, so the explorer searches every possibility for graphs of up to 14 vertices. The Petersen graph, with 10 vertices each of degree 3, has a Hamilton path but no Hamilton cycle, which makes it a favourite counterexample.

Minimum spanning trees

A spanning tree links all the vertices with no cycles, using exactly n − 1 edges for n vertices. In a weighted graph, the minimum spanning tree (MST) has the smallest total weight. It answers questions like "what is the cheapest way to connect these six villages to the water network?"

Kruskal's algorithm

  1. List the edges from lightest to heaviest.
  2. Take the lightest edge that does not create a cycle with edges already chosen.
  3. Repeat until you have n − 1 edges.

Prim's algorithm

  1. Start at any vertex.
  2. Add the lightest edge that connects the tree to a vertex not yet in it.
  3. Repeat until every vertex is included.

Both always give the minimum total. In the explorer's weighted example, Kruskal chooses A–D (5), C–E (5), D–F (6), A–B (7) and B–E (7) for a total of 30, and lists every edge it skipped because it would form a cycle. Prim starting from A adds the same edges in a different order. Exams often ask you to show the order of selection, which is exactly what the step list gives.

Graph colouring

Colour the vertices so that no edge joins two vertices of the same colour. The smallest number of colours needed is the chromatic number. Applications include exam timetables (vertices are exams, edges join exams with a shared student, colours are time slots) and assigning radio frequencies.

  • The Welsh-Powell method orders vertices by degree, largest first, and gives each the lowest colour not used by a neighbour. It is fast but does not always find the minimum.
  • An exact search tries all colourings with 1, 2, 3 … colours until one works.

A cycle with an even number of vertices needs 2 colours; an odd cycle needs 3; the complete graph K5 needs 5. The explorer shows both the greedy result and the exact chromatic number.

Shortest paths

Dijkstra's algorithm finds the shortest route between two vertices in a graph with non-negative weights by always expanding the closest unvisited vertex. It is included in the explorer so you can compare it with the spanning tree: the MST minimises total cable length, not the distance between two particular points.

Study tips

  • Always check degrees before searching for an Euler path; it saves time.
  • When showing Kruskal, write rejected edges too, with the reason.
  • For colouring proofs, find a triangle or odd cycle to show three colours are needed.

Limits

Exhaustive Hamilton and colouring searches are limited to 14 vertices. The explorer does not cover directed graphs, network flows or matchings, and it is intended for learning and checking homework rather than for large real-world networks.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages