computability and complexity
DESCRIPTION
Computability and Complexity. 12-1. The Class P. Computability and Complexity Andrei Bulatov. Computability and Complexity. 12-2. The Class of “Easy” Problems. Requirements to such a class:. Practical Must capture the idea of tractable problems Theoretical - PowerPoint PPT PresentationTRANSCRIPT
Computability and Complexity 12-1
Computability and ComplexityAndrei Bulatov
The Class P
Computability and Complexity 12-2
The Class of “Easy” Problems
Requirements to such a class:
• Practical
Must capture the idea of tractable problems
• Theoretical
Must be robust, that is independent of the model of computation
Computability and Complexity 12-3
Timecomp-lexity
Size n
10 20 30 40 50 60
n.00001
seconds.00002
seconds.00003
seconds.00004
seconds.00005
seconds.00006
seconds
.0001
seconds.0004
seconds.0009
seconds.0016
seconds.0025
seconds.0036
seconds
.001
seconds.008
seconds.027
seconds.064
seconds.125
seconds.216
seconds
.1
seconds3.2
seconds24.3
seconds1.7
minutes5.2
minutes13.0
minutes
.001
seconds1.0
seconds17.9
minutes12.7
days35.7
years366
centuries
.059
seconds58
minutes6.5
years3855
centuries centuries centuries
2n
3n
5n
n2
n38102 13103.1
Computability and Complexity 12-4
Different Models of Computation
Lemma 1. We can simulate t steps of a k-tape TM with an equivalent one-tape TM in steps.)( 2tO
Lemma 2. We can simulate t steps of a RAM computation with a 3-tape TM in steps.)( 3tO
It seems that improving our machines we can obtain any polynomial speed-up!
Computability and Complexity 12-5
Different Encodings
Lemma 3. For any number n, the length of the encoding of n in base and the length of the encoding of n in base are related by a constant factor (provided )
1b
2b1, 21 bb
Lemma 4. For any graph G, the length of the encoding of G as an adjacency matrix, and the length of the encoding of G as a list of edges, are both related by a polynomial factor to the number of vertices
It seems that improving encodings we can shorten the input by a polynomial factor!
Definition Definition
0
]TIME[
k
knP
Computability and Complexity 12-6
The Class P
• The class P contains all classes TIME[t(n)], where t(n) is a polynomial of finite degree
Note:
Computability and Complexity 12-7
Robustness of P
The class P is the same for all existing models of computation(except for quantum computation)
The class P is the same for all existing methods of encoding
The class P is said to be robust — it is a mathematical objectthat does not depend on the exact details of the computationalmodel or encoding
In fact, P can be define in ways that do not refer to machines at all(but we will not pursue that idea here)
Computability and Complexity 12-8
P doable?
The class P is a reasonable mathematical model of the class ofproblems which are tractable or “solvable in practice”
However, the correspondence is not exact:
• When the degree of the polynomial is high then the time grows so fast that in practice the problem is not solvable
• The constants may also be very large
(These problems usually seem to arise only in artificially created problems; for naturally defined problems the polynomials and constantsare not too large)
• Some algorithms, exponential in principal, works satisfactory in practice (e.g. Simplex method for Linear Programming)
Computability and Complexity 12-9
Proving a Problem is in P
• The most direct way to show that a problem is in P is to give a a polynomial time algorithm that solves it
• Even a naive polynomial time algorithm often provides a good insight into how the problem can be solved efficiently
To find such an algorithm we generally need to identify an approach to the problem that is considerably better than “brute-force” search
• Because of robustness, we do not generally need to specify all the details of the machine model or even the encoding (e.g. pseudo-code is sufficient)
Computability and Complexity 12-10
A Problem in P
Instance: 3 integers, a, b and g.
Question: Does GCD(a,b)=g?
Greatest Common Divisor (GCD)
(When g=1 this is equivalent to the problem Relatively Prime)
Computability and Complexity 12-11
Proof: GCD(a,b) can be computed by Euclid’s algorithm
Function GCD(a,b) : integer
Begin
if b=0 then
GCD(a,b):= a
else
GCD := GCD(b,a mod b)
end
This algorithm polynomial in the length of the input numbers(logarithmic in their value)
Computability and Complexity 12-12
The Satisfiability Problem
Instance: A conjunctive normal form .
Question: Is satisfiable?
Satisfiability
Instance: A conjunctive normal form every clause of which contains exactly k literals.
Question: Is satisfiable?
k-Satisfiability
Computability and Complexity 12-13
Resolution
Axioms: a set of clauses
Proof rules:
• resolution C X C, D X D
C, D C D
(C D is called the resolvent of C and D) R
Theorem A 2-Satisfiability instance, , is unsatisfiable if and only if
Theorem A 2-Satisfiability instance, , is unsatisfiable if and only if R
Computability and Complexity 12-14
Example:
YXZXZYZXYX , , , ,(1) (2) (3) (4) (5)
,ZX
Proof:
,ZY ,YX ,YX ,ZX
,XXX ,YX ,XXX ,ZX
This algorithm works in , because the number of all possible 2-clausesis related by a quadratic factor to the number of variables
)( 2nO
Computability and Complexity 12-15
A Better Algorithm for 2-Satisfiability
1. Declare all clauses unsatisfied and literals unassigned2. Select an arbitrary unassigned variable X and assign X true,
X false3. Select an unsatisfied clause
4. Repeat step 3, until either
a) if neither literal is assigned, ignore;b) if either literal is assigned true, declare clause satisfied;c) if both are false, restart the algorithm setting X false,
and X true. If a conflict occurs again, declare unsatisfiable
d) if one literal false, other unsatisfied, set the other to true, its negation to false, and declare the clause satisfied
a) all clauses are satisfied, return satisfiableb) All clauses remaining unsatisfied have no variables assigned.
In this case return to step 2
Computability and Complexity 12-16
Polynomial-time reducibility
Another way to prove that a problem is in P is to use a reduction
Definition A language A is polynomially reducible to a language B , denoted A B, if a polynomial-time computable function f exists such that for all *x
BA )(xfx
This fundamental tool of complexity theory was introduced by Karp in 1972
Computability and Complexity 12-17
Key Property of Polynomial-time Reducibility
Lemma
A B and B P implies A P
Proof:
The composition of polynomials is a polynomial
Computability and Complexity 12-18
Reductions in P
Almost all members of P can be reduced to each other
Theorem If B is any language in P, B , B *, then for any A P, A B
Theorem If B is any language in P, B , B *, then for any A P, A B
Proof: Choose w B and some w B.
Define the function f by setting
A
A
xw
xwxf
if'
if)(
Since A P, f is computable in polynomial-time, and is a reductionfrom A to B
Computability and Complexity 12-19
Colourability
• Let G (V,E) be a graph, with nodes V and edges E
• A function f : V {1,…,n} is a (proper) colouring if connected nodes are assigned different values ( colours)
Instance: A graph G.
Question: Is there a colouring of G using at most k colours?
k-Colourability
(When k = 2 this is equivalent to Bipartite)
Computability and Complexity 12-20
2-Colourability 2-Satisfiability
We can reduce 2-COLOURABILITY to 2-SATISFIABILITY• For each vertex the graph we create a variable
• For each edge we add two clauses
iv iX
),( ji vv
)()( jiji XXXX and
This translation of a 2-COLOURABILITY problem to a 2-SATISFIABILITYproblem is computable in polynomial time. Now we check it satisfies the reducibility condition:
• If graph is 2-colourable, use 2-colouring to assign truth values to variables (one colour is true, the other false)
• If formula satisfiable, define 2-colouring by setting true variables to colour 1 and false to colour 2, if adjacent vertices get same colour one of the associated clauses is not satisfied, hence must have 2-colouring
Computability and Complexity 12-21
An Aside
Some problems have been shown to be in P by non-constructivearguments (i.e. by proving a polynomial time algorithm must exist).
E.g. the problem Knotlessness — can a given graph be embedded in 3-dimensional space without knots
In these cases we may not even know how to find an exponentialalgorithm!
(See Bovet and Cresceni for more discussion of this)