P, NP, NP-Complete, and NPhard

Size: px
Start display at page:

Download "P, NP, NP-Complete, and NPhard"

Transcription

1 P, NP, NP-Complete, and NPhard Problems Zhenjiang Li 21/09/2011

2 Outline Algorithm time complicity P and NP problems NP-Complete and NP-Hard problems

3 Algorithm time complicity

4 Outline What is this course about? What are algorithms? What does it mean to analyze an algorithm? Comparing time complexity Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 7 / 31

5 Computational Problem Definition A computational problem is a specification of the desired input-output relationship Example (Computational Problem) Sorting Input: Sequence of n numbers a 1,, a n Output: Permutation (reordering) a 1, a 2,, a n such that a 1 a 2 a n Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 8 / 31

6 Instance Definition A problem instance is any valid input to the problem. Example (Instance of the Sorting Problem) 8, 3, 6, 7, 1, 2, 9 Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 9 / 31

7 Algorithm Definition An algorithm is a well defined computational procedure that transforms inputs into outputs, achieving the desired input-output relationship Definition A correct algorithm halts with the correct output for every input instance. We can then say that the algorithm solves the problem Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 10 / 31

8 Example: Insertion Sort Pseudocode: Input: A[1... n] is an array of numbers for j 2 to n do key A[j]; i j 1; while i 1 and A[i] > key do A[i + 1] A[i]; i i 1; end A[i + 1] key; end Sorted key Unsorted Where in the sorted part to put key? Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 11 / 31

9 How Does It Work? An incremental approach: To sort a given array of length n, Example at the ith step it sorts the array of the first i items by making use of the sorted array of the first i 1 items in the (i 1)th step Sort A = 6, 3, 2, 4, 5 with insertion sort Step 1: 6, 3, 2, 4, 5 Step 2: 3, 6, 2, 4, 5 Step 3: 2, 3, 6, 4, 5 Step 4: 2, 3, 4, 6, 5 Step 5: 2, 3, 4, 5, 6 Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 12 / 31

10 Outline What is this course about? What are algorithms? What does it mean to analyze an algorithm? Comparing time complexity Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 13 / 31

11 Analyzing Algorithms Predict resource utilization 1 Memory (space complexity) 2 Running time (time complexity) focus of this course depends on the speed of the computer depends on the implementation details depends on the input, especially on the size of the input In light of the above factors, how can we compare different algorithms in terms of their running times? We want to find a way of measuring running times that is mathematically elegant and machine-independent. Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 14 / 31

12 Machine-independent running time 1 We will measure the running time as the number of primitive operations (e.g., addition, multiplication, comparisons) used by the algorithm 2 We will measure the running time as a function of the input size. Let n denote the input size and let T (n) denote the running time for input of size n. Input size n: rigorous definition given later sorting: number of items to be sorted graphs: number of vertices and edges Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 15 / 31

