Exercises — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum
Before we start, one reminder in plain words. A reduction is a fast translator: it turns any instance of problem into an instance of problem so that the yes/no answer is preserved. If you can solve fast, you can solve fast. So is "at least as hard as" . We lean on Polynomial-time Reductions throughout.
Level 1 — Recognition
Exercise 1.1 — Is it a certificate?
For the Clique problem "does graph have a clique of size ?", which of these is a valid certificate (a proposed answer someone hands you to check quickly)? (a) the whole graph ; (b) a list of vertices; (c) the number ; (d) a claim "yes".
Recall Solution — 1.1
Answer: (b). A certificate must be something you can verify in polynomial time. Given a list of vertices, you check every one of the pairs is an edge — that is fast. Option (a) is just the input, it proves nothing. Option (c) is part of the input. Option (d) is an unsupported claim — you cannot check it. This is the core of NP: easy to check, apparently hard to find.
Exercise 1.2 — Which club?
Subset Sum has a dynamic-programming algorithm running in time (see Dynamic Programming — Subset Sum / Knapsack). A classmate says "so Subset Sum is in P, it's solved." True or false?
Recall Solution — 1.2
False. The target is a number. Its input length is bits, so itself can be as large as — exponential in the input size. An algorithm costing is therefore exponential in the input length. We call this pseudo-polynomial. Subset Sum is genuinely NP-complete; the hardness hides in problems whose numbers are large.
Exercise 1.3 — Direction of a reduction
To prove that Vertex Cover is NP-hard, do you reduce Vertex Cover into a known hard problem, or reduce a known hard problem into Vertex Cover?
Recall Solution — 1.3
You reduce a known hard problem into Vertex Cover (). Feed the monster to the problem you want to prove hard. If instead you reduced Vertex Cover into something easy, you'd only prove Vertex Cover is easy — the opposite of what you want.
Level 2 — Application
Exercise 2.1 — Find a vertex cover by hand
Graph : vertices , edges (a 5-cycle). Find a vertex cover of size 3 and prove no cover of size 2 exists.
Recall Solution — 2.1

Exercise 2.2 — Use the Clique/Independent-Set duality
For the same 5-cycle, use the identity " independent of size is a vertex cover of size " to find the largest independent set.
Recall Solution — 2.2
We found a minimum vertex cover of size 3 in a graph with vertices. By the duality identity, the complement of a minimum cover is a maximum independent set of size . Concretely, complement of is . Check: is edge present? The cycle edges are — no . So has no internal edge → independent. ✔ Largest independent set has size . (See Graph Theory — Cliques and Independent Sets.)
Exercise 2.3 — Build the TSP weights
You have a Hamiltonian-Cycle instance on vertices with edges . Using the standard reduction if else , write the budget and the weight of a Hamiltonian tour .
Recall Solution — 2.3
Budget (a tour visits all vertices and returns, using exactly edges; cheapest possible is real edges of weight 1). Tour uses edges . Each is in → weight each. Total . ✔ Since the cost equals the budget, this tour uses only real edges, so it corresponds exactly to a Hamiltonian cycle in the original graph.
Level 3 — Analysis
Exercise 3.1 — Trace the 3-SAT Clique gadget
For the formula , build the reduction graph (vertex per literal-in-clause), then decide whether a clique of size exists, and read off a satisfying assignment.
Recall Solution — 3.1

