# solu9 - This le contains the exercises hints and solutions...

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

This fle contains the exercises, hints, and solutions For Chapter 9 oF the book ”Introduction to the Design and Analysis oF Algorithms,” 2nd edition, by A. Levitin. The problems that might be challenging For at least some students are marked by ± ; those that might be diﬃcult For a majority oF students are marked by ² . Exercises 9.1 1. Give an instance oF the change-making problem For which the greedy al- gorithm does not yield an optimal solution. 2. Write a pseudocode oF the greedy algorithm For the change-making prob- lem, with an amount n and coin denominations d 1 >d 2 >. . .>d m as its input. What is the time eﬃciency class oF your algorithm? 3. Consider the problem oF scheduling n jobs oF known durations t 1 ,...,t n For execution by a single processor. The jobs can be executed in any order, one job at a time. You want to fnd a schedule that minimizes the total time spent by all the jobs in the system. (The time spent by one job in the system is the sum oF the time spent by this job in waiting plus the time spent on its execution.) Design a greedy algorithm For this problem. ± Does the greedy algo- rithm always yield an optimal solution? 4. Design a greedy algorithm For the assignment problem (see Section 3.4). Does your greedy algorithm always yield an optimal solution? 5. Bridge crossing revisited Consider the generalization oF the bridge cross- ing puzzle (Problem 2 in Exercises 1.2) in which we have n> 1 people whose bridge crossing times are t 1 ,t 2 n . All the other conditions oF the problem remain the same: at most two people at the time can cross thebr idge(andtheymovew iththespeedo Fthes lowero Fthetwo)and they must carry with them the only ﬂashlight the group has. Design a greedy algorithm For this problem and fnd how long it will take to cross the bridge by using this algorithm. Does your algorithm yields a minimum crossing time For every instance oF the problem? IF it does–prove it, iF it does not–fnd an instance with the smallest number oF people For which this happens. 6. Bachet-Fibonacci weighing problem ±ind an optimal set oF n weights { w 1 ,w 2 ,...,w n } so that it would be possible to weigh on a balance scale any integer load in the largest possible range From 1 to W , provided a. ± weights can be put only on the Free cup oF the scale. b. ² weights can be put on both cups oF the scale. 1

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

View Full Document
7. a. Apply Prim’s algorithm to the following graph. Include in the priority queue all the vertices not already in the tree. c a b d 5 4 7 6 e 23 45 b. Apply Prim’s algorithm to the following graph. Include in the priority queue only the fringe vertices (the vertices not in the current tree which are adjacent to at least one tree vertex). i e f j 9 5 h d g c b a l k 3 6 8 6 5 4 3 6 3 2 1 2 5 4 75 43 8. The notion of a minimum spanning tree is applicable to a connected weighted graph. Do we have to check a graph’s connectivity before ap- plying Prim’s algorithm or can the algorithm do it by itself?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 37

solu9 - This le contains the exercises hints and solutions...

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

View Full Document
Ask a homework question - tutors are online