Sie sind auf Seite 1von 18

CS 306 DAA, IIITDM Jabalpur

11/7/2012

NP-Complete Problems - I

The Story of Sissa and Moore


Lesson of Exponential Growth
Put one grain of rise in the first square of the chess board, two in the second, four in the third, eight in the forth, . And so on. 18,446,744,073,709,551,615 grains of rice

Exponential Growth
colonies of bacteria, cells in a fetus, transistor density in chips, the computer speed (Moores Law)

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Moores Law
Looks like providing a disincentive for developing polynomial algorithms ?
if an algorithm is exponential, why not wait it out until Moore's law makes it feasible NOT Really!!!

Claim:

Moores Law
Claim: a huge incentive for developing polynomial algorithms Why?
Boolean Satisfiability (SAT) complexity is O(2n) Sorting complexity is O(n logn)
Year 1975 1985 1995 2005 Variables (SAT) 25 31 38 45 Sorting 100 100 100 100

CS 306 DAA, IIITDM Jabalpur

11/7/2012

The Story of Sissa and Moore


The Morale of the Story:
Exponential algorithms make polynomially slow progress, while polynomial algorithms advance exponentially fast Exponential expansion is not sustainable!
Bacterial colonies run out of food Electronic chips hit the atomic scale Moore's law will stop doubling the speed of our computers within a decade or two

The progress will depend on algorithmic ingenuity, or some other new idea

Problem Solving
Shortest paths, MSTs, LCS, MCM, and many others
We know that we can solve them efficiently, though we are searching for a solution (path, tree, matching, etc.) from among an exponential population of possibilities

The quest for efficient algorithms


is about finding clever ways to bypass this process of exhaustive search, using clues from the input in order to dramatically narrow down the search space

CS 306 DAA, IIITDM Jabalpur

11/7/2012

So far So Good!
Algorithmic techniques that defeat the specter of exponentiality:
Greedy algorithms, Dynamic programming, Divide and conquer, Linear Programming

Now, the time has come to meet the quest's most embarrassing and persistent failures
For some other search problems, the fastest algorithms we know for them are all exponential

Difficult Problems
If a problem has an O(nk) time algorithm (where n being the input size and k is a constant), then we class it as having polynomial time complexity and as being efficiently solvable If there is no known polynomial time algorithm, then the problem is classed as intractable, or difficult, or Hard Problem.

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Euler vs. Rudrata Tours


The dividing line is not always obvious. Consider two apparently similar problems:
Euler's problem (often characterized as the Bridges of Knigsberg a popular 18th Century puzzle) Rudrata's (Hamiltonian) problem (after the great Irish mathematician who rediscovered it in the 19th century)

The Eulers Problem


The 18th century German city of Knigsberg was situated on the river Pregel The puzzle asks whether it is possible to take a tour through the park, crossing each bridge exactly once A
B D

CS 306 DAA, IIITDM Jabalpur

11/7/2012

The Eulers Problem


An exhaustive search requires starting at every possible point and traversing all the possible paths from that point - an O(n!) problem.

Eulerian Tour
Euler showed that an Eulerian Tour existed iff
1. it is possible to go from any vertex to any other by following the edges (the graph must be connected), and 2. every vertex must have an even number of edges connected to it, with at most two exceptions (which constitute the starting and ending points).

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Eulers Tour vs. Rudratas Tour


Thus we now have a O(n) problem to determine whether a path exists We can now easily see that the Bridges of Knigsberg does not have a solution A quick inspection shows that it does have a Hamiltonian path However there is no known efficient algorithm for determining whether a Rudratas tour exists.

The Rudratas Problem


Can one visit all the squares of the chessboard, without repeating any square, in one long walk that ends at the starting square and at each step makes a legal knight move? Also known as The Knight Tour Problem

CS 306 DAA, IIITDM Jabalpur

11/7/2012

The Rudratas Problem


The General Problem:
given a graph, find a cycle that visits each vertex exactly once or report that no such cycle exists Now known as Hamiltonian Cycle

