MAT2033 · Week 14 · "Connectivity, Euler and Hamilton paths,

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.

walkpathcircuitsimple pathconnected graphconnected componentcut vertexcut edge (bridge)vertex connectivityedge connectivitystrongly connectedweakly connectedEuler circuitEuler pathHamilton pathHamilton circuitDirac's theoremOre's theoremGray codeDijkstra's algorithmweighted graph

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:

  1. Euler = edges, Hamilton = vertices. Mixing them up is the most expensive mistake.
  2. In a connected graph, an Euler circuit exists   ⟺  \iff every degree is even. An Euler path (without a circuit) exists   ⟺  \iff exactly two vertices have odd degree.
  3. 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.
  4. A question on the number of paths ⇒\Rightarrow a power of the adjacency matrix.

Paths and circuits

In Rosen’s language (the terms of this course):

TermMeaning
path of length nna sequence v0,v1,…,vnv_0, v_1, \dots, v_n of nn consecutive edges (called a walk in some books)
circuita path with v0=vnv_0 = v_n
simple path / circuitno edge is repeated
lengththe 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 AA is the adjacency matrix, the number of paths of length rr from viv_i to vjv_j is (Ar)ij(A^r)_{ij}. Why: (A2)ij=∑kaikakj(A^2)_{ij} = \sum_k a_{ik}a_{kj}, that is, the number of intermediate vertices kk with an edge from ii to kk and from kk to jj.

For the 4-vertex graph in the questions:

A2=[2121131221211213]A^2 = \begin{bmatrix} 2&1&2&1\\ 1&3&1&2\\ 2&1&2&1\\ 1&2&1&3 \end{bmatrix}

The diagonal gives the degrees: a path of length 2 that leaves viv_i 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 κ(G)\kappa(G): the minimum number of vertices that must be deleted to disconnect the graph (or reduce it to a single vertex).
  • Edge connectivity λ(G)\lambda(G): the minimum number of edges that must be deleted to disconnect it.
  • Always κ(G)≤λ(G)≤min⁡vdeg⁡(v)\kappa(G) \le \lambda(G) \le \min_v \deg(v).

Examples: κ(Kn)=λ(Kn)=n−1\kappa(K_n) = \lambda(K_n) = n-1; κ(Km,n)=min⁡(m,n)\kappa(K_{m,n}) = \min(m,n); if there is a bridge then λ=1\lambda = 1, if there is a cut vertex then κ=1\kappa = 1.

In directed graphs: if for every a,ba, b there are directed paths both a→ba\to b and b→ab\to a, 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 5,3,3,35, 3, 3, 3. 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   ⟺  \iff every vertex has even degree.
  • An Euler path exists but no circuit   ⟺  \iff 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 GG has an Euler circuit, then every vertex of GG has even degree.

Proof. Let the Euler circuit start and end at aa, and follow it. The first edge contributes 1 to deg⁡(a)\deg(a). Each time the circuit passes through a vertex vv (including returns to aa before the end), it enters vv along one edge and leaves along another, contributing 2 to deg⁡(v)\deg(v). The last edge enters aa and contributes 1 more to deg⁡(a)\deg(a). Since the circuit uses every edge exactly once, these contributions count every edge end exactly once. Hence deg⁡(a)=1+2t+1\deg(a) = 1 + 2t + 1 for some integer t≥0t \ge 0, which is even, and every other vertex has degree equal to a sum of 2’s, which is even. ■\blacksquare

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: ab,bc,ca,cd,de,ecab, bc, ca, cd, de, ec (two triangles with the common vertex cc).

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):

TheoremCondition (GG simple, n≥3n \ge 3 vertices)
Diracevery vertex has degree ≥n/2\ge n/2
Orefor every non-adjacent u,vu, v, deg⁡(u)+deg⁡(v)≥n\deg(u) + \deg(v) \ge n

These conditions are sufficient but not necessary: in C10C_{10} the degrees are 2 and the conditions fail, but C10C_{10} itself is a Hamilton circuit.

Showing none exists (obstacles):

  1. If there is a vertex of degree 1, there is no Hamilton circuit (entering and leaving that vertex needs 2 edges).
  2. 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.
  3. If there is a cut vertex, there is no Hamilton circuit.
  4. In a bipartite graph whose sides are not the same size, there is no Hamilton circuit.