13 Three Kinds of Analysis: I Best Case: An instance for a given size n that results in the fastest possible running time. Example (Insertion sort) A[1] A[2] A[3] A[n] The number of comparisons needed is equal to } {{ } = n 1 = Θ(n) n 1 key Sorted Unsorted key is compared to only the element right before it. Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 16 / 31

14 Three Kinds of Analysis: II Worst Case: An instance for a given size n that results in the slowest possible running time. Example (Insertion sort) A[1] A[2] A[3] A[n] The number of comparisons needed is equal to (n 1) = n(n 1) 2 = Θ(n 2 ) key Sorted Unsorted key is compared to everything element before it. Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 17 / 31

15 Three Kinds of Analysis: III Average Case: Running time averaged over all possible instances for the given size, assuming some probability distribution on the instances. Example (Insertion sort) Θ(n 2 ), assuming that each of the n! instances is equally likely (uniform distribution). key Sorted Unsorted On average, key is compared to half of the elements before it. Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 18 / 31

16 Three Kinds of Analysis Best case: Clearly useless Worst case: Commonly used, will also be used in this course Gives a running time guarantee no matter what the input is Fair comparison among different algorithms Average case: Used sometimes Need to assume some distribution: real-world inputs are seldom uniformly random! Analysis is complicated Will not be used in this course Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 19 / 31

17 Outline What is this course about? What are algorithms? What does it mean to analyze an algorithm? Comparing time complexity Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 20 / 31

18 Comparing Time Complexity T (n) Algorithm 1 Algorithm 2 Which algorithm is superior for large n? T (n) for Algorithm 1 is 3n 3 + 6n 2 4n + 17 T (n) for Algorithm 2 is 7n 2 8n + 20 Clearly, Algorithm 2 is superior. n Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 21 / 31

19 Asymptotic Analysis T (n) Algorithm 1 Algorithm 2 T (n) for Algorithm 1 is 3n 3 + 6n 2 4n + 17 = Θ(n 3 ) T (n) for Algorithm 2 is 7n 2 8n + 20 = Θ(n 2 ) Θ-notation Drop low-order terms; ingore leading constants Look at growth of T (n) as n When n is large enough, a Θ(n 2 ) algortihm always beats a Θ(n 3 ) algorithm Lecture 1: Introduction COMP271: Design and Analysis of Algorithms 22 / 31 n

20 Big-Oh Asymptotic upper bound Definition (big-oh) f (n) = O(g(n)): There exists constant c > 0 and n 0 such that f (n) c g(n) for n n 0 When estimating the growth rate of T (n) using big-oh: ignore the low order terms ignore the constant coefficient of the most significant term n 0 cg(n) f(n) n f(n) = O(g(n)) Lecture 2: Asymptotic Notations and Recurrences COMP271: Design and Analysis of Algorithms 2 / 14

21 Big-Oh: Example Definition (big-oh) f (n) = O(g(n)): There exists constant c > 0 and n 0 such that f (n) c g(n) for n n 0 Example Let T (n) = 3n 2 + 4n + 5. Prove that T (n) = O(n 2 ). Proof. T (n) = 3n 2 + 4n + 5 3n 2 + 4n 2 + 5n 2 = 12n 2. Thus, T (n) 12n 2 for all n 1. Setting n 0 = 1 and c = 12 in the definition, we have that T (n) = O(n 2 ). Lecture 2: Asymptotic Notations and Recurrences COMP271: Design and Analysis of Algorithms 3 / 14

22 Big-Oh: More Example n 2 /2 3n = O(n 2 ) 1 + 4n = O(n) log 10 n = log 2 n log 2 10 = O(log 2 n) = O(log n) sin n = O(1), 10 = O(1), = O(1) n i=1 i 2 n n 2 = O(n 3 ) n i=1 i n n = O(n2 ) 2 10n is not O(2 n ) log(n!) = log(n) + log(n 1) + + log 1 = O(n log n) n i=1 1 i = O(log n) (on board) Lecture 2: Asymptotic Notations and Recurrences COMP271: Design and Analysis of Algorithms 4 / 14

23 Big-Omega Asymptotic lower bound Definition (big-omega) f (n) = Ω(g(n)): There exists constant c > 0 and n 0 such that f (n) c g(n) for n n 0. It is easy to show that n 2 2 n2 3n 4 for all n 12. Thus, n 2 /2 3n = Ω(n 2 ). n 0 f(n) cg(n) n f(n) = Ω(g(n)) Example log(n!) = log(n) + log(n 1) + + log 1 log(n) + log(n 1) + + log(n/2) n/2 log(n/2) = n/2 (log n 1) = Ω(n log n). Lecture 2: Asymptotic Notations and Recurrences COMP271: Design and Analysis of Algorithms 5 / 14

24 Big-Theta Asymptotic tight bound Definition (big-theta) f (n) = Θ(g(n)): f (n) = O(g(n)) and f (n) = Ω(g(n)) We have shown that and n 2 /2 3n = O(n 2 ), n 2 /2 3n = Ω(n 2 ). Therefore, we have that n 2 /2 3n = Θ(n 2 ). Usually (and in this course), it is sufficient to show only upper bounds (big-oh), though we should try to make these as tight as we can. Lecture 2: Asymptotic Notations and Recurrences COMP271: Design and Analysis of Algorithms 6 / 14

25 Some Thoughts on Algorithm Design Algorithm Design, as taught in this class, is mainly about designing algorithms that have small big-oh running times As n gets larger and larger, O(n log n) algorithms will run faster than O(n 2 ) ones and O(n) algorithms will beat O(n log n) ones Good algorithm design & analysis allows you to identify the hard parts of your problem and deal with them effectively Too often, programmers try to solve problems using brute force techniques and end up with slow complicated code! A few hours of abstract thought devoted to algorithm design often results in faster, simpler, and more general solutions. Lecture 2: Asymptotic Notations and Recurrences COMP271: Design and Analysis of Algorithms 7 / 14

26 Algorithm Tuning After algorithm design one can continue on to Algorithm tuning concentrate on improving algorithms by cutting down on the constants in the big O() bounds needs a good understanding of both algorithm design principles and efficient use of data structures In this course we will not go further into algorithm tuning For a good introduction, see chapter 9 in Programming Pearls, 2nd ed by Jon Bentley Lecture 2: Asymptotic Notations and Recurrences COMP271: Design and Analysis of Algorithms 8 / 14

27 P and NP problems

28 Decision Problems Definition: A decision problem is a question that has two possible answers, yes and no. Note: If is the problem and is the input we will often write to denote a yes answer and to denote a no answer. Note: This notation comes from thinking of as a language and asking whether is in the language (yes) or not (no). See CLRS, pp for more details Definition: An optimization problem requires an answer that is an optimal configuration. Remark: An optimization problem usually has a corresponding decision problem. Examples that we will see: MST vs. Decision Spanning Tree (DST) Knapsack vs. Decision Knapsack (DKnapsack) SubSet Sum vs. Decision Subset Sum (DSubset Sum) 13

29 Decision Problem: MST Optimization problem: Minimum Spanning Tree Given a weighted graph, find a minimum spanning tree (MST) of. Decision problem: Decision Spanning Tree (DST) Given a weighted graph and an integer, does have a spanning tree of weight at most? The inputs are of the form So we will write or to denote, respectively, yes and no answers. 14

30 Optimization and Decision Problems For almost all optimization problems there exists a corresponding simpler decision problem. Given a subroutine for solving the optimization problem, solving the corresponding decision problem is usually be trivial. Example: If we know how to solve MST we can solve DST which asks if there is an Spanning Tree with weight at most How? First solve the MST problem and then check if the MST has cost If it does, answer Yes. If it doesn t, answer No. Thus if we prove that a given decision problem is hard to solve efficiently, then it is obvious that the optimization problem must be (at least as) hard. Note: The reason for introducing Decision problems is that it will be more convenient to compare the hardness of decision problems than of optimization problems (since all decision problems share the same form of output, either yes or no.) 17

31 Decision Problems: Yes-Inputs and No-Inputs Yes-Input and No-Input: An instance of a decision problem is called a yes-input (resp. no-input) if the answer to the instance is yes (resp. no). CYC Problem: Does an undirected graph cycle? have a Example of Yes-Inputs and No-Inputs: a b 1 2 d c 4 3 Yes-input G No-input G 18

32 Decision Problems: Yes-Inputs and No-Inputs Decision Problem (TRIPLE): Does a triple? of nonnegative integers satisfy Example of Yes-Inputs:,. Example of No-Inputs:,. 19

33 Complexity Classes The Theory of Complexity deals with the classification of certain decision problems into several classes: the class of easy problems, the class of hard problems, the class of hardest problems; relations among the three classes; properties of problems in the three classes. Question: How to classify decision problems? Answer: Use polynomial-time algorithms. 21

34 Polynomial-Time Algorithms Definition: An algorithm is polynomial-time if its running time is, where is a constant independent of, and is the input size of the problem that the algorithm solves. Remark: Whether you use or (for fixed ) as the input size, it will not affect the conclusion of whether an algorithm is polynomial time. This explains why we introduced the concept of two functions being of the same type earlier on. Using the definition of polynomial-time it is not necessary to fixate on the input size as being the exact minimum number of bits needed to encode the input! 22

35 Nonpolynomial-Time Algorithms Definition: An algorithm is non-polynomial-time if the running time is not for any fixed. Example: Let s return to the brute force algorithm for determining whether a positive integer is a prime: it checks, in time, whether divides for each with. The complete algorithm therefore uses time. Conclusion: The algorithm is nonpolynomial! Why? The input size is, and so 24

36 Is Knapsack Polynomial? Recall the problem. We have a knapsack of capacity (a positive integer) and objects with weights and values, where and are positive integers. The optimization problem is to find the largest value of any subset that fits in the knapsack, that is,. The decision problem is, given, to find if there is a subset of the objects that fits in the knapsack and has total value at least? In class we saw a dynamic programming algorithm for soving the optimization version of Knapsack. Is this a polynomial algorithm? No! The size of the input is the is not polynomial in Depending upon the values of and, could even be exponential in It is unknown as to whether there exists a polynomial time algorithm for Knapsack. In fact, Knapsack is a -Complete problem, so anyone who could determine whether there was a polynomial-time algorithm for solving it would be proving that or and would win the prize from the Clay Institute! 25

37 Polynomial- vs. Nonpolynomial-Time Nonpolynomial-time algorithms are impractical. For example, to run an algorithm of time complexity for on a computer which does 1 Terraoperation ( operations) per second: It takes seconds years. For the sake of our discussion of complexity classes Polynomial-time algorithms are practical. Note: in reality an algorithm is not really practical. 26

38 Polynomial-Time Solvable Problems Definition: A problem is solvable in polynomial time (or more simply, the problem is in polynomial time) if there exists an algorithm which solves the problem in polynomial time. Examples: The integer multiplication problem, and the cycle detection problem for undirected graphs. Remark: Polynomial-time solvable problems are also called tractable problems. 27

39 The Class Definition: The class consists of all decision problems that are solvable in polynomial time. That is, there exists an algorithm that will decide in polynomial time if any given input is a yes-input or a no-input. How to prove that a decision problem is in? You need to find a polynomial-time algorithm for this problem. How to prove that a decision problem is not in? You need to prove there is no polynomial-time algorithm for this problem (much harder). 28

40 Certificates and Verifying Certificates We have already seen the class We are now almost ready to introduce the class Before doing so we must first introduce the concept of Certificates. Observation: A decision problem is usually formulated as: Is there an object satisfying some conditions? A Certificate is a specific object corresponding to a yes-input, such that it can be used to show the validity of that yes-input. By definition, only yes-input needs a certificate (a noinput does not need to have a certificate to show it is a no-input). Verifying a certificate: Given a presumed yes-input and its corresponding certificate, by making use of the given certificate, we verify that the input is actually a yes-input. 31

41 The Class Definition: The class consists of all decision problems such that, for each yes-input, there exists a certificate that can be verified in polynomial time. Remark: stands for nondeterministic polynomial time. The class was originally studied in the context of nondeterminism, here we use an equivalent notion of verification. 32

42 Satisfiability I We will now introduce Satisfiability (SAT), which, we will see later, is one of the most important problems. Definition: A Boolean formula is a logical formula which consists of boolean variables (0=false, 1=true), logical operations, NOT,, OR,, AND. These are defined by: 38

43 Satisfiability II A given Boolean formula is satisfiable if there is a way to assign truth values (0 or 1) to the variables such that the final result is 1. Example:. For example, the assignment,, makes true, and hence it is satisfiable. 39

44 SAT SAT problem: Determine whether an input Boolean formula is satisfiable. If an Boolean formula is satisfiable, it is a yes-input; otherwise, it is a no-input. Claim: SAT. Proof: The certificate consists of a particular 0 or 1 assignment to the variables. Given this assignment, we can evaluate the formula of length (counting variables, operations, and parentheses), it requires at most evaluations, each taking constant time. Hence, to check a certificate takes time. So we have SAT. 41

45 NP-Complete and NP-hard problems

46 Polynomial-Time Reductions Definition Let L 1 and L 2 be two decision problems. A Polynomial-Time Reduction from L 1 to L 2 is a transformation f with the following two properties: 1 f transforms an input x for L 1 into an input f (x) for L 2 such that a yes-input of L 1 maps to a yes-input of L 2, and a no-input of L 1 maps to a no-input of L 2. Y N f Y N 2 f (x) is computable in polynomial time (in size(x)). L1 L2 If such an f exists, we say that L 1 is polynomial-time reducible to L 2, and write L 1 P L 2. Lecture 22: NP-Completeness

47 Polynomial-Time Reductions Intuitively, L 1 P L 2 means L 1 is no harder than L 2. Given an algorithm A 2 for the decision problem L 2, we can develop an algorithm A 1 to solve L 1 : Algorithm for L 1 x input for L 1 Transformation f f(x) input for L 2 algorithm for L 2 yes/no answer for L 2 on f(x) yes/no answer for L 1 on x If A 2 is polynomial-time algorithm, so is A 1. Theorem If L 1 P L 2 and L 2 P, then L 1 P. Lecture 22: NP-Completeness

48 Reduction between Decision Problems Lemma (Transitivity of the relation P ) If L 1 P L 2 and L 2 P L 3, then L 1 P L 3. Proof. Since L 1 P L 2, there is a polynomial-time reduction f 1 from L 1 to L 2. Similarly, since L 2 P L 3, there is a polynomial-time reduction f 2 from L 2 to L 3. Note that f 1 (x) can be calculated in time polynomial in size(x). In particular this implies that size(f 1 (x)) is polynomial in size(x). f (x) = f 2 (f 1 (x)) can therefore be calculated in time polynomial in size(x). Furthermore x is a yes-input for L 1 if and only if f (x) is a yes-input for L 3 (why). Thus the combined transformation defined by f (x) = f 2 (f 1 (x)) is a polynomial-time reduction from L 1 to L 3. Hence L 1 P L 3. Lecture 22: NP-Completeness

49 The Class NP-Complete (NPC) We have finally reached our goal of introducing class NPC. Definition The class NPC of NP-complete problems consists of all decision problems L such that 1 L NP; 2 for every L NP, L P L. Intuitively, NPC consists of all the hardest problems in NP. Lecture 22: NP-Completeness

50 NP-Completeness and Its Properties Let L be any problem in NPC. Theorem 1 If there is a polynomial-time algorithm for L, then there is a polynomial-time algorithm for every L NP. 2 If there is no polynomial-time algorithm for L, then there is no polynomial-time algorithm for any L NPC. Proof. 1 By definition of NPC, for every L NP, L P L. Since L P, by the theorem on Slide 6, L P. 2 By the previous conclusion. Lecture 22: NP-Completeness

51 NP-Completeness and Its Properties According to the above theorem, either 1 all NP-Complete problems are polynomial time solvable, or 2 all NP-Complete problems are not polynomial time solvable. This is the major reason we are interested in NP-Completeness. Lecture 22: NP-Completeness

52 The Classes P, NP, and NPC Recall P NP. Question 1 Is NPC NP? Yes, by definition! Question 2 Is P = NP? Open problem! Probably very hard It is generally believed that P NP. Lecture 22: NP-Completeness

53 The Classes P, NP, and NPC Lecture 22: NP-Completeness

54 The Class NP-Complete (NPC) From the definition of NP-complete, it appears impossible to prove one problem L NPC! By definition, it requires us to show every L NP, L P L. But there are infinitely many problem in NP, so how can we argue there exists a reduction from every L to L? To prove the first NP-complete problem, we have to use the definition of NP, and the simplicity of the TM helps again. Once we have proved the first NP-complete problem, by to the transitivity property of the relation p, we have an easier way to show that a problem L NPC: Proof. (a) L NP; (b) for some L NPC, L P L. Let L be any problem in NP. Since L is NP-complete, L p L. Since L p L, by transitivity, L p L. Lecture 22: NP-Completeness

55 Cook s Theorem (Cook-Levin Theorem) Theorem (Cook s Theorem) SAT NPC. Proof. See p Lecture 22: NP-Completeness

56 Problem: CLIQUE Definition (Clique) A clique in an undirected graph G = (V, E) is a subset V V of vertices such that each pair u, v V is connected by an edge (u, v) E. In other words, a clique is a complete subgraph of G Example a vertex is a clique of size 1, an edge a clique of size Find a clique with 4 vertices CLIQUE Find a clique of maximum size in a graph. Lecture 22: NP-Completeness

57 NPC Problem: DCLIQUE The Decision Clique Problem DCLIQUE Given an undirected graph G and an integer k, determine whether G has a clique with k vertices. Theorem DCLIQUE NPC. Proof We need to show two things. (a) That DCLIQUE NP and (b) That there is some L NPC such that L P DCLIQUE. Lecture 22: NP-Completeness

58 Proof that DCLIQUE NPC Claim (a) DCLIQUE NP Proof. Proving (a) is easy. A certificate will be a set of vertices V V, V = k that is a possible clique. To check that V is a clique all that is needed is to check that all edges (u, v) with u v, u, v V, are in E. This can be done in time O( V 2 ) if the edges are kept in an adjacency matrix (and even if they are kept in an adjacency list how?). Lecture 22: NP-Completeness

59 Proof that DCLIQUE NPC (cont) Claim (b) There is some L NPC such that L P DCLIQUE. To prove (b) we will show that 3-SAT P DCLIQUE. Instance of 3-SAT problem Algorithm that Instance of clique problem C 1, C 2,..., C n transforms a graph G = (V, E) 3-SAT instance to and an integer k clique instance This will be the hard part. We will do this by building a gadget that allows a reduction from the 3-SAT problem (on logical formulas) to the DCLIQUE problem (on graphs, and integers). Lecture 22: NP-Completeness

60 Proof that DCLIQUE NPC (cont) Recall that the input to 3-SAT is a logical formula φ of the form φ = C 1 C 2 C n where each clause C i is a triple of the form C i = y i,1 y i,2 y i,3 where each literal y i,j is a variable or the negation of a variable. Example C 1 = (x 1 x 2 x 3 ), C 2 = ( x 1 x 2 x 3 ), C 3 = (x 1 x 2 x 3 ) We will define a polynomial transformation f from 3-SAT to DCLIQUE f : φ (G, k) that builds a graph G and integer k such that φ is a Yes-input to 3-SAT if and only if (G, k) is a Yes-input to DCLIQUE. Lecture 22: NP-Completeness

61 Proof that DCLIQUE NPC (cont) Suppose that φ is a 3-SAT formula with n clauses, i.e., φ = C 1 C 2 C n. We start by setting k = n. We now construct the graph G = (V, E). 1 For each clause C i = x i,1 x i,2 x i,3 we create 3 vertices, v1 i, v 2 i, v 3 i, in V so G has 3n vertices. We will label these vertices with the corresponding variable or variable negation that they represent. (Note that many vertices might share the same label) Example 2 We create an edge between vertices vj i and v i j if and only if the following two conditions hold: (a) vj i and v i j are in different triples, i.e., i i, and (b) vj i is not the negation of v i j. Example Note that the transformation maps all 3-SAT inputs to some DCLIQUE inputs, i.e., it does not require that all DCLIQUE inputs have pre-images from 3-SAT inputs. Lecture 22: NP-Completeness

62 Proof that DCLIQUE NPC (cont) Example φ = C 1 C 2 C 3 C 1 = (x 1 x 2 x 3 ), C 2 = ( x 1 x 2 x 3 ), C 3 = (x 1 x 2 x 3 ) C1 X1 X 2 X 3 X 1 X 1 C2 X 2 X 2 C3 Return X3 X3 Observe that the assignment X 1 =false, X 2 =false, X 3 =true satisfies φ (a yes-input for 3-SAT). This corresponds to the clique of size 3 comprising the x 2 node in C 1, the x 3 node in C 2, and the x 3 node in C 3 (a yes-input for DCLIQUE). Lecture 22: NP-Completeness

63 Proof that DCLIQUE NPC (cont) Correctness We claim that a 3-CNF formula φ with k clauses is satisfiable if and only if f (φ) = (G, k) has a clique of size k. : Suppose φ is satisfiable. Consider the satisfying truth assignment. Each of the k clauses has at least one true literal. Select one such true literal from each clause. Observe that these true literals must be logically consistent with each other (i.e., for any i, x i and x i will not both appear). Recall that in our construction of G we connect a pair of vertices if they are in different clauses and are logically consistent. Thus, for every pair of these literals, there must be an edge in G connecting the corresponding vertices. Thus these k vertices must form a clique. Lecture 22: NP-Completeness

64 Proof that DCLIQUE NPC (cont) : Suppose G has a clique of size k. Observe that there is no edge between vertices in the same clause. Hence, each clause contributes exactly one vertex to the clique. Moreover, since the construction of G connects only logically consistent vertices by an edge, every vertex in the clique must be logically consistent. Hence we can assign all the vertices in the clique to be true, and this truth assignment makes φ satisfiable. Lecture 22: NP-Completeness

65 Proof that DCLIQUE NPC (cont) Note that the graph G has 3k vertices and at most 3k(3k 1)/2 edges and can be built in O(k 2 ) time So f is a polynomial-time reduction. We have therefore just proven that 3-SAT P DCLIQUE. Since we already know that 3-SAT NPC and have seen that DCLIQUE NP, we have just proven that DCLIQUE NPC. Lecture 22: NP-Completeness

66 NP-Hard Problems Definition A problem L is NP-hard if problem in NPC can be polynomially reduced to it (but L does not need to be in NP). In general, the optimization versions of NP-Complete problems are NP-Hard. Example VC: Given an undirected graph G, find a minimum-size vertex cover. DVC: Given an undirected graph G and k, is there a vertex cover of size k? If we can solve the optimization problem VC, we can easily solve the decision problem DVC. Simply run VC on graph G and find a minimum vertex cover S. Now, given (G, k), solve DVC(G, k) by checking whether k S. If k S, answer Yes, if not, answer No. Lecture 22: NP-Completeness

67 Epilogue: How to Deal with Hard Problems Heuristics: All the hardness results (undecidability, NP-hardness) hold for any algorithm that solves the problem in general (worst-case analysis). There are many efficient algorithms solving these problems for typical cases. They run fast on typical inputs and find the optimal solutions (they may be slow on some contrived inputs). They run fast on all inputs and typically find near-optimal solutions (they may return bad solutions on some contrived inputs). Approximation algorithms: All the hardness results show that finding the optimal solutions is difficult, but there are efficient algorithms for finding solutions that are at most c times worse than the optimal ones. Average-case analysis: By assuming the input follows some distribution, it is possible to design algorithms whose running time is good on average. Lecture 22: NP-Completeness

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

Lecture 18: P & NP. Revised, May 1, CLRS, pp Lecture 18: P & NP Revised, May 1, 2003 CLRS, pp.966-982 The course so far: techniques for designing efficient algorithms, e.g., divide-and-conquer, dynamic-programming, greedy-algorithms. What happens

More information

Lecture 19: NP-Completeness 1

Lecture 19: NP-Completeness 1 Lecture 19: NP-Completeness 1 Revised Sun May 25, 2003 Outline of this Lecture Polynomial-time reductions. CLRS pp.984-5 The class N PC. CLRS p. 986 Proving that problems are N PC. SAT, CLIQUE, INDEPENDENT

More information

Limitations of Algorithm Power

Limitations of Algorithm Power Limitations of Algorithm Power Objectives We now move into the third and final major theme for this course. 1. Tools for analyzing algorithms. 2. Design strategies for designing algorithms. 3. Identifying

More information

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

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 Summary of the previous lecture Recall that we mentioned the following topics: P: is the set of decision problems (or languages) that are solvable in polynomial time. NP: is the set of decision problems

More information

Essential facts about NP-completeness:

Essential facts about NP-completeness: CMPSCI611: NP Completeness Lecture 17 Essential facts about NP-completeness: Any NP-complete problem can be solved by a simple, but exponentially slow algorithm. We don t have polynomial-time solutions

More information

Intro to Theory of Computation

Intro to Theory of Computation Intro to Theory of Computation LECTURE 25 Last time Class NP Today Polynomial-time reductions Adam Smith; Sofya Raskhodnikova 4/18/2016 L25.1 The classes P and NP P is the class of languages decidable

More information

NP Completeness and Approximation Algorithms

NP Completeness and Approximation Algorithms Winter School on Optimization Techniques December 15-20, 2016 Organized by ACMU, ISI and IEEE CEDA NP Completeness and Approximation Algorithms Susmita Sur-Kolay Advanced Computing and Microelectronic

More information

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

NP-Completeness. Until now we have been designing algorithms for specific problems NP-Completeness 1 Introduction Until now we have been designing algorithms for specific problems We have seen running times O(log n), O(n), O(n log n), O(n 2 ), O(n 3 )... We have also discussed lower

More information

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

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P Easy Problems vs. Hard Problems CSE 421 Introduction to Algorithms Winter 2000 NP-Completeness (Chapter 11) Easy - problems whose worst case running time is bounded by some polynomial in the size of the

More information

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

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA. Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA NP Completeness Susmita Sur-Kolay Advanced Computing and Microelectronics Unit

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 25 NP Completeness Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 NP-Completeness Some

More information

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 18 Reductions and NP-completeness Thanks to Kevin Wayne and the text authors who contributed to these slides Classify Problems According

More information

1. Introduction Recap

1. Introduction Recap 1. Introduction Recap 1. Tractable and intractable problems polynomial-boundness: O(n k ) 2. NP-complete problems informal definition 3. Examples of P vs. NP difference may appear only slightly 4. Optimization

More information

Computational Complexity

Computational Complexity Computational Complexity Problems, instances and algorithms Running time vs. computational complexity General description of the theory of NP-completeness Problem samples 1 Computational Complexity What

More information

Introduction. Pvs.NPExample

Introduction. Pvs.NPExample Introduction Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 09 NP-Completeness (Chapter 34) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu I

More information

Geometric Steiner Trees

Geometric Steiner Trees Geometric Steiner Trees From the book: Optimal Interconnection Trees in the Plane By Marcus Brazil and Martin Zachariasen Part 3: Computational Complexity and the Steiner Tree Problem Marcus Brazil 2015

More information

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

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch] NP-Completeness Andreas Klappenecker [based on slides by Prof. Welch] 1 Prelude: Informal Discussion (Incidentally, we will never get very formal in this course) 2 Polynomial Time Algorithms Most of the

