Complexity (Pre Lecture)

Similar documents
Chapter 7: Time Complexity

Theory of Computation Time Complexity

TIME COMPLEXITY AND POLYNOMIAL TIME; NON DETERMINISTIC TURING MACHINES AND NP. THURSDAY Mar 20

CS154, Lecture 13: P vs NP

Time Complexity. CS60001: Foundations of Computing Science

CSE 105 THEORY OF COMPUTATION

CS5371 Theory of Computation. Lecture 19: Complexity IV (More on NP, NP-Complete)

CS154, Lecture 13: P vs NP

Time Complexity (1) CSCI Spring Original Slides were written by Dr. Frederick W Maier. CSCI 2670 Time Complexity (1)

CISC 4090 Theory of Computation

Lecture 16: Time Complexity and P vs NP

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) Spring l. Blum TIME COMPLEXITY AND POLYNOMIAL TIME;

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

CSE 105 Theory of Computation

Finish K-Complexity, Start Time Complexity

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

Applied Computer Science II Chapter 7: Time Complexity. Prof. Dr. Luc De Raedt. Institut für Informatik Albert-Ludwigs Universität Freiburg Germany

Lecture 3: Nondeterminism, NP, and NP-completeness

Complexity: moving from qualitative to quantitative considerations

The Class NP. NP is the problems that can be solved in polynomial time by a nondeterministic machine.

CSE 135: Introduction to Theory of Computation NP-completeness

Computational complexity

6.045: Automata, Computability, and Complexity (GITCS) Class 15 Nancy Lynch

CSE 105 THEORY OF COMPUTATION

NP-Completeness. A language B is NP-complete iff B NP. This property means B is NP hard

Theory of Computation

CSE 105 THEORY OF COMPUTATION

Lecture 17: Cook-Levin Theorem, NP-Complete Problems

CSCI3390-Lecture 16: NP-completeness

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan August 30, Notes for Lecture 1

BBM402-Lecture 11: The Class NP

22c:135 Theory of Computation. Analyzing an Algorithm. Simplifying Conventions. Example computation. How much time does M1 take to decide A?

SOLUTION: SOLUTION: SOLUTION:

COMPLEXITY THEORY. PSPACE = SPACE(n k ) k N. NPSPACE = NSPACE(n k ) 10/30/2012. Space Complexity: Savitch's Theorem and PSPACE- Completeness

Polynomial time reduction and NP-completeness. Exploring some time complexity limits of polynomial time algorithmic solutions

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

P, NP, NP-Complete, and NPhard

Advanced topic: Space complexity

Chapter 2 : Time complexity

Computability Theory

Lecture 22: PSPACE

Computability and Complexity

Computability Theory

Correctness of Dijkstra s algorithm

15.1 Proof of the Cook-Levin Theorem: SAT is NP-complete

Intro to Theory of Computation

More Turing Machines. CS154 Chris Pollett Mar 15, 2006.

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

NP, polynomial-time mapping reductions, and NP-completeness

Space Complexity. The space complexity of a program is how much memory it uses.

CS294: Pseudorandomness and Combinatorial Constructions September 13, Notes for Lecture 5

Lecture 25: Cook s Theorem (1997) Steven Skiena. skiena

Advanced Topics in Theoretical Computer Science

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Asymptotic notation : big-o and small-o

Computability Theory. CS215, Lecture 6,

P and NP. Or, how to make $1,000,000.

Theory of Computation CS3102 Spring 2015 A tale of computers, math, problem solving, life, love and tragic death

Notes for Lecture Notes 2

Intro to Theory of Computation

Computational Complexity

Theory of Computation. Ch.8 Space Complexity. wherein all branches of its computation halt on all

Introduction to Complexity Theory

The Cook-Levin Theorem

Turing Machines and Time Complexity

Friday Four Square! Today at 4:15PM, Outside Gates

Welcome to... Problem Analysis and Complexity Theory , 3 VU

Lecture 18: PCP Theorem and Hardness of Approximation I

NP Complete Problems. COMP 215 Lecture 20

