Applied Computer Science II Chapter 7: Time Complexity Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany
Overview Measuring complexity The class P The class NP NP-completeness Additional NP-complete problems
Measuring complexity How much time needed to decide a language Use Machine M1
Measuring complexity Worst-case versus average-case We typically use big-O and small-o notation (cf. ACS I); asymptotic analysis
Big-O
Small-o
Time Complexity
Analyzing algorithms
2-tape machine
Complexity relationship among models
Definition 7.9 including figure 7.1
Differences in models Polynomial difference between single- and multiple tape deterministic TM Exponential difference between deterministic and non-deterministic TM Compare exponential versus polynomial behaviour !
Towards the class P Distinction between : Exponential algorithms –Brute force search –Impractical Polynomial –Practical –Robust for reasonable models of computation (I.e. polynomially equivalent) Here, we ignore differences between, e.g., level of abstraction
P is invariant for all models of computation that are polynomially equivalent to a single tape deterministic TM P roughly corresponds to the class of problems that are realistically solvable on a computer
Conventions High-level descriptions of algorithms Abstraction of specific model used (as long as polynomially equivalent) Algorithms proceed in numbered stages Analysis in two steps : –A polynomial bound on the number of stages –Each stage can be implemented in polynomial time on deterministic single tape TM (or poly. Equivalent model)
Conventions Encoding method for problems We use notation as before Reasonable methods require encoding and decoding of objects into other (internal ?) representation to require polynomial time. E.g (unreasonable) instead of 9 (or other base k-notation)
Encoding Graphs Option 1 : –List of nodes –List of edges Option 2 : –Adjacency matrix
Figure 7.2
Insert algorithm
Towards the class NP
HAMPATH Easy to obtain exponential time algorithm : –Generate all paths of length m (no. of nodes) and check whether they are hamiltonian Polynomial verifiability : –Checking whether a given path is hamiltonian can be done in polynomial time Verifying existence of hamiltonian path is easier than determining the existence Consider also Similar for COMPOSITES
The class NP
NTM for HAMPATH Algorithm
Proof
P versus NP
P= the class of languages where membership can be decided quickly NP=the class of languages where membership can be verified quickly NP-complete problems : if a polynomial time (determ.) algorithm exists for one NP-complete problem, then P=NP
Polynomial time reducibility Fig 7.6
Proof: N works in polynomial time
Fig 7.7
NP-completeness
Set Covering
BinPacking
Traveling Salesman Problem
Coloring
Key Reductions SAT 3SAT SetCoverClique VertexCover SubsetSum Partition BinPacking Hampath UHampath TSP Coloring
Conclusions The class P The class NP NP-completeness(e.g. 3SAT) Polynomial time reductions Two further classes : –coNP : –NP-hard:
Standard Reference Garey and Johson, Computers and Intractability – A guide to the theory of NP- completeness, W.H.Freeman, 1979.