Automata Theory CS Complexity Theory I: Polynomial Time

Similar documents
Graduate Algorithms CS F-21 NP & Approximation Algorithms

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

NP Completeness and Approximation Algorithms

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

Limitations of Algorithm Power

Automata Theory CS S-18 Complexity Theory II: Class NP

Polynomial-Time Reductions

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

Computational Intractability 2010/4/15. Lecture 2

Introduction to Complexity Theory

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

NP Complete Problems. COMP 215 Lecture 20

Design and Analysis of Algorithms

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

NP-Completeness. ch34 Hewett. Problem. Tractable Intractable Non-computable computationally infeasible super poly-time alg. sol. E.g.

SAT, Coloring, Hamiltonian Cycle, TSP

NP and Computational Intractability

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 22 Lecturer: David Wagner April 24, Notes 22 for CS 170

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

NP and Computational Intractability

NP-Completeness. Subhash Suri. May 15, 2018

Intro to Theory of Computation

Tractability. Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time?

NP-completeness. Chapter 34. Sergey Bereg

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

Data Structures and Algorithms

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

CMSC 441: Algorithms. NP Completeness

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

COP 4531 Complexity & Analysis of Data Structures & Algorithms

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Show that the following problems are NP-complete

Essential facts about NP-completeness:

NP-Completeness and Boolean Satisfiability

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Lecture 4: NP and computational intractability

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

4/12/2011. Chapter 8. NP and Computational Intractability. Directed Hamiltonian Cycle. Traveling Salesman Problem. Directed Hamiltonian Cycle

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

Lecture #14: NP-Completeness (Chapter 34 Old Edition Chapter 36) Discussion here is from the old edition.

NP-Complete Problems. More reductions

NP-Complete Reductions 2

NP-Completeness. NP-Completeness 1

CS 5114: Theory of Algorithms

More NP-Complete Problems

Admin NP-COMPLETE PROBLEMS. Run-time analysis. Tractable vs. intractable problems 5/2/13. What is a tractable problem?

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Spring Lecture 21 NP-Complete Problems

Data Structures in Java

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

CS 350 Algorithms and Complexity

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness

P, NP, NP-Complete. Ruth Anderson

8.5 Sequencing Problems

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

Lecture 15 - NP Completeness 1

NP-Complete problems

Algorithms Design & Analysis. Approximation Algorithm

Theory of Computation Time Complexity

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

NP-Completeness. Until now we have been designing algorithms for specific problems

CSCI3390-Lecture 17: A sampler of NP-complete problems

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

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

Limits to Approximability: When Algorithms Won't Help You. Note: Contents of today s lecture won t be on the exam

SAT, NP, NP-Completeness

Introduction. Pvs.NPExample

NP-Complete Problems. Complexity Class P. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

Algorithm Design and Analysis

1. Introduction Recap

Tecniche di Verifica. Introduction to Propositional Logic

CS 350 Algorithms and Complexity

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35.

3130CIT Theory of Computation

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?

Polynomial-time Reductions

BBM402-Lecture 11: The Class NP

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

NP-Complete Reductions 1

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Computability and Complexity Theory: An Introduction

Algorithms: COMP3121/3821/9101/9801

Lecture 18: P & NP. Revised, May 1, CLRS, pp

Boolean circuits. Lecture Definitions

Computability and Complexity Theory

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

CS311 Computational Structures. NP-completeness. Lecture 18. Andrew P. Black Andrew Tolmach. Thursday, 2 December 2010

CS21 Decidability and Tractability

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

CSCI3390-Second Test with Solutions

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

1 Computational problems

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

The Cook-Levin Theorem

CS/COE

COMP Analysis of Algorithms & Data Structures

Transcription:

Automata Theory CS411-2015-17 Complexity Theory I: Polynomial Time David Galles Department of Computer Science University of San Francisco

17-0: Tractable vs. Intractable If a problem is recursive, then there exists a Turing machine that always halts, and solves it. However, a recursive problem may not be practically solvable Problem that takes an exponential amount of time to solve is not practically solvable for large problem sizes Today, we will focus on problems that are practically solvable

17-1: Language Class P A language L is polynomially decidable if there exists a polynomially bound Turing machine that decides it. A Turing Machine M is polynomially bound if: There exists some polynomial function p(n) For any input string w, M always halts within p( w ) steps The set of languages that are polynomially decidable is P

17-2: Language Class P P is the set of languages that can reasonably be decided by a computer What about n 100, or 10 100000 n 2 Can these running times really be reasonably solvable What about n loglogn Not bound by any polynomial, but grows very slowly until n gets quite large

17-3: Language Class P P is the set of languages/problems that can reasonably be solved by a computer What about n 100, or 10 100000 n 2 Problems that have these kinds of running times are quite rare Even a huge polynomial has a chance at being solvable for large problems if you throw enough machines at it unlike exponential problems, where there is pretty much no hope for solving large problems

