Docsity

Combinatorial Search Problems and NP-Completeness, Apuntes de Representación de Datos y Diseño de Algoritmos

Toggle sidebar
bg1
NP-Complete Problems
Richard M. Karp
University of California Berkeley
The International Computer Science Institute
Transcription by F. Palomo Lozano and I. Medina Bulo
University of Cádiz, Spain
Department of Computer Languages and Systems
This talk is concerned with combinatorial search problems, problems that have the character
of a puzzle. Just as the solver of a jigsaw puzzle is required to assemble the pieces so that
they fix together perfectly, the solver of a combinatorial search problem is required to
find the pattern or an arrangement for a finite set of ob jects so as to satisfy some set
of constraints. The combinatorial search problems have the character of searching for a
needle, the desired solution, in a very large haystack, the set of all possible solutions. 1:00
Many combinatorial search problems have very simple and elegant solution algorithms but
there are others which require an immense amount of computation even though they have
been studied extensively from the dawn of the computer age or in some cases even for
centuries. The basic question that we will be examining in this talk is how to distinguish
the easy combinatorial search problems from the hard ones and, in particular, to determine
whether the hard ones are really intrinsically hard or whether some day we may hope to
crack them as well.
Let me begin with a couple of examples to illustrate the kinds of problems we’ll be dis-
cussing.
The first example is called the shortest network problem or the Steiner tree problem. It is
a problem that might arise in the design of a local area telephone network. The data for
the problem consists of a set of points in the plane, there are green points, which we are
required to connect together, and red points, which are optional. 2:00
The problem is to choose line segments each of which joins two of the points, so as to
interconnect all of the green points possibly using some of the red points as intermediate
junctions.
So the rules of the game are that any pair of points may be joined by a line segment and
1
...... to find the collection of line segments of minimum total length that connect all of
the green points together possibly using some of the red points.
Here is the optimal solution or the minimum length solution to this example. You notice
that the solution is in the form of a tree, that all of the green points are connected together
by the links of the tree and that some of the red points are used as intermediate junctions,
but others are omitted.
The problem of finding an optimal solution to the Steiner tree problem has proved to be
extremely elusive. 3:00
There are examples with just a few dozen points with which we touch the limits of even
the most powerful computers. Anyway if we change the conditions of the problem ever so
slightly, we obtain a problem which is essentially trivial to solve. If we consider the special
case where there are no optional points, where all the points are green, where all the points
are required to be connected together, then there is a very simple algorithm capable of
obtaining minimum cost solutions to problems with tens of thousands of points. And this
is the fundamental situation that arises constantly in the study of these combinatorial
search problems: that even a very slight alteration in the conditions of the problem can
make the difference between an intractable problem and a trivial one.
As another example, let’s consider the problem called the assignment problem which in-
volves matching workers with jobs. In this problem, we are given nworkers and njobs
and we want to find the one-to-one pairing or matching of the workers with the jobs at
minimum cost. Each pairing of a worker with a job has associated with it a numerical
cost. So the data for the problem consists of an n×nmatrix where the rows correspond
to the workers, the columns to the jobs and the cells to the pairings. In this tiny 3×3
example, the first row would correspond to the first worker, the second row to the second
worker and so on, and similarly the columns would correspond to the jobs. The entry 4 is
the cost of pairing worker number 1 with job number 2. And, in this particular example,
the minimum cost pairing associates worker 1 with job 2, worker 2 with job 3, and worker
3 with job 1 for a total cost of 4 + 1 + 7 or 12. 5:00
It turns out that although this problem seems to have the “needle in a haystack” character
that is characteristic of hard combinatorial problems, it’s actually ...... an easy problem.
There is an elegant algorithm which allows us to solve very large instances of this problem,
instances with thousands of workers and jobs, rapidly on a computer. So again we see this
phenomenon that some of these problems are remarkable easy, others remarkably resistant.
With this background let’s take the step of giving a general definition of the class of
problems that we are interested in.
We can define a combinatorial search problem in general as follows:
Among a very large, but finite, structured set of possible solutions, find one
that satisfies a set of stated constraints.
2
pf3
pf4
pf5

Vista previa parcial del texto

¡Descarga Combinatorial Search Problems and NP-Completeness y más Apuntes en PDF de Representación de Datos y Diseño de Algoritmos solo en Docsity!

NP

-Complete Problems

Richard M. Karp

University of California Berkeley

The International Computer Science Institute

Transcription by F. Palomo Lozano and I. Medina Bulo

University of Cádiz, Spain

Department of Computer Languages and Systems

This talk is concerned with

