






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







9/24/ A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne
Weighted interval scheduling problem. Job j starts at sj, finishes at fj, and has weight or value vj. Two jobs compatible if they don't overlap. Goal: find maximum weight subset of mutually compatible jobs. Time f g h e a b c d 0 1 2 3 4 5 6 7 8 9 10 OPT( j ) = max( v i
Bottom-up dynamic programming. Unwind recursion. Input: n, s 1 ,…,sn , f 1 ,…,fn , v 1 ,…,vn Sort jobs by finish times so that f 1 ≤ f 2 ≤ ... ≤ fn. Compute p(1), p(2), …, p(n) Iterative-Compute-Opt { M[0] = 0 for j = 1 to n M[j] = max(vj + M[p(j)], M[j-1]) } how fast? Total time = (sorting) + O( n ) = O( n log( n ))
Q. Dynamic programming algorithms computes optimal value. What if we want the solution itself? A. Do some post-processing. # of recursive calls ≤ n ⇒ O(n). Run M-Compute-Opt(n) Run Find-Solution(n) Find-Solution(j) { if (j = 0) output nothing else if (vj + M[p(j)] > M[j-1]) print j Find-Solution(p(j)) else Find-Solution(j-1) }
7
Least squares. Foundational problem in statistic and numerical analysis. Given n points in the plane: (x 1 , y 1 ), (x 2 , y 2 ) ,... , (xn, yn). Find a line y = ax + b that minimizes the sum of the squared error: Solution. Calculus ⇒ min error is achieved when
SSE = ( yi − axi − b ) 2 i = 1 n ∑ € a = n xi yi − ( xi ) ∑ i ( yi ) ∑ i ∑ i n xi 2 − ( xi ) 2 ∑ i ∑ i , b = yi − a xi ∑ i ∑ i n x y O ( n ) time
8
Segmented least squares. Points lie roughly on a sequence of several line segments. Given n points in the plane (x 1 , y 1 ), (x 2 , y 2 ) ,... , (xn, yn) with x 1 < x 2 < ... < xn, find a sequence of lines that minimizes f(x). Q. What's a reasonable choice for f(x) to balance accuracy and parsimony? x y goodness of fit number of lines Note: discontinuous functions permitted!
10
Notation. OPT(j) = minimum cost for points p 1 , pi+1 ,... , pj. e(i, j) = minimum sum of squares for points pi, pi+1 ,... , pj. To compute OPT(j): Last segment uses points pi, pi+1 ,... , pj for some i. Cost = e(i, j) + c + OPT(i-1). € OPT ( j ) = 0 if j = 0 min 1 ≤ i ≤ j
11
Running time. O(n^3 ). Bottleneck = computing e(i, j) for O(n 2 ) pairs, O(n) per pair using previous formula. INPUT: n, p 1 ,…,pN , c Segmented-Least-Squares() { M[0] = 0 for j = 1 to n for i = 1 to j compute the least square error eij for the segment pi,…, pj for j = 1 to n M[j] = min (^1) ≤ i ≤ j (eij + c + M[i-1]) return M[n] } can be improved to O(n^2 ) by pre-computing ei,j’s