Introduction to NP Instructor: Neelima Gupta 1.

Slides:



Advertisements
Similar presentations
NP-Hard Nattee Niparnan.
Advertisements

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.
NP-Completeness More Reductions. Definitions P: is the class of all decision problems which can be solved in polynomial time, O(n^k) for some constant.
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Concept of Completeness and hardness for a complexity class Definition.
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Complexity 16-1 Complexity Andrei Bulatov Non-Approximability.
CSC5160 Topics in Algorithms Tutorial 2 Introduction to NP-Complete Problems Feb Jerry Le
1 Pseudo-polynomial time algorithm (The concept and the terminology are important) Partition Problem: Input: Finite set A=(a 1, a 2, …, a n } and a size.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
The Theory of NP-Completeness
NP-Complete Problems Problems in Computer Science are classified into
Analysis of Algorithms CS 477/677
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Chapter 11: Limitations of Algorithmic Power
GRAPH Learning Outcomes Students should be able to:
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
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.
MS 101: Algorithms Instructor Neelima Gupta
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Approximation Algorithms
CSC 413/513: Intro to Algorithms NP Completeness.
Polynomial-time reductions We have seen several reductions:
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
Data Structures & Algorithms Graphs
1 Design and Analysis of Algorithms Yoram Moses Lecture 11 June 3, 2010
Unit 9: Coping with NP-Completeness
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
1/24 Introduction to Graphs. 2/24 Graph Definition Graph : consists of vertices and edges. Each edge must start and end at a vertex. Graph G = (V, E)
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.
NP-Complete problems.
Instructor Neelima Gupta Table of Contents Class NP Class NPC Approximation Algorithms.
NP-Algorithms Tractable vs Intractable Some problems are intractable: as they grow large, we are unable to solve them in reasonable time.
CSCI 2670 Introduction to Theory of Computing November 17, 2005.
LIMITATIONS OF ALGORITHM POWER
Algorithms for hard problems Introduction Juris Viksna, 2015.
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Approximation Algorithms by bounding the OPT Instructor Neelima Gupta
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
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.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
The NP class. NP-completeness
P & NP.
Chapter 10 NP-Complete Problems.
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 29 NP-Completeness and course wrap-up
CS4234 Optimiz(s)ation Algorithms
Computability and Complexity
CS154, Lecture 16: More NP-Complete Problems; PCPs
Analysis and design of algorithm
ICS 353: Design and Analysis of Algorithms
Richard Anderson Lecture 25 NP-Completeness
Approximation Algorithms
Chapter 11 Limitations of Algorithm Power
NP-Complete Problems.
Prabhas Chongstitvatana
The Theory of NP-Completeness
CS154, Lecture 16: More NP-Complete Problems; PCPs
Instructor: Aaron Roth
Presentation transcript:

Introduction to NP Instructor: Neelima Gupta 1

Table of Contents Problems to be discussed Clique Vertex Cover Hamiltonian Cycle Independent Set Set Cover Subset Sum

Optimization Problems we have seen Weighted Interval Scheduling Matrix Chain Multiplication Segmented Least Squares Knapsack Sequence Alignment Shortest Path - Solvable in Polynomial Time by Dynamic Programming or Greedy Approach except 0-1 Knapsack which is Pseudo-polynomial.

Optimization Vs Decision Problems In case of Optimization problems, each feasible solution has an associated value, and we want the feasible solution with the ‘best’ value. Eg: Shortest path problem Given an undirected graph (G,s,t), we want to compute the shortest path from vertex s to vertex t (path using fewest edges).

Optimization & Decision Problems In case of Decision problems, the answer to the problem is a simple ‘yes’ or a ‘no’ (more formally, 1 or 0). We can obtain a related decision problem for a given optimization problem by bounding the value to be optimized. Eg: Shortest path problem (Decision Version 1) Given an undirected graph (G,s,t,k), is there a path from vertex s to vertex t consisting of exactly k edges? Shortest path problem (decision version 2) Given an undirected graph (G,s,t,k), is there a path from vertex s to vertex t consisting of at most k edges?

Exercise 1 Give the decision versions (of type 2) for the following problems : i. Longest Common Subsequence ii. Matrix Chain Multiplication iii. Optimal Binary Search Tree iv. Activity Selection Problem v. Minimum Spanning Tree

