Presentation is loading. Please wait.

Presentation is loading. Please wait.

Greedy Algorithms Seize the moment. Elements and Concerns Often an optimization problem Feasible solutions can be built in steps Quality of the next step.

Similar presentations


Presentation on theme: "Greedy Algorithms Seize the moment. Elements and Concerns Often an optimization problem Feasible solutions can be built in steps Quality of the next step."— Presentation transcript:

1 Greedy Algorithms Seize the moment

2 Elements and Concerns Often an optimization problem Feasible solutions can be built in steps Quality of the next step choices can be measured May produce good solutions quickly May not produce an optimum

3 Ex. 1: Making Change Objectives – Give proper change – Reduce coin count Assume – 1¢, 5¢, 10¢, and 25¢ coins – Need change for a $1.26 purchase from $2.00

4 Change Algorithm What is the largest coin smaller than the remaining change needed? Set aside a coin of that size and subtract the coin’s value from the change needed. Repeat two steps above until no more change is needed. Does this always work?

5 Ex. 1: Making Change Assume – 1¢, 5¢, and 11¢ coins – Need 15¢ in change Does the “greedy” approach minimize the coin count this time? How would you verbalize what changed?

6 Ex. 2: Minimize Average Access Time Using Sequential Storage Optimize average access time for files stored on tapes Assume – Always start at front of tape – Access time for any file is the sum of the access times for itself and all preceding files – All files are accessed with equal frequency

7 Ex. 2: Notation

8 Ex. 2: The Objective Function

9 Ex. 2: An Instance Suppose three files, f1, f2, and f3, with transfer times 34, 12, and 26 time units, respectively. There are six permutations and their AATs are: – f1, f2, f3; AAT = (34 + 34 + 12 + 34 +12 + 26)/3=50.67 – f1, f3, f2; AAT = (34 + 34 + 26 + 34 + 26 + 12)/3=55.33 – f2, f1, f3 ; AAT = (12 + 12 + 34 + 12 + 34 + 26)/3=43.33 – f2, f3, f1 ; AAT = (12 + 12 + 26 + 12 + 26 + 34)/3=40.67 – f3, f1, f2 ; AAT = (26 + 26 + 34 + 26 + 34 + 12)/3=52.67 – f3, f2, f1 ; AAT = (26 + 26 + 12 + 26 + 12 + 34)/3=45.33

10 Ex. 2: Algorithm What would be a greedy algorithm? Does this algorithm always work? Why? Are there other examples of this type of approach? – Huffman coding?

11 Ex. 2: Greedy Always Works

12

13 Ex. 2: Access Time Comparison

14

15 Ex. 3: TSP What would be crucial concerns if designing a “greedy” algorithm for TSP?


Download ppt "Greedy Algorithms Seize the moment. Elements and Concerns Often an optimization problem Feasible solutions can be built in steps Quality of the next step."

Similar presentations


Ads by Google