Lecture 22 Complexity and Reductions

Slides:



Advertisements
Similar presentations
NP-Hard Nattee Niparnan.
Advertisements

Reducibility Class of problems A can be reduced to the class of problems B Take any instance of problem A Show how you can construct an instance of problem.
What is Intractable? Some problems seem too hard to solve efficiently. Question 1: Does an efficient algorithm exist?  An O(a ) algorithm, where a > 1,
1 NP-completeness Lecture 2: Jan P The class of problems that can be solved in polynomial time. e.g. gcd, shortest path, prime, etc. There are many.
CPE702 Complexity Classes Pruet Boonma Department of Computer Engineering Chiang Mai University Based on Material by Jenny Walter.
Great Theoretical Ideas in Computer Science for Some.
Computability and Complexity 13-1 Computability and Complexity Andrei Bulatov The Class NP.
Computational problems, algorithms, runtime, hardness
The Theory of NP-Completeness
Chapter 11: Limitations of Algorithmic Power
Hardness Results for Problems
Programming & Data Structures
MCS312: NP-completeness and Approximation Algorithms
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
CSC 413/513: Intro to Algorithms NP Completeness.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
CSE373: Data Structures & Algorithms Lecture 22: The P vs. NP question, NP-Completeness Lauren Milne Summer 2015.
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness and course wrap up.
Lecture 6 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 29.
CPS Computational problems, algorithms, runtime, hardness (a ridiculously brief introduction to theoretical computer science) Vincent Conitzer.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
Lecture 25 NP Class. P = ? NP = ? PSPACE They are central problems in computational complexity.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 30, 2014.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Introduction to NP Instructor: Neelima Gupta 1.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Great Theoretical Ideas in Computer Science.
The Theory of NP-Completeness
The NP class. NP-completeness
NP-Complete Problems.
P & NP.
Chapter 10 NP-Complete Problems.
Computational Complexity Theory
Computational problems, algorithms, runtime, hardness
Richard Anderson Lecture 26 NP-Completeness
Lecture 2-2 NP Class.
Great Theoretical Ideas in Computer Science
Part VI NP-Hardness.
Richard Anderson Lecture 29 NP-Completeness and course wrap-up
Lecture 22 Complexity and Reductions
Lecture 5 Dynamic Programming
Lecture 5 NP Class.
NP-Completeness Yin Tat Lee
Analysis and design of algorithm
ICS 353: Design and Analysis of Algorithms
Intro to NP Completeness
Parameterised Complexity
Richard Anderson Lecture 25 NP-Completeness
Chapter 8 NP and Computational Intractability
Linear Programming Duality, Reductions, and Bipartite Matching
1. for (i=0; i < n; i+=2) if (A[i] > A[i+1]) swap(A[i], A[i+1])
Richard Anderson Lecture 30 NP-Completeness
Chapter 11 Limitations of Algorithm Power
Chapter 34: NP-Completeness
NP-completeness The Chinese University of Hong Kong Fall 2008
CPS 173 Computational problems, algorithms, runtime, hardness
CS 3343: Analysis of Algorithms
NP-Completeness Yin Tat Lee
Instructor: Aaron Roth
Lecture 24 Classical NP-hard Problems
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
Our old list of problems
RAIK 283 Data Structures & Algorithms
ADVANCED COMPUTATIONAL MODELS AND ALGORITHMS
Lecture 23 NP-Hard Problems
Presentation transcript:

Lecture 22 Complexity and Reductions

Outline How do we compare complexity of problems? Why do we care about complexity Naïve comparisons Reductions Easy problems and Hard problems, P and NP Definitions: P and NP Examples of NP problems Polynomial time reductions.

Recap Algorithms: Design Ideas: Graph Algorithms Linear Program Divide and Conquer Dynamic Programming Greedy Graph Algorithms Shortest Path Minimum Spanning Tree Matching Linear Program

Limitation of Algorithms? Question: What problems are easier to solve using algorithms, what problems cannot be solved using efficient algorithms? I cannot find a fast algorithm for this problem. This problem does not have a fast algorithm.

Comparing problems Question: For two problems A and B, how do we know A is simpler than B? Idea: Best algorithm for A is faster than best algorithm for B. How can we know this even if we don’t know how the best algorithm for A or B?

Idea 1: Special cases If A is a special case of B, then A is simpler than B. Example: A: Shortest path on graphs with no negative edge. B: Shortest path on graphs with general edge weight. Example 2: A: Linear Program in canonical form. B: A general linear program. Problem: cannot compare two problems that are not directly related Also hard to tell whether A is slightly simpler or much simpler.

Idea 2: Similarity in Problem Statement Conjecture: If problems A and B have similar problem statements, they also have similar difficulty. Not true! Example: A: Given graph G with positive edge weights, find the shortest path from s to t that has no duplicate vertex. B: Given graph G with positive edge weights, find the longest path from s to t that has no duplicate vertex. Example 2: A: Color vertices graph with 2 colors, such that all edges connect two vertices of different colors. B: Color vertices graph with 3 colors, such that all edges connect two vertices of different colors.