More information

Growth of Functions (CLRS 2.3,3)

Growth of Functions (CLRS 2.3,3) Growth of Functions (CLRS 2.3,3) 1 Review Last time we discussed running time of algorithms and introduced the RAM model of computation. Best-case running time: the shortest running time for any input

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Computational Complexity CLRS 34.1-34.4 University of Manitoba COMP 3170 - Analysis of Algorithms & Data Structures 1 / 50 Polynomial

More information

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

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9 1 Computational Complexity and Intractability: An Introduction to the Theory of NP Chapter 9 2 Objectives Classify problems as tractable or intractable Define decision problems Define the class P Define

More information

NP-Completeness Review

NP-Completeness Review CS124 NP-Completeness Review Where We Are Headed Up to this point, we have generally assumed that if we were given a problem, we could find a way to solve it. Unfortunately, as most of you know, there

More information

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

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015 CS 374: Algorithms & Models of Computation, Spring 2015 NP Completeness Lecture 23 November 19, 2015 Chandra & Lenny (UIUC) CS374 1 Spring 2015 1 / 37 Part I NP-Completeness Chandra & Lenny (UIUC) CS374

More information

NP Complete Problems. COMP 215 Lecture 20

NP Complete Problems. COMP 215 Lecture 20 NP Complete Problems COMP 215 Lecture 20 Complexity Theory Complexity theory is a research area unto itself. The central project is classifying problems as either tractable or intractable. Tractable Worst