combinatorial search problems

, problems that have the character

of a puzzle. Just as the solver of a jigsaw puzzle is required to assemble the pieces so thatthey fix together perfectly, the solver of a combinatorial search problem is required tofind the pattern or an arrangement for a finite set of objects so as to satisfy some setof constraints.

The combinatorial search problems have the character of searching for a

needle, the desired solution, in a very large haystack, the set of all possible solutions.

Many combinatorial search problems have very simple and elegant solution algorithms butthere are others which require an immense amount of computation even though they havebeen studied extensively from the dawn of the computer age or in some cases even forcenturies. The basic question that we will be examining in this talk is how to distinguishthe easy combinatorial search problems from the hard ones and, in particular, to determinewhether the hard ones are really intrinsically hard or whether some day we may hope tocrack them as well.Let me begin with a couple of examples to illustrate the kinds of problems we’ll be dis-cussing.The first example is called the

shortest network problem

or the

Steiner tree problem

. It is

a problem that might arise in the design of a local area telephone network. The data forthe problem consists of a set of points in the plane, there are green points, which we arerequired to connect together, and red points, which are optional.

The problem is to choose line segments each of which joins two of the points, so as tointerconnect all of the green points possibly using some of the red points as intermediatejunctions.So the rules of the game are that any pair of points may be joined by a line segment and

to find the collection of line segments of minimum total length that connect all of

the green points together possibly using some of the red points.Here is the optimal solution or the minimum length solution to this example. You noticethat the solution is in the form of a tree, that all of the green points are connected togetherby the links of the tree and that some of the red points are used as intermediate junctions,but others are omitted.The problem of finding an optimal solution to the Steiner tree problem has proved to beextremely elusive.

There are examples with just a few dozen points with which we touch the limits of eventhe most powerful computers. Anyway if we change the conditions of the problem ever soslightly, we obtain a problem which is essentially trivial to solve. If we consider the specialcase where there are no optional points, where all the points are green, where all the pointsare required to be connected together, then there is a very simple algorithm capable ofobtaining minimum cost solutions to problems with tens of thousands of points. And thisis the fundamental situation that arises constantly in the study of these combinatorialsearch problems: that even a very slight alteration in the conditions of the problem canmake the difference between an intractable problem and a trivial one.As another example, let’s consider the problem called the

assignment problem

which in-

volves matching workers with jobs.

In this problem, we are given

n

workers and

n

jobs

and we want to find the one-to-one pairing or matching of the workers with the jobs atminimum cost.

Each pairing of a worker with a job has associated with it a numerical

cost. So the data for the problem consists of an

n

×

n

matrix where the rows correspond

to the workers, the columns to the jobs and the cells to the pairings.

In this tiny

×

example, the first row would correspond to the first worker, the second row to the secondworker and so on, and similarly the columns would correspond to the jobs. The entry 4 isthe cost of pairing worker number 1 with job number 2. And, in this particular example,the minimum cost pairing associates worker 1 with job 2, worker 2 with job 3, and worker3 with job 1 for a total cost of

or 12.

It turns out that although this problem seems to have the “needle in a haystack” characterthat is characteristic of hard combinatorial problems, it’s actually

an easy problem.

There is an elegant algorithm which allows us to solve very large instances of this problem,instances with thousands of workers and jobs, rapidly on a computer. So again we see thisphenomenon that some of these problems are remarkable easy, others remarkably resistant.With this background let’s take the step of giving a general definition of the class ofproblems that we are interested in.We can define a combinatorial search problem in general as follows:

Among a very large, but finite, structured set of possible solutions, find onethat satisfies a set of stated constraints.

There are some variants of this definition that are also of interest.

Sometimes we are

interested in decision problems, problems of the yes-no character where we don’t ask tofind the solution, but simply to determine whether a solution exists.

Sometimes, as in

the example of the Steiner tree problem or in the assignment problem, we are looking foran optimal solution, that is, we associate with every possible solution a cost and we areseeking a solution of minimum cost.There are many areas of application arising in Industry, in Engineering, in ManagementScience, in the Natural Sciences and in Mathematics that give rise to this combinatorialsearch problems.

Let me give a few examples. Scheduling is a rich and fertile area for such problems, schedul-ing of manufacturing operations, of the airline flights, of classes within school, schedulingthe National Football League, all of these areas give rise to difficult combinatorial searchproblems. For example, in scheduling classes at school the data might consist of the list ofthe classes to be given and, for each, an indication of which teachers are available for thatclass, which rooms are suitable, which hours of the day are suitable for the class. Theremight be constrains as to the number of classes a teacher can teach, constrains which saythat two courses cannot be given at the same time because too many students want totake both, etc. And, given all of these constrains, we want to weave together a schedule,put together the pieces of the puzzle in such a way as to satisfy the conditions.