17-4: Reachability Given a Graph G, and two vertices x and y, is there a path from x to y in G? Note that this is a Problem and not a Language, though we can easily convert it into a language as follows: L reachable = {w : w = en(g)en(x)en(y), there is a path from x to y in G} Can encode G: Numbering all of the vertices Give an adjacency matrix, using binary encoding of each vertex

17-5: Reachability Let A[] be the adjacency matrix A[i,j] = 1 if link from v i to v j for (i=0; i< V ; i++) { A[i,i] = 1; for (i=0; i < V ; i++) for (j=0; j < V ; j++) for (k=0; k < V ; k++) if (A[i,j] && A[j,k]) A[i,k] = 1; }

17-6: Java/C vs. Turing Machine But wait... that s Java/C code, not a Turing Machine! If a C program can execute in n steps, then we can simulate the C program with a Turing Machine that takes at most p(n) steps, for some polynomial function p. We will use Java/C style pseudo-code for many of the following problems

17-7: Euler Cycles Given an undirected graph G, is there a cycle that traverses every edge exactly once?

17-8: Euler Cycles Given an undirected graph G, is there a cycle that traverses every edge exactly once? 3 2 4 6 5 9 7 8 10 1 11 13 12

17-9: Euler Cycles We can determine if a graph G has an Euler cycle in polynomial time. A graph G has an Euler cycle if and only if: G is connected All vertices in G have an even # of adjacent edges

17-10: Euler Cycles Pick any vertex, start following edges (only following an edge once) until you reach a dead end (no untraversed edges from the current node). Must be back at the node you started with Why? Pick a new node with untraversed edges, create a new cycle, and splice it in Repeat until all edges have been traversed

17-11: Hamiltonian Cycles Given an undirected graph G, is there a cycle that visits every vertex exactly once?

17-12: Hamiltonian Cycles Given an undirected graph G, is there a cycle that visits every vertex exactly once?

17-13: Hamiltonian Cycles Given an undirected graph G, is there a cycle that visits every vertex exactly once? Very similar to the Euler Cycle problem No known polynomial-time solution

17-14: Traveling Salesman Given an undirected, completely connected graph G with weighted edges, what is the minimal length circuit that connects all of the vertices? 6 4 4 3 7 9 2 1 7 5

17-15: Traveling Salesman Given an undirected, completely connected graph G with weighted edges, what is the minimal length circuit that connects all of the vertices? 6 4 Path Cost:18 4 3 7 9 2 1 7 5

17-16: Decision vs. Optimization A Decision Problem has a yes/no answer Is there a path from vertex i to vertex j in graph G? Is there an Euler cycle in graph G? Is there a Hamiltonian cycle in graph G? An Optimization Problem tries to find an optimal solution, from a choice of several potential solutions What is the cheaptest cycle in a weigted graph?

17-17: Decision vs. Optimization Given an undirected, completely connected graph G with weighted edges, what is the minimal length circuit that connects all of the vertices? This is an optimization problem, and not a decision problem We can easily convert it into a decision problem: Given a weighted, undirected graph G, is there a cycle with cost no greater than k?

17-18: Decision vs. Optimization For every optimization problem Find the lowest cost solution to a problem We can create a similar decision problem Is there a solution under cost k?

17-19: Decision vs. Optimization If we can solve the optimization version of a problem in polynomial time, we can solve the decision version of the same problem in polynomial time. Find the optimal solution, check to see if it is under the limit If we can solve the decision version of the problem, we can solve the optimization version of the same problem Modified binary search

17-20: Integer Partition Set S of non-negative numbers {a 1...a n } Is there a set P {1,2,...n} such that a i = a i i P i P Can we partition the set into two subsets, each of which has the same sum?

17-21: Integer Partition S = {3,5,7,10,15,20} Can break S into: {3,5,7,15} {10, 20}

17-22: Integer Partition S = {1,4,9,10,15,27} No valid partiton Sum of all numbers is 66 Each partition needs to sum to 34 (why?) No subset of S sums to 34

17-23: Solving Integer Partition H = sum of all integers in S divided by 2 B(i) = {b H : b is the sum of some subset of a 1...a i } a 1 = 5,a 2 = 20,a 3 = 17,a 4 = 30,H = 36 B(0) = {0} B(1) = {0,5} B(2) = {0,5,20,25} B(3) = {0,5,17,20,22,25} B(4) = {0,5,17,20,22,25,30,35} Partition iff H B(n)

17-24: Solving Integer Partition Computing B(n) (inefficient): B(0) = {0} for (i = 1;i <= n;i++) B(i) = B(i 1) for (j = i;j < H;j ++) if (j a i ) B(i 1) add j to B(i) (copy) (How might we make this more efficient?)

