CSE 105 THEORY OF COMPUTATION

Similar documents
CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

CSE 105 Theory of Computation

Chapter 7: Time Complexity

CISC 4090 Theory of Computation

Time Complexity. CS60001: Foundations of Computing Science

Theory of Computation Time Complexity

Computational Models Lecture 11, Spring 2009

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

CS154, Lecture 13: P vs NP

Lecture 16: Time Complexity and P vs NP

Computability and Complexity

Complexity (Pre Lecture)

CS154, Lecture 13: P vs NP

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

Computational complexity

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

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

Finish K-Complexity, Start Time Complexity

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

Computability Theory

CSE 135: Introduction to Theory of Computation NP-completeness

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

BBM402-Lecture 11: The Class NP

Computational Complexity

CSE 105 THEORY OF COMPUTATION

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

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

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

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

CSE 105 THEORY OF COMPUTATION

CS5371 Theory of Computation. Lecture 18: Complexity III (Two Classes: P and NP)

Lecture 19: Finish NP-Completeness, conp and Friends

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

Complexity Theory Part I

Chapter 2 : Time complexity

Turing Machines and Time Complexity

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Lecture 3: Nondeterminism, NP, and NP-completeness

Intro to Theory of Computation

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Announcements. Problem Set 7 graded; will be returned at end of lecture. Unclaimed problem sets and midterms moved!

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?

CSE 105 THEORY OF COMPUTATION

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

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

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

Algorithms and Theory of Computation. Lecture 19: Class P and NP, Reduction

CP405 Theory of Computation

The Cook-Levin Theorem

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

Intractable Problems [HMU06,Chp.10a]

The P versus NP Problem. Dean Casalena University of Cape Town CSLDEA001

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

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.

Complexity: moving from qualitative to quantitative considerations

1 Non-deterministic Turing Machine

UNIT-VIII COMPUTABILITY THEORY

Computer Sciences Department

Advanced Topics in Theoretical Computer Science

CSE 105 THEORY OF COMPUTATION

NP Complete Problems. COMP 215 Lecture 20

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Design and Analysis of Algorithms

CSE 105 THEORY OF COMPUTATION

Introduction to Complexity Theory

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

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

Complexity Theory Part II

Theory of Computation

NP Completeness and Approximation Algorithms

CSE 105 THEORY OF COMPUTATION

NP-Completeness and Boolean Satisfiability

1 Computational Problems

CSE 105 THEORY OF COMPUTATION

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

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

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

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

Notes for Lecture Notes 2

q FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) Spring L. Blum. REVIEW for Midterm 2 TURING MACHINE

Intro to Theory of Computation

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

CSCE 551 Final Exam, Spring 2004 Answer Key

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

Lecture 18: PCP Theorem and Hardness of Approximation I

Complexity Theory Part I

Correctness of Dijkstra s algorithm

Intro to Theory of Computation

Lecture 20: conp and Friends, Oracles in Complexity Theory

Advanced topic: Space complexity

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

P, NP, NP-Complete, and NPhard

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size.

Intractable Problems. Time-Bounded Turing Machines Classes P and NP Polynomial-Time Reductions

conp, Oracles, Space Complexity

CSCI FOUNDATIONS OF COMPUTER SCIENCE

Transcription:

CSE 105 THEORY OF COMPUTATION Fall 2016 http://cseweb.ucsd.edu/classes/fa16/cse105-abc/

Logistics HW7 due tonight Thursday's class: REVIEW Final exam on Thursday Dec 8, 8am-11am, LEDDN AUD Note card allowed Bring photo ID, pens New seating map to be posted New review guide to be posted No review session outside class; office hours instead.

