Tutorials › Graph Theory (Undergraduate) › Reducing 3-SAT to Clique

Complexity of Graph Problems · Tutorial 740 of 799

Reducing 3-SAT to Clique

Learn how compatible literal occurrences encode satisfiability as a clique and why the resulting graph and certificate checks are polynomial in size.

Advanced 10 min read

What You'll Learn

  • Define one graph vertex for each literal occurrence, including repeated occurrences.
  • Add edges only between compatible occurrences in different clauses.
  • Prove both directions of the satisfiability–clique equivalence.
  • Handle empty formulas and clauses in the correspondence.
  • Bound the construction time and output size by a polynomial.
  • Verify membership in CLIQUE using a polynomial-size certificate.

The Reduction Idea

A reduction can translate a question about logical assignments into a question about a graph. For 3-SAT, the key is to make a choice of one true literal from each clause. A graph can enforce the consistency of those choices: connect two choices when their literals can both be true. Then a clique that contains one choice from every clause represents a consistent selection.

We use a 3-CNF formula \(\varphi=C_1\land\cdots\land C_m\), where each clause has at most three literal occurrences. A literal is a variable or its negation. Repeated literals count as separate occurrences; for example, the three occurrences in \((x\lor x\lor x)\) are distinct positions. Clauses may be empty, in which case the formula is unsatisfiable. The formula with no clauses, \(m=0\), is true. These conventions make the construction and its boundary cases precise.

Definition: Two literals are compatible if they are not complementary literals of the same variable. Thus \(x\) and \(x\) are compatible, but \(x\) and \(\neg x\) are not. A clique in a simple graph is a set of vertices such that every two distinct vertices in the set are adjacent. The CLIQUE decision problem asks, given a graph \(G\) and a nonnegative integer \(k\), whether \(G\) has a clique of size at least \(k\). The empty set is a clique of size \(0\).

For each literal occurrence, create a vertex labelled by its clause and its position in that clause. Two vertices are adjacent precisely when they represent compatible literals in different clauses. In particular, occurrences in the same clause are never adjacent, even if their literals are identical.

Construction: Given \(\varphi=C_1\land\cdots\land C_m\), let \(G_\varphi=(V,E)\), where \(V\) contains one vertex for each literal occurrence. Put an edge between two distinct vertices exactly when their occurrences belong to different clauses and their literals are compatible. Output the CLIQUE instance \((G_\varphi,m)\).

The clause labels play an essential role. They ensure that a clique cannot select two occurrences from one clause. The compatibility condition plays the other role: it prevents the selected literals from requiring contradictory values for a variable.

Why Satisfiability Matches Clique Size

Theorem: For every 3-CNF formula \(\varphi\) with \(m\) clauses, \(\varphi\) is satisfiable if and only if \(G_\varphi\) has a clique of size at least \(m\).

Proof. First suppose \(\varphi\) is satisfiable. In each clause choose one literal occurrence that is true under a satisfying assignment. If \(m=0\), this makes no choices, and the empty set is a clique of size \(0\). If \(m\ge 1\), the chosen occurrences lie in distinct clauses. No two chosen literals can be complementary: a variable and its negation cannot both be true under one assignment. Therefore each pair of chosen vertices is adjacent by the construction. They form a clique of size \(m\), so \(G_\varphi\) has a clique of size at least \(m\).

Conversely, suppose \(G_\varphi\) has a clique \(S\) of size at least \(m\). If \(m=0\), the formula has no clauses and is true. Now suppose \(m\ge1\). No two vertices in \(S\) can come from the same clause, because there are no edges between vertices from the same clause. Hence \(|S|\le m\), since there are only \(m\) clauses. Together with \(|S|\ge m\), this gives \(|S|=m\). Moreover, \(S\) contains exactly one occurrence from each clause: it contains at most one per clause, and \(m\) vertices distributed among \(m\) clauses must occupy all \(m\) clauses.

Because \(S\) is a clique, every pair of its selected literals is compatible. Thus no variable is selected both positively and negatively. Assign each variable that appears positively among the selected literals the value true, and each variable that appears negatively the value false. These instructions do not conflict. Assign any remaining variables arbitrarily. In each clause, the selected occurrence is now true, so every clause is true and \(\varphi\) is satisfiable. This proves both directions. \(\square\)

An empty clause causes no exception to the argument: it contributes no vertex, so a clique cannot contain one vertex from that clause. When \(m\ge1\), a clique of size \(m\) is therefore impossible. This matches the fact that a formula containing an empty clause is unsatisfiable.

Worked Constructions

Worked Example: A Satisfying Assignment Gives a Clique

Let \(\varphi=(x\lor y\lor z)\land(\neg x\lor\neg y\lor w)\). Name the three occurrences in the first clause \(a,b,c\), representing \(x,y,z\), and name those in the second clause \(d,e,f\), representing \(\neg x,\neg y,w\). Thus \(V(G_\varphi)=\{a,b,c,d,e,f\}\), and the target clique size is \(m=2\).

There are \(3\cdot3=9\) possible pairs with one endpoint in each clause. The pair \(ad\) is excluded because \(x\) and \(\neg x\) are complementary; \(be\) is excluded because \(y\) and \(\neg y\) are complementary. The other seven pairs are compatible, so the graph is explicitly

$$ V(G_\varphi)=\{a,b,c,d,e,f\},\qquad E(G_\varphi)=\{ae,af,bd,bf,cd,ce,cf\}. $$

Set \(x=\text{true}\) and \(y=\text{false}\) (the values of \(z,w\) do not matter). The first clause is true because \(x\) is true, and the second is true because \(\neg y\) is true. The corresponding selected vertices are \(a\) and \(e\). Since \(ae\in E(G_\varphi)\), they form a clique of size \(2\), as required.

