Welcome to our next lesson in the "Discrete Mathematics" module. In our previous session, we delved into the structural connectivity of graphs, using Depth-First Search to identify critical failure points like cut vertices and bridges. We focused on what happens when parts of a graph are removed. Now, we shift our perspective to traversal, exploring paths that cover the entire graph in specific ways.
This lesson addresses a classic and frequently tested topic in graph theory: Eulerian and Hamiltonian paths and circuits. You will learn the precise conditions for determining if a graph allows for a path that visits every edge exactly once (an Eulerian path) or a path that visits every vertex exactly once (a Hamiltonian path). Mastering these concepts is crucial, as they often appear in GATE as direct "true/false" or "which of these properties hold" questions.
Let's begin with a problem that famously gave birth to graph theory itself.
The Königsberg Bridge Problem and Eulerian Paths
In the 18th century, the city of Königsberg (now Kaliningrad) was set on a river and included two large islands connected to each other and the mainland by seven bridges. A popular puzzle of the time was to find a walk through the city that would cross each of the seven bridges exactly once.
The great mathematician Leonhard Euler solved this by modeling the problem with a graph. He represented the land masses as vertices and the bridges as edges. This transformed the puzzle into a question about the graph: can you trace a path that covers every edge exactly once?
This leads us to the formal definitions of Eulerian paths and circuits.
Euler and Hamiltonian Paths and Circuits
This video provides a concise introduction to Eulerian and Hamiltonian paths. It starts with the core definitions and then explains the simple but powerful conditions for the existence of an Eulerian path, using the Königsberg problem as a prime example.
Please watch the following segments: First, watch the definitions of Eulerian paths and circuits. Next, focus on the conditions for their existence, which are based on vertex degrees. Finally, watch the explanation of the Königsberg bridge problem to see how these concepts are applied to a real-world scenario.
As the video explains, the key to identifying Eulerian paths lies entirely in the degrees of the vertices. Let's formalize Euler's findings for a connected, undirected graph:
-
An Eulerian Circuit is a path that traverses every edge exactly once and starts and ends at the same vertex. A graph has an Eulerian circuit if and only if every vertex has an even degree.
- Intuition: To complete a circuit, for any intermediate vertex you visit, you must enter it via one edge and leave it via another. This pairs up the edges connected to that vertex. The start/end vertex also follows this, as the final edge of the circuit pairs with the first edge.
-
An Eulerian Path is a path that traverses every edge exactly once but starts and ends at different vertices. A graph has an Eulerian path if and only if it has exactly two vertices of odd degree. The path must start at one of the odd-degree vertices and end at the other.
- Intuition: The two odd-degree vertices serve as the unique start and end points of the path. Every other vertex must have an even degree, as you must enter and leave it an equal number of times.
-
If a graph has more than two vertices of odd degree, it has neither an Eulerian path nor a circuit. In the case of the Königsberg bridge problem, all four land masses (vertices) had an odd number of bridges (degree 3, 3, 3, and 5), so Euler proved such a walk was impossible.
For your GATE preparation, questions about Eulerian paths are often a quick check of vertex degrees. Given a graph, you can rapidly sum up the degrees to answer the question.
The Elusive Hamiltonian Path
Now, let's switch our focus from edges to vertices.
A Hamiltonian path is a path in a graph that visits every vertex exactly once. A Hamiltonian cycle (or circuit) is a Hamiltonian path where an edge connects the end vertex back to the start vertex, forming a cycle.
You might expect a similarly elegant rule for Hamiltonian cycles, but here lies one of the most significant distinctions in graph theory and computer science.
Euler and Hamiltonian Paths and Circuits
Let's return to the same introductory video to get the definitions for Hamiltonian paths and see why they are different.
Watch the segments on: The definitions of Hamiltonian paths and circuits. The examples shown from this timestamp. Notice that the narrator doesn't provide a simple rule, but rather identifies the paths by "guess and check".
The problem of determining whether a graph has a Hamiltonian cycle is NP-complete. This means there is no known efficient (polynomial-time) algorithm to solve it for all graphs. You won't be asked to find a complex Hamiltonian cycle in the GATE exam. Instead, you'll be tested on certain sufficient conditions that guarantee a cycle exists.
Two of the most famous sufficient conditions are Dirac's Theorem and Ore's Theorem.
18- Hamiltonian Graphs Cycle Path in Graph Theory Discrete Mathematics
This video from KnowledgeGATE is specifically tailored for GATE aspirants. It clearly defines Hamiltonian paths/cycles and then explains Dirac's and Ore's theorems with relevant examples.
Please watch the entire video. Pay close attention to: The formal definitions of Hamiltonian path and cycle. Dirac's Theorem and how to apply it. The condition is deg(v) >= n/2 for all vertices v. Ore's Theorem, a more general condition. The condition is deg(u) + deg(v) >= n for all non-adjacent pairs u, v. The worked examples, which show how to test these conditions on a graph.
Let's summarize these crucial theorems for a simple graph G with n vertices, where n >= 3.
-
Dirac's Theorem (1952): If the degree of every vertex
vis at least , i.e., for all , thenGhas a Hamiltonian cycle. -
Ore's Theorem (1960): If for every pair of non-adjacent vertices
uandv, the sum of their degrees is at leastn, i.e., , thenGhas a Hamiltonian cycle.
Crucial Point: These are sufficient, not necessary, conditions.
- If a graph satisfies Dirac's or Ore's theorem, it must have a Hamiltonian cycle.
- If a graph does not satisfy these theorems, it might still have a Hamiltonian cycle. The theorems give you no information in this case.
For example, a simple cycle graph on n vertices has a Hamiltonian cycle (it is one itself). However, every vertex has a degree of 2. If , then , so the graph does not satisfy Dirac's theorem, yet it clearly has a Hamiltonian cycle.
Eulerian vs. Hamiltonian: A Summary for GATE
This table summarizes the key differences, which are essential to remember.
| Feature | Eulerian Path/Circuit | Hamiltonian Path/Cycle |
|---|---|---|
| Object of Interest | Visits every edge exactly once. | Visits every vertex exactly once. |
| Existence Condition | Simple, necessary and sufficient condition based on vertex degrees. | No simple condition known. The problem is NP-complete. |
| Key Rule | Circuit: All vertices even degree. Path: Exactly 2 odd-degree vertices. |
Sufficient Conditions: Dirac's () and Ore's (). |
| Complexity | Verifiable in polynomial time, . | NP-complete. |
Conclusion
In this lesson, we explored two fundamental types of graph traversals. You learned the straightforward, degree-based rules for identifying Eulerian paths and circuits—a concept born from a classic puzzle. In contrast, you discovered the complexity behind Hamiltonian paths and cycles, understanding that while finding them is computationally hard, sufficient conditions like Dirac's and Ore's theorems can provide powerful guarantees.
Key Takeaways:
- Eulerian circuits/paths are all about edges. Their existence depends entirely on the parity of vertex degrees. This is an easy check and a common source of GATE questions.
- Hamiltonian cycles/paths are all about vertices. The general problem is NP-complete. For GATE, you must know the sufficient conditions given by Dirac's and Ore's theorems and understand that they are a one-way implication.
- To solve a problem, first identify whether it asks about edges (Eulerian) or vertices (Hamiltonian), then apply the corresponding rule or theorem.
In our next lesson, we will narrow our focus to a particularly important class of graphs: trees. Trees are connected graphs that contain no cycles. We will explore their unique properties, their different forms (like rooted and binary trees), and their critical role in computer science, including the concept of spanning trees.