02-greedy

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

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

View Full Document Right Arrow Icon
Greedy Algorithms CS 4102: Algorithms Spring 2014 Mark Floryan 1
Background image of page 1

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

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

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

View Full Document Right Arrow Icon
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)
Background image of page 4
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
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
Making Change  7
Background image of page 7

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

View Full Document Right Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full Document Right Arrow Icon
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
Background image of page 10
Algorithm for making change 11 This algorithm makes change for an amount  A   using coins of denominations               denom [1] >  denom [2] > ∙∙∙ >  denom [ n ] = 1.
Background image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
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 Right Arrow Icon
Ask a homework question - tutors are online