Connectivity, Euler and Hamilton paths
Definitions of paths and circuits, components, cut vertices and bridges, counting paths with matrix powers, the degree condition for Euler circuits/paths, Dirac's and Ore's theorems for Hamilton circuits, and a brief look at Dijkstra's algorithm.
This week’s question is usually in two parts: “Does this graph have an Euler circuit / Euler path?” and “Does it have a Hamilton circuit?”. The Euler part is entirely degree counting; the Hamilton part is trial and error plus a few theorems. A definition question on connectivity and a short shortest-path (Dijkstra) question may also come. It is not on the midterm, it is a final exam topic.
Golden rules:
- Euler = edges, Hamilton = vertices. Mixing them up is the most expensive mistake.
- In a connected graph, an Euler circuit exists every degree is even. An Euler path (without a circuit) exists exactly two vertices have odd degree.
- For Hamilton there is no general “if and only if” criterion. To say one exists, write the circuit or use Dirac/Ore; to say none exists, show an obstacle.
- A question on the number of paths a power of the adjacency matrix.
Paths and circuits
In Rosen’s language (the terms of this course):
| Term | Meaning |
|---|---|
| path of length | a sequence of consecutive edges (called a walk in some books) |
| circuit | a path with |
| simple path / circuit | no edge is repeated |
| length | the number of edges (not the number of vertices) |
Intuition: vertices are stations on the field, edges are running lines. A training course is a path; if you return to the station you started from, it is a circuit.
Counting paths with matrices
If is the adjacency matrix, the number of paths of length from to is . Why: , that is, the number of intermediate vertices with an edge from to and from to .
For the 4-vertex graph in the questions:
The diagonal gives the degrees: a path of length 2 that leaves and comes back = going along an edge and returning.
Connectivity
An undirected graph is connected if there is a path between every two vertices. A graph that is not connected splits into components: maximal connected subgraphs. An isolated vertex is a component by itself.
A cut vertex: a vertex whose deletion (together with its edges) increases the number of components. A bridge (cut edge): an edge whose deletion increases the number of components.
TIP · the bridge test. If an edge is on a cycle, it cannot be a bridge, because the rest of the cycle still connects its two ends. First mark the cycles, then check the remaining edges.
Measures:
- Vertex connectivity : the minimum number of vertices that must be deleted to disconnect the graph (or reduce it to a single vertex).
- Edge connectivity : the minimum number of edges that must be deleted to disconnect it.
- Always .
Examples: ; ; if there is a bridge then , if there is a cut vertex then .
In directed graphs: if for every there are directed paths both and , the graph is strongly connected; if it becomes connected when you ignore directions, it is weakly connected.
Euler circuits and paths
An Euler circuit: a simple circuit that uses every edge exactly once. An Euler path: a simple path that uses every edge exactly once.
The story: the 7 bridges of Königsberg. 4 land masses (vertices), 7 bridges (edges), degrees . Euler showed that there is no tour crossing each bridge once.
Theorem. In a connected multigraph with at least two vertices:
- An Euler circuit exists every vertex has even degree.
- An Euler path exists but no circuit exactly two vertices have odd degree. The path starts and ends at these two vertices.
Intuition: every time the tour passes through a vertex, it enters along one edge and leaves along another: it adds 2 to the degree. So every vertex other than the start and end must have even degree.
A fully written proof (necessary condition)
Claim. If a connected multigraph has an Euler circuit, then every vertex of has even degree.
Proof. Let the Euler circuit start and end at , and follow it. The first edge contributes 1 to . Each time the circuit passes through a vertex (including returns to before the end), it enters along one edge and leaves along another, contributing 2 to . The last edge enters and contributes 1 more to . Since the circuit uses every edge exactly once, these contributions count every edge end exactly once. Hence for some integer , which is even, and every other vertex has degree equal to a sum of 2’s, which is even.
In plain words: follow the circuit, each “pass-through” adds 2 to a vertex; the starting vertex gets 1 + 1 from the first and last edges. The reverse direction (if every degree is even there is a circuit) is a constructive proof: build a circuit, find new circuits from the remaining edges and splice them in (Hierholzer). On the final, usually the necessary condition or only the application of the theorem is asked.
Application example. The “butterfly” graph: (two triangles with the common vertex ).
degrees: a 2, b 2, c 4, d 2, e 2 -> all even, connected
Euler circuit: a, b, c, d, e, c, a
Hamilton circuit? c is a cut vertex (deleting it separates {a,b} and {d,e})
-> you would have to pass through c twice -> NO Hamilton circuit
The same graph is perfect for Euler and impossible for Hamilton. The best example showing that the two concepts are independent.
Hamilton paths and circuits
A Hamilton path: a simple path that passes through every vertex exactly once. A Hamilton circuit: a circuit that returns to its starting vertex and passes through every other vertex exactly once.
Unlike Euler, there is no known simple “if and only if” condition for a Hamilton circuit (the problem is NP-complete). You have two kinds of tools.
Showing one exists (sufficient conditions):
| Theorem | Condition ( simple, vertices) |
|---|---|
| Dirac | every vertex has degree |
| Ore | for every non-adjacent , |
These conditions are sufficient but not necessary: in the degrees are 2 and the conditions fail, but itself is a Hamilton circuit.
Showing none exists (obstacles):
- If there is a vertex of degree 1, there is no Hamilton circuit (entering and leaving that vertex needs 2 edges).
- Both edges of a vertex of degree 2 are forced in the circuit. If three forced edges meet at one vertex, or they close a small incomplete circuit, that is a contradiction.
- If there is a cut vertex, there is no Hamilton circuit.
- In a bipartite graph whose sides are not the same size, there is no Hamilton circuit.
Special graphs: () always has a Hamilton circuit, and the number of different circuits is . () has a Hamilton circuit: a Gray code (consecutive codes differ in one bit) is exactly a Hamilton circuit in .
PITFALL · Using the Euler condition for Hamilton. “All degrees are even, so there is a Hamilton circuit” is wrong. In the butterfly graph all degrees are even but there is no Hamilton circuit. Conversely, in the degrees are 3 (odd) but there is a Hamilton circuit.
Shortest path: Dijkstra (briefly)
The length of a shortest path between two vertices in a weighted graph. Dijkstra’s algorithm (when there are no negative weights):
- Give the start the label 0 and the others .
- Among the vertices not yet finalized, choose the one with the smallest label and finalize it.
- Update the labels of its neighbors: .
- Repeat until the target is finalized.
For the graph in the question, the order of finalizing:
a:0 -> c:2 -> b:3 -> d:8 -> e:10 -> z:13
path (trace back): z <- e <- d <- b <- c <- a length 13
Note: the first label of is 4 (edge ), but 3 via . A vertex’s label can drop before it is finalized; once finalized it does not change. The complexity is .
Common mistakes
| Wrong | The truth |
|---|---|
| Mixing up Euler and Hamilton | Euler: every edge once. Hamilton: every vertex once |
| Starting an Euler path at any vertex | Start at one of the two odd-degree vertices, end at the other |
| Not checking connectivity in the Euler condition | If not connected (apart from isolated vertices), there is no Euler circuit |
| “Dirac fails, so there is no Hamilton circuit” | Dirac is a sufficient condition; failing it says nothing |
| The number of Hamilton circuits in is | Start and direction count the same: |
| Measuring path length by the number of vertices | Length = number of edges |
| Counting an edge on a cycle as a bridge | An edge on a cycle cannot be a bridge |
| Not counting an isolated vertex as a component | A vertex of degree 0 is a component by itself |
Test yourself
Exam-style questions. Solve them on paper first, then reveal the answer.
Which of , , , , have an Euler circuit? Which have an Euler path but no Euler circuit?
Show answer
In a connected graph, an Euler circuit exists every degree is even. An Euler path (not a circuit) exists exactly two vertices have odd degree.: all 4, circuit exists. : all 5, six odd vertices, neither exists.: degrees 4 and 2, circuit exists. : 3 vertices of degree 4, 4 vertices of degree 3; four odd vertices, neither exists.: 2 vertices of degree 3, 3 vertices of degree 2; exactly two odd vertices, a path exists but no circuit.
Graph has vertices and edges . Does have an Euler circuit or an Euler path? If a path exists, give one.
Show answer
Degrees: 2, 3, 4, 4, 2, 1. The odd ones are and : no circuit, a path exists and its ends must be and .
One path: . All 8 edges are used once.
A multigraph has four vertices with degrees . Does it have an Euler path?
Show answer
All four vertices have odd degree. An Euler path allows at most 2 odd-degree vertices (the ends). There is neither a circuit nor a path. (The Königsberg bridges problem has exactly these degrees.)
has vertices and edges . How many paths (walks) of length 2 are there from to ? Of length 3?
Show answer
The number of paths (walks) of length from to is the entry of .
Length 2: the middle vertex must be adjacent to both and : and . (, ).
Length 3: (, ).
has vertices and edges . Find all cut vertices and all cut edges (bridges).
Show answer
Structure: triangle , bridge , triangle , bridge .
Cut vertex: a vertex whose deletion increases the number of components. If 3 is deleted, breaks off; if 4 is deleted, and are separated; if 6 is deleted, 7 is left alone. Deleting 1, 2, 5 or 7 leaves the graph connected.
Bridge: the edges of a triangle lie on a cycle, so they cannot be bridges. The edges not on a cycle are and .
How many different Hamilton circuits does have? (Circuits that differ only in starting point or direction are the same.)
Show answer
Fix the starting vertex and order the remaining 4 vertices: . Each circuit was counted in two directions: . The general formula is .
A simple graph has 8 vertices and every vertex has degree at least 4. Must it have a Hamilton circuit? Which theorem do you use?
Show answer
Dirac: if and every vertex has degree , a Hamilton circuit exists. Here and every degree is . The condition holds, so a circuit definitely exists (for example is in this class).
Does have a Hamilton circuit? A Hamilton path?
Show answer
In a bipartite graph every edge switches sides, so a circuit goes and needs equal numbers of vertices on the two sides. , so there is no Hamilton circuit.
For a path the sides may differ by at most 1: is a Hamilton path.
Show that has a Hamilton circuit.
Show answer
In , two vertices are adjacent if they differ in exactly one bit. A Gray code does this: .
Every consecutive pair differs in one bit, and the last vertex and also differ in one bit. All 8 vertices are visited once.
Use Dijkstra's algorithm to find the length of a shortest path from to in the weighted graph with edges.
Show answer
Order of finalizing: (0). Neighbors: , . The smallest is (2): , , . (3): . (8): , . (10): . (13) is finalized. The path is .
How many connected components does the graph with vertices and edges have?
Show answer
The components: (triangle), , (path), (isolated vertex). An isolated vertex is also a component: 4 in total.
Find the vertex connectivity and the edge connectivity .
Show answer
: if you delete the side with 3 vertices, the 4 remaining vertices are not connected to each other, so the graph falls apart. Fewer is not enough: even if you delete 2 vertices, vertices remain on both sides, and every vertex on one side is connected to all of the other side. .: to isolate a vertex you must cut its 4 edges; deleting fewer edges does not disconnect the graph. .
Verification: Existence of Euler circuits/paths was checked with node by backtracking search over all edge orders, Hamilton circuits by counting all vertex orders, cut vertices and bridges by deleting them one by one and counting components, path counts with powers of the adjacency matrix, connectivity numbers by trying all subsets, and the Dijkstra result by computing it in code (verify/MAT2033/14.mjs).