# aa2-sol - Problem Set 2 Solutions Due Feb 26 cs2me3 Winter...

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

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: Problem Set 2 Solutions Due: Feb 26 cs2me3 Winter 2007 Part A This problem is very similar in flavor to the segmented least squares problem. We observe that the last line ends with word ω n and has to start with some word ω j ; breaking off words ω j , ··· ,ω n we are left with a recursive sub-problem on ω 1 , ··· ,ω j- 1 . Thus, we define OPT [ i ] to be the value of the optimal solution on the set of words W i = { ω 1 , ··· ,ω i } , for any i ≤ j , let S i,j denote the slack of a line containing the words ω i , ··· ,ω j ; as a notational device, we define S i,j = ∞ if these words exceed total length L . For each fixed i , we can compute all S i,j in O ( n ) time by considering values of j in increasing order; thus we can compute all S i,j in O ( n 2 ) time. As noted above, the optimal solution must begin the last line somewhere (at word ω j ), and solve the sub-problem on the earlier lines optimally. We thus have the recurrence OPT [ n ] = min 1 ≤ j ≤ n S 2 j,n + OPT [ j- 1] and the line of words ω j , ··· ,ω n is used in an optimum solution if and only if the minimum is obtained using index j . Finally, we just need a loop to build up all these values: Compute all values S i,j as described above Set OPT[0]=0 For k=1, ··· ,n OPT[k]= min 1 ≤ j ≤ k S 2 j,k +OPT[j-1] Endfor Return OPT[n] As noted above, it takes O ( n 2 ) time to compute all values S i,j . Each iteration of the loop takes time O ( n ), and there are O ( n ) iterations. Thus the total running time is O ( n 2 ). By tracing back through the array OPT, we can recover the optimal sequence of line breaks that achieve the value OPT [ n ] in O ( n ) additional time. Part B 1a Suppose by way of contradiction that T and T are two distinct MCST of G . Since T and T have the same number of edges, but are not equal, there is some edge e in T but not in T ....
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

aa2-sol - Problem Set 2 Solutions Due Feb 26 cs2me3 Winter...

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

View Full Document
Ask a homework question - tutors are online