yohandi
A recent graduate with a strong interest in algorithms and data structures.

Karp's Classics Challenge 1: Knapsack to Partition

In 1972, Richard Karp published a paper titled "Reducibility Among Combinatorial Problems," in which he demonstrated that 21 decision problems were NP-complete. What is fascinating is that, until this date, no one has conclusively proven whether these problems can be solved using a polynomial-time algorithm. In layman's terms: if one can find a polynomial-time solution to any of these problems, like the Boolean Satisfiability Problem (SAT), then a domino effect ensues, and all NP problems would collapse to being polynomial-time solvable. Conversely, disproving the polynomial-time solvability for one inherently disproves it for all.

Post Script - pretty much, this blog series is my proving exercises before my final exam for the postgraduate course that I took, DDA6050: Analysis of Algorithms, draws near. Through this series, I attempt to prove the NP-completeness of Karp's problems from the ground up without relying much on established proofs.

Challenge Progress

Knapsack (simplified)

Given:

  • an integer
    KaTeX can only parse string typed expression
  • a set of non-negative integers
    KaTeX can only parse string typed expression
  • an integer
    KaTeX can only parse string typed expression

Task:

  • Decide whether there is a subset
    KaTeX can only parse string typed expression
    such that
    KaTeX can only parse string typed expression

Partition

Given:

  • an integer
    KaTeX can only parse string typed expression
  • a set of non-negative integers
    KaTeX can only parse string typed expression

Task:

  • Decide whether there is a subset
    KaTeX can only parse string typed expression
    such that
    KaTeX can only parse string typed expression

Partition is NP

The question of whether the Partition problem lies within NP can be addressed by examining the verification process for a potential solution, which we'll call a certificate. For the Partition problem, this certificate is a subset

KaTeX can only parse string typed expression
drawn from the indices
KaTeX can only parse string typed expression
of the given set of integers.

To verify the certificate's correctness, we start by computing the sum of the integers that are indexed by

KaTeX can only parse string typed expression
, which we denote as
KaTeX can only parse string typed expression
. In parallel, we also determine the sum of the integers that aren't indexed by
KaTeX can only parse string typed expression
, represented by
KaTeX can only parse string typed expression
. Our main criterion for correctness then hinges on a straightforward comparison: are these two sums equal? If they are, our algorithm acknowledges the validity of the Partition and returns yes. If not, it simply returns no.

In terms of computational efficiency, this verification process is quite tractable. Calculating both summations takes linear time, specifically

KaTeX can only parse string typed expression
, and comparing them is a constant-time operation. Because the entire verification process is polynomial in
KaTeX can only parse string typed expression
, we can confidently state that the Partition problem is NP.

Partition is NP-hard by Knapsack

Let's consider a known NP-hard problem, Knapsack.

Given an instance of the simplified version of Knapsack problem with items

KaTeX can only parse string typed expression
and an integer
KaTeX can only parse string typed expression
, we then construct an instance of the Partition problem as follows:

  • Compute
    KaTeX can only parse string typed expression
    , which is half of the sum of the items in
    KaTeX can only parse string typed expression
    , i.e.,
    KaTeX can only parse string typed expression
    .
  • Form a new set
    KaTeX can only parse string typed expression
    .

The result of this transformation is

KaTeX can only parse string typed expression
, the goal is to find a subset of
KaTeX can only parse string typed expression
that sums to
KaTeX can only parse string typed expression
.

(

KaTeX can only parse string typed expression
) Suppose there is a solution to the Knapsack problem where a subset
KaTeX can only parse string typed expression
that sums up to
KaTeX can only parse string typed expression
. Then, a solution to the Partition problem must also exist, as we can assign
KaTeX can only parse string typed expression
into
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
to the other subset
KaTeX can only parse string typed expression
. This is confirmed as
KaTeX can only parse string typed expression
.

(

KaTeX can only parse string typed expression
) Conversely, if there is a subset of
KaTeX can only parse string typed expression
that sums up to
KaTeX can only parse string typed expression
, say
KaTeX can only parse string typed expression
, we may conclude that both
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
elements are not in the same subset as
KaTeX can only parse string typed expression
. If the element
KaTeX can only parse string typed expression
; then,
KaTeX can only parse string typed expression
, we found
KaTeX can only parse string typed expression
as our answer to the Knapsack problem. Otherwise, the element
KaTeX can only parse string typed expression
; then,
KaTeX can only parse string typed expression
, which is the complement subset of the answer to the Knapsack problem.

This proves that

KaTeX can only parse string typed expression
iff
KaTeX can only parse string typed expression
.

The transformation involves adding two numbers to

KaTeX can only parse string typed expression
, which can be done in a constant time. Additionally, calculating
KaTeX can only parse string typed expression
requires summing over
KaTeX can only parse string typed expression
, which is done in
KaTeX can only parse string typed expression
. Hence,
KaTeX can only parse string typed expression
is a polynomial time transformation, which proves that the Partition problem is NP-hard.

Partition is NP-complete

Since the Partition problem is both in NP and NP-hard, we conclude that the Partition problem is NP-complete; hence, shown.