More information

NP-Completeness Theory

NP-Completeness Theory NP-Completeness Theory The topics we discussed so far are positive results: Given a problem, how to design efficient algorithms for solving it. NP-Completeness (NPC for sort) Theory is negative results.

More information

NP-Complete Problems. More reductions

NP-Complete Problems. More reductions NP-Complete Problems More reductions Definitions P: problems that can be solved in polynomial time (typically in n, size of input) on a deterministic Turing machine Any normal computer simulates a DTM

More information

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

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter 2006 NP-Completeness (Chapter 8) Given positive integers a, b, c Question 1: does there exist a positive integer x such that

More information

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

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm Outline 1 NP-Completeness Theory 2 Limitation of Computation 3 Examples 4 Decision Problems 5 Verification Algorithm 6 Non-Deterministic Algorithm 7 NP-Complete Problems c Hu Ding (Michigan State University)

More information

CS 583: Algorithms. NP Completeness Ch 34. Intractability

CS 583: Algorithms. NP Completeness Ch 34. Intractability CS 583: Algorithms NP Completeness Ch 34 Intractability Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time? Standard working

More information

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

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Limitations of Algorithms We conclude with a discussion of the limitations of the power of algorithms. That is, what kinds

More information

Computational Complexity

Computational Complexity Computational Complexity S. V. N. Vishwanathan, Pinar Yanardag January 8, 016 1 Computational Complexity: What, Why, and How? Intuitively an algorithm is a well defined computational procedure that takes