Check: The edge count from the construction is \(9-2=7\), agreeing with the displayed edge set. The selected literals \(x\) and \(\neg y\) are compatible, and substituting the assignment makes both selected literals true.

Worked Example: An Unsatisfiable Formula Has No Target Clique

Let \(\varphi=(x\lor x\lor x)\land(\neg x\lor\neg x\lor\neg x)\). Label the occurrences in the first clause \(a_1,a_2,a_3\) and those in the second \(b_1,b_2,b_3\). Then

$$ V(G_\varphi)=\{a_1,a_2,a_3,b_1,b_2,b_3\},\qquad E(G_\varphi)=\varnothing. $$

Indeed, there are \(3\cdot3=9\) pairs across the two clauses, and every pair represents \(x\) together with \(\neg x\), so all nine are incompatible. There are no edges within either clause by definition. The target size is \(m=2\), but an edgeless graph with at least one vertex has no clique of size \(2\): any two distinct vertices would need an edge. The formula is also unsatisfiable, since its first clause requires \(x\) to be true while its second requires \(x\) to be false.

Check: The construction produces six vertices and zero edges. No pair of vertices forms a 2-clique, matching the unsatisfiability of the formula.

Worked Example: Equal Literals Are Compatible

Let \(\varphi=(p\lor q\lor r)\land(p\lor\neg q\lor s)\). Label the first clause’s occurrences \(a,b,c\), representing \(p,q,r\), and the second clause’s occurrences \(d,e,f\), representing \(p,\neg q,s\). The vertices are \(\{a,b,c,d,e,f\}\). Of the \(3\cdot3=9\) pairs across the clauses, only \(be\) is incompatible. In particular, \(a\) and \(d\) both represent \(p\), so they are compatible and adjacent. The full edge set is

$$ E(G_\varphi)=\{ad,ae,af,bd,bf,cd,ce,cf\}. $$

With \(p=\text{true}\), both clauses are true, and the selected occurrences \(a,d\) give the clique \(\{a,d\}\) of size \(2\). By contrast, \(\{b,e\}\) is not a clique because \(be\notin E(G_\varphi)\): choosing \(q\) and \(\neg q\) would be contradictory.

Check: The edge count is \(9-1=8\), matching the eight listed edges. The selected pair \(a,d\) is an edge, and both selected literals are true when \(p=\text{true}\).

Polynomial Size and Construction Time

Let \(L\) be the number of literal occurrences in the formula. Since there are at most three occurrences per clause, \(L\le3m\). The graph has exactly \(L\) vertices. To build its edge set, examine each pair of occurrences, check whether their clause labels differ, and check whether their literals are complementary. There are at most \(L(L-1)/2\) pairs to examine. The checks use the encoded variable names and signs, so each takes time polynomial in the formula’s encoding length. Writing the vertices and all accepted pairs also takes polynomial space and time. The output integer \(m\) has polynomial encoding length. Therefore \(\varphi\mapsto(G_\varphi,m)\) is computable in polynomial time and produces an output of polynomial size.

This is a polynomial-time many-one reduction: the theorem proves that the formula is a yes-instance of 3-SAT exactly when the produced pair is a yes-instance of CLIQUE. The direction matters: the output asks for a clique of size equal to the number of clauses, not for a clique of some unrelated size.

Why CLIQUE Is in NP

To verify membership in NP, a yes-instance needs a certificate whose length is polynomial in the input size and a deterministic verification procedure that runs in polynomial time. For a CLIQUE input \((G,k)\) with \(n=|V(G)|\), use an \(n\)-bit vector to specify a subset \(S\subseteq V(G)\). The verifier counts the selected vertices, checks \(|S|\ge k\), and checks every pair of distinct selected vertices against the graph’s edge list (or adjacency matrix). These checks take polynomial time in the explicit graph encoding, and the certificate has length \(n\). If \(k>n\), the size check rejects; if \(k=0\), the empty certificate set is accepted.

Takeaway: The construction has one vertex per occurrence, but its edges encode two constraints at once: a clique cannot choose twice from one clause, and its chosen literals cannot contradict one another. A polynomial-size subset certificate then verifies a proposed clique in polynomial time.

Common Mistake: Adding Edges Within Clauses

A tempting but incorrect variation is to connect every pair of compatible occurrences, including occurrences from the same clause. This removes the guarantee that a clique of size \(m\) represents one choice from each of the \(m\) clauses.

For the unsatisfiable formula \((x\lor x\lor x)\land(\neg x\lor\neg x\lor\neg x)\), adding within-clause edges would make \(a_1a_2\) an edge, since both occurrences represent \(x\). The mistaken graph would then have a 2-clique \(\{a_1,a_2\}\), even though the formula is unsatisfiable and the target is \(m=2\). The error is that both vertices came from the first clause. In the correct construction there are no within-clause edges, so every clique of size \(m\) must select once from every clause.

Check Your Understanding

Use the occurrence labels and compatibility rule from the construction when answering.

  1. For \((u\lor v)\land(\neg u\lor w)\), list the occurrence pairs that are excluded from the edge set and explain why.
  2. Why does a clique of size \(m\) in a graph constructed from \(m\) clauses have exactly one vertex from each clause?
  3. Explain why two occurrences of the same positive literal in different clauses are compatible.
  4. What does the construction produce for a formula with no clauses, and why does this match its satisfiability?
  5. Describe a polynomial-size certificate and the checks used to verify that a graph has a clique of size at least \(k\).