1 / 9

Lecture 8 Greedy Algorithms

Lecture 8 Greedy Algorithms. Design and Analysis. Designing a Greedy Algorithm: 1. Break the problem into a sequence of decisions. 2. Identify a rule for the “best” option. Analyzing a Greedy Algorithm: Important! Often fails if you cannot find a proof.

hovan
Download Presentation

Lecture 8 Greedy Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 8 Greedy Algorithms

  2. Design and Analysis • Designing a Greedy Algorithm: • 1. Break the problem into a sequence of decisions. • 2. Identify a rule for the “best” option. • Analyzing a Greedy Algorithm: • Important! Often fails if you cannot find a proof. • Technique: Proof by contradiction.Assume there is a better solution, show that it is actually not better than what the algorithm did.

  3. Example 2: Fractional Knapsack • There is a knapsack that can hold items of total weight at most W. There are now n items with weights w1,w2,…, wn. Each item also has a value v1,v2,…,vn. • The items are infinitely divisible: can put ½ (or any fraction) of an item into the knapsack. • Goal: Select fractions p1,p2,…,pn such that • Capacity constraint: p1w1+p2w2+…+pnwn <= W • Maximum Value: p1v1+p2v2+…+pnvnmaximized.

  4. Designing the Algorithm • Think of the problem as making a sequence of decisions- Pick one item to put into the knapsack • Think of all the options for the first decision, use a simple criteria to select the “best” • Question: Which item should we put in first?A. The one that has max valueB. The one that has min weightC. The one that has max value/weight

  5. Proof Idea • Assume there is a better solution OPT • Find some contradiction • Previously: can make the solution OPT the same as ALG, so OPT cannot be better • Fractional Knapsack: By combining ALG and OPT, can find a better solution.

  6. Example 3: Horn-SAT • Considers puzzles like • If Mr. Smith has a dog, then Mrs. Brown has a cat. • If Mr. Jones has a dog, then he has a cat too. • If Mr. Smith has a dog and Mr. Jones has a cat, then Mrs. Peacock has a dog. • If Mrs. Brown and Mr. Jones share a pet of the same species, then Mr. Smith has a cat • All the men have dogs. • Not all women have cats.

  7. Example 3: Horn-SAT • Logical formulas • Variable – true or false • Negation • Horn Clauses • Problem: Given a set of Horn clauses, determine whether there exists an assignment to variables such that all clauses are satisfied.

  8. Designing the Algorithm • Think of the problem as making a sequence of decisions- Decide which variables are true • Think of all the options for the first decision, use a simple criteria to select the “best” • Question: Which variable has to be true?

  9. Proof Idea • If the algorithm succeeds, then there is clearly an assignment • Need to show: if the algorithm fails, then no assignment can satisfy the clauses • Assume there is actually an assignment, how to find a contradiction?

More Related