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
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 subproblem 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 subproblem 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[j1] 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
 Spring '08
 Pearly

Click to edit the document details