A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Hamiltonian Paths, Cycles, and NP-Completeness

College Depth 84 in the knowledge graph ☐ I know this ☆ Set as goal
7topics build on this
402prerequisites beneath it
See this on the map →
Walks, Trails, Paths, and Cycles in Graphs→→Hamiltonian Paths and Cycles
graph-theory hamiltonian np-complete

Core Idea

A Hamiltonian path visits every vertex exactly once; a Hamiltonian cycle does so and returns to the start. Unlike Eulerian paths, no simple degree-based characterization exists. The Hamiltonian cycle problem is NP-complete, making it computationally hard in general.

Explainer

From your study of walks, paths, and cycles, you know that a path visits vertices without repetition and a cycle returns to its starting vertex. A Hamiltonian path is a path that visits every vertex exactly once — it exhausts the entire vertex set. A Hamiltonian cycle does the same but returns to the starting vertex, forming a cycle that covers every vertex. The name comes from William Rowan Hamilton, who marketed a puzzle asking players to find such a route on a dodecahedron.

The first thing to notice is how different Hamiltonian paths are from Eulerian paths, which traverse every edge exactly once. Eulerian paths have a clean degree-based characterization: a connected graph has an Eulerian path if and only if it has exactly zero or two vertices of odd degree. No analogous theorem exists for Hamiltonian paths. You cannot determine whether a Hamiltonian path exists just by looking at degree sequences. There are partial sufficient conditions — Dirac's theorem guarantees a Hamiltonian cycle if every vertex has degree ≥ n/2 — but no tight necessary-and-sufficient criterion based on local structure alone.

This asymmetry has a deep reason: the Hamiltonian cycle problem is NP-complete. NP-completeness means that no known efficient (polynomial-time) algorithm solves it in the worst case, and moreover, it is at least as hard as every other problem in the class NP. In practical terms, deciding whether any given large graph has a Hamiltonian cycle requires, in the worst case, examining exponentially many possibilities. This is why the Travelling Salesman Problem — which asks for the shortest Hamiltonian cycle in a weighted graph — is one of the most famous hard problems in computer science.

For small or structured graphs, special cases help. Bipartite graphs with unequal part sizes cannot have Hamiltonian cycles (a parity argument shows this). Complete graphs always have them. Graphs satisfying Dirac's or Ore's condition are guaranteed to have them. But in general, the lack of a degree-based shortcut means Hamiltonian problems require fundamentally different techniques from Eulerian ones — and are vastly harder to resolve algorithmically. The contrast between Eulerian paths (polynomial-time decidable) and Hamiltonian paths (NP-complete) is one of the cleanest illustrations in combinatorics of how subtly problem difficulty can vary.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Set Operations: Union, Intersection, and Complement → Proof by Cases → Proving by Cases and Exhaustion → Vacuous Truth and Trivial Cases → Proof by Cases (Proof by Exhaustion) → Mathematical Induction → Graph Paths, Cycles, and Connectivity → Trees and Spanning Trees → Planar Graphs and Euler's Formula → Graph Coloring and the Chromatic Number → Graph Coloring and Chromatic Numbers → Bipartite Graphs and Matching Problems → Bipartite Graphs and 2-Colorability → Graph Matching and Hall's Marriage Theorem → Network Flows: Maximum Flow and Minimum Cut → Walks, Trails, Paths, and Cycles in Graphs → Hamiltonian Paths, Cycles, and NP-Completeness

Longest path: 85 steps · 402 total prerequisite topics

Prerequisites (1)

Leads To (1)