More information

SAT, NP, NP-Completeness

SAT, NP, NP-Completeness CS 473: Algorithms, Spring 2018 SAT, NP, NP-Completeness Lecture 22 April 13, 2018 Most slides are courtesy Prof. Chekuri Ruta (UIUC) CS473 1 Spring 2018 1 / 57 Part I Reductions Continued Ruta (UIUC)

More information

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

Tractability. Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time? Tractability Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time?» Standard working definition: polynomial time» On an input

More information

Lecture 18: More NP-Complete Problems

Lecture 18: More NP-Complete Problems 6.045 Lecture 18: More NP-Complete Problems 1 The Clique Problem a d f c b e g Given a graph G and positive k, does G contain a complete subgraph on k nodes? CLIQUE = { (G,k) G is an undirected graph with

More information

Theory of Computation Time Complexity

Theory of Computation Time Complexity Theory of Computation Time Complexity Bow-Yaw Wang Academia Sinica Spring 2012 Bow-Yaw Wang (Academia Sinica) Time Complexity Spring 2012 1 / 59 Time for Deciding a Language Let us consider A = {0 n 1

More information

CS 350 Algorithms and Complexity

CS 350 Algorithms and Complexity 1 CS 350 Algorithms and Complexity Fall 2015 Lecture 15: Limitations of Algorithmic Power Introduction to complexity theory Andrew P. Black Department of Computer Science Portland State University Lower

More information

Complexity (Pre Lecture)

Complexity (Pre Lecture) 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

More information

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Lecture 1: Asymptotics, Recurrences, Elementary Sorting Lecture 1: Asymptotics, Recurrences, Elementary Sorting Instructor: Outline 1 Introduction to Asymptotic Analysis Rate of growth of functions Comparing and bounding functions: O, Θ, Ω Specifying running

More information

Part V. Intractable Problems

Part V. Intractable Problems Part V Intractable Problems 507 Chapter 16 N P-Completeness Up to now, we have focused on developing efficient algorithms for solving problems. The word efficient is somewhat subjective, and the degree

More information

CS 350 Algorithms and Complexity

CS 350 Algorithms and Complexity CS 350 Algorithms and Complexity Winter 2019 Lecture 15: Limitations of Algorithmic Power Introduction to complexity theory Andrew P. Black Department of Computer Science Portland State University Lower

More information

Correctness of Dijkstra s algorithm

Correctness of Dijkstra s algorithm Correctness of Dijkstra s algorithm Invariant: When vertex u is deleted from the priority queue, d[u] is the correct length of the shortest path from the source s to vertex u. Additionally, the value d[u]

More information

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

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas CSE 417 Introduction to Algorithms Winter 2007 Some Algebra Problems (Algorithmic) Given positive integers a, b, c Question 1: does there exist a positive integer x such that ax = c? NP-Completeness (Chapter

More information

1.1 P, NP, and NP-complete

1.1 P, NP, and NP-complete CSC5160: Combinatorial Optimization and Approximation Algorithms Topic: Introduction to NP-complete Problems Date: 11/01/2008 Lecturer: Lap Chi Lau Scribe: Jerry Jilin Le This lecture gives a general introduction

More information

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

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan August 30, Notes for Lecture 1 U.C. Berkeley CS278: Computational Complexity Handout N1 Professor Luca Trevisan August 30, 2004 Notes for Lecture 1 This course assumes CS170, or equivalent, as a prerequisite. We will assume that the

More information

1 Primals and Duals: Zero Sum Games

1 Primals and Duals: Zero Sum Games CS 124 Section #11 Zero Sum Games; NP Completeness 4/15/17 1 Primals and Duals: Zero Sum Games We can represent various situations of conflict in life in terms of matrix games. For example, the game shown

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 26 Computational Intractability Polynomial Time Reductions Sofya Raskhodnikova S. Raskhodnikova; based on slides by A. Smith and K. Wayne L26.1 What algorithms are

More information

Lecture 14 - P v.s. NP 1

Lecture 14 - P v.s. NP 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) February 27, 2018 Lecture 14 - P v.s. NP 1 In this lecture we start Unit 3 on NP-hardness and approximation

More information

Algorithms Design & Analysis. Approximation Algorithm

Algorithms Design & Analysis. Approximation Algorithm Algorithms Design & Analysis Approximation Algorithm Recap External memory model Merge sort Distribution sort 2 Today s Topics Hard problem Approximation algorithms Metric traveling salesman problem A

More information

Theory of Computation Chapter 9

Theory of Computation Chapter 9 0-0 Theory of Computation Chapter 9 Guan-Shieng Huang May 12, 2003 NP-completeness Problems NP: the class of languages decided by nondeterministic Turing machine in polynomial time NP-completeness: Cook

More information

Introduction to Complexity Theory

Introduction to Complexity Theory Introduction to Complexity Theory Read K & S Chapter 6. Most computational problems you will face your life are solvable (decidable). We have yet to address whether a problem is easy or hard. Complexity

More information

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

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size. 10 2.2. CLASSES OF COMPUTATIONAL COMPLEXITY An optimization problem is defined as a class of similar problems with different input parameters. Each individual case with fixed parameter values is called

More information

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?

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? N P NP Completeness Announcements Friday Four Square! Today at 4:15PM, outside Gates. Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Explore P, NP, and their connection. Did

More information

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 501 Advanced Data

More information

Notes for Lecture 21

Notes for Lecture 21 U.C. Berkeley CS170: Intro to CS Theory Handout N21 Professor Luca Trevisan November 20, 2001 Notes for Lecture 21 1 Tractable and Intractable Problems So far, almost all of the problems that we have studied

More information

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

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 Problems are divided into complexity classes. Informally: So far in this course, almost all algorithms had polynomial running time, i.e., on inputs of size n, worst-case running time

More information

2. ALGORITHM ANALYSIS

2. ALGORITHM ANALYSIS 2. ALGORITHM ANALYSIS computational tractability asymptotic order of growth survey of common running times Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs Computational Complexity IE 496 Lecture 6 Dr. Ted Ralphs IE496 Lecture 6 1 Reading for This Lecture N&W Sections I.5.1 and I.5.2 Wolsey Chapter 6 Kozen Lectures 21-25 IE496 Lecture 6 2 Introduction to

More information

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018 CS 61B More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018 Here is a review of some formulas that you will find useful when doing asymptotic analysis. ˆ N i=1 i = 1 + 2 + 3 + 4 + + N = N(N+1)

More information

Recap from Last Time

Recap from Last Time NP-Completeness Recap from Last Time Analyzing NTMs When discussing deterministic TMs, the notion of time complexity is (reasonably) straightforward. Recall: One way of thinking about nondeterminism is

More information

ICS 252 Introduction to Computer Design

ICS 252 Introduction to Computer Design ICS 252 fall 2006 Eli Bozorgzadeh Computer Science Department-UCI References and Copyright Textbooks referred [Mic94] G. De Micheli Synthesis and Optimization of Digital Circuits McGraw-Hill, 1994. [CLR90]

More information

INTRO TO COMPUTATIONAL COMPLEXITY

INTRO TO COMPUTATIONAL COMPLEXITY MA/CSSE 473 Day 38 Problems Decision Problems P and NP Polynomial time algorithms INTRO TO COMPUTATIONAL COMPLEXITY 1 The Law of the Algorithm Jungle Polynomial good, exponential bad! The latter is obvious,

More information

NP-completeness. Chapter 34. Sergey Bereg

NP-completeness. Chapter 34. Sergey Bereg NP-completeness Chapter 34 Sergey Bereg Oct 2017 Examples Some problems admit polynomial time algorithms, i.e. O(n k ) running time where n is the input size. We will study a class of NP-complete problems

More information

CISC 4090 Theory of Computation

CISC 4090 Theory of Computation CISC 4090 Theory of Computation Complexity Professor Daniel Leeds dleeds@fordham.edu JMH 332 Computability Are we guaranteed to get an answer? Complexity How long do we have to wait for an answer? (Ch7)

More information

NP-Completeness. Subhash Suri. May 15, 2018

NP-Completeness. Subhash Suri. May 15, 2018 NP-Completeness Subhash Suri May 15, 2018 1 Computational Intractability The classical reference for this topic is the book Computers and Intractability: A guide to the theory of NP-Completeness by Michael

More information

Lecture 3: Nondeterminism, NP, and NP-completeness

Lecture 3: Nondeterminism, NP, and NP-completeness CSE 531: Computational Complexity I Winter 2016 Lecture 3: Nondeterminism, NP, and NP-completeness January 13, 2016 Lecturer: Paul Beame Scribe: Paul Beame 1 Nondeterminism and NP Recall the definition

More information

More NP-Complete Problems

More NP-Complete Problems CS 473: Algorithms, Spring 2018 More NP-Complete Problems Lecture 23 April 17, 2018 Most slides are courtesy Prof. Chekuri Ruta (UIUC) CS473 1 Spring 2018 1 / 57 Recap NP: languages/problems that have

More information

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu Analysis of Algorithm Efficiency Dr. Yingwu Zhu Measure Algorithm Efficiency Time efficiency How fast the algorithm runs; amount of time required to accomplish the task Our focus! Space efficiency Amount

More information

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

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35. NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979. NP-Completeness 1 General Problems, Input Size and

More information

CSE 421 NP-Completeness

CSE 421 NP-Completeness CSE 421 NP-Completeness Yin at Lee 1 Cook-Levin heorem heorem (Cook 71, Levin 73): 3-SA is NP-complete, i.e., for all problems A NP, A p 3-SA. (See CSE 431 for the proof) So, 3-SA is the hardest problem

More information

Great Theoretical Ideas in Computer Science. Lecture 7: Introduction to Computational Complexity

Great Theoretical Ideas in Computer Science. Lecture 7: Introduction to Computational Complexity 15-251 Great Theoretical Ideas in Computer Science Lecture 7: Introduction to Computational Complexity September 20th, 2016 What have we done so far? What will we do next? What have we done so far? > Introduction

More information

Data Structures and Algorithms. Asymptotic notation

Data Structures and Algorithms. Asymptotic notation Data Structures and Algorithms Asymptotic notation Estimating Running Time Algorithm arraymax executes 7n 1 primitive operations in the worst case. Define: a = Time taken by the fastest primitive operation

More information

Data Structures and Algorithms Running time and growth functions January 18, 2018

Data Structures and Algorithms Running time and growth functions January 18, 2018 Data Structures and Algorithms Running time and growth functions January 18, 2018 Measuring Running Time of Algorithms One way to measure the running time of an algorithm is to implement it and then study

More information

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Computability and Complexity Theory: An Introduction

Computability and Complexity Theory: An Introduction Computability and Complexity Theory: An Introduction meena@imsc.res.in http://www.imsc.res.in/ meena IMI-IISc, 20 July 2006 p. 1 Understanding Computation Kinds of questions we seek answers to: Is a given

More information

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

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University Algorithms NP -Complete Problems Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr The Class P Definition 13.2 Polynomially bounded An algorithm is said to be polynomially bounded if its worst-case

More information

Lecture 15 - NP Completeness 1

Lecture 15 - NP Completeness 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) February 29, 2018 Lecture 15 - NP Completeness 1 In the last lecture we discussed how to provide

More information

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

Friday Four Square! Today at 4:15PM, Outside Gates P and NP Friday Four Square! Today at 4:15PM, Outside Gates Recap from Last Time Regular Languages DCFLs CFLs Efficiently Decidable Languages R Undecidable Languages Time Complexity A step of a Turing

More information

The Time Complexity of an Algorithm

The Time Complexity of an Algorithm CSE 3101Z Design and Analysis of Algorithms The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. Purpose To estimate how long a program will run. To estimate

More information

Ch01. Analysis of Algorithms

Ch01. Analysis of Algorithms Ch01. Analysis of Algorithms Input Algorithm Output Acknowledgement: Parts of slides in this presentation come from the materials accompanying the textbook Algorithm Design and Applications, by M. T. Goodrich

More information

NP-Hardness reductions

NP-Hardness reductions NP-Hardness reductions Definition: P is the class of problems that can be solved in polynomial time, that is n c for a constant c Roughly, if a problem is in P then it's easy, and if it's not in P then

More information

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

Class Note #20. In today s class, the following four concepts were introduced: decision Class Note #20 Date: 03/29/2006 [Overall Information] In today s class, the following four concepts were introduced: decision version of a problem, formal language, P and NP. We also discussed the relationship

More information

NP-Complete Reductions 1

NP-Complete Reductions 1 x x x 2 x 2 x 3 x 3 x 4 x 4 CS 4407 2 22 32 Algorithms 3 2 23 3 33 NP-Complete Reductions Prof. Gregory Provan Department of Computer Science University College Cork Lecture Outline x x x 2 x 2 x 3 x 3

More information

Lecture 20: conp and Friends, Oracles in Complexity Theory

Lecture 20: conp and Friends, Oracles in Complexity Theory 6.045 Lecture 20: conp and Friends, Oracles in Complexity Theory 1 Definition: conp = { L L NP } What does a conp computation look like? In NP algorithms, we can use a guess instruction in pseudocode:

More information

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

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65 Undecidable Problems Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, 2018 1/ 65 Algorithmically Solvable Problems Let us assume we have a problem P. If there is an algorithm solving

More information

CP405 Theory of Computation

CP405 Theory of Computation CP405 Theory of Computation BB(3) q 0 q 1 q 2 0 q 1 1R q 2 0R q 2 1L 1 H1R q 1 1R q 0 1L Growing Fast BB(3) = 6 BB(4) = 13 BB(5) = 4098 BB(6) = 3.515 x 10 18267 (known) (known) (possible) (possible) Language:

More information

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler Complexity Theory Complexity Theory VU 181.142, SS 2018 6. The Polynomial Hierarchy Reinhard Pichler Institut für Informationssysteme Arbeitsbereich DBAI Technische Universität Wien 15 May, 2018 Reinhard

More information

The Time Complexity of an Algorithm

The Time Complexity of an Algorithm Analysis of Algorithms The Time Complexity of an Algorithm Specifies how the running time depends on the size of the input. Purpose To estimate how long a program will run. To estimate the largest input

More information

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

The Complexity Classes P and NP. Andreas Klappenecker [partially based on slides by Professor Welch] The Complexity Classes P and NP Andreas Klappenecker [partially based on slides by Professor Welch] P Polynomial Time Algorithms Most of the algorithms we have seen so far run in time that is upper bounded

More information

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

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181. Complexity Theory Complexity Theory Outline Complexity Theory VU 181.142, SS 2018 6. The Polynomial Hierarchy Reinhard Pichler Institut für Informationssysteme Arbeitsbereich DBAI Technische Universität

More information

1 Computational problems

1 Computational problems 80240233: Computational Complexity Lecture 1 ITCS, Tsinghua Univesity, Fall 2007 9 October 2007 Instructor: Andrej Bogdanov Notes by: Andrej Bogdanov The aim of computational complexity theory is to study

More information

ECS122A Handout on NP-Completeness March 12, 2018

ECS122A Handout on NP-Completeness March 12, 2018 ECS122A Handout on NP-Completeness March 12, 2018 Contents: I. Introduction II. P and NP III. NP-complete IV. How to prove a problem is NP-complete V. How to solve a NP-complete problem: approximate algorithms

More information

3.1 Asymptotic notation

3.1 Asymptotic notation 3.1 Asymptotic notation The notations we use to describe the asymptotic running time of an algorithm are defined in terms of functions whose domains are the set of natural numbers N = {0, 1, 2,... Such

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 MA008 p.1/36 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 2 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/36 Content of lecture 2 Examples Review data structures Data types vs. data

More information

Complexity and NP-completeness

Complexity and NP-completeness Lecture 17 Complexity and NP-completeness Supplemental reading in CLRS: Chapter 34 As an engineer or computer scientist, it is important not only to be able to solve problems, but also to know which problems

More information

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

The P-vs-NP problem. Andrés E. Caicedo. September 10, 2011 The P-vs-NP problem Andrés E. Caicedo September 10, 2011 This note is based on lecture notes for the Caltech course Math 6c, prepared with A. Kechris and M. Shulman. 1 Decision problems Consider a finite

More information

CSE 3500 Algorithms and Complexity Fall 2016 Lecture 25: November 29, 2016

CSE 3500 Algorithms and Complexity Fall 2016 Lecture 25: November 29, 2016 CSE 3500 Algorithms and Complexity Fall 2016 Lecture 25: November 29, 2016 Intractable Problems There are many problems for which the best known algorithms take a very long time (e.g., exponential in some

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION 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

More information

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

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT Definition: A language B is NP-complete if: 1. B NP 2. Every A in NP is poly-time reducible to B That is, A P B When this is true, we say B is NP-hard On

More information

NP-Complete Reductions 2

NP-Complete Reductions 2 x 1 x 1 x 2 x 2 x 3 x 3 x 4 x 4 12 22 32 CS 447 11 13 21 23 31 33 Algorithms NP-Complete Reductions 2 Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline NP-Complete

More information

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

Lecture #14: NP-Completeness (Chapter 34 Old Edition Chapter 36) Discussion here is from the old edition. Lecture #14: 0.0.1 NP-Completeness (Chapter 34 Old Edition Chapter 36) Discussion here is from the old edition. 0.0.2 Preliminaries: Definition 1 n abstract problem Q is a binary relations on a set I of

More information