Unformatted text preview: lusion 92 Greedy algorithm summary Algorithms we saw: Coin change Knapsack algorithm Interval scheduling Prim’s MST Kruskal’s MST Dijkstra’s shortest path Huffman Codes 93 Greedy Method: Overview Optimization problems: terminology Solutions judged on some criteria: Objective function A solution must meet certain constraints: A solution is
feasible 94 Example: Sum of edge weights in path is smallest Example: All edges in solution are in graph, form a simple path One (or more) feasible solutions that scores highest (by
the objective function) is the optimal solution(s) Greedy Method: Overview Greedy strategy: Build solution by stages, adding one item to partial
solution found so far At each stage, make locally optimal choice based on the
greedy rule (sometimes called the selection function) Locally optimal, i.e. best given what info we have now Irrevocable, a choice can’t be un-done Sequence of locally optimal choices leads to globally
optimal solution (hopefully) 95 Must prove this for a given problem!
Approximation algorithms, heuristics Proving them correct Given a greedy algorithm, how do you show it is
optimal? As opposed to other types of algorithms (divide-andconquer , etc.) One way is to compare the solution given with an
optimal solution Another way is through induction 96 Proving a greedy algorithm is correct
Show that it fulfills the greedy-choice property 1. Does making a greedy choice at any arbitrary point yield
an optimal solution? Consider an optimal solution to a sub-problem Show that making the greedy choice will yield an optimal
solution to the overall problem Show that it has optimal sub-structure 2. Show that a solution to a problem contains optimal
solutions to sub-problems . Or
97 induction! Warning! Proving that an algorithm makes a greedy choice at
each stage is NOT the same as showing that the
algorithm has the greedy choice property The first is a property of the algorithm designed The second shows that making the greedy choice will
yield an optimal solution to the overall problem 98...
View Full Document
This note was uploaded on 02/25/2014 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.
- Spring '10