Reductions A general way of comparing the difficulty of two problems. A can be “reduced to” B, if given a solution to problem B, we can also solve problem A. “Solution to B”: Think of as a magical function that is already implemented, given input to problem B, can return the correct answer.

Reduction Examples A: Find the median of an array. B: Sort an array. A can be reduced to B, because we can first sort the array, and then return the middle element. Runtime of A ≤ Runtime of B + Time of Reduction. Median(X) { Sort(X); return X[(X.length+1)/2]; }

Reduction Examples A: Longest increasing subsequence. B: Longest common subsequence. A can be reduced to B, because given a sequence X[], we can first sort it to get Y[] then the LIS of X[] is equal to the LCS of X[] and Y[]. Runtime of A ≤ Runtime of B + Time of Reduction. LIS(X) { Y = MergeSort(X); return LCS(X, Y); }

General Recipe for Reduction Reducing A to B. If we can solve B, we can also solve A. If the additional steps in the program are easy, we can claim A is easier than B. Later we will see a specific type of reductions. A(X) { do something call B do something else }

Outline How do we compare complexity of problems? Why do we care about complexity Naïve comparisons Reductions Easy problems and Hard problems, P and NP Definitions: P and NP Examples of NP problems Polynomial time reductions.

Easy Problems and Hard Problems Easy problem: problems that can be solved in polynomial time. (O(n), O(nlog n), O(n3), … ) Hard problem: problems that (we believe) cannot be solved in polynomial time. Complexity: How hard it is to solve a problem. Complexity class: A set of problems that are “similar” in difficulty.

Decision Problems Problems that have Yes/No answers. Many problems can be converted into decision problems: Shortest Path: Find the shortest path from s to t. Decision version: Is there a path from s to t that has cost at most L? Minimum Spanning Tree Decision version: Is there a spanning tree with cost at most W?

Easy problems: Class P All decision problems that can be solved in polynomial time. These are considered to be easy problems. All problems we covered in this course are in P.

NP problems Consider a puzzle like sudoku Given the solution, it is easy to check that it is correct But it can be much harder to find the solution.

“Easy to verify” problems: NP All decision problems such that we can verify the correctness of a solution in polynomial time. What does it mean to verify? A prover (who may take a long time to run) will provide the verifier an answer and an explanation. Verify: Takes the input, answer and explanation. If the answer is yes, there should exists an explanation that can convince the verifier. If the answer is no, no matter what explanation you provide, the verifier should not be convinced.

NP problems Verifier: Checking every row, column and square. This is a correct solution. NP problem: does this sudoku have a solution? Prover: Yes, and here is a solution. This Photo by Unknown Author is licensed under CC BY-SA-NC

“Easy to verify” problems: NP Example 2: Is there a path from s to t that has cost at most L? If the answer is Yes, the prover will also give a path. How to verify: Given a path, we can just check 1. It is a path from s to t. 2. The total length is at most L.

“Easy to verify” problems: NP Example 3: Is number x a composite number? If the answer is Yes, the prover will give x = yz. How to verify: Given the solution, we can check 1. x = yz 2. y, z are integers between 2 and x.

Example 4: 3-COLORING 3-COLORING: Check whether there is a way to color vertices of the graph using 3 colors, such that no edge connect two vertices of the same color. input Prover: Yes, the graph can be colored by 3 colors.

“Easy to verify” problems: NP All decision problems such that we can verify the correctness of a solution in polynomial time. Example: 3-COLORING Prover: Yes, the graph can be colored by 3 colors. Verifier: OK, that is indeed a solution.

P vs. NP All problems in P are also in NP. If I can solve the problem, I don’t need an explanation. We don’t know if P = NP, but we believe P is not equal to NP. (Intuition: Solving a problem is harder than setting a problem) NP P

Polynomial time reductions A(X) { do something call B do something else } Recall: General Reduction Polynomial time reduction Can only spend polynomial time Cannot do any post-processing. A(X) { spend polynomial time to prepare an input Y for problem B return B(Y) }

Polynomial time reductions Reduce A to B: if there is a polynomial time algorithm that can transform an instance X of problem A to an instance Y of problem B in polynomial time, such that the answers are the same, then this is called a polynomial time reduction. If answer to X is YES, answer to Y is also YES If answer to X is NO, answer to Y is also NO A is easier, if B can be solved in polynomial time, then A can also be solved in polynomial time. X: instance of A Y: instance of B reduction

Hard problems: NP complete Hardest problems in NP. If A is in NP, and B is a NP complete problem, then A can be reduced to B. Corollary: If any of the NP-hard problems can be solved in polynomial time, then P = NP. Theorem: Cook-Levin: Circuit-SAT is NP-complete.

Harder problems? There are problems that are not in NP. Example 1: Halting Problem: given the code of a program, check if it will terminate or not. This problem is not even solvable. Example 2: Playing chess: given a chess board with n*n size, with 4n chess pieces, decide whether the first player can always win. This is believed to be PSPACE complete, and very unlikely to be in NP.