Special graphs: KnK_n (n≥3n\ge 3) always has a Hamilton circuit, and the number of different circuits is (n−1)!2\frac{(n-1)!}{2}. QnQ_n (n≥2n \ge 2) has a Hamilton circuit: a Gray code (consecutive codes differ in one bit) is exactly a Hamilton circuit in QnQ_n.

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 K4K_4 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):

  1. Give the start the label 0 and the others ∞\infty.
  2. Among the vertices not yet finalized, choose the one with the smallest label and finalize it.
  3. Update the labels of its neighbors: L(v)=min⁡(L(v), L(u)+w(u,v))L(v) = \min\big(L(v),\ L(u) + w(u,v)\big).
  4. 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 bb is 4 (edge abab), but 3 via cc. A vertex’s label can drop before it is finalized; once finalized it does not change. The complexity is O(n2)O(n^2).

Common mistakes

WrongThe truth
Mixing up Euler and HamiltonEuler: every edge once. Hamilton: every vertex once
Starting an Euler path at any vertexStart at one of the two odd-degree vertices, end at the other
Not checking connectivity in the Euler conditionIf 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 KnK_n is n!n!Start and direction count the same: (n−1)!2\frac{(n-1)!}{2}
Measuring path length by the number of verticesLength = number of edges
Counting an edge on a cycle as a bridgeAn edge on a cycle cannot be a bridge
Not counting an isolated vertex as a componentA vertex of degree 0 is a component by itself

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1medium

Which of K5K_5, K6K_6, K2,4K_{2,4}, K3,4K_{3,4}, K2,3K_{2,3} have an Euler circuit? Which have an Euler path but no Euler circuit?

Show answer
Circuit: K5, K2,4. Path only: K2,3

In a connected graph, an Euler circuit exists   ⟺  \iff every degree is even. An Euler path (not a circuit) exists   ⟺  \iff exactly two vertices have odd degree.K5K_5: all 4, circuit exists. K6K_6: all 5, six odd vertices, neither exists.K2,4K_{2,4}: degrees 4 and 2, circuit exists. K3,4K_{3,4}: 3 vertices of degree 4, 4 vertices of degree 3; four odd vertices, neither exists.K2,3K_{2,3}: 2 vertices of degree 3, 3 vertices of degree 2; exactly two odd vertices, a path exists but no circuit.

Question 2medium

Graph GG has vertices a,b,c,d,e,fa,b,c,d,e,f and edges ab,ac,bc,bd,cd,ce,de,dfab, ac, bc, bd, cd, ce, de, df. Does GG have an Euler circuit or an Euler path? If a path exists, give one.

Show answer
Euler path only, from b to f: b, a, c, b, d, c, e, d, f

Degrees: aa 2, bb 3, cc 4, dd 4, ee 2, ff 1. The odd ones are bb and ff: no circuit, a path exists and its ends must be bb and ff.
One path: b→a→c→b→d→c→e→d→fb\to a\to c\to b\to d\to c\to e\to d\to f. All 8 edges are used once.

Question 3easy

A multigraph has four vertices with degrees 5,3,3,35, 3, 3, 3. Does it have an Euler path?

Show answer
No

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.)

Question 4medium

GG has vertices v1,v2,v3,v4v_1,v_2,v_3,v_4 and edges v1v2,v1v4,v2v3,v2v4,v3v4v_1v_2, v_1v_4, v_2v_3, v_2v_4, v_3v_4. How many paths (walks) of length 2 are there from v1v_1 to v3v_3? Of length 3?

Show answer
Length 2: 2. Length 3: 2

The number of paths (walks) of length rr from viv_i to vjv_j is the (i,j)(i,j) entry of ArA^r.
Length 2: the middle vertex must be adjacent to both v1v_1 and v3v_3: v2v_2 and v4v_4. A132=2A^2_{13} = 2 (v1v2v3v_1v_2v_3, v1v4v3v_1v_4v_3).
Length 3: A133=∑kA1k2Ak3=A122+A142=1+1=2A^3_{13} = \sum_k A^2_{1k}A_{k3} = A^2_{12} + A^2_{14} = 1 + 1 = 2 (v1v2v4v3v_1v_2v_4v_3, v1v4v2v3v_1v_4v_2v_3).

Question 5medium

GG has vertices 1,…,71,\dots,7 and edges 12,13,23,34,45,46,56,6712, 13, 23, 34, 45, 46, 56, 67. Find all cut vertices and all cut edges (bridges).

Show answer
Cut vertices 3, 4, 6; bridges 34 and 67

Structure: triangle {1,2,3}\{1,2,3\}, bridge 3434, triangle {4,5,6}\{4,5,6\}, bridge 6767.
Cut vertex: a vertex whose deletion increases the number of components. If 3 is deleted, {1,2}\{1,2\} breaks off; if 4 is deleted, {1,2,3}\{1,2,3\} and {5,6,7}\{5,6,7\} 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 3434 and 6767.

Question 6medium

How many different Hamilton circuits does K5K_5 have? (Circuits that differ only in starting point or direction are the same.)

Show answer
12