The various networks that flood our society provide many interested examples of combi-natorial search problems. Here the challenge is to route a commodity through a networkso as best to use the capacity of the network.

The commodities may be vehicles as in

a transportation network, phone calls as in a telephone system, pieces of information orpackets of information as in a computer network, oil or gas as in pipeline systems.The field of VLSI design, the design of the microchips within our computers is anotherimportant application area for combinatorial problems.

The design of a very large scale

integrated circuit chip is analogous to the planning of a medium-size city. Tens of thousandsof components have to be placed on the chip and wires interconnecting them appropriatelyhave to be laid down on the chip subject to the technological and special constraints ofthe chip itself. So we get vast problems of arrangement and layout in this area.An area which is increasingly giving rise to interesting combinatorial search problems isComputational Biology.For example, in order to study the structure of the very large DNA molecule, it’s necessaryto break that molecule up into a large number of smaller overlapping fragments and to studythe structure of each of these fragments and then finally to mathematically reassemble thefragments by looking for pairs that are likely to overlap. And the number of arrangementshere is very large and we get a vast combinatorial problem.And similarly in Cryptography the problem of breaking codes gives rise to importantcombinatorial problems with a number theoretic flavor.

Many of the basic combinatorial search problems can be expressed in terms of structurescalled graphs.A graph is simply a set of points called vertices, certain pairs of which are joined by edges.So, for example, here we have an edge joining these two vertices, an edge joining these two,and so forth.Let me give you a couple of examples about combinatorial search problems involvinggraphs.

A classic problem, which was first studied by the mathematician Euler in the

eighteenth century, is the

Eulerian walk problem

. Given a graph, we ask, is there a closed

walk that covers each edge exactly once? In other words, can you put your pencil downon a vertex of the graph and trace a chain of edges covering each edge exactly once andending up back at the starting point?

This seems like a difficult problem but Euler discovered an elegant and simple criterion forits solution. Such a walk exists, assuming that the graph has no isolated vertices, if, andonly if, the graph is connected, meaning that there’s a path for any vertex to any othervertex, and each vertex indeed has an even number of neighbors. Since these conditionsare readily check, the problem of deciding whether a graph has an Eulerian walk is an easycomputational problem. Here is an example.We can easily see by inspection that this graph is connected and each vertex indeed doeshave an even number of neighbors, for example, this vertex has four neighbors, and becausethese conditions are fulfilled, we don’t have to bother to trace out the Eulerian walk, weknow that the walk must exist.A very similar sounding problem is the

Hamiltonian circuit problem

. Here we are asking

for a closed walk that starts at a vertex of the graph and visits all the vertices of the graph,visiting each one exactly once. This problem, although it sounds deceptively similar to theearlier one, is much more difficult. In this example, we can begin searching, we can startat vertex one and successively visit vertices three, five, two, four, nine, eight, seven, sixand ten, almost completing the tour but failing because vertex ten, the last vertex on thewalk, is not adjacent to vertex one.It turns out that although there are other many new

possible in this example, there

is no Hamiltonian circuit here, there is no closed walk that visits each vertex exactly once.

As far as we know, the Hamiltonian circuit problem is a hard combinatorial problem.Every algorithm known for its solution runs into a

combinatorial explosion

, an exponential

growth in the number of computation steps required to solve the problem as the number ofvertices increases. So this problem seems remarkably more difficult than the rather trivialEulerian walk problem.

And this leads us to the central question that we would be investigating here. Are thesecombinatorial explosions inevitable?

Is the fact that we do not know how to solve the

Hamiltonian circuit problem efficiently simply an artifact of our ignorance or there is

Let’s look at some of the properties of this notion of reducibility.

We observe that if problem

L

is reducible to problem

M

, and problem

M

is solvable in

polynomial time, then

L

is also solvable in polynomial time and the diagram indicates how

this is proved.Assuming that we have a box that will decide membership in

M

in polynomial time, then

to solve problem

L

on an input

x

, we simply transform that input through the polynomial-

time transformation

F

to a new string

F

x

and then present the new string to the decision

procedure for

M

. The concatenation of these two operations, according to the definition,

solves problem

L

and so this is further confirmation that if problem

L

is reducible to

problem

M

, then problem

M

is at least as hard as problem

L

. This means that we can

gather evidence for the difficulty of some problem

M

by showing that many seemingly hard

problems are reducible to it.