17-25: Solving Integer Partition Computing B(n) (inefficient): B(0) = {0} for (i = 1;i <= n;i++) B(i) = B(i 1) for (j = i;j < H;j ++) if (j a i ) B(i 1) add j to B(i) (copy) Running time: O(nH). Polynomial?

17-26: Solving Integer Partition Running time: O(nH). Not polynomial. n integers of size 2 n n integers, each of which has n digits H n 2 2n Length of input n 2 Not the most efficient algorithm to solve the problem All known solutions require exponential time, however

17-27: Unary Integer Partition Given a set S of non-negative numbers {a 1...a n }, encoded in unary Is there a set P {1,2,...n} such that a i = a i i P i P This problem can be solved in Polynomial time In fact, the previous algorithm will solve the problem in polynomial time! How can this be?

17-28: Unary Integer Partition Given a set S of non-negative numbers {a 1...a n }, encoded in unary Is there a set P {1,2,...n} such that a i = a i i P i P This problem can be solved in Polynomial time We ve made the problem description exponentially longer In general, it doesn t matter how you encode a problem as long as you don t use unary to encode numbers!

17-29: Satisfiability A Boolean Formula in Conjunctive Normal Form (CNF) is a conjunction of disjunctions. (x 1 x 2 ) (x 3 x 2 x 1 ) (x 5 ) (x 3 x 1 x 5 ) (x 1 x 5 x 3 ) (x 5 ) A Clause is a group of variables x i (or negated variables x j ) connected by ORs ( ) A Formula is a group of clauses, connected by ANDs ( )

17-30: Satisfiability Satisfiability Problem: Given a formula in Conjunctive Normal Form, is there a set of truth values for the variables in the formula which makes the formula true? (x 1 x 4 ) (x 2 x 4 ) (x 3 x 2 ) (x 1 x 4 ) (x 2 x 3 ) (x 2 x 4 ) Satisfiable: x 1 = T, x 2 = F, x 3 = T, x 4 = F (x 1 x 2 ) (x 1 x 2 ) (x 1 x 2 ) (x 1 x 2 ) Not Satisfiable

17-31: 2-SAT 2-SAT is a special case of the satisfiability problem, where each clause has no more than 2 variables. Both of the following problems are instances of 2-SAT (x 1 x 4 ) (x 2 x 4 ) (x 3 x 2 ) (x 1 x 4 ) (x 2 x 3 ) (x 2 x 4 ) (x 1 x 2 ) (x 1 x 2 ) (x 1 x 2 ) (x 1 x 2 )

17-32: 2-SAT 2-SAT is in P given an instance of 2-SAT, we can determine if the formula is satisfiable in polynomial time If a variable x i is true: Every clause that contains x i is true. For every clause of the form (x i x j ), variable x j must be true. For every clause of the form (x i x j ), variable x j must be false.

17-33: 2-SAT 2-SAT is in P given an instance of 2-SAT, we can determine if the formula is satisfiable in polynomial time If a variable x i is false: Every clause that contains x i is true. For every clause of the form (x i x j ), variable x j must be true. For every clause of the form (x i x j ), variable x j must be false. Once we know the truth value of a single variable, we can use this information to find the truth value of many other variables

17-34: 2-SAT (x 1 x 4 ) (x 2 x 4 ) (x 3 x 2 ) (x 1 x 4 ) (x 2 x 3 ) (x 2 x 4 ) If x 1 is true...

17-35: 2-SAT (x 1 x 4 ) (x 2 x 4 ) (x 3 x 2 ) (x 1 x 4 ) (x 2 x 3 ) (x 2 x 4 ) If x 1 is true...

17-36: 2-SAT (x 2 x 4 ) (x 3 x 2 ) (x 4 ) (x 2 x 3 ) (x 2 x 4 ) If x 1 is true Then x 4 must be false...

17-37: 2-SAT (x 2 x 4 ) (x 3 x 2 ) (x 4 ) (x 2 x 3 ) (x 2 x 4 ) If x 1 is true Then x 4 must be false...

17-38: 2-SAT (x 2 ) (x 3 x 2 ) (x 2 x 3 ) If x 1 is true Then x 4 must be false Then x 2 must be false...

17-39: 2-SAT (x 2 ) (x 3 x 2 ) (x 2 x 3 ) If x 1 is true Then x 4 must be false Then x 2 must be false...

17-40: 2-SAT (x 3 ) If x 1 is true Then x 4 must be false Then x 2 must be false Then x 3 must be true...

17-41: 2-SAT (x 3 ) If x 1 is true Then x 4 must be false Then x 2 must be false Then x 3 must be true And the formula is satisfiable

