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

Hamiltonian Path and Cycle Problems

Graduate Depth 98 in the knowledge graph ☐ I know this ☆ Set as goal
12topics build on this
500prerequisites beneath it
See this on the map →
NP-Completeness and Cook-Levin Theorem→→Partition and Subset Sum ProblemsVertex Cover and Clique Problems
np-complete graph-problems path-problems

Core Idea

The Hamiltonian cycle problem asks if a graph contains a cycle visiting each vertex exactly once; Hamiltonian path is the variant without returning to start. Both are NP-complete. Unlike shortest-cycle detection (solvable in polynomial time by DFS), finding a Hamiltonian path/cycle appears intrinsically hard, requiring potentially checking all permutations. The problems highlight the distinction between decision (NP) and optimization: verifying a Hamiltonian cycle is quick, but finding one seems impossible in polynomial time.

Explainer

From your study of NP-completeness, you know that certain problems sit at the hardest tier of NP — if any one of them could be solved in polynomial time, then every problem in NP could be. The Hamiltonian path and cycle problems are classic members of this club. A Hamiltonian cycle in a graph is a cycle that visits every vertex exactly once and returns to the starting vertex. A Hamiltonian path is the same idea without the return — a path that touches every vertex exactly once. The decision versions ask simply: does a given graph contain one?

The problem is deceptively easy to state but fiendishly hard to solve. Consider a small graph with 20 vertices. A brute-force approach would try all possible orderings of the vertices — that is 20! (about 2.4 × 1018) permutations. Even for modest graph sizes, exhaustive search is completely infeasible. No one has found a polynomial-time algorithm, and the NP-completeness of the Hamiltonian cycle problem (proved by Richard Karp in 1972 via reduction from the satisfiability problem) gives strong theoretical evidence that no such algorithm exists. What makes the problem tantalizing is the verification asymmetry: if someone hands you a sequence of vertices and claims it is a Hamiltonian cycle, you can check it in O(n) time by confirming that every vertex appears exactly once and that each consecutive pair is connected by an edge.

It is instructive to contrast Hamiltonian problems with their close cousin, the Eulerian path/cycle problem, which asks whether a graph has a path or cycle that traverses every *edge* exactly once. Euler's theorem gives a clean characterization: an Eulerian circuit exists if and only if every vertex has even degree, and this can be checked (and the circuit constructed) in polynomial time. The switch from "every edge once" to "every vertex once" transforms the problem from tractable to intractable — a striking illustration of how small changes in problem specification can produce enormous jumps in computational difficulty.

The Hamiltonian cycle problem underpins many real-world optimization challenges. The Traveling Salesman Problem (TSP) — find the shortest route visiting every city exactly once — is essentially the optimization version of the Hamiltonian cycle problem with weighted edges. Because exact solutions are intractable for large inputs, practical approaches rely on approximation algorithms, heuristics, and special-case structure (for example, if edge weights satisfy the triangle inequality, a 1.5-approximation exists). Understanding the Hamiltonian problem's NP-completeness is what justifies this turn to approximation: we are not settling for "good enough" out of laziness, but because finding the exact optimum is provably as hard as solving the hardest problems in NP.

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 → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Finite State Machines (FSMs) → Deterministic Finite Automata (DFA) → Nondeterministic Finite Automata (NFA) → Two-Way Finite Automata → NFA to DFA Conversion (Subset Construction) → DFA Properties and Minimization Algorithms → Regular Languages: Definition and Characterization → Context-Free Grammars (CFGs) → Pushdown Automata (PDA) → Equivalence of CFGs and Pushdown Automata → Closure Properties of Context-Free Languages → Limitations of Context-Free Languages → Pumping Lemma for Context-Free Languages → Turing Machines → Variants of Turing Machines and Equivalence → Nondeterministic Time Complexity and NP → The P vs. NP Problem → Complexity Class P: Polynomial Time → Complexity Class NP: Nondeterministic Polynomial Time → NP-Completeness and Cook-Levin Theorem → Hamiltonian Path and Cycle Problems

Longest path: 99 steps · 500 total prerequisite topics

Prerequisites (1)

Leads To (2)