Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.

Similar presentations


Presentation on theme: "ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department."— Presentation transcript:

1 ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department

2 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Reading Assignment M. Alsuwaiyel, Introduction to Algorithms: Design Techniques and Analysis, World Scientific Publishing Co., Inc. 1999. Chapter 10 Sections 1 – 4 2

3 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms NP-Complete Problems Problems in Computer Science are classified into Tractable: There exists a polynomial time algorithm that solves the problem O(n k ) Intractable: Unlikely for a polynomial time algorithm solution to exist NP-Complete Problems 3

4 103 ICS 353: Design and Analysis of Algorithms Decision Problems vs. Optimization Problems Decision Problem: Yes/no answer Optimization Problem: Maximization or minimization of a certain quantity When studying NP-Completeness, it is easier to deal with decision problems than optimization problems 4

5 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Element Uniqueness Problem Decision Problem: Element Uniqueness Input: A sequence of integers S Question: Are there two elements in S that are equal? Optimization Problem: Element Count Input: A sequence of integers S Output: An element in S of highest frequency What is the algorithm to solve this problem? How much does it cost? 5

6 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Coloring a Graph Decision Problem: Coloring –Input: G=(V,E) undirected graph and k , k > 0. –Question: Is G k-colorable? Optimization Problem: Chromatic Number –Input: G=(V,E) undirected graph –Output: The chromatic number of G,  (G) i.e. the minimum number  (G) of colors needed to color a graph in such a way that no two adjacent vertices have the same color. 6

7 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Clique Definition: A clique of size k in G, for some +ve integer k, is a complete subgraph of G with k vertices. Decision Problem Input: Question: Optimization Problem Input: Output: 7

8 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Vertex Cover Definition: A vertex cover of an undirected graph G=(V,E) is a subset C  V such that each edge e=(x,y)  E is incident to at least one vertex in C, i.e. x  C or y  C. Decision Problem Input: Question: Optimization Problem Input: Output: 8

9 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Independent Set Definition: Given an undirected graph G=(V,E) a subset S  V is called an independent set if for each pair of vertices x, y  S, (x,y)  E Decision Problem Input: Question: Optimization Problem Input: Output: 9

10 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms From Decision To Optimization For a given problem, assume we were able to find a solution to the decision problem in polynomial time. Can we find a solution to the optimization problem in polynomial time also? 10

11 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Deterministic Algorithms Definition: Let A be an algorithm to solve problem . A is called deterministic if, when presented with an instance of the problem , it has only one choice in each step throughout its execution. If we run A again and again, is there a possibility that the output may change? What type of algorithms did we have so far? 11

12 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms The Class P Definition: The class of decision problems P consists of those whose yes/no solution can be obtained using a deterministic algorithm that runs in polynomial time of steps, i.e. O(n k ), where k is a non-negative integer and n is the input size. 12

13 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Examples Sorting: Given n integers, are they sorted in non-decreasing order? Set Disjointness: Given two sets of integers, are they disjoint? Shortest path: 2-coloring: Theorem: A graph G is 2-colorable if and only if G is bipartite 13

14 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Closure Under Complementation C C CA class C of problems is closed under complementation if for any problem   C the complement of  is also in C. Theorem: The class P is closed under complementation 14

15 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Non-Deterministic Algorithms A non-deterministic algorithm A on input x consists of two phases: Guessing: An arbitrary “string of characters y” is generated in polynomial time. It may Correspond to a solution Not correspond to a solution Not be in proper format of a solution Differ from one run to another Verification: A deterministic algorithm verifies The generated “string of characters y” is in proper format Whether y is a solution in polynomial time 15

16 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Non-Deterministic Algorithms (Cont.) Definition: Let A be a nondeterministic algorithm for a problem . We say that A accepts an instance I of  if and only if on input I, there exists a guess that leads to a yes answer. Does it mean that if an algorithm A on a given input I leads to an answer of no for a certain guess, that it does not accept it? What is the running time of a non-deterministic algorithm? 16