Class NP The class of decision problems for which there is a polynomially bounded nondeterministic algorithm. Or Equivalently The class of decision problems which can be verified in polynomial time.

Verification A Verification algorithm takes as an input, a problem instance, and a certificate and decides whether it is a yes-instance. A(x,y) = 1; iff, y is a valid certificate. input certificate instance

Verification: Shortest Path Example Let L 1 - SP = { : Э a path from s to t of length = k} Let x  SP, then we claim that Э a certificate y such that, can be verified in polynomial time. What is that? Ans: Since x  SP, Э a path (sequence of vertices) from s to t of length = k. This path itself serves as the certificate y. What does the verification algorithm do? Ans: Just check that the given sequence of vertices in y indeed forms a path in G (i.e. check that between every consecutive pair of vertices there is an edge in G) and, That its length is k.

Verification – Running Time Adjacency Matrix Representation of Graphs: Checking an edge takes constant time. Linked List representation of Graphs: To check an edge, we can scan the adjacency list of one of its end points. Since length of the adjacency list is O(V), it can be checked in O(V) time. In either case checking an edge takes O(V) time. How many checks? Ans: O(V) Thus the total time is O(V 2 ) time. Hence, we can verify the certificate in polynomial time.

More NP Problems Clique Vertex Cover Hamiltonian Cycle Independent Set Set Cover Subset Sum

Definition: Clique Given an undirected graph G =(V,E), a clique is a subset V’of V such that every pair of vertices in V’ is connected by an edge in E. In the graph to the right, vertices {1,2,5} form a clique since there is an edge between every pair of edges of this set.

Green ovals represent CLIQUE for this graph G

Clique Problem OPTimization Problem : Given an undirected graph G find a largest Clique in G. Decision problem: Given G, does there exist a clique of size equal to k in G? Clique = {(G,k): G contains a clique of size k}

Clique is in NP Clique = { : G has a clique of size k} For x = in Clique, does there exist a certificate y: |y| = polynomial in the length of x and a polynomial time algorithm that can use y to verify that x is in Clique? Show the existence of y, Show that |y| = polynomial in the length of |x|, Give an algorithm that verifies x using y, Show that the algorithm runs in polynomial time in |y| and |x| and hence in polynomial time in the length of |x|. SO, FOUR STEPS TO SHOW THAT A PROBLEM IS IN NP

Verification Let x (=(G,k))  Clique, then we claim that Э a certificate y such that, i.e. can be verified in polynomial time. Since x  Clique, Э a clique of size k in G (by the definition of the set). This set of vertices itself serves as the certificate y. Clearly |y| is no more than the number of vertices in G. i.e. |y| = O(|x|) What does the verification algorithm do? Ans: Just check that the given set of vertices in y indeed forms a clique in G and, That its size is k.

Verification Algorithm Algo: For every pair of vertices u and v in y, check that there exists an edge (u,v) in G Running Time: : k C 2 * degree(u) = k C 2.O(V) = O(k 2 ).O(V) =O(V 2.V) =O(V 3 ) Checking the |y| is k takes constant time. Hence, we can verify the certificate in polynomial time.

Vertex Cover A vertex cover of an undirected graph G = (V,E) is a subset V’ of V, such that if an edge (u,v) Є E, then at least one of u and v is in V’.

with V` = {1,2,3,4} edges covered are, with V` = {1,2,3,4,6} edges covered are, Minimal set V` to cover all edges is {2,3,6,8},

Vertex Cover Problem OPTimization Problem : Given an undirected graph G find a smallest vertex cover in G. VC(G,k) : Given G, does there exist a vertex cover of size equal to k in G? VC = {(G,k): G contains a vertex cover of size k}

Vertex Cover is in NP VC = { : G has a vertex cover of size k} For x = inVC, does there exist a certificate y: |y| = polynomial in the length of x and a polynomial time algorithm that can use y to verify that x is in VC? Show the existence of y, Show that |y| = polynomial in the length of |x|, Give an algorithm that verifies x using y, Show that the algorithm runs in polynomial time in |y| and |x| and hence in polynomial time in the length of |x|. SO, FOUR STEPS TO SHOW THAT A PROBLEM IS IN NP

Verification Let x (=(G,k))  VC, then we claim that Э a certificate y such that, i.e. can be verified in polynomial time. Since x  VC, Э a vertex cover of size k in G (by the definition of the set). This set of vertices itself serves as the certificate y. Clearly |y| is no more than the number of vertices in G. i.e. |y| = O(|x|) What does the verification algorithm do? Ans: Just check that the given set of vertices in y indeed forms a vertex cover in G and, That its size is k.

Verification Algorithm For every edge (u,v) in G check that at least one of the vertices u and v is in y. Running Time: |E| |y| =O(E V) Checking that |y| is k takes constant time. Hence, we can verify the certificate in polynomial time.

Hamiltonian Cycle A Hamiltonian cycle of an undirected graph, G, is a simple cycle that spans every vertex.

Forming an HC,

However, for the graph G`, there does not exist any Hamiltonian cycle. 1) with vertices 1,2,3,4 – not an HC 2) with vertices 1,2,5,6,3 – again not an HC

