David Luebke 1 1/14/2016 CS 332: Algorithms NP Completeness.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

CS 332: Algorithms NP Completeness David Luebke /2/2017.
1 P, NP, and NP-Complete Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Analysis of Algorithms
Greed is good. (Some of the time)
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,
Department of Computer Science & Engineering
David Luebke 1 5/4/2015 CS 332: Algorithms Dynamic Programming Greedy Algorithms.
The Theory of NP-Completeness
CPE702 Complexity Classes Pruet Boonma Department of Computer Engineering Chiang Mai University Based on Material by Jenny Walter.
Review: Dynamic Programming
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
Lecture 7: Greedy Algorithms II Shang-Hua Teng. Greedy algorithms A greedy algorithm always makes the choice that looks best at the moment –My everyday.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
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
Chapter 11: Limitations of Algorithmic Power
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
P, NP, and NP-Complete Suzan Köknar-Tezel.
Week 2: Greedy Algorithms
Lecture 7: Greedy Algorithms II
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
NP Complete: The Exciting Conclusion Review For Final
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Programming & Data Structures
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
CSCE350 Algorithms and Data Structure
Bold Stroke January 13, 2003 Advanced Algorithms CS 539/441 OR In Search Of Efficient General Solutions Joe Hoffert
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
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
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
David Luebke 1 10/24/2015 CS 332: Algorithms Greedy Algorithms Continued.
CSC 413/513: Intro to Algorithms NP Completeness.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
Prof. Mario Pavone Computazione Naturale CdL Magistrale in Informatica SDAI – DMI – UniCt Teoria.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
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.
Greedy Methods and Backtracking Dr. Marina Gavrilova Computer Science University of Calgary Canada.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
CSC 201: Design and Analysis of Algorithms Greedy Algorithms.
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.
NP-Complete problems.
Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality.
NP-Complete Problems Algorithm : Design & Analysis [23]
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
NP-Algorithms Tractable vs Intractable Some problems are intractable: as they grow large, we are unable to solve them in reasonable time.
CSE 589 Part V One of the symptoms of an approaching nervous breakdown is the belief that one’s work is terribly important. Bertrand Russell.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
Greedy Algorithms BIL741: Advanced Analysis of Algorithms I (İleri Algoritma Çözümleme I)1.
NPC.
David Luebke 1 2/18/2016 CS 332: Algorithms NP Completeness Continued: Reductions.
CSC 413/513: Intro to Algorithms
1 Ch 10 - NP-completeness Tractable and intractable problems Decision/Optimization problems Deterministic/NonDeterministic algorithms Classes P and NP.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
1 The Theory of NP-Completeness 2 Review: Finding lower bound by problem transformation Problem X reduces to problem Y (X  Y ) iff X can be solved by.
CS 154 Formal Languages and Computability May 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS6045: Advanced Algorithms Greedy Algorithms. Main Concept –Divide the problem into multiple steps (sub-problems) –For each step take the best choice.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
P & NP.
CS 3343: Analysis of Algorithms
RAIK 283 Data Structures & Algorithms
Presentation transcript:

David Luebke 1 1/14/2016 CS 332: Algorithms NP Completeness

David Luebke 2 1/14/2016 Administrivia l Homework 5 clarifications: n Deadline extended to Thursday Dec 7 n However, no late assignments will be accepted u This is so that I can discuss it in class n You may not work with others on this one

David Luebke 3 1/14/2016 Review: Dynamic Programming l When applicable: n Optimal substructure: optimal solution to problem consists of optimal solutions to subproblems n Overlapping subproblems: few subproblems in total, many recurring instances of each n Basic approach: u Build a table of solved subproblems that are used to solve larger ones u What is the difference between memoization and dynamic programming? u Why might the latter be more efficient?

David Luebke 4 1/14/2016 Review: Greedy Algorithms l A greedy algorithm always makes the choice that looks best at the moment n The hope: a locally optimal choice will lead to a globally optimal solution n For some problems, it works u Yes: fractional knapsack problem u No: playing a bridge hand l Dynamic programming can be overkill; greedy algorithms tend to be easier to code

