{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This preview shows pages 1–8. 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right Arrow Icon
6 Does Dijkstra’s algorithm give the optimal solution for a graph with negative edge weights ? No !!! Dijkstra’s algorithm is a heuristic for solving shortest path problems with negative edge weights !!! 1 1 2 3 4 2 3 -2
Image of page 6
7 Procedure MST( G :graph; var T :set of edges) var T , j , n : integer; T i , T j : tree; begin T := ; T i = { i }; i = 1, 2, …, n ; while | T | < n- 1 and E do begin choose an edge e ij such that w ( e ij ) = min{ w ( e ab ) } e ab E E := E \ { e ij }; if e ij does not creat a cycle then
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern