← Student tools · Problem 23 · Lecture 10 · Round 2 (30 pts)

HAMPATH ∈ NP · verifying a Hamiltonian path

Certificate = a vertex sequence; verifier checks length, distinctness, edges.

CLO-3R2·30 ptsL10
🔊 Listen

HAMPATH = {⟨G, s, t⟩ : G is a directed graph containing a Hamiltonian path from s to t}. A Hamiltonian path visits every vertex exactly once. Finding one in general graphs is famously hard — but verifying one is easy. This asymmetry is the textbook NP example.

The verifier · what to check, in what order

Given input (G, s, t) plus certificate π = v1 v2 … vn:

  1. Length check: |π| = n (every vertex appears exactly once).
  2. Distinctness check: vi ≠ vj for all i ≠ j (no repeats).
  3. Endpoint check: v1 = s and vn = t.
  4. Edge check: for each adjacent pair (vi, vi+1), there is an edge in G.

Time: O(n²) (or O(n) with a hash set). HAMPATH ∈ NP.

HAMPATH is NP-complete (Karp 1972). 3SAT reduces to HAMPATH via a clever gadget construction — see Sipser §7.5.

Four local checks · all must pass for π to be a Hamiltonian path 1 · Length |π| == n? π visits every vertex exactly once 2 · Distinctness all vᵢ different? no vertex repeats 3 · Endpoints v₁ = s, vₙ = t? starts at s, ends at t 4 · Edges exist (vᵢ, vᵢ₊₁) ∈ E? consecutive vertices are actually edges All four must pass · failure of any one → reject Each check is local — reads constant amount of data per step. Total: O(n²) time. Polynomial in input size.
🔊 Listen
Step through verification of a candidate path Auto-plays
🔊 Listen
🔊 Listen

Sipser: §7.3 (HAMPATH as NP example), §7.5 (NP-complete chain). Lecture notes: Module 5 slide 5. Companion problems: P21 (verifier vs solver), P30 (HAMPATH reduction).