CS300-05_Algorithm_Design - 3. Greedy Algorithm c 25...

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

View Full Document Right Arrow Icon
How can you minimize the number of coins in returning 63 ? 11 25 c 10 c 5 c 1 c quarter dime nickel penny = 2 quarters … 13 = 1 dime …… 3 = 3 pennies 0 6 coins This is the optimal solution !!! 3. Greedy Algorithm c
Background image of page 1

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

View Full DocumentRight Arrow Icon
22 Choose the option which is “locally optimal” in some particular sense !!! C depending on problems Making Changes Coins = { 1, 5, 10, 25 } Amount # of coins H H H H In order the minimize # of coins, reduce the amount of money as much as possible at each stage. Basic Strategy
Background image of page 2
33 Does this method always work? Well, … How about coins = { 1, 5, 11 } for making change of 15? Is this optimal? no !!! H This is a “heuristic ”. c = 1 . ..… 4 = 4 . ..… 0 5
Background image of page 3

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

View Full DocumentRight Arrow Icon
44 step 0 (initialization) v 1 := 0 vj := w1j, j = 2, 3, …, n P := { 1 }, T = {2, 3, …, n } step 1 (Designation of Permanent Label) if T = ( , then stop (if k = d , then stop) step 2 (Revision of Tentative Labels) vj := min { vj , vk + akj }, jj T Find k such that vk = min{ vj } jj T T := T\{ k } P := P { k } Greedy Ap- proach Dijkstra’s Shortest Path Algorithm 1 1 2 3 4 2 3 2 s d 1 2 4
Background image of page 4
55 s = 1, d = 4 1 1 2 3 4 2 3 2 w 12 = 1, w 23 = 3, w 24 = 2, w 34 = 2 v 1 := 0, v 2 := 1, v 3 := ” , v 4 := ” P = { 1 }, T = { 2, 3, 4 } 0 min{ v j } = { v 2, v 3, v 4 } = v 2 jj T 1 M H k = 2 T = { 2, 3, 4 }/{ 2 } = { 3, 4 } P = { 1 } { 2 } = { 1, 2 } 0 1 Is k = 4? No !! v 3 = { v 3, v 2 + w 23 } = { , 1 + 3 } = 4 v 4 = { v 4, v 2 + w 24 } = { , 1 + 2 } = 3 min{ v j } = { v 3, v 4 } = v 4 jj T 4 3 H k = 4 T = { 3, 4 }/{ 4 } = { 3 } P = { 1, 2 } { 4 } = { 1, 2, 4 } 0 1 3 Is k = 4? Yes !! Stop. 1 - 2 - 4 is the shortest path of length 3
Background image of page 5

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

View Full DocumentRight Arrow Icon
Does Dijkstra’s algorithm give the optimal solution for a graph with negative edge weights ? No !!!
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/07/2010 for the course CS 300 taught by Professor Shin during the Spring '10 term at Korea Advanced Institute of Science and Technology.

Page1 / 32

CS300-05_Algorithm_Design - 3. Greedy Algorithm c 25...

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

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