Vous êtes sur la page 1sur 6

COSC 341: Lecture 22

Other N P-complete problems

Introduction

In todays lecture, we are going to discuss some other N P-complete problems and in
particular look at the SUBSET-SUM problem. The goal is two-fold: rst to give you
extra exposure to N P-completeness proofs; and second to broaden the areas in which
we see N P-complete problems. In fact, N P-complete problems tend to turn up in just
about every interesting area including, but not limited to: graph theory, hardware layout,
optimisation, combinatorics, and pattern recognition.
Today we are going to prove that the SUBSET-SUM problem is N P-complete. Remember
that the basic methodology in proving N P-completeness is:
1. Prove the problem lies in the class N P
2. Find an N P-complete problem that reduces to it.

SUBSET-SUM

Denition 2.1 (SUBSET-SUM). Given a set, S of positive whole numbers and an integer
t, does there exist a subset of S whose sum is t?
Theorem 2.2. The SUBSET-SUM problem is N P-complete.
Proof. As usual, showing that something lies in N P is often straightforward. For SUBSETSUM the non-deterministic algorithm is:
1. Guess a subset T of S
2. Check that the members of T sum to t (linear)
3. or, in certicate terms, T is the certicate.
The second part is more difcult. We choose to reduce 3-SAT to SUBSET-SUM. The basic
idea is that from the 3-SAT problem we create a set of (potentially very large) integers.
1

COSC 341: Lecture 22

Other N P-complete problems

The integers are sparse in the sense that they have at most two non-zero digits which
are always 1. We use this sparseness to generate the sum we need if it is possible.
Given an arbitrary instance I of 3-SAT we must construct, in polynomial time, an instance
I (which is a set S and an integer t) of SUBSET-SUM such that I is satisable if and only
if S has a subset which sums to t.
Suppose the variables of I are x1 , x2 , . . . , xn and there are m clauses C1 , C2 , . . . , Cm in the
boolean formula.
Now we make the instance of SUBSET-SUM.
We write out the decimal digits of the instance in a table, where each digit depends on a
xed rule or a property of how literals belong to clauses. In this table the only non-zero
digits that occur are 1 and 3, all blanks are 0.
The integers in the set are
y1 , z1 , . . . , yn , zn , g1 , h1 , . . . , gm , hm
and the target integer is t. They are dened as shown in Figure 1 with an example of a
particular reduction shown in Figure 2. Note that an integer is represented as a row of
the table.
Remember that we have to show that:
1. if there is a satisfying assignment, then there is a subset sum equal to t, and
2. if there is a subset sum, there must be a satisfying assignment.
2.1

Satisfying assignment = subset sum

Suppose we have a satisfying assignment. Choose the elements that add up to t as follows:
If xi = T choose yi
If xi = F choose zi
2

COSC 341: Lecture 22

Other N P-complete problems

Figure 1: Constructing an instance of SUBSET-SUM; all digits in decimal

COSC 341: Lecture 22

Other N P-complete problems

Figure 2: Reduction of (x1 x2 x3 ) (x1 x2 x4 )

COSC 341: Lecture 22

Other N P-complete problems

This already ensures that the rst n digits of t are correct.


Consider the last m digits. Look at the one that is headed by Cj .
The clause Cj contains between 1 and 3 true values. If xi = T then yi was chosen and if
xi = T then zi was chosen. So the true members of Cj give 1s in the Cj column. We
can choose 0, 1, or 2 of {gj , hj } to make the correct digit 3 for this column.
2.2

Subset sum = satisfying assignment

Suppose we have a subset S0 that sums to t.


Look at the rst n digits of t. Since they are all 1, exactly one from each pair {yi , zi } must
belong to our subset S0 . We dene a truth assignment by
If yi S0 dene xi = T
If zi S0 dene xi = F
Now look at the last m digits of t. They are all 3. Look at the column underneath Cj .
Since the lower right quadrant can contribute at most two 1s towards the 3 some 1 has
been contributed from the top right quadrant. But a 1 in column Cj says that Cj contains
a true value.

FAIR DIVISION

Recall that the FAIR DIVISION problem involves splitting a set of integers in two such
that the sum of the two sets is equal.
Theorem 3.1. FAIR DIVISION is N P-complete
Proof. It should be obvious that FAIR DIVISION is in N P. We can reduce
SUBSET-SUM
to FAIR DIVISION by transforming {s1 , . . . , sn }, t to {s1 , . . . , sn , 2t si }.
5

COSC 341: Lecture 22

Other N P-complete problems

Suppose there is a subset sum with k elements: without loss of generality, assume the

rst k elements1 so ki si = t. Then the FAIR DIVISION


solution can be produced with
the two sets being: {s1 , . . . , sk } and {sk+1 , . . . , sn , 2t si }.

Suppose there is FAIR DIVISION of {s1 , . . . , sn , 2t si }. Then:


k

si =

i=0

i=k+1

2t =

si + 2t

si +

i=0

2t =

i=0

si +

i=0

2t =

t=

i=0
k

si +

si

i=0

si .

Why is this OK?

si

i=k+1
n

i=k+1

i=0

si

i=0

si

i=0

si +

si

i=k+1

si

Vous aimerez peut-être aussi