Sie sind auf Seite 1von 16

Computational

Complexity
Algorithm performance and difficulty of problems
So 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?


Why polynomial algorithms are better
Computer performing 1M operations per second

Size of the input


10 30 60
n 0.00001s 0.00003s 0.00006s
n2 0.0001s 0.0009s 0.0036s
n5 0.1s 24.3s 13m
2n 0.001s 17.9m 36600y
3 n 0.059s 6.5y 1.3x10 y
15

Computing time
Why polynomial algorithms are better

present 100 times 1000 times


computer faster faster
n N1 100 N1 1000 N1
n2 N2 10 N2 31.6 N2
n 5 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 h


Easy and difficult problems
Border bet ween easy and difficult problems:
existence of a polynomial time algorithm in the
input size
The existence of a polynomial time algorithm is
easy to certify (the algorithm itself is the
certificate)
How can we certify the non existence of a
polynomial time algorithm?

Computational complexity theory


[Garey and Johnson 1979]
A few definitions
Problem: question expressed in abstract terms
whose answer depends on a set of input
parameters
Instance of a problem: specification of the input
parameters
Algorithm 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
What is a step?
Computational models
Simple models with infinite memory that can
simulate any (sequential) real computer
Turing machine
Random Access Machine
Pointer machine...
Complexity measure of one algorithm
Number of elemental operations performed by
the algorithm
worst case
express the number of operations in function
of the input size
give the asymptotic measure (neglect the
constants and the lower order term)

O(f(n)) notation
Pseudopolynomial algorithms
Example: algorithm that solves the knapsack reducing
the problem to a shortest (longest) path on an acyclic
graph
O(nb) complexity
Polynomial in the input but not in the input size

(unless unary encoding is considered)
Classification of the problems
Problems in decision form: the expected answer is yes or no

Examples
connectivity problem
scheduling problem
SAT
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 k
Class NP
A problem P belongs to the class NP if
it is in decision form
it 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
Class P

A problem P belongs to the class P if


it belongs to NP
there is a polynomial time algorithm that

solves any instance of P

P ⊆ NP
Polynomial reduction
Let 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 time
Consequences of polynomial reductions
P ∝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


Class NP-complete
Q ∈NP-complete if

Q ∈NP

for each problem P ∈NP



P ∝Q
This implies that if Q could be solved in polynomial time
then any problem could be solved in polynomial time

thus P = NP
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]

Das könnte Ihnen auch gefallen