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
1 25 c 10 c 5 c 1 c quarter dime nickel penny c How can you return 63 in changes to minimize the number of coins ? 25 63 = 2 quarters … 13 10 13 = 1 dime …… 3 1 3 = 3 pennies 0 6 coins This is the optimal solution !!! 3. Greedy Algorithm
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Choose the option which is “locally optimal” in some particular sense !!! depending on problems Making Changes Coins = { 1, 5, 10, 25 } Amount # of coins 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
3 Is this method true in general? Well, … How about coins = { 1, 5, 11 } for making change of 15? Is this optimal? no !!! This is a “heuristic ”. c 11 15 = 1 . ..… 4 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
4 step 0 (initialization) v 1 := 0 v j := w 1j , 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) v j := min { v j , v k + a kj }, 2200 j T go to step 1 Find k such that v k = min{ v j } j T T := T\{ k } P := P { k } Greedy Approach Dijkstra’s Shortest Path Algorithm 1 1 2 3 4 2 3 2 s d 1 2 4
Background image of page 4
5 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 j T 1 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 j T 4 3 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.

Page1 / 31

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