David Luebke 5 1/14/2016 Review: Activity-Selection Problem l The activity selection problem: get your money’s worth out of a carnival n Buy a wristband that lets you onto any ride n Lots of rides, starting and ending at different times n Your goal: ride as many rides as possible l Naïve first-year CS major strategy: n Ride the first ride, when get off, get on the very next ride possible, repeat until carnival ends l What is the sophisticated third-year strategy?

David Luebke 6 1/14/2016 Review: Activity-Selection l Formally: n Given a set S of n activities u s i = start time of activity i f i = finish time of activity i n Find max-size subset A of compatible activities n Assume activities sorted by finish time l What is optimal substructure for this problem?

David Luebke 7 1/14/2016 Review: Activity-Selection l Formally: n Given a set S of n activities u s i = start time of activity i f i = finish time of activity i n Find max-size subset A of compatible activities n Assume activities sorted by finish time l What is optimal substructure for this problem? n A: If k is the activity in A with the earliest finish time, then A - {k} is an optimal solution to S’ = {i  S: s i  f k }

David Luebke 8 1/14/2016 Review: Greedy Choice Property For Activity Selection l Dynamic programming? Memoize? Yes, but… l Activity selection problem also exhibits the greedy choice property: n Locally optimal choice  globally optimal sol’n n Them 17.1: if S is an activity selection problem sorted by finish time, then  optimal solution A  S such that {1}  A u Sketch of proof: if  optimal solution B that does not contain {1}, can always replace first activity in B with {1} (Why?). Same number of activities, thus optimal.

David Luebke 9 1/14/2016 Review: The Knapsack Problem l The 0-1 knapsack problem: n A thief must choose among n items, where the ith item worth v i dollars and weighs w i pounds n Carrying at most W pounds, maximize value l A variation, the fractional knapsack problem: n Thief can take fractions of items n Think of items in 0-1 problem as gold ingots, in fractional problem as buckets of gold dust l What greedy choice algorithm works for the fractional problem but not the 0-1 problem?

David Luebke 10 1/14/2016 Homework 4 l Problem 1 (detecting overlap in rectangles): n “Sweep” vertical line across rectangles; keep track of line-rectangle intersections with interval tree n Need to sort rectangles by X min, X max n Then need to do O(n) inserts and deletes n Total time: O(n lg n)

David Luebke 11 1/14/2016 Homework 4 l Problem 2: Optimizing Kruskal’s algorithm n Edge weights integers from 1 to |V|: u Use counting sort to sort edges in O(V+E) time = O(E) time (Why?)  Bottleneck now the disjoint-set unify operations, so total algorithm time now O(E  (E,V)) n Edge weights integers from 1 to constant W: u Again use counting sort to sort edges in O(W+E) time u Which again = O(E) time  Which again means O(E  (E,V)) total time

David Luebke 12 1/14/2016 Homework 4 l Problem 3: Optimizing Prim’s algorithm n Running time of Prim’s algorithm depends on the implementation of the priority queue n Edge weights integers from 1 to constant W: u Implement queue as an array Q[1..W+1] u The ith slot in Q holds doubly-linked list of vertices with key = i (What does slot W+1 represent?) u Extract-Min() takes O(1) time (How?) u Decrease-Key() takes O(1) time (How?) u Total asymptotic running time of Prims: O(E)

David Luebke 13 1/14/2016 Homework 4 l Problem 4: n No time to cover here, sorry

David Luebke 14 1/14/2016 NP-Completeness l Some problems are intractable: as they grow large, we are unable to solve them in reasonable time l What constitutes reasonable time? Standard working definition: polynomial time n On an input of size n the worst-case running time is O(n k ) for some constant k n Polynomial time: O(n 2 ), O(n 3 ), O(1), O(n lg n) n Not in polynomial time: O(2 n ), O(n n ), O(n!)

