Reaves.dev

v0.1.0

built using

Phoenix v1.7.20

NP Complete Graph Problems

Stephen M. Reaves

::

2025-03-18

Proving IS, Clique, and Vertex-Cover are NP-Complete

Summary

We show that we can reduce from 3SAT to Independent Set, then from IS to Clique and Vertex Cover.

Contents

Independent Set

For an undirected graph G=(V,E), a subset of vertices S is an independent set if no edges are contained in S

  • i.e x,yS,(x,y)∉E \forall x,y \in S, (x,y) \not\in E
Gaabba--bdda--db--dccc--bc--d

The challenge is to find the maximum IS

The Max IS problem is not known to be in NP since there’s no way to verify the max size in polynomial time.

Change input to include a goal g such that the size of S is at least g

IS in NP

Given input G,g and solution S, in O(n2) O(n^2) time we can check all pairs x,yS,(x,y)∉E \forall x,y \in S , (x,y) \not\in E , and in O(n) time check size of S is at least g.

Reduce 3SAT to IS

Consider 3SAT input f with variables x1,,xn x_1, \ldots, x_n and clauses c1,,cm c_1, \ldots, c_m , we’ll define a graph G and set g = m

For each clause ci c_i , create ci \left\lvert c_i \right\rvert vertices

There will be two types of edges

  • Clause edges
  • Variable edges

Clause c=(x1x3ˉx2) c = \left( x_1 \lor \bar{x_3} \lor x_2 \right)

Gx1x1x2x2x1--x2x3Bx3Bx2--x3Bx3B--x1

c=(x4ˉx5) c = \left( \bar{x_4} \lor x_5 \right)

Gx4Bx4Bx5x5x4B--x5

c=(x1ˉ) c = \left( \bar{x_1} \right)

Gx1Bx1B

IS S has at most 1 vertex per clause. Since g=m, a 3SAT solution has exactly 1 vertex per clause.

We could take 1 vertex per sub-graph and create an assignment

Gx1x1x2x2x1--x2x3Bx3Bx2--x3Bx3B--x1x4Bx4Bx5x5x4B--x5x1Bx1B

This leads to x1=T,x5=T,x1=F x_1 = T, x_5 = T, x_1 = F

Since we have a contradiction, we need to create new edges from any xixiˉ x_i \rightarrow \bar{x_i}

Gx1x1x2x2x1--x2x1Bx1Bx1--x1Bx3Bx3Bx2--x3Bx3B--x1x4Bx4Bx5x5x4B--x5

These new edges (yellow in above) are variable edges

Example

f=(xˉyzˉ)(xyˉw)(xˉwˉ)(yˉzw)f = \left( \bar{x} \lor y \lor \bar{z} \right) \land \left( x \lor \bar{y} \lor w \right) \land \left( \bar{x} \lor \bar{w} \right) \land \left( \bar{y} \lor z \lor w \right)

Gcluster_onecluster_twocluster_threecluster_fourxBxByyxB--yxxxB--xzBzBy--zByB2yBy--yB2zB--xByByBx--yBxB2xBx--xB2yB--ywwyB--ww--xwBwBw--wBxB2--wBw2wwB--w2zzyB2--zw2--yB2z--zBz--w2
Gcluster_onecluster_twocluster_threecluster_fourxBxByyxB--yxxxB--xzBzBy--zByB2yBy--yB2zB--xByByByB--ywwyB--wx--yBxB2xBx--xB2w--xwBwBw--wBxB2--wBw2wwB--w2zzyB2--zw2--yB2z--zBz--w2

Corresponds to x = F, y = F, w = F, and z has no constraints

Correctness

f has a satisfying assignment      \iff G has an independent set of size at least g

Forward Claim

Consider a satisfying assignment for f.

For each clause c, take 1 of the satisfied literals

  • add corresponding vertex to S
    • S=m=g \left\lvert S \right\rvert = m = g

S has 1 vertex per clause and not both xi and xiˉ x_i \text{ and } \bar{x_i} . This corresponds to not having any clause edges nor any variable edges, so S is an IS. \blacksquare

Reverse Claim

Take an independent set S of size at least g.

S has 1 vertex per clause

  • set corresponding literal to True
    • every clause is satisfied

No contradictory literals since we added edges xixiˉ x_i \leftrightarrow \bar{x_i}

S is a valid assignment that satisfies every clause. \blacksquare

Clique

Clique
A fully connected subgraph

For a graph G=(V,E), a subset of vertices S is a clique if x,y,S,(x,y)E \forall x,y, \in S, (x,y) \in E

Input: Undirected graph G and goal g

Output: SV S \subset V where S is a clique of size at least g if it exists, NO otherwise

Clique in NP

Given input (G,g) and S

  • x,yS \forall x,y \in S , check that (x,y)E (x,y) \in E
    • O(n3) O(n^3) , trivially, down to O(n2) O(n^2)

Reduce IS to Clique

Clique is opposite of IS.

Given an input for IS, G=(V,E), let Gˉ=(V,Eˉ) where: Eˉ:{(x,y):(x,y)∉E} G=(V,E), \text{ let } \bar{G} = \left( V, \bar{E} \right) \text{ where: } \bar{E}: \left\lbrace (x,y) : (x,y) \not\in E \right\rbrace

(x,y)Eˉ    (x,y)∉E (x,y) \in \bar{E} \iff (x,y) \not\in E

S is a clique in Gˉ     \bar{G} \iff S is an IS in G G

Given an input for IS, G=(V,E), let Gˉ&g G=(V,E), \text{ let } \bar{G} & g be input to the clique problem.

If we get a solution S for clique, return S for IS. If we get NO, return NO.

Vertex Cover

For a graph G, a subset of vertices S is a vertex cover if every edge is touching at least one vertex in S.

(x,y)E,xSyS \forall (x,y) \in E, x \in S \lor y \in S

Input: G and budget b

Output: Vertex cover S of size at most b, if one exists, NO otherwise

VC in NP

Given input (G,b) and solution S,

  • (x,y)E (x,y) \in E , check x and/or y are in S
    • O(n + m)
  • Check that S is at most size of b
    • O(n)

Reduce IS to VC

Claim: S S is a VC     Sˉ \iff \bar{S} is an IS

Forward Claim

Take vertex cover S

(x,y)E:{1 of {x,y}S1 of {x,y}Sˉ \forall (x,y) \in E : \begin{cases} \ge 1 \text{ of } \lbrace x,y \rbrace \in S \ \le 1 \text{ of } \lbrace x,y \rbrace \in \bar{S} \end{cases}

Sˉ \therefore \bar{S} is an IS

Reverse Claim

Take an IS Sˉ \bar{S}

(x,y)E,1 of {x,y}Sˉ \forall (x,y) \in E, \le 1 \text{ of } \lbrace x,y \rbrace \in \bar{S}

S covers every edge