4.6.26 · D2Theory of Computation

Visual walkthrough — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

1,955 words9 min readBack to topic

Step 1 — The two characters, drawn side by side

WHAT. Two puzzles sit on the table. On the left, a logic puzzle. On the right, a graph puzzle. We will build a bridge between them.

Let me define every word before using it.

WHY. We want to prove Clique is at least as hard as 3-SAT. The tool for "at least as hard" is a reduction (see Polynomial-time Reductions): a fast translator turning any 3-SAT formula into a graph so that

Here (Greek "phi") is our formula and is its number of clauses. The double arrow means "yes on the left exactly when yes on the right" — the two puzzles always give the same answer.

PICTURE. The logic puzzle and the graph puzzle facing each other, with the translator arrow between.

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

Step 2 — One dot per literal-in-a-clause

WHAT. Take the formula and make one vertex for every literal occurrence. Not one per variable — one per slot in a clause.

Our running example (2 clauses, so ):

  • gives three dots: . (The subscript = "lives in clause 1".)
  • gives three dots: .

So vertices, arranged in triangles of choice — one triple per clause.

WHY. Each clause needs one true literal to be happy. A vertex will mean "I nominate this literal to be the true one for its clause." Grouping by clause keeps the promise one nominee per clause visible.

WHY no edges inside a triple. We deliberately draw no edge between the three dots of the same clause. A clique can never take two vertices from one clause, so a clique is forced to pick at most one nominee per clause — exactly the rule we want.

PICTURE. Two clause-groups, three dots each, no internal lines.

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

Step 3 — The edge rule: connect the compatible nominations

WHAT. Draw an edge between two dots and iff both conditions hold:

Reading the two guards:

  • different clauses — we never link inside one triple (Step 2's rule restated).
  • not contradictory — never link to . You cannot set true and true at the same time, so those two nominations must never appear together.

For our example, listing every cross-clause pair, the only forbidden ones are (that is vs ) and (that is vs ). Every other cross pair gets an edge. So out of the cross-clause pairs, exactly are blocked and are drawn.

WHY. An edge says "these two nominations can coexist." A clique is a set of mutually-coexisting nominations — precisely a consistent set of true literals, one per clause.

PICTURE. Same 6 dots, now with the good edges drawn (chalk-blue) and the two blocked pairs and shown as red dashed "no edges."

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

Step 4 — Set the target size to

WHAT. We ask for a clique of size

WHY exactly , not more or less. A clique cannot exceed because it may use at most one vertex per clause (no intra-clause edges), and there are clauses. So is the biggest a clique could possibly be. Asking for a clique of full size therefore means: hit every clause exactly once — every clause gets a nominee. That is the graph-language for satisfy the whole formula.

PICTURE. A "ceiling meter": max possible clique = number of clauses; we want to touch the ceiling.

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

Step 5 — Forward direction: satisfied formula ⇒ clique of size

WHAT. Suppose the switches are set so is satisfied. In each clause pick one literal that came out true — call it that clause's winner. Take the winner-vertices.

WHY they form a clique. Take any two winners (from ) and (from ):

  • They are in different clauses (), so guard 1 passes.
  • Both are true under the same assignment, so they cannot be and (those can't both be true) — guard 2 passes.

Both guards pass for every pair ⇒ all pairs are adjacent ⇒ the winners form a clique of size . ✔

PICTURE. Assignment lights and ; the edge between them thickens into a size-2 clique.

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

Step 6 — Backward direction: clique of size ⇒ satisfying assignment

WHAT. Now suppose the graph has a clique of size . Read it back as logic: for each vertex in , set its literal true.

WHY it's one per clause. and no two clique vertices share a clause (no intra-clause edges), so uses exactly one vertex from each clause. Every clause thus gets a literal we made true ⇒ every clause is satisfied.

WHY it's consistent. Could we accidentally command and ? That would need both and in — but guard 2 forbids an edge between them, so they can't both be in a clique. No contradiction ever arises; leftover variables can be set arbitrarily. ✔

Steps 5 and 6 together give both directions of the , so the reduction is correct.

PICTURE. A clique highlighted in the graph, an arrow "read off" turning it into a truth table, all clauses ticked green.

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

Step 7 — Edge & degenerate cases (never leave a gap)

WHAT & WHY, case by case:

  • A clause with a repeated literal, e.g. . Still three vertices (one per slot); the two dots simply behave identically. No edge between them (same clause) — harmless.
  • Two clauses sharing a literal, e.g. both contain : vertices and do get an edge (different clauses, not opposites), correctly allowing to serve both.
  • A variable appearing only positively (or only negatively). Then no pair exists to block — fewer forbidden edges, never a problem.
  • The empty formula (). Zero clauses ⇒ zero vertices ⇒ we ask for a clique of size , which trivially exists ⇒ matches "the empty formula is vacuously satisfiable." ✔
  • An unsatisfiable formula, e.g. clauses forcing and both true across all choices. Then every size- selection contains a contradictory pair with no edge between them ⇒ no clique of size ⇒ graph says "no," matching logic's "no." ✔
  • Is the translation fast? We list vertices and check each of the pairs once — that is work, comfortably polynomial. This is what makes it a polynomial-time reduction (see Polynomial-time Reductions).

PICTURE. A 2×2 chalkboard grid: repeated literal, shared literal, empty formula, unsatisfiable core — each with a tick or cross.

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

The one-picture summary

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum
Recall Feynman retelling — say it like a story

We had a logic puzzle: pick a true literal in each clause without ever picking both and . I turned every literal-slot into a dot, then drew a line between two dots only if they belong to different clauses and aren't opposites — that line means "these two picks can live together." A group where everyone is connected to everyone (a clique) is just a set of picks that all agree and cover every clause. Asking for a clique as big as the number of clauses is asking to make every clause happy at once. So: big clique found = formula satisfiable; no big clique = unsatisfiable. Same puzzle, different costume — and the translation only took time, so any fast Clique-solver would instantly solve 3-SAT. That's why Clique inherits 3-SAT's hardness.