IN210 − lecture 8 Strategy: Understand two classes in-depth. N PC P formal languages Next: • Extend the “map of classes”. • Show how to use it for organizing our views on — problems — solutions — other issues Autumn 1999 1 of 14 IN210 − lecture 8 Other classes Def. 1 (Co-N P) A language L is in class Co-N P if its complement Lc is in N P. Note: The complement of a formal language L is • formally all the strings (over the given alphabet) that are not in the set L. • informally the reverse property, i.e. all the instances that don’t have the property corresponding to language L. Co NP NP P Example: N ON -M ATCHING and N ON -H AMILTONICITY are in Co-N P. Autumn 1999 2 of 14 IN210 − lecture 8 Lemma 1 A language L is Co-N P-complete if its complement Lc is N P-complete. Proof: A reduction R from L0c to Lc is also a reduction from L0 to L. Co-N P L0 R L NP L0c R c L 0c L 0 L R R Σ* Lc L Σ* Example: • N ON -H AMILTONICITY • N ON -S ATISFIABILITY • N ON -C LIQUE • N ON - . . . are Co-N P-complete problems. They don’t seem to have “ID’s” (efficient membership proofs). Autumn 1999 3 of 14 IN210 − lecture 8 Def. 2 (Polynomial Space, PSPACE) [ PSPACE = SPACE (nk ) k (Note: Space complexity is measured as number of tape squares used on (the work tape of) a TM.) Lemma 2 NTIME f (n) ⊆ SPACE f (n) Proof: A TM moves its head one square at a time. Corollarly 1 N P, Co-N P ⊆ PSPACE Examples of PSPACE-complete problems: • QUANTIFIED B OOLEAN F ORMULAS (∃x1)(∀x2)(∃x3) · · · (Qxn)B • Generalized games (n × n boards) Def. 3 (Exponential time, EXP) k [ EXP = TIME 2n k f (n) Lemma 3 SPACE f (n) ⊆ TIME k for some constant k. Proof (idea): The maximum number of distinct configuration with f (n) tape squares used is |Q| · f (n) · |Γ|f (n). Corollarly 2 PSPACE ⊆ EXP Autumn 1999 4 of 14 IN210 − lecture 8 .. Map of classes Not acceptable ... Undecidable EXP TIME a cut! PSPACE Co NP NP = complete or "hardest" problems in a class P Are inclusions proper (()? • P ( N P? • P ( PSPACE? Autumn 1999 5 of 14 IN210 − lecture 8 Do complexity classes really exist? Theorem 1 (Time Hierachy Theorem) If f (n) ≥ n is a proper complexity function then TIME f (n) ( TIME (f (2n + 1))3 . Basic message: Given more time we can (provably) solve more problems. Corollarly 3 P ( EXP In other words: L ∈ EXP-complete ⇒ L 6∈ P. Autumn 1999 6 of 14 IN210 − lecture 8 Are complexity classes practically relevant? Assumptions, abstractions, modeling simplifications are possible weak points of thoery as a model: • Problem ; ; formal language ; — search/optimization • Solution, algorithm decision Turing machine Alternative approaches to computation: — Analog computation — Biological computers — Neural networks — Quantum computers — ... • Real time ; ; # of TM steps (discrete, finite) • Real intractability worst case / best solution Alternative approaches to algorithm design & analysis: — Approximation — Average-case analysis — Randomized algorithms — Autumn 1999 ... 7 of 14 IN210 − lecture 8 Placing problems on the map • Problem ↔ complexity • Complexity = performance of best possible algorithm • Lower bound ≤ complexity ≤ upper bound — Upper bound → algorithm — Lower bound → reduction, etc. Autumn 1999 8 of 14 IN210 − lecture 8 Examples (insights) Finding a path in a graph • any path: “greedy” algorithm (linear time) s For all v 0 neighbors of v: Mark v 0 s t G • shortest path: iterative improvement, Dijkstra (polynomial time) 4 s 6 a Let v be node with smallest D(v). 1 For all v 0 neighbors of v: 0 0 0 b D(v ) = min[D(v) + d(v, v ), D(v )] • longest path: NP-complete (exhaustive search, backtracking, exponential time) H AMILTONICITY ∝ Longest path Autumn 1999 9 of 14 IN210 − lecture 8 Matching 1DM a b 2DM a b 1 2 greedy (lin. time) O (n) 3DM 1 2 iterative improvement 3 O n alg. exhaustive search 2n O 2 alg. Satisfiability 1SAT (x1) ∧ · · · 2SAT (x1 ∨ x2) ∧ · · · 3SAT (x1 ∨ ¬x2 ∨ ¬x3)∧ Generalization: Matroid intersection 1 matroid Autumn 1999 2 matroids 3 matroids 10 of 14 IN210 − lecture 8 Placing real-world problems on the map • Decision problems . . . is there a . . . • Search problems . . . find a . . . • Optimization problems . . . find the largest/smallest . . . Def. 4 Problem L is N P-easy if there exists a problem L0 ∈ N P such that L ∝ L0. Note: We generalize the notion of polynomial reduction (∝) in order to deal with search/optimization problems: • We allow a polynomial number of “calls” to ML0 instead of just 1. • We allow the output to be a general string instead of just YES or NO. (G&J calls this Turing reduction, ∝T ) Note: If L ∈ N P-easy and P=N P then L ∈ P, i.e. L is not any more difficult/complex than N P-complete problems. Autumn 1999 11 of 14 IN210 − lecture 8 Example (of basic technique) Theorem 2 Search version of H AMILTONICITY is N P-easy. Proof: (Turing) reduction to decision version of H AMILTONICITY: G RT G0 Y Hd alg. Ham. cycle in G or "Doesnt’ exist" N Algorithm for search-HAM a 0 1. G ← G b c e d 2. Run Hd on G0. If HD (G0) = ’NO’ then output “Ham. path doesn’t exist” else remove an edge from G0: Autumn 1999 12 of 14 IN210 − lecture 8 a 0 0 3. G ← G − {a, b} b c e d 4. Run Hd on G0. If HD (G0) = ’YES’ then remove another edge from G0 (goto step 3), else mark edge {a, b}, return {a, b} to G0 and remove an unmarked edge: a 0 0 5. G ← G + {a, b} − {e, d} b c e d 6. . . . eventually the graph will only have n marked edges left, namely the Hamiltonian cycle. Autumn 1999 13 of 14 IN210 − lecture 8 Def. 5 Problem L is N P-equivalent if L is both N P-hard and N P-easy. Examples: Search versions of HAM, C LIQUE, SAT, . . . are N P-equivalent. Optimization problems – are they harder? We say that language (problem) L is in class DP if it can be defined by L = L1 ∩ L2 where L1 is an N P language (property) and L2 is a Co-N P language (property). Example: Opt-TSP is DP-complete. When we say “t is the shortest tour in G and t has length=K” we say two things: • There is a tour of length K in G. (N P-property) • There is no tour of length K − 1 in G. (Co-N P-property) Question: Is Opt-TSP N P-equivalent? Autumn 1999 14 of 14