Theory of Computer Science. Theory of Computer Science. E1.1 Motivation. E1.2 How to Measure Runtime? E1.3 Decision Problems. E1.

Similar documents
Theory of Computer Science

Theory of Computer Science. Theory of Computer Science. E2.1 P and NP. E2.2 Polynomial Reductions. E2.3 NP-Hardness and NP-Completeness. E2.

Theory of Computer Science. Theory of Computer Science. E4.1 Overview E4.2 3SAT. E4.3 Graph Problems. E4.4 Summary.

Theory of Computer Science. Theory of Computer Science. E2.1 P and NP. E2.2 Polynomial Reductions. E2.3 NP-Hardness and NP-Completeness. E2.

Theory of Computer Science

Theory of Computer Science. Theory of Computer Science. E5.1 Routing Problems. E5.2 Packing Problems. E5.3 Conclusion.

Theory of Computer Science

Theory of Computer Science

Theory of Computer Science. Theory of Computer Science. E3.1 Overview. E3.2 Cook-Levin Theorem E3.3 3SAT. E3.4 Summary. Further Reading (German)

Theory of Computer Science. Theory of Computer Science. D7.1 Introduction. D7.2 Turing Machines as Words. D7.3 Special Halting Problem

Theory of Computer Science

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

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

Theory of Computer Science. Theory of Computer Science. D8.1 Other Halting Problem Variants. D8.2 Rice s Theorem

CSE 105 THEORY OF COMPUTATION

P versus NP. Math 40210, Fall November 10, Math (Fall 2015) P versus NP November 10, / 9

Complexity (Pre Lecture)

NP-Completeness. NP-Completeness 1

Principles of Knowledge Representation and Reasoning

P versus NP. Math 40210, Spring September 16, Math (Spring 2012) P versus NP September 16, / 9

Theory of Computer Science. D5.1 Introduction. Theory of Computer Science. D5.2 Primitive Recursion vs. LOOP. D5.3 µ-recursion vs.

P vs. NP. Data Structures and Algorithms CSE AU 1

Turing Machines and Time Complexity

CMPT307: Complexity Classes: P and N P Week 13-1

The P-vs-NP problem. Andrés E. Caicedo. September 10, 2011

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

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?

Data Structures in Java

Theoretical computer science: Turing machines

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 Theory. Knowledge Representation and Reasoning. November 2, 2005

CMSC 441: Algorithms. NP Completeness

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

NP-Completeness. NP-Completeness 1

P, NP, NP-Complete. Ruth Anderson

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

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

Complexity Theory Part II

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

Computer Sciences Department

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

Lecture 14 - P v.s. NP 1

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

6-1 Computational Complexity

Design and Analysis of Algorithms

1 Computational Problems

The Complexity Classes P and NP. Andreas Klappenecker [partially based on slides by Professor Welch]

Advanced topic: Space complexity

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm

Lecture 6: Oracle TMs, Diagonalization Limits, Space Complexity

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

Notes for Lecture Notes 2

Theory of Computation

Essential facts about NP-completeness:

COP 4531 Complexity & Analysis of Data Structures & Algorithms

: Computational Complexity Lecture 3 ITCS, Tsinghua Univesity, Fall October 2007

Artificial Intelligence. 3 Problem Complexity. Prof. Dr. Jana Koehler Fall 2016 HSLU - JK

NP-Completeness and Boolean Satisfiability

NP Completeness and Approximation Algorithms

Computational complexity

Lecture 3: Nondeterminism, NP, and NP-completeness

Introduction to Complexity Theory

CSE 105 THEORY OF COMPUTATION

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

NP-Completeness Part II

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

COMPUTATIONAL COMPLEXITY

Foundations of Artificial Intelligence

Computational complexity theory

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

M. Smith. 6 September 2016 / GSAC

Class Note #20. In today s class, the following four concepts were introduced: decision

Complexity Theory Part I

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

A An Overview of Complexity Theory for the Algorithm Designer

CS 301. Lecture 17 Church Turing thesis. Stephen Checkoway. March 19, 2018

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

Correctness of Dijkstra s algorithm

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

Intractable Problems [HMU06,Chp.10a]

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

Topics in Complexity Theory

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Lecture Notes 4. Issued 8 March 2018

CS154, Lecture 13: P vs NP

Decidability and Undecidability

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

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

NP-Complete Problems. More reductions