Time complexity (a bird's-eye-view tour) Section 7.1: time complexity, asymptotic upper bounds. Section 7.2: polynomial time, P Section 7.3: NP, polynomial verifiers, nondeterministic machines. Decidability vs. Complexity

Today's learning goals Sipser Sections 7.1, 7.2, 7.3 Describe how the runtime of Turing machines can be used to compare problems: which is harder? Compute the big-o class of the runtime of a TM from its implementation-level description. Distinguish between implementation-level decisions that impact the big-o class of the runtime and those that don't. Define the time complexity class P and name some problems in P Distinguish between polynomial and exponential DTIME Define nondeterministic running time Analyse a (nondeterministic) algorithm to determine whether it is in P (respecitvely, NP) Define the class NP and name some problems in NP State and explain P=NP? Define NP-completeness Explain the connection between P=NP? and NP-completeness Describe how reductions are used both for questions of decidability and of complexity.

Time complexity Goal: Which decidable questions are intrinsically easier (faster) or harder (slower) to compute? Algorithms that halt might take waaaaaaaaaaaay too long e.g., too long for any reasonable applications.

Measuring time For a given algorithm working on a given input, how long do we need to wait for an answer? How does the running time depend on the input in the worst-case? averagecase? Expect to have to spend more time on larger inputs. What's in common among all problems that are efficiently solvable?

Measuring time For a given algorithm working on a given input, how long do we need to wait for an answer? Count steps! How does the running time depend on the input in the worstcase? average-case? Big-O What's in common among all problems that are efficiently solvable? Time(n)

Time complexity For M a deterministic decider, its running time or time complexity is the function f: N R + given by f(n) = maximum number of steps M takes before halting, over all inputs of length n. worst-case analysis

Time complexity For M a deterministic decider, its running time or time complexity is the function f: N R + given by f(n) = maximum number of steps M takes before halting, over all inputs of length n. Instead of calculating precisely, estimate f(n) by using big-o notation.

TM analysis M 1 = "On input string w: 1. If the current tape location is blank, halt and accept. 2. Otherwise, cross off this cell s contents and move the tape head one position to the right. 3. If the current tape location is blank, halt and reject. 4. Otherwise, cross off this cell s contents and move the tape head one position to the right. 5. Go to step 1.

TM analysis M 1 = "On input string w: 1. If the current tape location is blank, halt and accept. 2. Otherwise, cross off this cell s contents and move the tape head one position to the right. 3. If the current tape location is blank, halt and reject. 4. Otherwise, cross off this cell s contents and move the tape head one position to the right. 5. Go to step 1. Is M 1 a decider? A. Yes. B. No. C. It depends on w. D. I don't know.

TM analysis M 1 = "On input string w: 1. If the current tape location is blank, halt and accept. 2. Otherwise, cross off this cell s contents and move the tape head one position to the right. 3. If the current tape location is blank, halt and reject. 4. Otherwise, cross off this cell s contents and move the tape head one position to the right. 5. Go to step 1. One step is one transition: a (possible) change in internal state, a change in current symbol on the tape, and a move fo the tape head How many steps are executed by M 1 on 1010? A. 1 B. 4 C. 5 D. None of the above. E. I don't know.

TM analysis M 1 = "On input string w: 1. If the current tape location is blank, halt and accept. 2. Otherwise, cross off this cell s contents and move the tape head one position to the right. 3. If the current tape location is blank, halt and reject. 4. Otherwise, cross off this cell s contents and move the tape head one position to the right. 5. Go to step 1. L(M 1 ) = { w such that w is even}. M 1 takes n+1 steps to halt on input of size n. Running time of M 1 is O(n).

{0 k 1 k k 0 } M 2 = On input w: 1. Scan across the tape and reject if w not of the form 0*1*. 2. Repeat the following while there are both 0s and 1s on tape: Scan across tape, each time crossing off a single 0 and a single 1. 3. If 0 s remain after all 1 s checked off, reject. 4. If 1 s remain after all 0 s checked off, reject. 5. Otherwise, accept. For input w of length n, how many steps does stage 1 take? A. O(1) B. O(n) C. O(n 2 ) D. It depends on n in a different way from B, C E. I don't know.

{0 k 1 k k 0 } M 2 = On input w: 1. Scan across the tape and reject if w not of the form 0*1*. 2. Repeat the following while there are both 0s and 1s on tape: Scan across tape, each time crossing off a single 0 and a single 1. 3. If 0 s remain after all 1 s checked off, reject. 4. If 1 s remain after all 0 s checked off, reject. 5. Otherwise, accept. How many times do we repeat stage 2 (in the worst case)? A. n B. 2n C. n/2 C. n 2 E. I don't know.

Big-O review Sipser p. 249 To add big-o terms: pick maximum Can drop / ignore constants Polynomials: use highest order term log a b = O(log 2 b) = O(log b)

{0 k 1 k k 0 } M 2 = On input w: 1. Scan across the tape and reject if w not of the form 0*1*. 2. Repeat the following while there are both 0s and 1s on tape: Scan across tape, each time crossing off a single 0 and a single 1. 3. If 0 s remain after all 1 s checked off, reject. 4. If 1 s remain after all 0 s checked off, reject. 5. Otherwise, accept. Running time of M 2 is O(n) + O(n 2 ) + O(n) + O(n) = O(n 2 ) Running time of M 2 is O(n 2 ).

Time complexity classes TIME(t(n)) = { L L is decidable by a TM running in O(t(n)) } Exponential Polynomial Logarithm

Why is it okay to group all polynomial running times? Contains all the "feasibly solvable" problems. Invariant for all the "usual" deterministic TM models multitape machines (Theorem 7.8) multi-write

Working with P Problems encoded by languages of strings Need to make sure coding/decoding of objects can be done in polynomial time. Algorithms can be described in high-level or implementation level CAUTION: not allowed to guess / make non-deterministic moves.

Graph problems PATH { < G,s,t > G a directed graph with directed path from s to t} CONNECTED { < G > G a directed graph with single connected component.} etc. Compute running time of graph algorithms in terms of number of nodes!

PATH Sipser p. 260 M = On input <G,s,t> where G is digraph, s and t are nodes in G: 1. Place mark on node s 2. Repeat until no additional nodes are marked Scan edges of G. If edge (a,b) is found where a is marked and b is unmarked, mark b. 3. If t is marked, accept; otherwise, reject.

PATH Sipser p. 260 M = On input <G,s,t> where G is digraph, s and t are nodes in G: 1. Place mark on node s 2. Repeat until no additional nodes are marked Scan edges of G. If edge (a,b) is found where a is marked and b is unmarked, mark b. 3. If t is marked, accept; otherwise, reject. Running time of M is O(1) + O(n * n 2 ) + O(1) = O(n 3 ) PATH is in P.

Time complexity classes TIME(t(n)) = { L L is decidable by a TM running in O(t(n)) } Exponential Polynomial Logarithmic Brute-force search Invariant under many models of TMs May not need to read all of input

Which machine model? q0 q0 deterministic computation nondeterministic computation q rej q acc q acc q rej q rej

Time complexity For M a deterministic decider, its running time or time complexity is the function f: N R + given by f(n) = maximum number of steps M takes before halting, over all inputs of length n. For M a nondeterministic decider, its running time or time complexity is the function f: N R + given by f(n) = maximum number of steps M takes before halting on any branch of its computation, over all inputs of length n.

Time complexity classes DTIME ( t(n) ) = { L L is decidable by O( t(n) ) deterministic, single-tape TM } NTIME ( t(n) ) = { L L is decidable by O( t(n) ) nondeterministic, single-tape TM } Is DTIME(n 2 ) a subset of DTIME(n 3 )? A. Yes B. No C. Not enough information to decide D. I don't know

Time complexity classes DTIME ( t(n) ) = { L L is decidable by O( t(n) ) deterministic, single-tape TM } NTIME ( t(n) ) = { L L is decidable by O( t(n) ) nondeterministic, single-tape TM } Is DTIME(n 2 ) a subset of NTIME(n 2 )? A. Yes B. No C. Not enough information to decide D. I don't know

Time complexity classes DTIME ( t(n) ) = { L L is decidable by O( t(n) ) deterministic, single-tape TM } NTIME ( t(n) ) = { L L is decidable by O( t(n) ) nondeterministic, single-tape TM } Is NTIME(n 2 ) a subset of DTIME(n 2 )? A. Yes B. No C. Not enough information to decide D. I don't know

"Feasible" i.e. P Can't use nondeterminism Can use multiple tapes Often need to be "more clever" than naïve / brute force approach Examples PATH = {<G,s,t> G is digraph with n nodes there is path from s to t} RELPRIME = { <x,y> x and y are relatively prime integers} Use Euclidean Algorithm to show in P L(G) = {w w is generated by G} where G is any CFG Use Dynamic Programming to show in P

"Verifiable" i.e. NP Best known solution is brute-force Look for some "certificate" if had one, could check if it works quickly P = NP?

Examples in NP for graphs Sipser p. 264,268,284 HAMPATH = { <G,s,t> G is digraph with a path from s to t that goes through every node exactly once } CLIQUE = { <G,k> G is an undirected graph with a k-clique } VERTEX-COVER = { <G,k> G is an undirected graph with a Subset of k nodes s.t. each edge incident with one of them Complete subgraph with k nodes k-node vertex cover}

Examples in NP for graphs Sipser p. 264,268,284 CLIQUE = { <G,k> G is an undirected graph with a k-clique } Complete subgraph with k nodes How many possible k-cliques are there? How long does it take to confirm "clique-ness"?

Examples in NP optimization Sipser p. 264,268 TSP = { <G,k> G is complete weighted undirected graph where weight between node i and node j is "distance" between them; there is a tour of all cities with total distance less than k } How many possible tours are there? How long does it take to check the distance of a single tour?

Examples in NP for numbers Sipser p. 265,269 COMPOSITES = { x x is an integer >2 and is not prime} SUBSET-SUM = { <S,t> S={x 1,..,x k } and some subset sums to t}

Examples in NP for logic Sipser p. 271 SAT = { <φ> φ is a satisfiable Boolean formula } Is < > in SAT? A. Yes B. No C. Not enough information to decide D. I don't know

P vs. NP Problems in P (Membership in any) CFL PATH E DFA EQ DFA Addition, multiplication of integers Problems in NP Any problem in P HAMPATH CLIQUE VERTEX-COVER TSP SAT

Decidable NP? P CF Regular

Reductions to the rescue Sipser p. 271,276 1970s Stephen Cook and Leonid Levin indepdendently and in parallel lay foundations of NP-completeness Intuitively: if an NP-complete problem has a polynomial algorithm, then all NP problems are polynomail time solvable. A language B is NP-complete if it is in NP and every A in NP is polynomial-time reducible to it. Cook-Levin Theorem: SAT is NP-complete.

What would prove that P = NP? 1970s Stephen Cook and B. Leonid Showing Levin that there indepdendently are two distinct and NP-in parallel lay foundations of NP-completeness problems. Intuitively: if an NP-complete problem has a polynomial algorithm, then all NP problems are polynomail time solvable. A language B is NP-complete if it is in NP and every A in NP is polynomial-time reducible to it. Cook-Levin Theorem: SAT is NP-complete. Reductions to the rescue A. Showing that a problem solvable Sipser by p. 271,276 bruteforce methods has a nondeterministic solution. C. Finding a polynomial time solution for an NPcomplete problem. D. Proving that an NP-complete problem is not solvable in polynomial time. E. I don't know