• No results found

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

N/A
N/A
Protected

Academic year: 2022

Share "Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li"

Copied!
9
0
0

Loading.... (view fulltext now)

Full text

(1)

CISC 4080 Yanjun Li

Computer Algorithms

NP-Complete Problems

• The quest for efficient algorithms is about finding clever ways to bypass the process of exhaustive search, using clues from the input in order to dramatically narrow down the search space.

• NP-completeness is a form of bad news.

– Evidence that many important problems can't be solved quickly.

NP-completeness

(2)

Computational Complexity Theory

• This subject is dedicated to classifying problems by how hard they are.

• Yes-or-no problems

– We care more about “Does a certain structure exist” rather than “how do I find the structure”.

• We will discuss the classification defined in terms of yes-or-no problems.

CISC 4080 Yanjun Li

• P : Problems that can be solved in polynomial time.

– T(n) = O(nc)

– Example: sorting, minimum spanning tree

• E : Problems that can be solved in exponential time if no polynomial-time algorithm can be developed for it.

– T(n) = O(nu(n))

Classification of Problems

(3)

CISC 4080 Yanjun Li

• NP : Nondeterministic polynomial time.

– Nondeterministic is guessing a solution.

– A problem is in NP if you can quickly (in polynomial time) test whether a solution is correct (without worrying about how hard it might be to find the solution).

– Problems in NP are still relatively easy: if only we could guess the right solution, we could then quickly test it.

Classification of Problems

• Undecidable: For some problems, we can prove that there is no algorithm that

always solves them, no matter how much time is allowed.

– There are as many problems as there are real numbers, and only as many programs as there are integers, so there are not enough programs to solve all the problems.

Classification of Problems

(4)

Long Simple Paths

• A simple path in a graph is just one without any repeated edges or vertices.

• Problem of finding long simple path:

– Given a graph G, vertices s and t, and a number k, does there exist a simple path from s to t with at least k edges?

• We do not know whether it is in P. So far, no algorithm running in polynomial time that solves this problem.

• It is in NP: Testing whether the answer is correct could be done in linear time.

CISC 4080 Yanjun Li

Examination Scheduling

• A school has n courses and m days in which to schedule examinations.

• An optimal schedule would be one where no student has to take two examinations on the same day.

• There are O(mn) possible different schedules.

• It is in NP: it is difficult to find a good one, it is easy to check a schedule to see how near

(5)

CISC 4080 Yanjun Li

• Given n items, each with a weight and a value, is there a collection of items with total weight less than W, which has a total value greater than g?

• A dynamic programming scheme for KNAPSACK with running time O(nW), which is exponential in the input size since it involves W rather than logW.

• And we have the usual exhaustive algorithm as well, which looks at all subsets of items - all 2nof them.

• It is in NP : it is easy to test whether a solution is correct.

Knapsack

Hamiltonian Cycle

• Does a given graph G have a cycle visiting each vertex exactly once?

• It is in NP :

– Perform an exhaustive search for all possible path ( not polynomial time)

– Test whether one path is a Hamiltonian cycle (in polynomial time)

(6)

CISC 4080 Yanjun Li

Traveling Salesman Problem

• In the traveling salesman problem (TSP) we are given n vertices and all n(n-1)/2 distances (cost) between them, as well as a budget b. We are asked to find a tour, a cycle that passes through n vertex exactly once, of total cost is b or less.

• It is in NP : In fact, n factorial different tours are possible. And, if we have a tour, we can easily check to see the cost of it.

Problems of complexity theory

• The most famous open problem in theoretical science is whether P = NP.

In other words, if it's always easy to check a solution, should it also be easy to find the solution?

– It's false. But we also don't have a

(7)

CISC 4080 Yanjun Li

Reduction

• One problem is easier than another.

• A is easier than B (A < B)

– if we have an algorithm for solving A that uses a small number of calls to a subroutine for B.

– “Easier” means if one problem can be solved in polynomial time, so can the other. It is possible for the algorithms for A to be slower than those for B, even though A < B.

• If A < B, and B is in P, so is A.

Reduction Example

• Hamiltonian cycle vs. longest simple path

• Solution with longest simple path as subroutine

– This solution does O(m) work outside m calls to the subroutine.

• Hamiltonian cycle < longest simple path

for each edge (u,v) of G

if there is a simple path of length n-1 from u to v return yes //path + edge from a cycle

return no

(8)

CISC 4080 Yanjun Li

• A problem A in NP is NP-complete when, for every other problem B in NP, B < A.

• Theorem: an NP-complete problem exists.

– if A < B and B < C, then A < C.

– if A is NP-complete, B is in NP, and A < B, B is NP- complete.

• We start with one specific problem that we prove NP-complete, and we then prove that it's easier than lots of others which must therefore also be NP-complete.

• Hamiltonian cycle is known to be NP-complete.

NP-completeness

(9)

CISC 4080 Yanjun Li

• Use a heuristic : a solution to a reasonable fraction of the common cases.

• Solve the problem approximately instead of exactly.

• Use an exponential time solution anyway.

If you really have to solve the problem exactly.

What we should do ?

References

Related documents

This paper compares employment and earnings of British graduates from ethnic minorities to those of white British graduates to analyse whether ethnic labour market differences

Long-term cardiac follow-up in relapse- free patients after six courses of fluorouracil, epirubicin, and cyclophosphamide with either 50 or 100mg of epirubicin, as adjuvant therapy

This pattern indicates the odds (the percentage of fleet drivers driving on the north loop over the percentage of fleet drivers driving on the east loop) of the off-rush hour and

if any NP problem can be reduced to X in polynomial time • A problem is NP- complete if it is both: • In NP • and

Observation: If G is colored with k colors then each color class (nodes of same color) form an independent set in G...

Decision problem polynomial-time (Karp) reduces to decision problem if given any instance of , we can construct an instance of in polynomial time s.t if and only

Español proposes establishing a budget ($5,000) to send its members to CoDA various conferences in places such as Madrid, Puerto Rico or Venezuela, as part of the committee's

The proposed technique uses a fixed-size approach based on an approximation of the feature map (via the Nystr¨om method) to solve the pri- mal optimization problem characterizing