













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Reviews of various algorithms and concepts related to np-completeness, including dynamic programming, greedy algorithms, activity selection, and np-complete problems. The reviews cover the concepts of optimal substructure, overlapping subproblems, and the greedy choice property, as well as specific problems such as the knapsack problem and the hamiltonian cycle problem.
Typology: Slides
1 / 21
This page cannot be seen from the preview
Don't miss anything!














Review: Dynamic Programming
■ Optimal substructure: optimal solution to problem consists of optimal solutions to subproblems ■ Overlapping subproblems: few subproblems in total, many recurring instances of each ■ Basic approach: ○ Build a table of solved subproblems that are used to solve larger ones ○ What is the difference between memoization and dynamic programming? ○ Why might the latter be more efficient?
Review: Activity-Selection Problem
■ Buy a wristband that lets you onto any ride ■ Lots of rides, starting and ending at different times ■ Your goal: ride as many rides as possible
■ Ride the first ride, when get off, get on the very next ride possible, repeat until carnival ends
Review: Activity-Selection
■ Given a set S of n activities ○ s (^) i = start time of activity i fi = finish time of activity i ■ Find max-size subset A of compatible activities ■ Assume activities sorted by finish time
Review: Greedy Choice Property For Activity Selection
■ Locally optimal choice ⇒ globally optimal sol’n ■ Them 17.1: if S is an activity selection problem sorted by finish time, then ∃ optimal solution A ⊆ S such that {1} ∈ A ○ 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.
Review: The Knapsack Problem
■ A thief must choose among n items, where the i th item worth vi dollars and weighs w (^) i pounds ■ Carrying at most W pounds, maximize value
■ Thief can take fractions of items ■ Think of items in 0-1 problem as gold ingots, in fractional problem as buckets of gold dust
Polynomial-Time Algorithms
■ Of course: every algorithm we’ve studied provides polynomial-time solution to some problem ■ We define P to be the class of problems solvable in polynomial time
■ No: Turing’s “Halting Problem” is not solvable by any computer, no matter how much time is given ■ Such problems are clearly intractable, not in P
NP-Complete Problems
■ No polynomial-time algorithm has been discovered for an NP-Complete problem ■ No suprapolynomial lower bound has been proved for any NP-Complete problem, either
■ The biggest open problem in CS
P and NP
■ What the hell is that?
Nondeterminism
■ If a solution exists, computer always guesses it ■ One way to imagine it: a parallel computer that can freely spawn an infinite number of processes ○ Have one processor work on each possible solution ○ All processors attempt to verify that their solution works ○ If a processor finds it has a working solution ■ So: NP = problems verifiable in polynomial time
NP-Complete Problems
■ If any one NP-Complete problem can be solved in polynomial time… ■ …then every NP-Complete problem can be solved in polynomial time… ■ …and in fact every problem in NP can be solved in polynomial time (which would show P = NP ) ■ Thus: solve hamiltonian-cycle in O( n^100 ) time, you’ve proved that P = NP. Retire rich & famous.
Reduction
■ 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 ○ What do you suppose “easily” means? ○ This rephrasing is called transformation ■ Intuitively: If P reduces to Q, P is “no harder to solve” than Q
Using Reductions
■ If P is NP-Complete, P ∈ NP and all problems R are reducible to P ■ Formally: R ≤p P ∀ R ∈ NP
■ This is the key idea you should take away today
Coming Up
■ Graph coloring (= register allocation) ■ Hamiltonian cycle ■ Hamiltonian path ■ Knapsack problem ■ Traveling salesman ■ Job scheduling with penalities ■ Many, many more