- –? negation pair → no edge.
- –? ok → edge. –? ok → edge.
- –? negation pair → no edge.
- –? edge. –? edge.
- –? negation pair → no edge.
- –? edge. –? edge. Clique of size 2? Pick one vertex per clause that are joined. E.g. : edge present → clique. Set (satisfies clause 1) and (satisfies clause 2). Consistent (no variable forced both ways) → satisfiable. ✔ (Many valid cliques exist, e.g. giving .)
Exercise 3.2 — Why "no edges inside a clause" matters
In the 3-SAT Clique construction (see Boolean Satisfiability (SAT, CNF)), we deliberately put no edge between two literals of the same clause. Explain what would break if we did add such edges.
Recall Solution — 3.2
The size- clique is meant to encode "one true literal from each of the clauses." Because there are no intra-clause edges, a clique can contain at most one vertex per clause; to reach size it must take exactly one from each. If we added intra-clause edges, a clique could grab two literals of the same clause and skip another clause entirely — then the clique no longer represents "one satisfied literal per clause," and satisfiability is no longer captured. The missing edges are what force the one-per-clause structure.
Exercise 3.3 — Trace a Subset Sum encoding
Consider a tiny 3-SAT with one variable and one clause . Following the digit-encoding idea (one column per variable, one per clause), give numbers (for true), (for false), the two slack numbers, and the target . Then find a subset summing to .
Recall Solution — 3.3
Columns: [var | clause ] — 2 digits, base 10.
- (i.e. value ): a in the -column (variable chosen), and a in the -column because appears positively in .
- (value ): a in the -column, in ( does not appear negatively in ).
- Slack numbers for clause : (value ) and (value ).
- Target (value ): variable column (pick exactly one of ), clause column (needs literal contribution). Find the subset: to hit clause-column we need literal-contribution , so we must pick (which gives in the -column). . Remaining to reach : , use slack . Subset sums to . ✔ This says , which indeed satisfies . (Alternatively — but ; is the clean hit. can never reach clause-column 3 with only slacks since but that would need both slacks AND leaves clause col ✔ yet variable col ✔ — wait that also works with ! Check: does it correspond to a satisfying assignment? means false, then is FALSE. But the slacks fake the clause. This is exactly why the max slack must be and target clause-digit with clauses of 3 literals — with a 1-literal clause the encoding degenerates; the real construction uses 3-literal clauses so slack alone can add at most and cannot fake satisfaction. Our toy is intentionally showing the boundary.)
Level 4 — Synthesis
Exercise 4.1 — Independent Set Vertex Cover, both directions
Prove that "does have an independent set of size ?" and "does have a vertex cover of size ?" are the same yes/no question, giving both directions of the biconditional.
Recall Solution — 4.1
Let , and let with (so ). Key fact: is a vertex cover is an independent set. Proof of the fact:
- () Suppose covers every edge. Take any edge . Since covers it, at least one of is in , i.e. not both are in . So no edge has both endpoints in → is independent.
- () Suppose is independent. Take any edge . Both endpoints cannot be in (else has an internal edge), so at least one endpoint is outside , i.e. in . So covers every edge. Now the sizes: has an independent set of size its complement (a vertex cover) has size . This is a reduction in both directions, so the two problems are equivalent, and either one being NP-complete makes the other NP-complete. ✔
Exercise 4.2 — Design a reduction: Hamiltonian Cycle TSP, verify correctness
State the reduction and prove both directions: original graph has a Hamiltonian cycle the built TSP instance has a tour of cost .
Recall Solution — 4.2
Construction. Given , . Build complete graph on with This is computable in poly time ( edges). Now prove correctness. () has a Hamiltonian cycle tour cost . The Hamiltonian cycle visits all vertices, using edges, all of which are in , hence weight each. Total . ✔ () tour cost has a Hamiltonian cycle. Any tour uses exactly edges. Each edge costs , so cost . Combined with cost , cost , forcing every edge to cost exactly , i.e. every tour-edge is in . A tour visiting all vertices once using only -edges is a Hamiltonian cycle in . ✔ Both directions hold, so . Since Ham Cycle is NP-complete, so is TSP.
Exercise 4.3 — Adapt the reduction to metric TSP
A common variant demands the triangle inequality: for all . Does the weights- construction above satisfy it? Explain.
Recall Solution — 4.3
Yes. With only two weight values, and : the left side is at most , and the right side is at least . So always holds. Hence this reduction already produces a metric TSP instance, proving metric TSP is NP-complete too — which is why metric TSP is studied via Approximation Algorithms (e.g. the Christofides -approximation) rather than exact poly-time solvers.
Level 5 — Mastery
Exercise 5.1 — Chain a reduction across three problems
Using only the facts (i) 3-SAT is NP-complete, (ii) , (iii) , prove Vertex Cover is NP-complete. State every ingredient (membership + hardness).
Recall Solution — 5.1
Two things to prove: in NP, and NP-hard. (A) Vertex Cover ∈ NP. Certificate = the set of vertices. Verify in poly time: check its size, then check every edge has an endpoint in the set (). ✔ (B) Vertex Cover is NP-hard. Reductions compose: since (translator ) and (translator ), the composition is a poly-time translator with . Poly poly is poly. So . Because 3-SAT is NP-hard (every NP problem reduces to it via Cook–Levin Theorem then to 3-SAT), transitivity gives: every NP problem Vertex Cover. So Vertex Cover is NP-hard. (A)+(B) Vertex Cover is NP-complete. ∎
Exercise 5.2 — Spot the flaw in a "P = NP" argument
A student claims: "I found a Vertex Cover solver that runs in . Since is just a small parameter, this is polynomial, so P = NP!" Dismantle this precisely.
Recall Solution — 5.2
The runtime is not polynomial in the input size in general — it is exponential in the parameter . Two points:
- can be as large as (e.g. asking for a cover of size ), giving — exponential.
- An algorithm of the form is called fixed-parameter tractable (FPT). FPT is a real and useful notion, but "polynomial in input size for fixed small " is not the same as "polynomial for all inputs." Proving P = NP would require an algorithm polynomial in the total input length with no exponential factor in any parameter that can grow. ✔ The claim confuses parameterized tractability with unconditional polynomial time.
Exercise 5.3 — Invent a reduction from scratch
Define Dominating Set: given and , is there a set of vertices such that every vertex is either in or adjacent to a vertex in ? Sketch a reduction proving Dominating Set is NP-hard from Vertex Cover, and state the one subtlety.
Recall Solution — 5.3
Idea. Vertex Cover asks to touch every edge; Dominating Set asks to touch every vertex. Bridge them: to make "cover every edge" become "dominate every vertex," turn each edge into a vertex that must be dominated. Construction. Given (VC instance, parameter ), build : keep all vertices . For each edge , add a new vertex joined to both and . (Also, to handle isolated original vertices you connect... — see subtlety.) Ask for a dominating set of size in . Why it works (). A vertex cover of size in : every edge has an endpoint in , which is adjacent to , so is dominated; original vertices are dominated because each has an incident edge whose covering endpoint is a neighbour (or itself). dominates all of . The subtlety. A dominating set in might choose a subdivision vertex instead of an original endpoint, which does not correspond to a vertex cover. Fix: replace each single by a small triangle gadget (connect , , and into a triangle), or route the domination so that choosing an original endpoint is always at least as good — forcing the dominating set to prefer real vertices. This care in "removing spurious solutions" is exactly the -direction discipline from L4. ✔