Computability and Complexity CISC462, Fall 2018, Space complexity 1

Logarithmic space. Evgenij Thorstensen V18. Evgenij Thorstensen Logarithmic space V18 1 / 18

1 Computational Problems

Lecture 19: Finish NP-Completeness, conp and Friends

CS154, Lecture 17: conp, Oracles again, Space Complexity

Week 2: Defining Computation

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

CSCI 1590 Intro to Computational Complexity

Computational Models Lecture 11, Spring 2009

Time to learn about NP-completeness!

Space Complexity. Huan Long. Shanghai Jiao Tong University

Complexity. Complexity Theory Lecture 3. Decidability and Complexity. Complexity Classes

1 Non-deterministic Turing Machine

CSCI3390-Second Test with Solutions

CP405 Theory of Computation

Week 3: Reductions and Completeness

Polynomial Time Computation. Topics in Logic and Complexity Handout 2. Nondeterministic Polynomial Time. Succinct Certificates.

Chapter 1 - Time and Space Complexity. deterministic and non-deterministic Turing machine time and space complexity classes P, NP, PSPACE, NPSPACE

CS20a: NP completeness. NP-complete definition. Related properties. Cook's Theorem

CS151 Complexity Theory. Lecture 1 April 3, 2017

Time to learn about NP-completeness!

Limitations of Algorithm Power

CSE 555 HW 5 SAMPLE SOLUTION. Question 1.

MTAT Complexity Theory October 13th-14th, Lecture 6

MTAT Complexity Theory September 15th, Lecture 3

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

CSC 5170: Theory of Computational Complexity Lecture 4 The Chinese University of Hong Kong 1 February 2010

Could we potentially place A in a smaller complexity class if we consider other computational models?

Definition: conp = { L L NP } What does a conp computation look like?

Transcription:

Complexity (Pre Lecture) Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Fall 2018 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 1 / 70

Why? What can we always compute efficiently? What can we not always compute efficiently? How can we sometimes solve hard problems efficiently? Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 2 / 70

Outline Time Complexity Complexity Relationships Multi-Tape Turing Machines Nondeterministic Turing Machines P vs. NP NP-Completeness Other NP-Complete Problems Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 3 / 70

Time Complexity Outline Time Complexity Complexity Relationships Multi-Tape Turing Machines Nondeterministic Turing Machines P vs. NP NP-Completeness Other NP-Complete Problems Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 4 / 70

Time Complexity Measuring Time I Computation takes time I Physical TM: read-transition-write Two different questions: I 1. How fast is a computer? 2. How fast is an algorithm? Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 5 / 70