Let me give you a concrete example of reducibility between two combinatorial problems.In this example, one of the problems is the so-called

satisfiability problem

that arises

in propositional logic, or computer scientists might say boolean algebra, and the secondproblem involved is a problem arising in graph theory called the

3-coloring problem

Let us first deal with the satisfiability problem.

The satisfiability problem involves ex-

pressions that are built up by applying the logical connectives: “and”, “or” and “not”, topropositional or boolean variables. So we start with propositional variables

A

B

C

, etc.,

each of which may be assigned the value “true” or the value “false”.A literal is either a propositional variable or its negation.

So

A

denotes the negation of

variable

A

A

is true precisely as

A

is false. Next, we define a clause as a logical “or” of

a set of literals. So the clause shown here would be true if either

A

is true or

B

is false,

or

D

is false, so that

D

is true, or

F

is true. And finally, we define a conjunctive normal

form formula as the “and”, a logical “and”, of a set of clauses. So the formula shown herewould be true if each of the clauses is true and any given clause would be true if at leastone of the literals in that clause is true.We will say then that a conjunctive normal form or CNF formula is satisfiable if there issome assignment of truth values to the variables that makes the formula true. The formulashown here is satisfiable because we can make it true by setting

B

C

and

D

false and

A

true, if we do that then the first clause is true because

A

is true, the second and third

clauses because

B

is false and

B

is true, and the last clause because

D

is false, so the

D

is true.

Each of these clauses contains a true literal and hence each is true and their

conjunction is also true.The satisfiability problem then takes as its input a CNF formula and the input is acceptedif that formula is satisfiable.

Now let us turn to the second problem that is involved in our reduction.This is a problem from the graph theory called the 3-coloring problem. A graph is said to

be 3-colorable if we can color each of its vertices with one of the three colors, red, greenand blue, in such a way that no two adjacent vertices are assigned the same color.It turns out that this graph is not 3-colorable.

We can trace thru a chain of reasoning

that will determine this. First of all, because vertices 2, 3 and 4 form a triangle, no two ofthem can get the same color, so they must get distinct colors. Similarly, 3, 4 and 6 form atriangle so they must get distinct colors and, since it is only 3 colors that are available, 2and 6 must get the same color. And continuing a chain of reasoning along these lines wewill eventually conclude that there is no assignment of colors such that we avoid havingtwo adjacent vertices got the same color.So the decision problem here is the 3-coloring problem, given a graph, to decide whetheror not it can be colored with three colors.Now we are going to link these two problems by showing that the 3-coloring problemis reducible to the satisfiability problem.

If you recall instead the definition this means

that we have to give a transformation which is easily computed, that is, polynomial-timecomputable, which will take any instance of the 3-coloring problem, that is, any graph, andproduce from that an instance of the satisfiability problem, that is, a conjunctive normalform formula, such that the graph is 3-colorable if, and only if, the formula that we haveproduced is satisfiable.In this particular case, what we have to do is define appropriate propositional variables todescribe all of the conditions that are required of the 3-coloring.So we will do that in the following way: for each vertex

i

in the graph we will introduce a

variable

R

i

, which is true if vertex

i

gets the color red,

B

i

which is true if vertex

i

gets the

color blue, and

G

i

which is true if, and only if, vertex

i

is assigned the color green. And

in terms of these boolean or propositional variables we can write down all the conditionsof the problem.Each of the conditions will be expressed as a clause. So, first of all, for each vertex

i

, we

write down the clause

R

i

B

i

G

i

, that simply says that vertex

i

must receive some color,

either red or blue or green.

The next trio of clauses associated with a given vertex

i

asserts that the vertex doesn’t

receive two distinct colors. For example, the clause

R

i

B

i

asserts that either the

i

vertex

does not receive the color red or it does not receive the color blue, in other words, it’s notboth red and blue, and in a similar way, the next two clauses assert that it’s not both redand green, and that it’s not both blue and green.The other clauses that we have to write express the condition that two adjacent verticesmust not get the same color. So we look at each edge of the graph

i, j

and we write three

clauses for that edge. The first one,

R

i

R

j

, says that either

i

is not red or

j

is not red, in

other words,

i

and

j

do not both get color red: that would be a violation of the coloring

conditions. And the other clauses, similarly, say that the two adjacent vertices

i

and

j

are

not both blue and are not both green.