David Luebke 15 1/14/2016 Polynomial-Time Algorithms l Are some problems solvable in polynomial time? n Of course: every algorithm we’ve studied provides polynomial-time solution to some problem n We define P to be the class of problems solvable in polynomial time l Are all problems solvable in polynomial time? n No: Turing’s “Halting Problem” is not solvable by any computer, no matter how much time is given n Such problems are clearly intractable, not in P

David Luebke 16 1/14/2016 NP-Complete Problems l The NP-Complete problems are an interesting class of problems whose status is unknown n No polynomial-time algorithm has been discovered for an NP-Complete problem n No suprapolynomial lower bound has been proved for any NP-Complete problem, either l We call this the P = NP question n The biggest open problem in CS

David Luebke 17 1/14/2016 An NP-Complete Problem: Hamiltonian Cycles l An example of an NP-Complete problem: n A hamiltonian cycle of an undirected graph is a simple cycle that contains every vertex n The hamiltonian-cycle problem: given a graph G, does it have a hamiltonian cycle? u Draw on board: dodecahedron, odd bipartite graph n Describe a naïve algorithm for solving the hamiltonian-cycle problem. Running time?

David Luebke 18 1/14/2016 P and NP l As mentioned, P is set of problems that can be solved in polynomial time l NP (nondeterministic polynomial time) is the set of problems that can be solved in polynomial time by a nondeterministic computer n What the hell is that?

David Luebke 19 1/14/2016 Nondeterminism l Think of a non-deterministic computer as a computer that magically “guesses” a solution, then has to verify that it is correct n If a solution exists, computer always guesses it n One way to imagine it: a parallel computer that can freely spawn an infinite number of processes u Have one processor work on each possible solution u All processors attempt to verify that their solution works u If a processor finds it has a working solution n So: NP = problems verifiable in polynomial time

David Luebke 20 1/14/2016 P and NP l Summary so far: n P = problems that can be solved in polynomial time n NP = problems for which a solution can be verified in polynomial time n Unknown whether P = NP (most suspect not) l Hamiltonian-cycle problem is in NP: n Cannot solve in polynomial time n Easy to verify solution in polynomial time (How?)

David Luebke 21 1/14/2016 NP-Complete Problems l We will see that NP-Complete problems are the “hardest” problems in NP: n If any one NP-Complete problem can be solved in polynomial time… n …then every NP-Complete problem can be solved in polynomial time… n …and in fact every problem in NP can be solved in polynomial time (which would show P = NP) n Thus: solve hamiltonian-cycle in O(n 100 ) time, you’ve proved that P = NP. Retire rich & famous.

David Luebke 22 1/14/2016 Reduction l The crux of NP-Completeness is reducibility n Informally, a problem P can be reduced to another problem Q if any instance of P can be “easily rephrased” as an instance of Q, the solution to which provides a solution to the instance of P u What do you suppose “easily” means? u This rephrasing is called transformation n Intuitively: If P reduces to Q, P is “no harder to solve” than Q

David Luebke 23 1/14/2016 Reducibility l An example: n P: Given a set of Booleans, is at least one TRUE? n Q: Given a set of integers, is their sum positive? n Transformation: (x 1, x 2, …, x n ) = (y 1, y 2, …, y n ) where y i = 1 if x i = TRUE, y i = 0 if x i = FALSE l Another example: n Solving linear equations is reducible to solving quadratic equations u How can we easily use a quadratic-equation solver to solve linear equations?

David Luebke 24 1/14/2016 Using Reductions l If P is polynomial-time reducible to Q, we denote this P  p Q l Definition of NP-Complete: n If P is NP-Complete, all problems R  NP are reducible to P n Formally: R  p P  R  NP l If P  p Q and P is NP-Complete, Q is also NP- Complete n This is the key idea you should take away today

David Luebke 25 1/14/2016 Coming Up l Given one NP-Complete problem, we can prove many interesting problems NP-Complete n Graph coloring (= register allocation) n Hamiltonian cycle n Hamiltonian path n Knapsack problem n Traveling salesman n Job scheduling with penalities n Many, many more

David Luebke 26 1/14/2016 The End