Theory of Computation Chapter 1: Introduction

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

Computational Models Lecture 11, Spring 2009

Computational complexity theory

Limitations of Algorithm Power

Analysis of Algorithms. Unit 5 - Intractable Problems

Complexity and NP-completeness

CS6901: review of Theory of Computation and Algorithms

Show that the following problems are NP-complete

NP-Completeness. Subhash Suri. May 15, 2018

Transcription:

Theory of Computer Science May 18, 2016 E1. Complexity Theory: Motivation and Introduction Theory of Computer Science E1. Complexity Theory: Motivation and Introduction Malte Helmert University of Basel May 18, 2016 E1.1 Motivation E1.2 How to Measure Runtime? E1.3 Decision Problems E1.4 Nondeterminism E1.5 Summary M. Helmert (Univ. Basel) Theorie May 18, 2016 1 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 2 / 40 Overview: Course Overview: Complexity Theory contents of this course: logic How can knowledge be represented? How can reasoning be automated? automata theory and formal languages What is a computation? computability theory What can be computed at all? complexity theory What can be computed efficiently? Complexity Theory E1. Motivation and Introduction E2. P, NP and Polynomial Reductions E3. Cook-Levin Theorem E4. Some NP-Complete Problems, Part I E5. Some NP-Complete Problems, Part II M. Helmert (Univ. Basel) Theorie May 18, 2016 3 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 4 / 40

Further Reading (German) Further Reading (English) Literature for this Chapter (German) Literature for this Chapter (English) Theoretische Informatik kurz gefasst by Uwe Schöning (5th edition) Chapter 3.1 Introduction to the Theory of Computation by Michael Sipser (3rd edition) Chapter 7.1 M. Helmert (Univ. Basel) Theorie May 18, 2016 5 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 6 / 40 A Scenario (1) E1.1 Motivation Example Scenario You are a programmer at a logistics company. Your boss gives you the task of developing a program to optimize the route of a delivery truck: The truck begins its route at the company depot. It has to visit 50 stops. You know the distances between all relevant locations (stops and depot). Your program should compute a tour visiting all stops and returning to the depot on a shortest route. M. Helmert (Univ. Basel) Theorie May 18, 2016 7 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 8 / 40

A Scenario (2) What You Don t Want to Say Example Scenario (ctd.) You work on the problem for weeks, but you do not manage to complete the task. All of your attempted programs compute routes that are possibly suboptimal, or do not terminate in reasonable time (say: within a month). What do you say to your boss? I can t find an efficient algorithm, I guess I m just too dumb. Source: M. Garey & D. Johnson, Computers and Intractability, Freeman 1979, p. 2 M. Helmert (Univ. Basel) Theorie May 18, 2016 9 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 10 / 40 What You Would Like to Say What Complexity Theory Allows You to Say I can t find an efficient algorithm, because no such algorithm is possible! I can t find an efficient algorithm, but neither can all these famous people. Source: M. Garey & D. Johnson, Computers and Intractability, Freeman 1979, p. 2 Source: M. Garey & D. Johnson, Computers and Intractability, Freeman 1979, p. 3 M. Helmert (Univ. Basel) Theorie May 18, 2016 11 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 12 / 40

Why Complexity Theory? Why Reductions? Complexity Theory Complexity theory tells us which problems can be solved quickly ( simple problems ) and which ones cannot ( hard problems ). German: Komplexitätstheorie This is useful in practice because simple and hard problems require different techniques to solve. If we can show that a problem is hard we do not need to waste our time with the (futile) search for a simple algorithm. Reductions An important part of complexity theory are (polynomial) reductions that show how a given problem P can be reduced to another problem Q. German: Reduktionen useful for theoretical analysis of P and Q because it allows us to transfer our knowledge between them often also useful for practical algorithms for P: reduce P to Q and then use the best known algorithm for Q M. Helmert (Univ. Basel) Theorie May 18, 2016 13 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 14 / 40 Test Your Intuition! (1) Test Your Intuition! (2) The following slide lists some graph problems. The input is always a directed graph G = V, E. How difficult are the problems in your opinion? Sort the problems from easiest (= requires least amount of time to solve) to hardest (= requires most time to solve) no justification necessary, just follow your intuition! anonymous and not graded 1 Find a simple path (= without cycle) from u V to v V with minimal length. 2 Find a simple path (= without cycle) from u V to v V with maximal length. 3 Determine whether G is strongly connected (every node is reachable from every other node). 4 Find a cycle (non-empty path from u to u for any u V ; multiple visits of nodes are allowed). 5 Find a cycle that visits all nodes. 6 Find a cycle that visits a given node u. 7 Find a path that visits all nodes without repeating a node. 8 Find a path that uses all edges without repeating an edge. M. Helmert (Univ. Basel) Theorie May 18, 2016 15 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 16 / 40

