Quinn’s Mind Palace

NP-completeness proofs (3): set-related problems

In this article, we’ll explore three fundamental NP-completeness proofs involving set-based problems: set cover, partition, and subset sum. These proofs demonstrate elegant reductions between different computational problems and provide insights into the nature of NP-completeness. — At least, I hope it do provide insights to you. 😆

Have fun proving them by yourself!

P1: Set cover problem

Definition.

Set cover decision: Given a set of elements U, a collection S of subsets of U, and an integer k, does there exist a selection of k or fewer sets from S whose union equals U?


Proof by reduction from vertex cover.

  1. Certificate: Verifying m sets of n elements would costs O(nm), which is in polytime. Thus the problem is NP.

  2. Vertex cover decision: Given a graph G(V,E) and an integer k, does there exist a subset of vertices SV such that |S|k and for each edge (u,v)E, at least u or v belongs to S?

  3. Reduction: Let U=E. For each vertex u, put all edges connected to u into a set Su.

    Given an algorithm to find a set cover of size k that covers U, i.e. covers all edges in the graph, then we can pick either u or v for each edge (u,v)E to form a vertex cover of size k.

  4. The construction of set cover inputs costs O(|V||E|) since we are iterating through all edges connected to all vertices. This reduction is in polytime. In conclusion, the set cover decision problem is NP-complete.

P2: Partition problem

Definition.

Partition decision: Given a set of integers S, can it be partitioned into two subsets A and A such that A=SA and xAx=xAx ?


Proof by reduction from subset sum.

  1. Certificate: Calculating xAx and xAx are both O(n), so verification is in polytime. Thus, the problem is NP.

  2. Subset sum decision: Given a set of integers S and an integer T, does there exist a subset SS such that xSx=T ?

  3. Reduction: Construct a set S=S{p,q} where p=S and q=2T, which sums to 2S+2T.

    Given an algorithm to partition S into two subsets, R and R, they must be of equal sum S+T. Each subset cannot contain both p and q due to p+q>S+T; one subset R must contain p, and then the rest of the integers in R must sum to T. This solves subset sum problem.

  4. Calculating S is O(n), thus the reduction is in polytime. In conclusion, the partition decision problem is NP-complete.

P3: Subset sum problem

Definition.

Subset sum decision: Given a set of integers S and an integer T, does there exist a subset SS such that xSx=T ?


Proof by reduction from 3-SAT.

  1. Certificate: Calculating xSx is O(n), so verification is in polytime. Therefore, the problem is NP.

  2. 3-SAT: Given a 3-CNF formula of M clauses, does there exist a set of values that makes the formula True?

  3. Reduction: For each variable xi, create two base-2 integers Ai,Bi, whose bits are:

    • N variable-slots: only the i-th digit is marked 1, other digits are marked 0.
    • M clause-slots: for each clause Cj:
      • If xi exists in the clause Cj, then Ai’s N+j bit should be 1, otherwise 0.
      • If ¬xi exists in the clause Cj, then Bi’s N+j bit should be 1, otherwise 0.

    For example, for a formula (abc)(¬a¬bc), we have 3 variables and 2 clauses, therefore 5 digits:

    • A1: 10010 (being the 1st variable; a appearing in C1)
    • B1: 10001 (being the 1st variable; ¬a appearing in C2)
    • A2: 01010 (being the 2nd variable; b appearing in C1)
    • B2: 01001 (being the 2nd variable; ¬b appearing in C2)
    • A3: 00111 (being the 3rd variable; c appearing in C1 and C2)
    • B3: 00100 (being the 3rd variable; ¬c not appearing at all)

    Let the subset sum T=2N+M1 and in the example, 11111. By finding a satisfying subset, e.g., {A1,B2,B3}, we have found the answer to the 3-SAT as well, since each variable-slot is satisfied exactly once, and each clause-slot is satisfied also exactly once.

  4. The construction of the base-2 integers costs at least O(N+M), which is in polytime. In conclusion, the subset sum problem is NP-complete.

#Algorithms