CS3261

# CS3261 - 35 30 = 65> D Not enough space 25 = 60> D Not...

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

CS326 Algorithms Fall 07 Homework 2- Part 2 1-e 26 3 22 8 9 21 34 47

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

View Full Document
2-a i) No, greedy algorithms does not always produce the best solution. ii) Counter Example: Assume D=20 Assume program sizes as follows: 10, 6, 9, 4 Using the same greedy algorithm, it will select the programs from smallest to largest as follows: 4, 6, 9, 10 It will operate as follows to fill the memory space: 4 + 6 = 10 10 + 9 = 19 The algorithm will not be able to add the last ‘10’ because the only memory size available is 1 out of 20. (20-19=1) A better solution can be as follows: 4+6 = 10 10 + 10 = 20 The algorithm leaves out ‘9’ since choosing ‘10’ would produce a more optimal solution. 2-b i) No, greedy algorithms does not always produce the best solution. ii) Counter Example: Assume D=50 Assume program sizes as follows: 10, 20, 25, 30, 35
Using the same greedy algorithm, it will select the programs from largest to smallest as follows: 35, 30, 25, 20, 10 It will operate as follows to fill the memory space:

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.

Unformatted text preview: 35 + 30 = 65 > D Not enough space, skip 30 35 + 25 = 60 > D Not enough space, skip 25 35 + 20 = 55 > D Not enough space, skip 20 35 + 10 = 45 < D Accepted! The algorithm will consume 45 out of 50 units of memory. However, it is not the best solution to the problem. A better solution can be as follows: 30 + 20 = 50 (50 = = D) 3-a No. A short path in an original tree from one point to another will be also the shortest in the MST. 3-b Explanation:-If each edge has one and only one weight, then there will only be one MST.-If the edge of point A is larger than any edges connected to A, then it cannot be in the MST.-If the edge of point A is smaller than all other edges, then it will definitely be in the MST. In the following graph, the shortest path from A to F is: A, B , C, D, E, F If we take the MST of the graph, the path is also the same:...
View Full Document

## This note was uploaded on 03/30/2008 for the course CS 326 taught by Professor Dr.chandra during the Fall '07 term at New Haven.

### Page1 / 4

CS3261 - 35 30 = 65> D Not enough space 25 = 60> D Not...

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

View Full Document
Ask a homework question - tutors are online