Class P and NP
Euler's problem lies in the class P: problems solvable in Polynomial time Hamilton's problem is believed to lie in class NP (Non-deterministic Polynomial)

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Class P and NP
What is a Search Problem?
any proposed solution can be quickly checked for correctness (in Polynomial Time) A search problem is specified by an algorithm C that takes two inputs, an instance I and a proposed solution S, and runs in time polynomial in (I), i.e. We say S is a solution to I if and only if C (I, S) = true

All search problems are NP The class of all search problems that can be solved in polynomial time is denoted P

The Famous Problem: P NP ?


The Common Belief is that P NP
Otherwise, we need no Mathematician!!!

However, NO PROOF!

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Hard Problems and Easy Problems

NP Complete Problems
If P NP then we know that P is GOOD! What about the problems on the left side of the table?
all, in some sense, exactly the same problem we show that these problems are the hardest search problems in NP, so that if even one of them has a polynomial time algorithm, then every problem in NP has a polynomial time algorithm

10

CS 306 DAA, IIITDM Jabalpur

11/7/2012

NP-Complete Problems
There is a special class of problems in NP: the NP-complete problems. All the problems in NP are efficiently reducible to them. By efficiently, we mean in polynomial time, so the term polynomially reducible provides a more precise definition

Reduction

The Hardest Search Problems:


A search problem is NP-complete if all other search problems reduce to it

11

CS 306 DAA, IIITDM Jabalpur

11/7/2012

The Space of NP (Assuming P NP)

Reduction
A B (A is Polynomial Time Reducible to B)
Efficient Problems: If B is efficient then C is also efficient Hard Search Problems (NP Complete): If A is hard then B is also hard

So if A is NP-complete,
a new search problem B is also NP-complete, simply by reducing A to B This is how the set of NP-Complete problems has grown since then

12

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Satisfiability (SAT)
A Problem of great importance
chip testing computer design image analysis software engineering, and others

A canonical hard problem

Satisfiability
An Example
a collection of clauses, each consisting of the disjunction of several literals, a literal is either a Boolean variable (such as x) or the negation of one

The SAT Problem:


given a Boolean formula in conjunctive normal form, either find a satisfying truth assignment of the Boolean variables or else report that none exists.

13

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Satisfiability
Interestingly
1-SAT and 2-SAT are in P 3-SAT is NP-Complete A generalized SAT can be reduced to 3-SAT

Travelling Salesperson (TSP)


Another famous hard problem (NP-C) Nave complexity is O(Factorial (n-1)) A DP solution (still exponential) is follows

14

CS 306 DAA, IIITDM Jabalpur

11/7/2012

TSP
A DP Solution
Sub-Problems? let C (S, j) be the length of the shortest path visiting each node in S exactly once, starting at 1 and ending at j For |S| > 1, we define

Travelling Salesperson A DP Solution


The Algorithm

Time Complexity?

15

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Reductions Again
RUDRATA (s, t) PATH RUDRATA CYCLE ? RUDRATA CYCLE problem: given a graph, is there a cycle that passes through each vertex exactly once? RUDRATA (s, t)- PATH problem: given a graph with two vertices s and t, and we want a path starting at s and ending at t that goes through each vertex exactly once

RUDRATA PATH

RUDRATA CYCLE

16

CS 306 DAA, IIITDM Jabalpur

11/7/2012

RUDRATA PATH

RUDRATA CYCLE

We have to consider both the cases


When the instance of RUDRATA CYCLE has a solution When the instance of RUDRATA CYCLE does not have a solution

More on NP-Completeness
See the next lecture

17

CS 306 DAA, IIITDM Jabalpur

11/7/2012

Summary
Polynomial Time Complexity Problems which have solutions with time complexity O(nk) where k is a constant are said to have polynomial time complexity. Class P Set of problems which have solutions with polynomial time complexity. Non-deterministic Polynomial (NP) A problem which can be solved by a series of guessing (non-deterministic) steps but whose solution can be verified as correct in polynomial time is said to lie in class NP. Eulerian Path Path which traverses each arc of a graph exactly once A P-time problem Hamiltonian Path Path which passes through each node of a graph exactly once An NP-Complete problem NP-Complete Problems Set of problems which are all related to each other in the sense that if any one of them can be shown to be in class P, all the others are also in class P.

References
Chapter 8, Algorithms by S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani

18

Das könnte Ihnen auch gefallen