computational complexity - intranet...

16
Computational Complexity Wednesday, January 14, 2015

Upload: lamkhanh

Post on 28-May-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Computational Complexity

Wednesday, January 14, 2015

Page 2: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Algorithm performance and difficulty of problemsSo far we have seen problems admitting fast algorithms

flow problems, shortest path, spanning tree... and other problems for which we could not do better than solving with less efficient algorithms

knapsack, TSP, integer programming...

Can we classify problems depending on that?

Wednesday, January 14, 2015

Page 3: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Easy and difficult problemsBorder between easy and difficult problems: existence of a polynomial time algorithm in the input sizeThe existence of a polynomial time algorithm is easy to certify (the algorithm itself is the certificate)The non existence of a polynomial time algorithm cannot be certified

Computational complexity theory[Garey and Johnson 1979]

Wednesday, January 14, 2015

Page 4: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

A few definitionsProblem: question expressed in abstract terms whose answer depends on a set of input parametersInstance of a problem: specification of the input parametersAlgorithm for problem P: finite set of instructions that, if applied to any instance of P, provides in a finite number of steps a solution to the input instance or indicate that no solution exists

Wednesday, January 14, 2015

Page 5: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Computational modelsSimple models with infinite memory that can simulate any (sequential) real computer

Turing machineRandom Access MachinePointer machine...

Wednesday, January 14, 2015

Page 6: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Complexity measure of one algorithm

Number of elemental operations performed by the algorithm

worst caseexpress the number of operations in function of the input sizegive the asymptotic measure (neglect the constants and the lower order term)

O(f(n)) notation

Wednesday, January 14, 2015

Page 7: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Why polynomial algorithms are better

10 30 60n 0.00001s 0.00003s 0.00006sn2 0.0001s 0.0009s 0.0036sn5 0.1s 24.3s 13m2n 0.001s 17.9m 36600y3n 0.059s 6.5y 1.3x1015y

Computer performing 1M operations per second

Size of the input

Computing timeWednesday, January 14, 2015

Page 8: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Why polynomial algorithms are better

present computer

100 times faster

1000 times faster

n N1 100 N1 1000 N1n2 N2 10 N2 31.6 N2

n5 N3 2.5 N3 3.98 N3

2n N4 N4 + 6 N4 + 9

3n N5 N5 + 4 N5 + 6

size of the largest solvable instance in 1 hWednesday, January 14, 2015

Page 9: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Pseudopolynomial algorithmsExample: algorithm that solves the knapsack reducing the problem to a shortest (longest) path on an acyclic graphO(nb) complexityPolynomial in the input but not in the input size(unless unary encoding is considered)

Wednesday, January 14, 2015

Page 10: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Classification of the problemsProblems in decision form: the expected answer is yes or noExamples

connectivity problemscheduling problemSAT

How to deal with optimization problems?Decision version of the problem: fix an additional parameter k. Does there exist a solution with value ≤ k? (for min problems)

If we are able to solve the decision version of the problem we can solve efficiently also the optimization version by binary

search over kWednesday, January 14, 2015

Page 11: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Class NPA problem P belongs to the class NP if

it is in decision formit is certifiable in polynomial time

Given an instance of problem P and one possible solution x

There is a polynomial time algorithm that checks that solution x gives a YES answer to the given instance

Wednesday, January 14, 2015

Page 12: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Class P

A problem P belongs to the class P ifit belongs to NP

there is a polynomial time algorithm thatsolves any instance of P

P ⊆ NP

Wednesday, January 14, 2015

Page 13: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Polynomial reductionLet P and Q ∈ NP

P reduces in polynomial time to Q

P ∝ Q

Supposing that there exist a polynomial time (including constant) algorithm AQ solving Q then we can devise one

algorithm AP that calls AQ a polynomial number of times and solves P

Given an instance of P we can transform it in polynomial time into an instance of Q. The solution of Q can be transformed

into a solution of P in polynomial timeWednesday, January 14, 2015

Page 14: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Consequences of polynomial reductionsP ∝ Q

if there is a polynomial algorithm for Q⇒P ∈ P

if we can prove that P has no polynomial algorithm (hard to say)⇒Q ∉ P

∝ is reflexive and transitive

Wednesday, January 14, 2015

Page 15: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

Class NP-completeQ ∈NP-complete if

Q ∈NP

for each problem P ∈NP

P ∝ Q

This implies that if Q could be solved in polynomial timethen any problem could be solved in polynomial time

thus P = NP

Wednesday, January 14, 2015

Page 16: Computational Complexity - Intranet DEIBhome.deib.polimi.it/malucell/didattica/appunti/complexity.pdf · Complexity measure of one algorithm ... How to deal with optimization problems?

How can we prove that a problem is NP-complete?Making the reductions from all NP problems

(even those which have not been conceived yet)seems impractical

Exploit the transitivity of ∝ make the reduction from a known NP-complete problem

SAT is NP-complete [Cook-Levin 1971]

Wednesday, January 14, 2015