Tải bản đầy đủ (.pdf) (25 trang)

Slide phân tích và thiết kế giải thuật chap7completeness problems

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (147.49 KB, 25 trang )

.c
om

Chapter 7
NP-Completeness Problems

th

2. NP-Completeness

an

co

ng

1. Deterministic and Nondeterministic PolynomialTime Algorithms

du
o

ng

3. Cook’s Theorem

u

4. Some NP-Complete Problems

cu


5. Some Approaches to cope with NP-Complete
Problems

1

CuuDuongThanCong.com

/>

.c
om

Whether or not an efficient algorithm might
exist
For many problems we have several efficient
algorithms to solve.



However, many problems arise in practice which do
not have such efficient solving algorithms.



For a large class of problems we can’t even tell
whether or not an efficient algorithm might exist.

cu

u


du
o

ng

th

an

co

ng



2

CuuDuongThanCong.com

/>

Easy and hard problems
A great deal of research has been done in this area and lend
to the development of mechanisms by which new problems
can be classified as being as difficult as old problems.
• Sometimes, the line between “easy” and “hard” problems is
only simple.
Example:
„ Easy: Is there a path from x to y with weight ≤ M?

„ Hard: Is there a path from x to y with weight ≥M?
Problem 1 - BFS – in linear time
Problem 2 – in exponential time

cu

u

du
o

ng

th

an

co

ng

.c
om



3

CuuDuongThanCong.com


/>

.c
om

1. Deterministic and Nondeterministic
Polynomial-Time Algorithms

co

ng

P: The set of all problems that can be solved by deterministic
algorithms in polynomial time.

cu

u

du
o

ng

th

an

Deterministic: at any time, whatever the algorithm is
doing, there is only one thing that it could do next.

Example: Sorting by insertion belongs to P since its time is
proportional to N2 .

4

CuuDuongThanCong.com

/>

Nondeterminism

cu

u

du
o

ng

th

an

co

ng

.c
om


One way to extend the power of a computer is to endow it
with the power of non-determinism.
Non-determinism: when an algorithm is faced with a
choice of several options, it has the power to “guess” the
right one.
Nondeterministic algorithm
Example: Let A be an unsorted set of positive integers. An
nondeterministic algorithm NSORT(A, n) sorts the
numbers into ascending order and then outputs them in
that order.

5

CuuDuongThanCong.com

/>

ng

Function choice(1:n) can
choose one of the correct
position in the range from 1
to n.

cu

u

du

o

ng

th

an

co

// An array B is used as temporary array.
procedure NSORT(A,n)
// sort n positive integers //
begin
for i:= 1 to n do B[i]:= 0;
// guessing stage
for i:= 1 to n do
begin
j := choice(1:n);
if B[j] <> 0 then failure
else B[j]:= A[i]
end
// verification stage
for i:= 1 to n-1 do
if B[i] > B[i+1] then failure;
print(B);
success
end;

.c

om

An example of nondeterministic algorithm

6

CuuDuongThanCong.com

/>

An example of nondeterministic algorithm (cont.)

cu

u

du
o

ng

th

an

co

ng

.c

om

A deterministic interpretation of a nondeterministic
algorithm can be made by allowing unbounded parallelism
in computation.
Each time a choice to be made, the algorithm makes
several copies of itself. One copy is made for each of the
possible choice. Thus, many copies are executing at the
same time.
- The first copy to reach a successful completion
terminates all other computation.
- If a copy reaches a failure completion then only that
copy of the algorithm terminates.

7

CuuDuongThanCong.com

/>

.c
om

Nondeterministic algorithm

cu

u

du

o

ng

th

an

co

ng

In fact, a nondeterministic machine does not make any copies
of an algorithm every time a choice to be made.
Instead, it has the ability to select the “correct” element from
a set of allowable choices every time a choice is to be made.
A “correct” element is defined relative to a shortest sequence
of choices that leads to a successful termination.
In case there is no sequence of choices leading to a successful
termination, we shall assume that the algorithm terminates
in one unit of time with output “unsuccessful
computation”.

8

CuuDuongThanCong.com

/>

Nondeterministic algorithm (cont.)


an

co

ng

.c
om