How to Measure Runtime? E1.2 How to Measure Runtime? Time complexity is a way to measure how much time it takes to solve a problem. How can we define such a measure appropriately? German: Zeitkomplexität/Zeitaufwand M. Helmert (Univ. Basel) Theorie May 18, 2016 17 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 18 / 40 Example Statements about Runtime Precise Statements vs. General Statements Example statements about runtime: Running sort /usr/share/dict/words on the computer dakar takes 0.105 seconds. With a 1 MiB input file, sort takes at most 1 second on a modern computer. Quicksort is faster than sorting by insertion. Sorting by insertion is slow. Very different statements with different pros and cons. Example Statement about Runtime Running sort /usr/share/dict/words on the computer dakar takes 0.105 seconds. advantage: very precise disadvantage: not general input-specific: What if we want to sort other files? machine-specific: What happens on a different computer? even situation-specific: Will we get the same result tomorrow that we got today? M. Helmert (Univ. Basel) Theorie May 18, 2016 19 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 20 / 40

General Statements about Runtime General Statements about Runtime In this course we want to make general statements about runtime. We accomplish this in three ways: In this course we want to make general statements about runtime. We accomplish this in three ways: 1. General Inputs Instead of concrete inputs, we talk about general types of input: Example: runtime to sort an input of size n in the worst case Example: runtime to sort an input of size n in the average case here: runtime for input size n in the worst case 2. Ignoring Details Instead of exact formulas for the runtime we specify the order of magnitude: Example: instead of saying that we need time 1.2n log n 4n + 100, we say that we need time O(n log n). Example: instead of saying that we need time O(n log n), O(n 2 ) or O(n 4 ), we say that we need polynomial time. here: What can be computed in polynomial time? M. Helmert (Univ. Basel) Theorie May 18, 2016 21 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 22 / 40 General Statements about Runtime E1. Complexity Theory: Motivation and Introduction Decision Problems In this course we want to make general statements about runtime. We accomplish this in three ways: 3. Abstract Cost Measures Instead of the runtime on a concrete computer we consider a more abstract cost measure: Example: count the number of executed machine code statements Example: count the number of executed Java byte code statements Example: count the number of element comparisons of a sorting algorithms here: count the computation steps of a Turing machine (polynomially equivalent to other measures) E1.3 Decision Problems M. Helmert (Univ. Basel) Theorie May 18, 2016 23 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 24 / 40

E1. Complexity Theory: Motivation and Introduction Decision Problems Decision Problems E1. Complexity Theory: Motivation and Introduction Decision Problems Example: Decision vs. General Problem (1) As before, we simplify our investigation by restricting our attention to decision problems. More complex computational problems can be solved with multiple queries for an appropriately defined decision problem ( playing 20 questions ). Formally, decision problems are languages (as before), but we use an informal given / question notation where possible. Definition (Hamilton Cycle) Let G = V, E be a (directed or undirected) graph. A Hamilton cycle of G is a sequence of vertices in V, π = v 0,..., v n, with the following properties: π is a path: there is an edge from v i to v i+1 for all 0 i < n π is a cycle: v 0 = v n π is simple: v i v j for all i j with i, j < n π is Hamiltonian: all nodes of V are included in π German: Hamiltonkreis/Hamiltonzyklus M. Helmert (Univ. Basel) Theorie May 18, 2016 25 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 26 / 40 E1. Complexity Theory: Motivation and Introduction Decision Problems Example: Decision vs. General Problem (2) E1. Complexity Theory: Motivation and Introduction Decision Problems Algorithms for Decision Problems Example (Hamilton Cycles in Directed Graphs) P: general problem DirHamiltonCycleGen Input: directed graph G = V, E Output: a Hamilton cycle of G or a message that none exists E: decision problem DirHamiltonCycle Given: directed graph G = V, E Question: Does G contain a Hamilton cycle? These problems are polynomially equivalent: from a polynomial algorithm for one of the problems one can construct a polynomial algorithm for the other problem. (Without proof.) Algorithms for decision problems: Where possible, we specify algorithms for decision problems in pseudo-code (similar to WHILE programs). Since they are only yes/no questions, we do not have to return a general result. Instead we use the statements ACCEPT to accept the given input ( yes answer) and REJECT to reject it ( no answer). Where we must be more formal, we use Turing machines and the notion of accepting from chapter C7. M. Helmert (Univ. Basel) Theorie May 18, 2016 27 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 28 / 40

