greedy

greedy - Greedy Methods Problems whose solutions can be...

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

View Full Document Right Arrow Icon
Greedy Methods Greedy Methods
Background image of page 1

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

View Full DocumentRight Arrow Icon
Data Structures and Algorithms II Problems whose solutions can be “ranked” Travel Investment Course selection Feasible solutions stay on highway, finish in x days don’t spend more than one has finish in 4 years Optimal shortest distance, minimum time maximum returns, minimum risks best combination of depth and breadth Decisions which highways to take invest or not in a portfolio take a course or not
Background image of page 2
Data Structures and Algorithms II ± Decisions can be made ² one at a time, without backtracking ² Greedy method ² Which decisions to make next ? ² How to guarantee optimality? ± Try many (all) possible combinations and choose one which is the best ² Dynamic programming ² How to test multiple solutions efficiently?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Data Structures and Algorithms II The Greedy Method ± Input n elements stored in an array A ( 1:n ) ± Procedure Greedy ² Solution = NULL ² for i=1 to n do ¾ x = SELECT( A ) ¾ if FEASIBLE(Solution, x) ¾ then Solution = UNION(Solution, x) ¾ endif ² enddo ² return (Solution)
Background image of page 4
Data Structures and Algorithms II ± A sequence of n decisions w.r.t n inputs ± SELECT: select one of the remaining decisions to make according to some optimization measure ² once a decision is made, it will not become invalid at a later time ² optimization should be based on the partial solutions built so far ± FEASIBLE: whether the partial solution satisfies some preset constraints
Background image of page 5

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

View Full DocumentRight Arrow Icon
Data Structures and Algorithms II ± Strategy : construct feasible solutions one step at a time which optimize (minimize or maximize) a certain objective function ± Make the obvious decisions first ! ± Then try to show it is indeed optimal!
Background image of page 6
Data Structures and Algorithms II Knapsack problem ± Input: ² a set of n objects ² a knapsack of capacity M ± Output: fill the knapsack to maximize the total profit earned ± Feasibility constraint: ± Objective function: (, ) , . . . , PW i n ii = 1 WX M i n = 1 max PX X i n i = ≤≤ 1 01
Background image of page 7

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

View Full DocumentRight Arrow Icon
Data Structures and Algorithms II ± Example n M PPP WWW XX X W X P X ii i n i n == = = ∑∑ 32 0 25 2415 181510 1 2 15 02 0 2 8 2 0 2 3 12 0 3 1 01 1 2 20 315 123 11 , (, , ) ( , , ) , )(, ,) , ) (, , ) . (, ,) (,, ) . largest increase in profit smallest increase in weight largest increase in profit to weight ratio ( . , . , . P W P W P W 1 1 2 2 3 3 1391615) =
Background image of page 8
Data Structures and Algorithms II ± For all three algorithms ² decisions are made one object at a time ² the ordering is determined by some optimization measure ¾ Largest increase in profit ³ Include the remaining object of the largest profit ¾ Smallest increase in weight ³ Include the remaining object of the smallest weight ¾ Largest increase in profit/weight ³ Include the remaining object of the largest profit/weight ² never backtrack ² all greedy algorithms ² not all guarantee optimal
Background image of page 9

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

View Full DocumentRight Arrow Icon
Data Structures and Algorithms II ± Proposition : Greedy selection based on maximizing profit to weight ratio gives the optimal result ± General proof strategy : ² Assume that the greedy solution is ² Assume that the optimal solution is ² Then they better be different ² Transform Y into X without decreasing the profit of Y XX X X n = (, , . . . , ) 12 YY Y Y n = , . . . , )
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/06/2008 for the course CS 130B taught by Professor Suri during the Winter '08 term at UCSB.

Page1 / 75

greedy - Greedy Methods Problems whose solutions can be...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online