Note:
‰ The success and failure signals are equivalent to a stop
statement in a deterministic algorithm.
‰ The complexity of NSORT is O(n).

cu

u

du
o

ng

th

NP: the set of all problems that can be solved by
nondeterministic algorithms in polynomial time.
Example : “Is there a longest path from vertex x to
vertex y in a graph” is an NP problem.


9

CuuDuongThanCong.com

/>

.c
om

Circuit satisfiability problem

ng

th

an

co

ng

Given a logical formula of the form
(x1 + x3 + x5)*(x1+ ~x2 + x4)*(~x3 + x4 +x5)*
(x2 + ~x3 + x5)
where the xi ‘s represent Boolean variable (true or false),
“+” represents OR, “*” represents AND, and ~ represents
NOT.

cu


u

du
o

The CSP problem is to determine whether or not there
exists an assigment of truth values to the variables that
makes the formula true.
CSP is an NP problem.
Note: P is a subset of NP.
10

CuuDuongThanCong.com

/>

ng
co

cu

u

du
o

ng

th


an

procedure EVAL(E, n)
boolean x[n];
begin
for i:= 1 to n do
x[i] := choice(true, false)
endfor;
if (E is true) then success
else failure
end EVAL;

.c
om

Nondeterministic algorithm for CSP problem

11

CuuDuongThanCong.com

/>

.c
om

2. NP-Completeness

th


an

co

ng

There is a list of problems that are known to belong to NP
but might or might not belong to P. (That is, they are easy
to solve on a non-deterministic machine but, no one has
been able to find an efficient algorithm on a conventional
machine for any of them).

cu

u

du
o

ng

These problems has an additional property:
“If any of these problems can be solved in polynomial
time on a deterministic machine, then so can all problems
in NP.”

12

CuuDuongThanCong.com


/>

.c
om

Such problems are said to be NP-complete.

an

co

ng

Figure 6.1

th

NP-complete

P

cu

u

du
o

ng


NP

13

CuuDuongThanCong.com

/>

th

ng

du
o

u

cu



an

co



NP-complete problems form a subset of the most difficult
problems in NP.

The primary tool used to prove that problems are NPcomplete uses the idea of polynomial reducibility.
Any algorithm to solve a new problem in NP can be used to
solve some known NP-complete problem by the following
process.
transform any instance of the known NP-complete problem
to an instance of the new problem, solve the problem using
the given algorithm, then transform the solution back to a
solution of the NP-complete problem.

ng



.c
om

Polynomial reducibility

14

CuuDuongThanCong.com

/>

Polynomial reducibility (cont.)

co

ng


.c
om

To prove that a problem in NP is NP-complete, we need
only show that some known NP-complete problem is
polynomial reducible to it.

du
o

ng

th

an

Definition: Let L1 and L2 be problems. L1 reduces to L2,
(also written L1 α L2) if and only if there is a way to
transform L1 to L2 such that any deterministic algorithm
that solves L2 in polynomial time can be used to solve L1.

cu

u

The transformation must be done in polynomial time.

15

CuuDuongThanCong.com


/>

Polynomial reducibility (cont.)

an

co

ng

.c
om

To prove that a problem L is NP-complete, we need to prove
that:
1. L belongs to NP
2. Some known NP-complete problem is polynomially
reducible to L.

cu

u

du
o

ng

th


Example: Given two following problems
„ Traveling Salesman Problem: Given a set of cities and
distances between a pairs, find a tour of all the cities of
distance less than M.
„ Hamilton Cycle Problem: Given a graph, find a simple
cycle that includes all the vertices.
16

CuuDuongThanCong.com

/>

Polynomial reducibility (cont.)

th

an

co

ng

.c
om

Suppose we know the HCP is NP-complete and wish to
determine whether or not the TSP is also NP-complete.
Any algorithm for solving the TSP can be used to solve the
HCP, through the following reduction:

Given a instance of of the HCP (a graph), construct an
instance of the TSP as follows:

ng

• for cities for the TSP, use the set of vertices in the graph;

cu

u

du
o

• for distances between each pair of cities, uses 1 if there is
an edge between the corresponding vertices in the graph, 2
if there is no edge.
Then use the algorithm for the TSP to find a tour of
distance ≤ N (N the number of vertices in the graph). The
tour corresponds precisely to the Hamilton cycle .
17

