Introduction
Two famous problems in graph theory involve traversing graphs:
- Euler paths: Visit every edge exactly once
- Hamiltonian paths: Visit every vertex exactly once
These concepts have practical applications in routing, scheduling, and optimization.
Euler Paths and Circuits
Definitions
Euler Path: A path that uses every edge exactly once.
Euler Circuit (Euler Cycle): A circuit that uses every edge exactly once and returns to the starting vertex.
Historical Context
Seven Bridges of Königsberg (1736):
- Leonhard Euler solved this famous problem
- Asked: Can you cross all 7 bridges exactly once?
- Euler proved it’s impossible
- Founded graph theory
Example 1: Euler Circuit
Graph:
1 --- 2
| |
4 --- 3
Euler circuit: 1 → 2 → 3 → 4 → 1
All edges used exactly once, returns to start.
Example 2: Euler Path (not circuit)
Graph:
1 --- 2 --- 3
Euler path: 1 → 2 → 3
All edges used exactly once, but doesn’t return to start.
Example 3: No Euler Path
Graph:
2
/|\
1 3 4
No Euler path exists (we’ll see why below).
Euler’s Theorem
Theorem 1: Euler Circuit
A connected graph has an Euler circuit if and only if:
- Every vertex has even degree
Theorem 2: Euler Path
A connected graph has an Euler path if and only if:
- Exactly 0 or 2 vertices have odd degree
If 0 vertices have odd degree → Euler circuit exists If 2 vertices have odd degree → Euler path exists (between those two) If more than 2 have odd degree → No Euler path
Proof Intuition
Why even degrees for circuit?
- Every time you enter a vertex, you must leave it
- Each visit uses 2 edges (in and out)
- Total degree must be even
Why 2 odd degrees for path?
- Start and end vertices used odd number of times
- All other vertices entered and exited equal times
Examples with Verification
Example 1: Square
Graph:
1 --- 2
| |
4 --- 3
Degrees: All vertices have degree 2 (even)
Conclusion: Euler circuit exists ✓
Circuit: 1 → 2 → 3 → 4 → 1
Example 2: Path Graph
Graph:
1 --- 2 --- 3 --- 4
Degrees: deg(1)=1, deg(2)=2, deg(3)=2, deg(4)=1
Two odd-degree vertices: 1 and 4
Conclusion: Euler path exists (from 1 to 4 or vice versa) ✓
Path: 1 → 2 → 3 → 4
Example 3: Star Graph
Graph:
2
/|\
1 3 4
\|
5
Degrees: deg(2)=4, all others=1
Four odd-degree vertices: 1, 3, 4, 5
Conclusion: No Euler path ✗
Example 4: Complete Graph K₃
Graph:
1
/ \
2---3
Degrees: All vertices have degree 2 (even)
Conclusion: Euler circuit exists ✓
Circuit: 1 → 2 → 3 → 1
Example 5: Complete Graph K₄
Graph: K₄ (all pairs connected)
Degrees: All vertices have degree 3 (odd)
Four odd-degree vertices
Conclusion: No Euler path ✗
Finding Euler Paths: Fleury’s Algorithm
Algorithm:
- Start at a vertex with odd degree (if exists), otherwise any vertex
- At each step, choose an edge that:
- Hasn’t been used yet
- Is NOT a bridge (unless no other choice)
- Remove the edge after traversing
- Repeat until all edges used
Time Complexity: O(E²)
Example: Applying Fleury’s Algorithm
Graph:
1 --- 2
| \\ /|
| X |
| / \\|
4 --- 3
Check: All degrees are even (degree 4) → Euler circuit exists
Steps:
- Start at 1
- Go to 2 (edge {1,2})
- Go to 3 (edge {2,3})
- Go to 4 (edge {3,4})
- Go to 1 (edge {4,1})
- Continue visiting remaining edges…
Hamiltonian Paths and Circuits
Definitions
Hamiltonian Path: A path that visits every vertex exactly once.
Hamiltonian Circuit (Hamiltonian Cycle): A circuit that visits every vertex exactly once and returns to the starting vertex.
Example 1: Hamiltonian Circuit
Graph:
1 --- 2
| |
4 --- 3
Hamiltonian circuit: 1 → 2 → 3 → 4 → 1
All vertices visited exactly once.
Example 2: Hamiltonian Path (not circuit)
Graph:
1 --- 2 --- 3 --- 4
Hamiltonian path: 1 → 2 → 3 → 4
All vertices visited exactly once.
Example 3: Graph with No Hamiltonian Circuit
Graph:
1 --- 2
| |
3 4
| |
5 --- 6
No Hamiltonian circuit exists (try all possibilities - none work).
Key Difference: Euler vs. Hamiltonian
| Property | Euler | Hamiltonian |
|---|---|---|
| Visits | Every edge once | Every vertex once |
| Checking | Easy (check degrees) | Hard (NP-complete) |
| Theorem | Clear necessary and sufficient | Only necessary conditions known |
| Algorithm | Polynomial time | No known polynomial algorithm |
Necessary Conditions for Hamiltonian Circuit
Note: These conditions are necessary but NOT sufficient!
- Graph must be connected
- Must have at least 3 vertices
- No cut vertices (for circuits in certain cases)
These don’t guarantee a Hamiltonian circuit exists!
Sufficient Conditions: Dirac’s Theorem
Dirac’s Theorem (1952):
If G is a simple graph with n vertices (n ≥ 3) and every vertex has degree ≥ n/2, then G has a Hamiltonian circuit.
Example: Applying Dirac’s Theorem
Graph: K₅ (complete graph with 5 vertices)
- n = 5
- Every vertex has degree 4
- Check: 4 ≥ 5/2 = 2.5 ✓
Conclusion: Hamiltonian circuit exists ✓
Circuit: 1 → 2 → 3 → 4 → 5 → 1 (or any other ordering)
Sufficient Conditions: Ore’s Theorem
Ore’s Theorem (1960):
If G is a simple graph with n vertices (n ≥ 3) and for every pair of non-adjacent vertices u and v, deg(u) + deg(v) ≥ n, then G has a Hamiltonian circuit.
Note: Ore’s theorem is more general than Dirac’s theorem.
Example: Applying Ore’s Theorem
Graph with 5 vertices:
1
/|\
2-+-3
\|/
4---5
- Check all non-adjacent pairs
- If their degree sum ≥ 5, Hamiltonian circuit exists
Examples: Hamiltonian Analysis
Example 1: Petersen Graph
Famous example: Has no Hamiltonian circuit
Degrees: All vertices degree 3 Vertices: 10
Dirac’s test: 3 ≥ 10/2 = 5? NO (Doesn’t tell us anything - theorem doesn’t apply)
Result: Through exhaustive checking, no Hamiltonian circuit.
Example 2: Complete Graph Kₙ
Always has Hamiltonian circuit for n ≥ 3
Example path in K₄: 1 → 2 → 3 → 4 → 1
Example 3: Cycle Graph Cₙ
Always has Hamiltonian circuit (the cycle itself!)
Example C₅: 1 → 2 → 3 → 4 → 5 → 1
Example 4: Complete Bipartite K₃,₃
Has Hamiltonian circuit
Partition: V₁ = {1,2,3}, V₂ = {A,B,C}
Circuit: 1 → A → 2 → B → 3 → C → 1
Traveling Salesman Problem (TSP)
Problem: Find shortest Hamiltonian circuit in a weighted graph.
Applications:
- Delivery routes
- Circuit board drilling
- DNA sequencing
- Tour planning
Complexity: NP-hard (no known polynomial algorithm)
Example:
Cities: A, B, C, D with distances Goal: Visit all cities and return with minimum total distance
Approach: Find all Hamiltonian circuits and choose shortest
Comparison Summary
Euler Circuits
Easy to check:
- Count vertex degrees
- All even → Euler circuit exists
Easy to find:
- Fleury’s algorithm
- Polynomial time
Applications:
- Route planning (mail delivery)
- Drawing without lifting pen
- Network traversal
Hamiltonian Circuits
Hard to check:
- No simple test
- Must try different paths
Hard to find:
- No known polynomial algorithm
- NP-complete problem
Applications:
- Traveling Salesman Problem
- Tour planning
- DNA sequencing
Practical Applications
Euler Paths
- Snow plow routing: Clear all streets
- Mail delivery: Cover all routes
- Drawing puzzles: Draw figure without lifting pen
Hamiltonian Paths
- TSP: Minimize travel distance
- Scheduling: Visit all locations
- Knight’s tour: Chess problem
- DNA sequencing: Reconstruct sequence
Key Points for Exams
- Euler path: visits every edge exactly once
- Hamiltonian path: visits every vertex exactly once
- Euler circuit exists ↔ all even degrees
- Euler path exists ↔ exactly 2 odd-degree vertices
- Checking Euler: easy (polynomial)
- Checking Hamiltonian: hard (NP-complete)
- Dirac’s theorem: deg(v) ≥ n/2 → Hamiltonian circuit
- Ore’s theorem: generalization of Dirac’s
- TSP: find shortest Hamiltonian circuit
- Fleury’s algorithm: finds Euler path
Practice Problems
-
Does this graph have Euler circuit? 1---2---3---4 with 4---1
-
Graph has degrees: 2,2,2,2,3,3. Euler path or circuit?
-
Does complete graph K₆ have Hamiltonian circuit?
-
Can you draw a square without lifting pen or retracing? (Euler?)
-
Apply Dirac’s theorem to graph where all vertices have degree 5, n=8
-
What’s the difference between visiting all edges vs all vertices?
-
Does a tree with n vertices have Hamiltonian path?
-
Seven Bridges: If one bridge is added, can you cross all bridges once?
-
Give example of graph with Hamiltonian but no Euler circuit
-
Why is Hamiltonian circuit problem harder than Euler circuit?