Time Complexity Asymptotic (big-o) notation Definition: Asymptotic Upper Bound f (n) = O(g(n) represents the asymptotic upper bound of f (n) without regard for constant factors. Specifically: Given functions f and g: f, g : N R + If there exists natural numbers c and n 0 where: (n > n 0 ), (f (n) cg(n)), We indicate the asymptotic upper bound of f (n) as O(g(n)) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 6 / 70

Time Complexity Exercise: Big-O (1/2) 2n O(n) 3n + 2n 2 4 ln n 5 log 10 n = 5 ln n ln 10 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 7 / 70

Time Complexity Exercise: Big-O (2/2) Given: Input size n Function f (n) Positive, non-zero constants a, b, k Then: O(a) = O(a + f (n)) = O(a f (n)) = O(an k + bn k+1 ) = O(log k f (n)) = Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 8 / 70

Time Complexity Asymptotic Time Complexity Definition: Asymptotic Time Complexity The asymptotic time complexity of a Turing machine (algorithm) T that halts on all inputs is the asymptotic upper bound on the number of steps T takes for a given input size n. That is, given input of size n, Turing machine T will take some f (n) steps to compute its result. The asymptotic time complexity of T is O(f (n)) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 9 / 70

Time Complexity Time Complexity Terms Constant: O(1) Logarithmic: O(ln n) Linear: O(n) Quadratic: O(n 2 ) Cubic: O(n 3 ) Polynomial: O(n k ) Exponential: O(2 nα ), where α > 0 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 10 / 70

Time Complexity Example: Turing-Machine Time Complexity (0) Formal Description start q 0 1 x, R {0, 1} R # R x R q 2 # R q 4 x R 1 x, L L = {ω#ω ω {0, 1} } {0, 1, x} L {0, 1} L q R # L 7 q acc q 5 q 6 0 x, R # R q 1 q 3 0 x, L {0, 1} R x R x R Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 11 / 70

Time Complexity Example: Turing-Machine Time Complexity (1) High-Level Description 1. For each string in the first half of the input, replace with x and sweep to the corresponding position in the second half 2. If the item in the second half does not match, reject 3. Otherwise, the item matches, replace with x and sweep back to the next element in the first half 4. When all items have been matched and replaced with x, accept. ( n ( n 2 2 {}}{{}}{ for each item in the first half, sweep forward, + n 2 ) {}}{ then sweep back ) ( n ( n O 2 2 + n )) = O ( n 2) 2 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 12 / 70

Time Complexity Time Complexity Class Definition: Time Complexity Time For function t : N R +, the time complexity class time(t(n)) is the set of languages (problems) decidable by a Turing machine (algorithm) in time O(t(n)). Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 13 / 70

Time Complexity Example: Sorting Time Complexity Class Given: Sequence (x 0,..., x n ) X Order relation : X X B Find: Re-ordering of x, (y 0,..., y n ) where every y i y i+1 Assumptions: is O(1) Algorithms: Bubble Sort: O(n 2 ) Insertion Sort: O(n 2 ) Selection Sort: O(n 2 ) Heap Sort: O(n ln n) Merge Sort: O(n ln n) Time Complexity Class: O(n ln n) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 14 / 70

Time Complexity Example: Bit-sequence Sorting Given: Sequence (x 0,..., x n ) (B k ) Order relation : B k B k B Find: Re-ordering of x, (y 0,..., y n ) where every y i y i+1 Assumptions: is O(1) Algorithms: Bubble Sort: O(n 2 ) Insertion Sort: O(n 2 ) Selection Sort: O(n 2 ) Heap Sort: O(n ln n) Merge Sort: O(n ln n) Radix Sort: O(n) Time Complexity Class: O(n) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 15 / 70

Complexity Relationships Outline Time Complexity Complexity Relationships Multi-Tape Turing Machines Nondeterministic Turing Machines P vs. NP NP-Completeness Other NP-Complete Problems Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 16 / 70

Complexity Relationships Multi-Tape Turing Machines Multi-Tape Turing Machines Finite Control Q δ : Q {accept, reject} read k tapes {}}{ write k tapes {}}{ Γ k Q Γ k k moves: left, right, stay {}}{ {L, R, S} k a 0 a 1 b 0 b 1 b 2 b 3 c 0 c 1 c 2 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 17 / 70

Complexity Relationships Multi-Tape Turing Machines Simulate Multi-Tape on Single Tape Finite Control Q {accept, reject} virtual heads # a 0 a1 # b 0 b 1 b2 b 3 # c 0 c 1 c 2 # not head Γ {}}{ = Γ, tape head {}}{ tape separator {}}{ # Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 18 / 70

Complexity Relationships Multi-Tape Turing Machines Multi-Tape Simulation Complexity Theorem: Multi-Tape Simulation Complexity Let M be a multi-tape Turing machine with time complexity of O(f (n)). Then, we can simulate M with a single-tape Turing machine S with time complexity O(f 2 (n)). Proof Outline M takes O(f (n)) steps. Each step of the simulation M on S takes at most O(f (n)) steps. Thus, S is O(f 2 (n)). Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 19 / 70

Complexity Relationships Multi-Tape Turing Machines Multi-Tape Simulation Steps virtual heads # a 0 a1 # b 0 b 1 b2 b 3 # c 0 c 1 c 2 # To simulate a multi-tape move of M: 1. Scan single-tape of S to determine symbols under each virtual head (finite combinations) 2. Re-scan single-tape to update symbols and virtual head positions If a virtual head moves onto tape separator (#) 1. Write a blank symbol ( ) over the #. 2. Shift tape contents right by one space. 3. Resume simulation. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 20 / 70

Complexity Relationships Multi-Tape Turing Machines Multi-Tape Simulation Complexity Proof Details Writing the initial tape configuration of S takes O(n) to copy the length n input For each step of M, S makes two passes over the active (written/non-blank) portion of its tape: 1. Read the contents of the tape under each virtual head 2. Write the updated symbol under each virtual head The active portion of the tape has at most O(f (n)) entries, because we can write at most one new entry per step when moving right. (left moves do not grow the active portion) Thus, S takes O(n) + O(f 2 (n)) steps Assuming O(f 2 (n)) O(n), then S is O(f 2 (n)) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 21 / 70

Complexity Relationships Nondeterministic Turing Machines Nondeterministic Turing Machines Finite Control Q {accept, reject} read-write head γ 0... γ i... γ n... δ : Q Γ P (Q Σ {L, R}) }{{} set of successor configurations Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 22 / 70

Complexity Relationships Nondeterministic Turing Machines Nondeterministic TM Runtime Definition Definition: Nondeterministic Runtime For nondeterministic TM N that always accepts or rejects, the running time of N is function f : N N, where f (n) is the maximum number of steps used by N on any branch of the computation. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 23 / 70

Complexity Relationships Nondeterministic Turing Machines Nondeterministic TM Runtime Illustration Deterministic Start Nondeterministic Start... f (n).......... f (n) Accept/Reject Accept Reject Reject Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 24 / 70

Complexity Relationships Nondeterministic Turing Machines Nondeterministic Simulation Complexity Theorem: Nondeterministic Simulation Complexity Given nondeterministic TM N that always accepts or rejects and has runtime complexity f (n), there is an equivalent deterministic TM T with runtime complexity 2 O(f (n)). Proof Outline We simulate nondeterministic TM N with deterministic TM T. T searches the branches of N s nondeterministic computation. T s search requires 2 O(f (n)) steps. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 25 / 70

Complexity Relationships Nondeterministic Turing Machines Nondeterminism Branch Addressing C [0] = q 0 σ 0... σ n ( C [1] ) 0 ( C [1] ) 1... ( C [1] ) b ( C [1] ) 0,0... ( C [1] ) 0,b ( C [1] ) b,0... ( C [1] ) b,b............... ( C [1] ) b,... C acc Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 26 / 70

Complexity Relationships Nondeterministic Turing Machines Deterministic Simulation: Iterative Deepening Search Diagram Finite Control Q {accept, reject} σ 0 σ 1... σ n 1 σ n Input Tape γ 0 γ 1 γ 2 γ 3 Simulation Tape 2 0 4 Address Tape Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 27 / 70

Complexity Relationships Nondeterministic Turing Machines Nondeterministic Simulation Complexity Details Iterative deepening search: visit all nodes at depth d before visiting any nodes at d + 1 Node count given b branches at each level: O(b f (n) ) Time to visit (deepen from the root) a node: O(f (n)) Runtime: O(f (n)b f (n) ) = 2O(f (n)) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 28 / 70

P vs. NP Outline Time Complexity Complexity Relationships Multi-Tape Turing Machines Nondeterministic Turing Machines P vs. NP NP-Completeness Other NP-Complete Problems Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 29 / 70

P vs. NP The Class P Definition: The Class P P is the class of languages decidable in polynomial time by a deterministic, single-tape Turing machine: P = k N time(n k ) Deterministic computation models are polynomially-equivalent. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 30 / 70

P vs. NP Every Regular Language is in P Theorem Every Regular Language is in P. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 31 / 70

P vs. NP Every Context-Free Language is in P Theorem Every Context-Free Language is in P. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 32 / 70

P vs. NP DPLL Time Complexity Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 33 / 70

P vs. NP SAT Verification Time Complexity Given: φ: Boolean formula m: Bindings for predicates in φ (called model of φ) Algorithm: Find: Does m make φ true? m = φ Runtime: O( m + φ ) 1. Substitute m into φ 2. Evaluate resulting expression If is often faster to verify than to solve Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 34 / 70

P vs. NP Verifiers Definition: Verifier A verifier for language L is an algorithm V, where: L = {ω (ω, m) L (V ) for some string m} That is: ( m, ((ω, m) L (V ))) (ω L) m is a proof that ω L Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 35 / 70

P vs. NP Verify to Solve (nondeterministically) Given: Deterministic verifier V for language L Find: Nondeterministic TM N where: L (N) = L Algorithm: N = 1. Nondeterministically select (every) m. 2. Simulate V on each m 3. If any simulation of V accepts, N accepts Runtime: If V is O(f (n), then N is also O(f (n)) (but nondeterministic) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 36 / 70

P vs. NP Nondeterministic Time Complexity Class Definition: Nondeterministic Time Complexity Time For function t : N R +, the nondeterministic time complexity class ntime(t(n)) is the set of languages (problems) decidable by a Nondeterministic Turing machine in time O(t(n)). Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 37 / 70

P vs. NP The Class NP Definition: The Class NP NP is the class of languages with polynomial-time verifiers. Equivalently, NP is the class of languages decidable in polynomial time by a nondeterministic Turing machine: NP = k N ntime(n k ) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 38 / 70

P vs. NP P vs. NP P Decide in O(n k ) on DTM NP Verify in O(n k ) on DTM Decide in O(n k ) on NTM P NP NP P? = NP P P = NP Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 39 / 70

NP-Completeness Outline Time Complexity Complexity Relationships Multi-Tape Turing Machines Nondeterministic Turing Machines P vs. NP NP-Completeness Other NP-Complete Problems Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 40 / 70

NP-Completeness Cook-Levin Theorem Theorem: Cook-Levin Theorem (SAT P) (P = NP) Proof Outline 1. (P = NP) = (SAT P) We have a polynomial time, nondeterministic TM/algorithm to solve SAT, i.e., guess and verify 2. (SAT P) = (P = NP) We can reduce (convert) any nondeterministic TM to SAT. That is, solving SAT in polynomial time will solve any nondeterministic TM in polynomial time. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 41 / 70

NP-Completeness Reduction of A to B Given: Algorithm for language B Function g : Σ Σ, where: ω A g(ω) B Find: Algorithm for A Solution: A = {ω g(ω) B} 1. Apply g to ω 2. Apply B to resulting g(ω) Procedure A(ω) 1 return B(g(ω)); Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 42 / 70

NP-Completeness Reducing Nondeterministic TM to SAT Overview 1. Unroll: Represent one branch of NTM computation as a tableau. Each row is the NTM configuration at one step 2. Variables: Boolean variables represent entries in each cell of the tableau. 3. Formula: Boolean formula encodes the start, accept, and moves of the NTM. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 43 / 70

NP-Completeness Illustration: NTM Tableau # q 0 ω 0 ω 1... ω n... # start configuration # # second configuration n k... # # n k th configuration n k Represents configuration history for one branch Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 44 / 70

NP-Completeness SAT Variables τ [i,j] : Tableau contents at row i, column j Tableau values: S = Q Γ {#} Variables: S (nk ) 2 Boolean var {}}{ ( S l [i,j] ) tableau contents {}}{ (τ [i,j] = S l ) ( S l [i,j] ) is true when τ [i,j] contains S l Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 45 / 70

NP-Completeness Example: SAT Variables Tableau Q = {q 0, q 1 } Γ = {a, b} q 0 a b b q 1 b b a q 0 Cell 0,0 τ [0,0] = q 0 q [0,0] 0 = 1 q [0,0] 1 = 0 a [0,0] = 0 b [0,0] = 0 Boolean variable assignment encodes a TM branch Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 46 / 70

NP-Completeness Exercise: SAT Variables Tableau Cell 0,0 Cell 0,1 Cell 1,0 Q = {q 0, q 1 } τ [0,0] = q 0 τ [0,1] = a τ [1,0] = b Γ = {a, b} q 0 a b b q 1 b b a q 0 q [0,0] 0 = 1 q [0,0] 1 = 0 a [0,0] = 0 b [0,0] = 0 Boolean variable assignment encodes a TM branch Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 47 / 70

NP-Completeness SAT Formula Outline 1. Start configuration: φ start 2. Accept configuration: φ acc 3. Cell contents: φ cell 4. TM Move: φ move φ = φ start φ acc φ cell φ move Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 48 / 70

NP-Completeness SAT Formula Start and Accept Configurations Start: Start configuration holds at step 0, head pos. input string blank symbols {}}{{}}{{}}{ [0,0] φ start = q 0 σ [0,1] 0 σ [0,2] 1... σ [0,n+1] n [0,n+2]... [0,nk ] Accept: Some step visits the accept state, accept at step 0 accept at step 1 accept at step n {}}{{}}{{}} k { φ acc = q [0,0] [0,n a... q k] a q [1,0] [1,n a... q k] [n a... q k,0] [n a... q k,n k ] a Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 49 / 70

NP-Completeness SAT Formula Cell Contents and Exclusion φ cell = 0 i n k }{{} rows 0 i n k }{{} rows 0 j n k }{{} cols 0 j n k }{{} cols 0 l m }{{} symbols Cell i,j has some symbol { }} { cell contents {}}{ [i,j] s l 0 l m }{{} symbols cell contents {}}{ s l [i,j] = all others false {}}{ ( s ) [i,j] 0... s [i,j] l 1 s [i,j] [i,j] l+1... s m } {{ } cell i,j has only one symbol Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 50 / 70

NP-Completeness SAT Formula Window preservation TM Tape Configurations Tableau γ x γ y γ z... γ x γ y γ z... j 1 j j + 1 i... γ x γ y γ z... i + 1... γ x γ y γ z... γ x γ y γ z... γ x γ y γ z... no head near j { }}{ φ win = ( q [i,j 1] q [i,j] q [i,j+1]) q Q = s l S ( s l [i,j] s l [i+1,j] ) } {{ } preserve γ y Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 51 / 70

NP-Completeness SAT Formula Move Right q p γ y γ y, R q s TM Tape Configurations Tableau q p γ x γ y γ z q s γ x γ y γ z... γ x q p γ y γ z...... γ x γ y q s γ z... j 1 j j + 1 i... γ x q p γ y γ z... i + 1... γ x γ y q s γ z... φ δ = set state {}}{ q s [i+1,j+1] s l S ( [i,j 1] s l write tape {}}{ γ y [i+1,j+1] ) [i+1,j 1] s l } {{ } preserve γ x Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 52 / 70

NP-Completeness SAT Formula Move Left q p γ y γ y, L q s q p γ x γ y γ z q s TM Tape Configurations Tableau γ x γ y γ z... γ x q p γ y γ z...... q s γ x γ y γ z... j 1 j j + 1 i... γ x q p γ y γ z... i + 1... q s γ x γ y γ z... φ δ = set state {}}{ q s [i+1,j 1] s l S ( [i,j 1] s l write tape {}}{ γ y [i+1,j+1] ) [i+1,j] s l }{{} preserve γ x Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 53 / 70

NP-Completeness SAT Formula Move φ move = 0 i n k 0 j n k {}}{ [i,j] (φ ) win preserve window q Q tape head/state {}}{ q [i,j] = take one and only one transition {}}{ (φ ) [i,j] [i,j] (δ,q,0)... φ (δ,q,0,e) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 54 / 70

NP-Completeness SAT Formula Summary φ = φ start φ acc φ cell φ move Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 55 / 70

NP-Completeness SAT is NP Complete f : Φ Σ SAT : Φ B NTM : Σ B g : Σ Φ SAT Reduces to NTM Procedure SAT(φ) 1 return NTM(f (φ)); NTM Reduces to SAT Procedure NTM(σ) 1 return SAT(g(σ)); Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 56 / 70

NP-Completeness X is NP Complete f : Θ Σ X : Θ B NTM : Σ B g : Σ Θ f : Φ Σ f : Φ Σ X : Θ B SAT : Φ B NTM : Σ B g : Σ Φ g : Σ Φ Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 57 / 70

NP-Completeness All NP Complete Problems are Equivalent Every f, g P f : Ω 0 Ω 1 f : Ω 1 Ω 2 f : Ω n 1 Ω n f : Ωn Σ X 0 : Ω 0 B X 1 : Ω 1 B X n : Ω n B NTM : Σ B g : Ω 1 Ω 0 g : Ω 2 Ω 1 g : Ω n Ω n 1 g : Σ Ω n Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 58 / 70

NP-Completeness P vs. NP Summary X in NP: X has a deterministic, polynomial time verifier X is NP-hard: Polynomial time reduction from NTM (or any other NP-hard problem) to X X is NP-complete: In NP and NP-hard NP-hard NP-hard P NP NP-complete P = NP NP-complete NP P = NP P Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 59 / 70

NP-Completeness Cook and Levin Stephen Cook. The complexity of theorem proving procedures. 1971. Dantam (Mines CSCI-561) Leonid Levin. Universal search problems (Russian). 1973. Complexity (Pre Lecture) Fall 2018 60 / 70

Other NP-Complete Problems Outline Time Complexity Complexity Relationships Multi-Tape Turing Machines Nondeterministic Turing Machines P vs. NP NP-Completeness Other NP-Complete Problems Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 61 / 70

Other NP-Complete Problems 3SAT Given: Boolean formula φ in CNF with exactly three literals per clause: φ = (a 0 b 0 c 0 ) (a 1 b 1 c 1 )... (a n b n c n ) Find: Is φ satisfiabile? m, m = φ Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 62 / 70

Other NP-Complete Problems 3SAT is NP-Complete Reduce 3SAT to SAT: Trivially Reduce SAT to 3SAT: Rewrite nonconformant clauses as follows: (a) (a duplicate {}}{ a a ) duplicate {}}{ (a b) (a b a ) new variable new variable {}}{{}}{ (a b c d) (a b x ) ( x c d) recurse {}}{ (a b c d 0... d n ) (a b x) ( x c d 0... d n ) Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 63 / 70

Other NP-Complete Problems Hamiltonian Path Given: Directed graph G Nodes s and t in G Find: A path from s to t that visits all nodes in G exactly one time 3 5 s 1 2 t 4 6 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 64 / 70

Other NP-Complete Problems Hamiltonian Path is in NP Polynomial Time Verifier: 1. Check that path starts at s and ends at t 2. Check that path contains each node only once 3. Check that sequential nodes in path are adjacent in graph Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 65 / 70

Other NP-Complete Problems Hamiltonian Path is NP-Complete 3SAT reduces to HAMPATH φ = (x 0 x 1 x 2 ) ( x 0 x 1 x 2 ) ( x 0 x 1 x 2 ) s x 0 x 0 x 0 x 1 x 2 e 0 x 0 x 1 x 2 x 1 x 1 x 0 x 1 x 2 e 1 x 2 x 2 t Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 66 / 70

Other NP-Complete Problems Hamiltonian Path is NP-Complete 3SAT reduces to HAMPATH Solution m : x 0 x 1 x 2 s x 0 x 0 x 0 x 1 x 2 e 0 x 0 x 1 x 2 x 1 x 1 x 0 x 1 x 2 e 1 x 2 x 2 t Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 67 / 70

Other NP-Complete Problems CLIQUE Given: Undirected Graph G, number k Find: A set of k vertices that form a clique, i.e., every vertex in the set has an edge to every other vertex in the set NP-Complete Outline: 1. Verifier in P 2. Reduction from 3SAT 3 4 0 1 2 5 6 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 68 / 70

Other NP-Complete Problems VERTEX-COVER Given: Undirected Graph G, number k Find: A set of k vertices that touch every edge in G NP-Complete Outline: 1. Verifier in P 2. Reduction from 3SAT 3 4 0 1 2 5 6 Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 69 / 70

Other NP-Complete Problems Now What? NP is hard, I give up! NP Problems: a fast algorithm may exist NP-complete Problems: fast (worst-case) not known, maybe not possible? Practical Answer for NP-complete Problems: use a (modern) SAT solver. Dantam (Mines CSCI-561) Complexity (Pre Lecture) Fall 2018 70 / 70