17-42: Algorithm to solve 2-SAT Pick any variable x i. Set it to true Modify the formula, based on x i being true: Remove any clause that contains x i For any clause of the form (x i,x j ), Variable x j must be true. Recursively modify the formula based on x j being true. For any clause of the form (x i,x j ), Variable x j must be false. Recursively modify the formula based on x j being false.

17-43: Algorithm to solve 2-SAT Pick any variable x i. Set it to true Modify the formula, based on x i being true: When you are done with the modification, one of 3 cases may occur: All of the variables are set to some value, and the formula is thus satisfiable Several of the clauses have been removed, leaving you with a smaller problem. Pick another variable and repeat The choice of True for x i leads to a contradiction: some variable x j must be both true and false. In this case, restore the old formula, set x i to false, and repeat

17-44: Algorithm to solve 2-SAT Example: (x 1 x 3 ) (x 2 x 3 ) (x 2 x 3 ) (x 1 x 4 ) (x 1 x 2 ) First, we pick x 1, set it to true...

17-45: Algorithm to solve 2-SAT Example: (x 1 x 3 ) (x 2 x 3 ) (x 2 x 3 ) (x 1 x 4 ) (x 1 x 2 ) First, we pick x 1, set it to true Which means than x 4 must be true...

17-46: Algorithm to solve 2-SAT Example: (x 1 x 3 ) (x 2 x 3 ) (x 2 x 3 ) (x 1 x 4 ) (x 1 x 2 ) First, we pick x 1, set it to true Which means than x 4 must be true... And we have a smaller problem.

17-47: Algorithm to solve 2-SAT Example: (x 2 x 3 ) (x 2 x 3 ) First, we pick x 1, set it to true Which means than x 4 must be true And we have a smaller problem. Next, pick x 2, set it to true...

17-48: Algorithm to solve 2-SAT Example: (x 2 x 3 ) (x 2 x 3 ) First, we pick x 1, set it to true Which means than x 4 must be true And we have a smaller problem. Next, pick x 2, set it to true...

17-49: Algorithm to solve 2-SAT Example: (x 2 x 3 ) (x 2 x 3 ) First, we pick x 1, set it to true Which means than x 4 must be true And we have a smaller problem. Next, pick x 2, set it to true and x 3 must be both true and false. Whoops!

17-50: Algorithm to solve 2-SAT Example: (x 2 x 3 ) (x 2 x 3 ) First, we pick x 1, set it to true Which means than x 4 must be true And we have a smaller problem. Next, pick x 2, set it to true and x 3 must be both true and false. Back up, set x 2 to false...

17-51: Algorithm to solve 2-SAT Example: (x 2 x 3 ) (x 2 x 3 ) First, we pick x 1, set it to true Which means than x 4 must be true And we have a smaller problem. Next, pick x 2, set it to true and x 3 must be both true and false. Back up, set x 2 to false And all clauses are satisfied (value of x 3 doesn t matter)

17-52: Algorithm to solve 2-SAT Example: (x 1 x 2 ) (x 1 x 2 ) (x 3 x 4 ) (x 3 x 4 ) (x 1 x 3 ) First, we pick x 1, and set it to true

17-53: Algorithm to solve 2-SAT Example: (x 1 x 2 ) (x 1 x 2 ) (x 3 x 4 ) (x 3 x 4 ) (x 1 x 3 ) First, we pick x 1, and set it to true And x 2 must be both true and false. Back up...

17-54: Algorithm to solve 2-SAT Example: (x 1 x 2 ) (x 1 x 2 ) (x 3 x 4 ) (x 3 x 4 ) (x 1 x 3 ) First, we pick x 1, and set it to true And x 2 must be both true and false. Back up And set x 1 to be false...

17-55: Algorithm to solve 2-SAT Example: (x 1 x 2 ) (x 1 x 2 ) (x 3 x 4 ) (x 3 x 4 ) (x 1 x 3 ) First, we pick x 1, and set it to true And x 2 must be both true and false. Back up And set x 1 to be false And x 3 must be true...

17-56: Algorithm to solve 2-SAT Example: (x 1 x 2 ) (x 1 x 2 ) (x 3 x 4 ) (x 3 x 4 ) (x 1 x 3 ) First, we pick x 1, and set it to true And x 2 must be both true and false. Back up And set x 1 to be false And x 3 must be true And x 4 must be both true and false. No solution

17-57: Algorithm to solve 2-SAT Once we ve decided to set a variable to true or false, the marking off phase takes a polynomial number of steps Each variable will be chosen to be set to true no more than once, and chosen to be set to false no more than once more than once Total running time is polynomial

17-58: 3-SAT 3-SAT is a special case of the satisfiability problem, where each clause has no more than 3 variables. 3-SAT has no known polynomial solution Can t really do any better than trying all possible truth assignments to all variables, and see if they work.