Fix the starting vertex and order the remaining 4 vertices: 4!=244! = 24. Each circuit was counted in two directions: 24/2=1224/2 = 12. The general formula is (n−1)!2\frac{(n-1)!}{2}.

Question 7easy

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
Yes, by Dirac's theorem

Dirac: if n≥3n \ge 3 and every vertex has degree ≥n/2\ge n/2, a Hamilton circuit exists. Here n/2=4n/2 = 4 and every degree is ≥4\ge 4. The condition holds, so a circuit definitely exists (for example K4,4K_{4,4} is in this class).

Question 8medium

Does K2,3K_{2,3} have a Hamilton circuit? A Hamilton path?

Show answer
No circuit; yes, a path

In a bipartite graph every edge switches sides, so a circuit goes A,B,A,B,…A,B,A,B,\dots and needs equal numbers of vertices on the two sides. 2≠32 \neq 3, so there is no Hamilton circuit.
For a path the sides may differ by at most 1: b1,a1,b2,a2,b3b_1, a_1, b_2, a_2, b_3 is a Hamilton path.

Question 9medium

Show that Q3Q_3 has a Hamilton circuit.

Show answer
000, 001, 011, 010, 110, 111, 101, 100, back to 000

In Q3Q_3, two vertices are adjacent if they differ in exactly one bit. A Gray code does this: 000→001→011→010→110→111→101→100→000000\to001\to011\to010\to110\to111\to101\to100\to000.
Every consecutive pair differs in one bit, and the last vertex 100100 and 000000 also differ in one bit. All 8 vertices are visited once.

Question 10hard

Use Dijkstra's algorithm to find the length of a shortest path from aa to zz in the weighted graph with edgesab:4, ac:2, bc:1, bd:5, cd:8, ce:10, de:2, dz:6, ez:3ab{:}4,\ ac{:}2,\ bc{:}1,\ bd{:}5,\ cd{:}8,\ ce{:}10,\ de{:}2,\ dz{:}6,\ ez{:}3.

Show answer
13 (a, c, b, d, e, z)

Order of finalizing: aa (0). Neighbors: b=4b = 4, c=2c = 2. The smallest is cc (2): b=min⁡(4,2+1)=3b = \min(4, 2+1) = 3, d=10d = 10, e=12e = 12.bb (3): d=min⁡(10,3+5)=8d = \min(10, 3+5) = 8. dd (8): e=min⁡(12,8+2)=10e = \min(12, 8+2) = 10, z=14z = 14.ee (10): z=min⁡(14,10+3)=13z = \min(14, 10 + 3) = 13. zz (13) is finalized. The path is a,c,b,d,e,za, c, b, d, e, z.

Question 11easy

How many connected components does the graph with vertices 1,…,91,\dots,9 and edges 12,23,31,45,67,7812, 23, 31, 45, 67, 78 have?

Show answer
4

The components: {1,2,3}\{1,2,3\} (triangle), {4,5}\{4,5\}, {6,7,8}\{6,7,8\} (path), {9}\{9\} (isolated vertex). An isolated vertex is also a component: 4 in total.

Question 12hard

Find the vertex connectivity κ(K3,4)\kappa(K_{3,4}) and the edge connectivity λ(K5)\lambda(K_5).

Show answer
kappa(K3,4) = 3, lambda(K5) = 4

K3,4K_{3,4}: 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. κ=3=min⁡(m,n)\kappa = 3 = \min(m,n).K5K_5: to isolate a vertex you must cut its 4 edges; deleting fewer edges does not disconnect the graph. λ(Kn)=n−1=4\lambda(K_n) = n - 1 = 4.

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).

Review card

Walk: repeats allowed. Path (simple): no repeated edge. Circuit: returns to the start Connected: a path between every two vertices. Component: maximal connected piece (isolated vertex included) Cut vertex / bridge: deletion increases the number of components. An edge on a cycle can NOT be a bridge kappa <= lambda <= min degree; kappa(K_n) = lambda(K_n) = n - 1 number of paths of length r from v_i to v_j = (A^r)_{ij} EULER (every EDGE once), connected graph: circuit <=> all degrees even; path (not circuit) <=> EXACTLY 2 odd vertices, the ends are those K_n circuit: n odd; K_{m,n} circuit: m and n even HAMILTON (every VERTEX once): no general criterion Dirac: n>=3, every deg >= n/2 -> circuit exists Ore: for every non-adjacent u,v deg u + deg v >= n -> circuit exists Obstacles: a degree-1 vertex, a cut vertex, bipartite with unequal sides Number of Hamilton circuits in K_n is (n-1)!/2; Q_n: Gray code Dijkstra: finalize the smallest label, update neighbors (no negative weights)