hw2sol - Advanced Analysis of Algorithms - Homework II...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Advanced Analysis of Algorithms - Homework II (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV { ksmani@csee.wvu.edu } 1 Problems 1. Problem 15- 2 on Page 364 of [CLRS01]. Solution: Assume that the optimal solution packs the n words in r lines; this solution can be decomposed into two parts, viz., the words packed on the first line and the words packed in the remaining ( r- 1) lines. Regardless of the choice for the last word on line 1 , the remaining words must be packed optimally in the lines 2 through ( r- 1) . (Why?) We define s [ i,j ] to be cost if packing words w i through w j in one line. Likewise, p ij is defined as ( M- j + i- ∑ j t = i l t ) . Accordingly, s [ i,j ] = p 3 ij , if p ij ≥ 0 and j 6 = n = , if p ij ≥ 0 and j = n = ∞ , if p ij < Let m [ i,j ] denote the optimal cost of of packing words w i through w j . The entry of interest is m [1 ,n ] . It follows that: m [ i,j ] = min i ≤ k ≤ j ( s [ i,k ] + m [ k + 1 ,j ]) Each p ij entry can be computed in O ( n ) time and hence all the p ij entries can be computed in O ( n 3 ) time. Once the p ij values are computed, the s [ i,j ] values can be computed in O (1) time per entry for a total of O ( n 2 ) time. Finally, computing each entry in the m [ i,j ] table takes O ( n ) time and hence the table can be computed in O ( n 3 ) time. The above algorithm can be improved to run in O ( n 2 ) time; I leave this as an exercise. 2 2. Problem 15- 7 on Page 369 of [CLRS01]. Solution: Without loss of generality, assume that the jobs are ordered by their deadline, so that d 1 ≤ d 2 ≤ ... ≤ d n . We define A [ i,j ] to be the maximum profit that results from scheduling the jobs { a 1 ,a 2 ,...,a i } in the time interval [0 ,j ] . Note that the entry of interest is A [ n,d n ] , since any job scheduled after its deadline and in particular, after d n results in a profit of . Since each job has a processing time of at most n , we have d n ≤ n 2 . (Why?) We need the following lemma....
View Full Document

This note was uploaded on 05/11/2010 for the course COMPUTER S 301 taught by Professor . during the Spring '10 term at Kadir Has Üniversitesi.

Page1 / 4

hw2sol - Advanced Analysis of Algorithms - Homework II...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online