Nondeterminism E1.4 Nondeterminism To develop complexity theory, we need the algorithmic concept of nondeterminism. already known for Turing machines ( chapter C7): An NTM can have more than one possible successor configuration for a given configuration. Input x is accepted if there is at least one possible computation (configuration sequence) that leads to an end state. Here we analogously introduce nondeterminism for pseudo-code (or WHILE programs). German: Nichtdeterminismus M. Helmert (Univ. Basel) Theorie May 18, 2016 29 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 30 / 40 Nondeterministic Algorithms Nondeterministic Algorithms: Acceptance nondeterministic algorithms: All constructs of deterministic algorithms are also allowed in nondeterministic algorithms: IF, WHILE, etc. Additionally, there is a nondeterministic assignment: GUESS x i {0, 1} where x i is a program variable. German: nichtdeterministische Zuweisung Meaning of GUESS x i {0, 1}: x i is assigned either the value 0 or the value 1. This implies that the behavior of the program on a given input is no longer uniquely defined: there are multiple possible execution paths. The program accepts a given input if at least one execution path leads to an ACCEPT statement. Otherwise, the input is rejected. Note: asymmetry between accepting and rejecting! (cf. semi-decidability) M. Helmert (Univ. Basel) Theorie May 18, 2016 31 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 32 / 40

More Complex GUESS Statements Example: Nondeterministic Algorithms (1) We will also guess more than one bit at a time: GUESS x {1, 2,..., n} or more generally GUESS x S for a set S. These are abbreviations and can be split into log 2 n (or log 2 S ) atomic GUESS statements. Example (DirHamiltonCycle) input: directed graph G = V, E start := an arbitrary node from V current := start remaining := V \ {start} WHILE remaining : GUESS next remaining IF current, next / E: REJECT remaining := remaining \ {next} current := next IF current, start E: ACCEPT M. Helmert (Univ. Basel) Theorie May 18, 2016 33 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 34 / 40 Example: Nondeterministic Algorithms (2) Guess and Check With appropriate data structures, this algorithm solves the problem in O(n log n) program steps, where n = V + E is the size of the input. How many steps would a deterministic algorithm need? The DirHamiltonCycle example illustrates a general design principle for nondeterministic algorithms: guess and check In general, nondeterministic algorithms can solve a problem by first guessing a solution and then verifying that it is indeed a solution. (In the example, these two steps are interleaved.) If solutions to a problem can be efficiently verified, then the problem can also be efficiently solved if nondeterminism may be used. German: Raten und Prüfen M. Helmert (Univ. Basel) Theorie May 18, 2016 35 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 36 / 40

The Power of Nondeterminism E1. Complexity Theory: Motivation and Introduction Summary Nondeterministic algorithms are very powerful because they can guess the correct computation step. Or, interpreted differently: they go through many possible computations in parallel, and it suffices if one of them is successful. Can they solve problems efficiently (in polynomial time) which deterministic algorithms cannot solve efficiently? This is the big question! E1.5 Summary M. Helmert (Univ. Basel) Theorie May 18, 2016 37 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 38 / 40 E1. Complexity Theory: Motivation and Introduction Summary Summary (1) E1. Complexity Theory: Motivation and Introduction Summary Summary (2) Complexity theory deals with the question which problems can be solved efficiently and which ones cannot. here: focus on what can be computed in polynomial time To formalize this, we use Turing machines, but other formalisms are polynomially equivalent. We consider decision problems, but the results directly transfer to general computational problems. important concept: nondeterminism Nondeterministic algorithms can guess, i. e., perform multiple computations at the same time. An input receives a yes answer if at least one computation path accepts it. in NTMs: with nondeterministic transitions (δ(q, a) contains multiple elements) in pseudo-code: with GUESS statements M. Helmert (Univ. Basel) Theorie May 18, 2016 39 / 40 M. Helmert (Univ. Basel) Theorie May 18, 2016 40 / 40