17 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms The Class NP Definition: The class of decision problems NP consists of those decision problems for which there exists a nondeterministic algorithm that runs in polynomial time 17

18 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Example Show that the coloring problem belongs to the class of NP problems 18

19 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms P and NP Problems What is the difference between P problems and NP Problems? We can decide/solve problems in P using deterministic algorithms that run in polynomial time We can check or verify the solution of NP problems in polynomial time using a deterministic algorithm What is the set relationship between the classes P and NP? 19

20 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms NP-Complete Problems Definition: Let  and  ’ be two decision problems. We say that  ’ reduces to  in polynomial time, denoted by  ’  poly , if there exists a deterministic algorithm A that behaves as follows: When A is presented with an instance I’ of problem  ’, it transforms it into an instance I of problem  in polynomial time such that the answer to I’ is yes if and only if the answer to I is yes. 20

21 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms NP-Hard and NP-Complete Definition: A decision problem  is said to be NP-hard if  ’  NP,  ’  poly . Definition: A decision problem  is said to be NP-complete if  NP  ’  NP,  ’  poly . What is the difference between an NP-complete problem and an NP-hard problem? 21

22 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Conjunctive Normal Forms Definition: A clause is the disjunction of literals, where a literal is a boolean variable or its negation E.g., x 1  x 2  x 3  x 4 Definition: A boolean formula f is said to be in conjunctive normal form (CNF) if it is the conjunction of clauses. E.g., (x 1  x 2 )  (x 1  x 5 )  (x 2  x 3  x 4  x 6 ) Definition: A boolean formula f is said to be satisfiable if there is a truth assignment to its variables that makes it true. 22

23 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms The Satisfiability Problem Input: A CNF boolean formula f. Question: Is f satisfiable? Theorem: Satisfiability is NP-Complete Satisfiability is the first problem to be proven as NP-Complete The proof includes reducing every problem in NP to Satisfiability in polynomial time. 23

24 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Transitivity of  poly Theorem: Let ,  ’, and  ’’ be three decision problems such that   poly  ’ and  ’  poly  ’’. Then  poly  ’’. Proof: Corollary: If ,  ’  NP such that  ’  poly  and  ’  NP-complete, then   NP-complete Proof: How can we prove that   NP-hard? How can we prove that   NP-complete? 24

25 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Proving NP-Completeness SAT 3-CNF-SAT Subset-Sum CliqueHamiltonian CycleVertex-CoverTraveling Salesman 25

26 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Example NP-Complete Problems 3-CNF-SAT Input: Boolean formula f in CNF, such that each clause consists of exactly three literals. Question: Is f satisfiable. Hamiltonian Cycle Input: G = (V,E), undirected graph. Does G have a cycle that visits each vertex exactly once (Hamiltonian Cycle)? Traveling Salesman Input: A set of n cities with their intercity distances and an integer k. Question: Does there exist a tour of length less than or equal to k? A tour is a cycle that visits each vertex exactly once. 26

27 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Example 1 Show that the traveling salesman problem is NP-complete, assuming that the Hamiltonian cycle problem is NP-complete. 27

28 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Example 2 Prove that the Problem Clique is NP- Complete. Proof: 1.Clique  NP 2.Clique  NP-Hard SAT  poly Clique 28

29 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Example 3 Prove that the problem Vertex Cover is NP- Complete Proof: 29

30 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Example 4 Prove that the problem Independent Set is NP-Complete Proof: 30

31 NP-Complete Problems103 ICS 353: Design and Analysis of Algorithms Example NP-Complete Problems (Cont.) Subset Sum 3-Coloring 3D-Matching Hamiltonian Path Partition Knapsack Bin Packing Set Cover Multiprocessor Scheduling Longest Path … 31


Download ppt "ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department."

Similar presentations


Ads by Google