{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS300-05_Algorithm_Design

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

This preview shows pages 1–8. Sign up to view the full content.

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

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

View Full Document
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
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

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

View Full Document
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
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

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

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 32

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

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

View Full Document
Ask a homework question - tutors are online