{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

02-greedy

# 02-greedy - GreedyAlgorithms CS4102:Algorithms Spring2014...

This preview shows pages 1–12. Sign up to view the full content.

Greedy Algorithms CS 4102: Algorithms Spring 2014 Mark Floryan 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Overview 2
Inventory of greedy algorithms 3 Coin change Knapsack algorithm Interval scheduling Prim’s MST Kruskal’s MST Dijkstra’s shortest path Huffman Codes

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Greedy Method: Overview 4 Optimization problems: terminology A solution must meet certain constraints: solution is feasible Example: All edges in solution are in graph, form a simple path Solutions judged on some criteria: Objective function Example: Sum of edge weights in path is smallest One (or more) feasible solutions that scores best (by the objective function) is the optimal solution(s)
Greedy Method: Overview 5 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) Must prove this for a given problem! Approximation algorithms, heuristics

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Proving them correct 6 Given a greedy algorithm, how do you show it is optimal? As opposed to other types of algorithms (divide-and- conquer , etc.) One common way is to compare the solution given with an optimal solution
Making Change  7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Making change: algorithm description 8 The problem: Give back the right amount of change, and… Return the fewest number of coins! Inputs: the dollar-amount to return Also, the set of possible coins. (Do we have half-dollars? That affects the answer we give.) Output: a set of coins
Making change: algorithm solution 9 Problem description: providing coin change of a given amount in the fewest number of coins Inputs: the dollar-amount to return. Perhaps the possible set of coins, if it is non-obvious. Output: a set of coins that obtains the desired amount of change in the fewest number of coins Assumptions: If the coins are not stated, then they are the standard quarter, dime, nickel, and penny. All inputs are non-negative, and dollar amounts are ignored. Strategy: a greedy algorithm that uses the largest coins first

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Making Change 10 Inputs: Value N of the change to be returned An unlimited number of coins of values d1, d2,. ., dk Output: the smallest possible set of coins that sums to N Objective function? Smallest set Constraints on feasible solutions? Must sum to N Greedy rule: choose coin of largest value that is less than N - Sum(coins chosen so far) Always optimal? Depends on set of coin values
Algorithm for making change 11 This algorithm makes change for an amount  A   using coins of denominations               denom [1] >  denom [2] > ∙∙∙ >  denom [ n ] = 1.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 98

02-greedy - GreedyAlgorithms CS4102:Algorithms Spring2014...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online