NP Completeness Prof. Dr. Debora Weber-Wulff Winter term 2006/07
Inefficiency and Intractability • From the book: Algorithmics, the Spirit of Computing, David Harel. Addison-Wesley, 1992
Complexity Paradox? • Complicated algorithms often have a lower complexity than the simple, obvious solutions • But we have fast computers, so who cares, anyway?
Unfortunately,.... • There exist problems that cannot be solved in even quadratic time. • There are problems for which a solution just does not exist. • There are problems that also need exponential space!
Towers of Hanoi • What was the complexity? 2 N -1
Towers of Hanoi • Even moving a million rings a second, for 64 rings you need half a million years to complete the puzzle. • If you need 10 sec / ring, you need five trillion years! • This is provably the lower bound.
Decision problems • Don't do anything but answer "yes" or "no" • Purpose is to decide if a property holds for the input
The Monkey Puzzle • Can 9 of these be laid in a 3x3?
General Problem • Given N cards, N= M*M, each edge decorated with an upper or lower half of a figure. • Can the cards be laid out in an M*M pattern so that the figures of adjoining cards match?
Brute Force • For all possible cards and all possible orientations of the cards, lay them out in M*M • Return "yes" if this is a valid layout, otherwise continue • When all cases have been tested, return "no".
Complexity? • Disregarding the orientation: O(N!) • With the orientation: O(4*N!) which is still O (N!) • O(9) = 362 800, O(4*9) = 1 451 520
That's not so bad • But what about N=25? • 25! is a number with 26 digits, if you could test a million arrangements a second, you would need over 490 billion years to check it!
Isn't there a clever solution? • You can stop as soon as you find that the pattern is illegal • This does not really change the complexity. • There is no known way to solve this problem in Polynomial time
Reasonable vs. Unreasonable Time • Factorial grows faster than exponential, even though N 1000 is still greater than N! for many values of N. • For example at N=1165, the factorial oversteps the exponential function.
Good vs. Bad functions • Good functions run in Polynomial time: N k + c 1 *N k-1 + .... + c k-1 • We say they have an upper bound of N k • Everything else is superpolynomial
Superpolynomial • logarithmic, linear, quadratic, cubic – all are polynomial • 1.001 N + N 6 , 5 N , N N , N! are exponential or worse • N log N are superpolynomial but not 2 exponential
Growth rates
Tractable • Problems that are solvable in polynomial time are called tractable • Problems that are solvable in superpolynomial time are called intractable
Intractable Problems • Need impractically large amounts of time even on relatively small inputs • And there are lots of them.... close to 1000 different problems.
Proof? • Even worse, we have not been able to prove that no polynomial solution exists! • We just don't know! • This class of problems is called NPC, NP-complete problems, and it is growing
NP-Complete • Strangely enough, have a linear lower bound, but an exponential upper bound.
NP-Complete problems • Two-dimensional Arrangment • Path-finding (TSP) • Scheduling and Matching • Determining Logical Truth • Coloring Maps and Graphs
Short Certificates • Even though they are difficult to find, once we have a solution "yes", we can easily prove that it solves the problem. • We call this the short certificate or magic coin
Short Certificates • are often linear • For example, it is hard to find a Hamiltonian path, but easy to test that it is indeed one.
Magic Coin • We begin with a partial solution and extend it. • If we could flip a magic coin to determine whether the next step leads to a yes or no, we could win • This is called non-determinism
NPC • Non-deterministic Polynomial are those problems which are intractable, but have a non- deterministic polynomial certificate • C stands for Complete
Completeness • NPC problems are those which can be solved if we find a polynomial solution for even one!! • Either all NPC problems are tractable, or they are all intractable, but we just don't know!
Polynomial-time Reduction • It is possible in Polynomial time to reduce one NPC-Problem to another one. • TSP can be formulated as Hamiltonian Path.
P = NP? • This is one of the big research questions! • Open since it was posed in 1971
Testing for Primeness • Is a number not prime? • If the answer is yes, we deliver a short certificate, the two factors, which can be readily multiplied • So this is NP, but we do not know if it is NP complete, or even P!
Testing for Primeness • Is this number prime? • No short certificate, so not obvious, that it is in NP (but this has since been proven) • But we do not know if this is NP- complete or not!!!
Intractable and not NPC • Towers of Hanoi • Roadblock • Satisfiablity – reasoning about propositional calculus
Can it get worse? • Of course – double or triple exponential! • Satisfiability in Presburger Arithmetic
Complexity Classes
Imperfect Solutions • Sometimes we are happy with a solution that is not optimal – an approximation • Often heuristic (rule of thumb) methods yield good results, for example with TSP.
No amount of cleverness can help when your problem is NP!
Recommend
More recommend