Академический Документы
Профессиональный Документы
Культура Документы
. Introduction
Computational Complexity studies:
A major discovery in the area was that computational problems can vary
tremendously in the effort required to solve them precisely. The technical
term for a hard problem is "NP-complete" which essentially means: "abandon
all hope of finding an efficient algorithm for the exact solution of this
problem". Proving or knowing that a problem is NP-complete is not at all that
negative of course. Knowing such limitations, experts do not waste time in
impossible projects and instead turn to less ambitious approaches, for
example to find approximate solutions, to solve special cases or to alter the
problem a little so that it becomes tractable (even at the loss of some fit to
the real-life situation). The goal of this theory is therefore to assist algorithm
designers in directing their efforts towards promising areas and avoid
impossible tasks.
begin
input n (number of cities), C(n x n) (non negative integer distance matrix)
min = sufficiently large number (say, n times the maximum element of C)
for all possible tours, i.e. cyclic permutations of {1,2,...,n}
find length of tour
if length < min then
min=length, store tour
endif
next tour
end
Since there are (n-1)! possible tours, the for ... next loop is executed (n-1)!
times, each one requiring time O(n) (the time it takes to find the length of
the tour, that is add n integers). Therefore, this algorithm is of order (n-1)!
O(n) = O(n!). This is certainly prohibitive. If for example a solution to a 10city problem can be found in 1 second, increasing the number of cities to 20
would result to time: 20!/10! or about 20,000 years.
Compare this result to the performance of a good approximate algorithm for
the same problem, namely Lin's 3-optimal heuristic published in [2]. At every
iteration of this algorithm, a tour consists of links between cities. The main
idea is to locate at each step a triplet of cities which can be connected in a
better (length reducing) way. The algorithm stops when no such triplet can
be found. The solution is not guaranteed to be optimal but the time required
is O(n3). Now, if a 10-city problem takes 1 second, a 20-city one would
require only 7 more seconds.
2. An O(nlogn) sorting algorithm
The following algorithm is based on the observation that a list can be easily
sorted if it consists of two individually sorted lists. To sort the n elements of a
vector A(1),...,A(n) one would call the following recursive procedure with
parameters low=1, high=n:
Procedure mergesort(A,low,high)
input: A(low),A(low+1),...,A(high)
output: same numbers in non-decreasing order
begin
if low <high then
mid = [(low+high)/2] ! comment: [] stands for "greater integer smaller
than"
call mergesort(low,mid)
call mergesort(mid+1,high)
merge(low,mid,high) ! comment: auxiliary routine to combine the results,
complexity
function
With present
computer
With computer
100 times
faster
With computer
1000 times
faster
N1
100N1
1000N1
n2
N2
10 N2
31.6 N2
n3
N3
4.64 N3
10 N3
2n
N4
N4+6.64
N4+9.97
3n
N5
N5+4.19
N5+6.29
Matching problems
Classes P and NP
The class P consists of all those recognition problems for which a
polynomial-time algorithm exists.
For the class NP, we simply require that any "yes" answer is "easily"
verifiable. That is, both the encoding of the answer and the time it
takes to check its validity must be "short", i.e. polynomial or
polynomially-bounded. Formally we say that any "yes" instance of the
problem has the "succinct certificate" property.
To clarify, for the TSP-rec problem (see B1), just imagine we have a "yes"
answer, that is an ordering of the cities, say c1, c2, c3, ..., cn, such that the
sum of the links (c1,c2), (c2,c3), ... , (cn,c1) is less than or equal to L. How we
obtain this solution is irrelevant. It is clear that we can easily check the
length of the tour, so we know that TSP-rec is in NP. On the other hand, we
do not know if this problem is also in P, because no polynomial algorithm has
yet been found for it.
Class NP consists therefore of all "reasonable" problems of practical and/or
theoretical importance. For problems not in NP, even verifying that a solution
is valid can be extremely difficult.
As expected, the "easy" problems in class P are also "reasonable", i.e. they
also belong to NP. That is:
P is a subset of NP
To show this:
Suppose that there is a polynomial-time algorithm A for problem PA. Given
any "yes" instance x of PA, A will operate on x for a polynomial number of
steps and answer "yes". Now the record of this operation of A on x is a valid
certificate (polynomial in length, by definition). Indeed, one can check the
certificate simply by checking that it is a valid execution of A.
Hence, P NP. The important question now is whether P is a proper subset of
NP, i.e. P NP. This is a major conjecture in Complexity Theory, in words: "not
all reasonable problems can be solved efficiently". Although no formal
proof exists yet, it will be shown later that there is strong evidence for the
validity of this conjecture.
Another example of a recognition problem which, like TSP-rec, belongs to NP
but we do not know if it also belongs to P, is the recognition version of the
Maximum Clique problem. This problem is in NP, since a "yes" answer can
simply be verified by examining the list of nodes that are supposed to form a
clique and see that they are all connected to each other:
begin
(nodes v1,v2 ,..., vk are supposed to form a clique)
for i=1,...,k-1
for j=i+1,...,k ! comment: this double loop examines every pair of nodes in
v1,v2 ,..., vk
if there is no link between vi and vj exit and report "false"
next j
next i
report "true" and exit ! comment: no missing link found
end
(the latter implies that the subroutine for B can be called at most a
polynomially bounded number of times).
The proof is based on the fact that the composition of two polynomials is
polynomial.
The three basic cases are as follows:
(dB
dA=0
(dB
dB=1
(dB
dA. Indeed:
An example has already been presented in section B1: TSP reduces to TSPrec so TSP-rec is at least as hard as TSP.
A special case of polynomial reductions is of the following form:
The algorithm for A first constructs the input for the hypothetical subroutine
for B, then calls the latter exactly once, and finally returns the answer as its
own.
Reductions of this kind are called polynomial transformations (we then say
that problem A transforms in polynomial-time to problem B, and use the
notation A
B), and are especially useful because the polynomial
transformability relationship is transitive as it can easily be shown using
again the fact that the composition of two polynomials is a polynomial.
As an example, we will use the recognition version of the Integer
Programming Problem (IP) and show that SAT
IP-rec.
x1 + x2 + x3 1
x1 + (1-x2) 1
x2 + (1-x3) 1
x3 + (1-x1) 1
(1-x1) + (1-x2) + (1-x3)
calls once the algorithm for IP-rec and obtains a a "yes"or "no" answer,
IP-rec.
NP-complete problems
We say that a problem is NP-complete, if:
i. it belongs to class NP
ii. all the other problems in NP polynomially transform to it
all problems in NP
Hence, NP-complete problems are "the main targets" in the search for
algorithmic efficiency.
Now, to show that a "reasonable" problem (that is a problem in NP) is NPcomplete, it is sufficient to show that some other problem already known to
be NP-complete polynomially transforms to it, as the figure below suggests
(recall that polynomial transformability is transitive):
This would imply that all other problems in NP polynomially transform also to
A, therefore A is also NP-complete.
To start with, we still need to use the definition explicitly in order to find
some "first" NP-complete problem. This is discussed next.