Presentation is loading. Please wait.

Presentation is loading. Please wait.

Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks.

Similar presentations


Presentation on theme: "Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks."— Presentation transcript:

1 Greedy Algorithms

2 What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks best at that moment ( hoping to find the global optimal through local optimal choices )

3 Example 1: Coins There are 7 kinds of coins: – $0.1, $0.2, $0.5, $1, $2, $5, $10 What is the minimum number of coins needed to pay $18 exactly?

4 Example 2: Stamps There are 16 kinds of stamps – $0.10, $0.20, $0.50, $1.00, $1.40, $1.80, $1.90, $2.00, $2.40, $2.50, $3.00, $5.00, $10.00, $13.00,$20.00, $50.00 What is the minimum number stamps needed to pay $26 exactly ?

5 Greedy Algorithms Advantages – Easy to code – Efficient Disadvantages – Do not always yield optimal solution – Not easy to prove or disprove

6 Greedy Algorithms Examples – Dijkstra’s shortest path algorithm – Prim/Kruskal’s MST algorithms

7 Example 3: Fractional Knapsack There are N objects, each with weight w i and value v i. Any amount ( including fractions ) of each item can be taken provided that the total weight does not exceed W. How much of each item should we take in order to maximize the total value?

8 Optimal substructure An optimal solution to the original problem contains optimal solutions to the sub- problems

9 Greedy-choice Property We can arrive the globally optimal solution by making a locally optimal choice, and then solving the sub-problems

10 Example 4: 0-1 Knapsack problem The situation is the same, exactly that each item can only be taken or left behind Greedy solvable? Why?

11 Steps 1. Show the there is always an optimal solution which makes greedy choice 2.Show that if we combine an optimal solution to the sub-problem with the greedy choice, we can get a optimal solution to the original problem

12 Example 5: Activity There are n activities, starting at time s i and finishing at f i. Choose the maximum number of activities so that they do not overlap each other.

13 Example 5: Activity Greedy Solvable? If so, how? – By first start time? – By shortest duration? – By fewest overlap? – By first end time? – By...

14 Example 5: Activity Must there be an optimal solution contain the greedy choice? Does optimal substructure exist?

15 Example 6: Advertisement There are n intervals, [a i, b i ] Choosing the minimum number of points {p j } so that each interval contains at least one of the points

16 Example 6: Advertisement Must there be an optimal solution contain the greedy choice? Does optimal substructure exist?

17 Example 7: Bridge http://www.plastelina.net/games/game3.html Greedy Solvable?

18 Example 7: Bridge Spilt the cases into: – 3 or less people – 4 people – More than 4 people

19 Example 8: Egyptian fraction An Egyptian fraction is a sum of distinct unit fraction Given a fraction and express it as an Egyptian fraction


Download ppt "Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks."

Similar presentations


Ads by Google