Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 6 Greedy Algorithms

Similar presentations


Presentation on theme: "Lecture 6 Greedy Algorithms"— Presentation transcript:

1 Lecture 6 Greedy Algorithms

2 Basic Algorithm Design Techniques
Divide and conquer Dynamic Programming Greedy Common Theme: To solve a large, complicated problem, break it into many smaller sub-problems.

3 Greedy Algorithm If a problem requires to make a sequence of decisions, for the first decision, make the “best” choice given the current situation. (This automatically reduces the problem to a smaller sub-problem which requires making one fewer decisions)

4 Warm-up: Walking in Manhattan
“Walk in a direction that reduces distance to the destination.”

5 Greedy does not always work
Driving in New York: one-way streets, traffic…

6 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.

7 Fractional Knapsack Problem
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+…+pnvn maximized.

8 Example Capacity W = 10, 3 items with (weight, value) = (6, 20), (5, 15), (4, 10) Solution: Item Item 2. Weight = 10, Value = 32

9 Interval Scheduling There are n meeting requests, meeting i takes time (si, ti) Cannot schedule two meeting together if their intervals overlap. Goal: Schedule as many meetings as possible. Example: Meetings (1,3), (2, 4), (4, 5), (4, 6), (6, 8) Solution: 3 meetings ((1, 3), (4, 5), (6, 8))


Download ppt "Lecture 6 Greedy Algorithms"

Similar presentations


Ads by Google