And we see that the totality of these clauses expresses all of the conditions that are requiredof the coloring, so that, this set of clauses, comprising a CNF formula, is satisfiable if, andonly if, the original graph could be colored with three colors. And furthermore it’s ratherobvious that the algorithm to go from the graph to the set of clauses is rather trivial andthus can be carried out in polynomial time. So this establishes that 3-coloring is reducibleto satisfiability or, in other words, that satisfiability is at least as general, or at least ashard a problem as 3-coloring.Now we need one more key definition before we can approach the main results over thetheory.

It turns out that most of the combinatorial problems that arise in applications

have a characteristic form which is captured by the definitions of the class of problemscalled

NP

These problems have the character of that they are asking for the existence of a structurewhich may be hard to find but once pointed out is easy to check.

For example, in the

case of the Hamiltonian circuit problem, we are asking for a closed walk in a given graphin which each of its vertices is exactly once, it may be extremely difficult to find such awalk, but if somebody gives you one, gives you the list of successive vertices of one of sucha walk, it would be very trivial to check that list against the graph and to verify that itreally was a closed walk visiting every vertex of the graph. So, in that sense, Hamiltoniancircuit problem is easy to check.Let me give a more precise definition of the class of problems

NP

We’ll say that a decision problem

L

lies in

NP

if, and only if, there exists a

polynomial-time decision algorithm

A

with two inputs

x

and

y

, such that the

input

x

should be accepted in problem

L

if, and only if, there is another string

y

, that we call the witness, or the solution, of length bounded by a polynomial

in the length of

x

, such that algorithm

A

accepts the pair

x, y

So the idea behind of this definition is that even though problem

L

may be hard it lies in

NP

if once the solution is handed to you it’s not too difficult to check the solution against

the input and verify that it is indeed the solution.

And to illustrate this definition, let’s talk about the following decision problem. Given aninteger, to decide if the integer is composite or factorable. A composite integer is a numberlike 15, 3 times 5, or 56, 7 times 8, which can be written as the product of two factors, asdistinguished from prime number like 7, 11, or 13 which cannot be factored in such a way.

Now, how do we see that the set of integers that can be factored, the set of compositeintegers, lies in the class

NP

? Well, if an integer can be factored then there is an obvious

witness to that fact, namely, one of the factors, and the decision problem of checking thefactor against the number is trivial. So, for example, if we’re presented with the number 56

as an input then an appropriate witness to the compositeness or factorability of 56 wouldbe one of its divisors, 14, and given that witness we would simply check that 14 dividedinto 56, and was neither equal to 1 nor equal to 56.So even now we don’t know that the problem of testing whether a number is compositelies in

P

, it’s immediately seen that it lies in this broader class

NP

, and the reason for the

interest in

NP

is that nearly all of the combinatorial problems typically arising in practice

have versions that lies within the class

NP

So, for example, the Eulerian walk problem lies in

NP

because the witness in this case

would be just the walk itself, and it’s easy to check the walk and, for similar reasons, theHamiltonian circuit problem, the satisfiability problem, and the 3-coloring problem all liein

NP

For example, in the case of the 3-coloring problem the witness would be simply

the assignment of colors and given an assignment is rather trivial to check that no twoadjacent vertices have the same color.It’s also interesting, as a side comment on it, that sometimes the negations or the com-plements of these properties are not so obviously in

NP

. For example, if we look at the

Hamiltonian circuit problem, there is an obvious witness to the existence of the Hamilto-nian circuit, namely, the circuit itself, but there’s no obvious witness to the non-existence,in other words, there is no short hint or witness that one could write down which you canhand to somebody and thus enable that person to easily verify that the given graph didnot have a Hamiltonian circuit.

At least, we do not know of a general way of providing

such a witness.

So then, what is the relationship between the class

P

, of problems that are easily solved,

problems that are solvable in polynomial time, and

NP

, the class of problems for which

witnesses are checkable in polynomial time? It’s easy to see that every problem in

P

lies

in

NP

, but what about the converse? Does every problem in

NP

lie in

P

? Is

P

equal to

NP

This is generally considered the single most important open problem in theoretical Com-puter Science.Let’s look at some of the consequences of the unlikely proposition that

P

is equal to

NP

If

P

were equal to

NP

, then we could say that finding a solution to a problem is no harder

than checking a solution, because, after all,

P

is the class of problems for which solutions

are easy to find, and

NP

is the class which solutions are easy to check.

Putting it in terms of mathematical proof it would say that finding a proof of a theoremis no harder than checking a proof, something that we are hardly inclined to believe aswe think back to our tussle with plane Geometry in high-school where finding proofs weresometimes difficult but we knew that checking a proof was a simple matter of determiningthat each line of the proof followed from the axioms and postulates.If

P

were equal to

NP

it would further mean that many seemingly intractable problems,