CuuDuongThanCong.com

/>

Polynomial reducibility (cont.)

.c
om


That is HCP reduces to TSP, so the NP-completeness of
HCP implies the NP-completeness of TSP.

an

co

ng

The reduction of HCP to TSP is relative simple because the
problems are so similar.

du
o

ng

th

Actually, polynomial reductions can be quite complicated
and can connect problems which seem to be quite
dissimilar.

cu

u

Example: It is possible to reduce the satisfiability problem
to HCP. How?


18

CuuDuongThanCong.com

/>

3. Cook’s Theorem

th

an

co

ng

.c
om

But: How was the first problem proven to be NP-complete?
S.A. Cook (1971) gave a direct proof that CSP (Circurt
Satisfiability Problem) is NP-complete.
“If there is a polynomial time algorithm for satisfiability
problem, then all problems in NP can be solved in
polynomial time”

cu

u


du
o

ng

The proof is extremely complicated but it is based on a
general purpose computer known as a Turing machine.

19

CuuDuongThanCong.com

/>

4. Some NP-Complete Problems

co

ng

.c
om

Thousands of diverse problems are known to be NPcomplete. Of course, the list begins with satisfiability
problem and includes TSP and Hamilton-cycle problem, as
well as longest-path.

th


an

The following additional problems are representative:

du
o

ng

- Partition: Given a set of integers, can they be divided
into two sets whose sums are equal?

cu

u

- Integer linear programming: Given a linear problem, is
there a solution in integers?

20

CuuDuongThanCong.com

/>

cu

u

du

o

ng

th

an

co

ng

.c
om

- Multiprocessor scheduling: Given a deadline and a set of
tasks of varying length to be performed on two identical
processors, can the tasks be arranged so that the
deadline is met?
- VERTEX COVER: Given a graph and an integer N, is
there a set of fewer than N vertices which touched all the
edges?
- BIN PACKING: We are given n objects which have to
be placed in bins of equal capacity L. Object i requires li
units of bin capacity. The objective is to determine the
minimum number of bins needed to accommodate all n
objects.

21


CuuDuongThanCong.com

/>

P ≠ NP ?

ng

.c
om

These and many related problems have important natural
practical applications.

th

an

co

The fact that no good algorithm has been found for any of
these problems is surely strong evident that P ≠ NP?

cu

u

du
o


ng

Whether or not P= NP, the practical fact is that we have at
present no algorithms guaranteed to solve any of the NPcomplete problems efficiently.

22

CuuDuongThanCong.com

/>

.c
om

5. Some Approaches to cope with NP-Complete
Problems

ng

1. Use approximation algorithm that finds not the best
solution but a near-optimal solution.

th

an

co

2. Based on “average-time” performance, develop an
algorithm that finds the solution in some cases, but does

not necessarily work in all cases.

du
o

ng

3. Use with “efficient” exponential algorithms, for example,
backtracking algorithm.

cu

u

4. Invent heuristics and add it to the algorithm to improve
the performance of the algorithm.
5. Apply metaheuristics.

23

CuuDuongThanCong.com

/>

Heuristic and meta heuristic

cu

u


du
o

ng

th

an

co

ng

.c
om

ƒ Heuristics is knowledge in a specific problem that can be
used to guide the search process in finding a solution of an
algorithm. Thank to this heuristics, the algorithm becomes
more efficient.
ƒ Metaheuristics is a kind of more general heuristics which
can be used for solving several kinds of problems.
ƒ Recently, meta heuristics is an active research field with
the introduction of many popular metaheuristics, such as:
- genetic algorithm
- simulated annealing
- Tabu search
- ACO
- etc.
24


CuuDuongThanCong.com

/>

Contribution of the theory of NP-completeness

cu

u

du
o

ng

th

an

co

ng

.c
om

There are several NP-complete problems in the following
fields:
‰ numerical analysis,

‰ sorting and searching,
‰ string processing,
‰ geometry modeling
‰ graph processing
‰ image processing
‰ data mining
The most important practical contribution of the theory of
NP-completeness is that: it provides a mechanism to discover
a new problem from any of these diverse areas is “easy” or
“hard””.
25

CuuDuongThanCong.com

/>

×