Hamiltonian Cycle Problem of HC is to find a HC in the given graph. Decision Version: Given an undirected graph G, does G contain a Hamiltonian cycle? HC = {(G) : G contains a Hamiltonian cycle}

HC is in NP HC = { : G has a Hamiltonian cycle} For x = in HC, does there exist a certificate y: |y| = polynomial in the length of x and a polynomial time algorithm that can use y to verify that x is in HC? Show the existence of y, Show that |y| = polynomial in the length of |x|, Give an algorithm that verifies x using y, Show that the algorithm runs in polynomial time in |y| and |x| and hence in polynomial time in the length of |x|. SO, FOUR STEPS TO SHOW THAT A PROBLEM IS IN NP

Verification Let x (=(G)  HC, then we claim that Э a certificate y such that, i.e. can be verified in polynomial time. Since x  HC, G contains a Hamiltonian cycle (by the definition of the set). This sequence of vertices that forms a HC in G itself serves as the certificate y. Clearly |y| is no more than the number of vertices in G. i.e. |y| = O(|x|) What does the verification algorithm do? Ans: Just check that the given sequence of vertices in y indeed forms a Hamiltonian cycle in G.

Verification Algorithm Let y = Algo: For i =1 to m-1 check that (u i,u i+1 ) is an edge in G - check that (u m,u 1 ) is an edge in G - Check that no vertex is repeated. - Check that m = n (i.e. all the vertices have been spanned) Running Time: m |V| + m 2 + constant =O(V 2 ) Hence, we can verify the certificate in polynomial time.

Independent Set Given a graph G = (V,E), a subset S of V is said to be independent if no two nodes in S are joined by an edge in E.

Independent set of size 2

Independent set of size 3

Independent Set Problem OPTimization Problem : Given an undirected graph G find a largest independent set in G. Decision problem: Given G, does there exist an independent set of size equal to k in G? IS = {(G,k): G contains an independent set of size k}

IS is in NP (Exercise) IS = { : G has an IS of size k} For x = in IS, does there exist a certificate y: |y| = polynomial in the length of x and a polynomial time algorithm that can use y to verify that x is in IS? Show the existence of y, Show that |y| = polynomial in the length of |x|, Give an algorithm that verifies x using y, Show that the algorithm runs in polynomial time in |y| and |x| and hence in polynomial time in the length of |x|. SO, FOUR STEPS TO SHOW THAT A PROBLEM IS IN NP

Set Cover Problem Given a collection U of elements and a family S of subsets of U, a cover C is a sub-family of S ( i.e. a collection of subsets from S) whose union is U. Example: U = {1,2,3,4} S1 = {1,2}, S2 = {2,3}, S3 = {1,3,4}, S4 = {3,4}, S5 = {3}, S6 = {4} Then S1, S2, S3 is a cover of size 3; S1, S2, S6 is a cover of size 3; And S3, S1 is also a cover of size 2; We are interested in finding a cover of minimum size. Set Cover is in NP (Exercise)

Subset Sum Problem Given: A finite set S of integers and a target t є I. To Find: If there exists a subset S’ of S whose elements sum up to t. Subset Sum is in NP (Exercise)

Acknowledgement Scribe by MSc (Computer Science) Prashant Singh ( NP Class) Sapna Grover ( P and NP, Vertex Cover, HC….) Soniya Verma (Independent Set) Shivam Sharma (Clique)

End