Weighted Interval Scheduling and Segmented Least Squares: Dynamic Programming Solutions, Study notes of Computer Science

Solutions to the weighted interval scheduling and segmented least squares problems using dynamic programming. The weighted interval scheduling problem involves finding the maximum weight subset of mutually compatible jobs, while segmented least squares deals with finding a sequence of lines that minimizes the sum of the sums of the squared errors and the number of lines. The dynamic programming algorithms, their time complexities, and a discussion on how to find the solutions themselves.

Typology: Study notes

Pre 2010

Uploaded on 09/24/2009

koofers-user-qlv-1
koofers-user-qlv-1 🇺🇸

7 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
9/24/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne
Adam Smith
Algorithm Design and Analysis
LECTURE 17
Dynamic Programming
(WIS recap)
Segmented Least Squares
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Weighted Interval Scheduling and Segmented Least Squares: Dynamic Programming Solutions and more Study notes Computer Science in PDF only on Docsity!

9/24/ A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne

Adam Smith

Algorithm Design and Analysis

LECTURE 17

Dynamic Programming

• (WIS recap)

• Segmented Least Squares

Weighted Interval Scheduling

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

  • OPT( p ( j )) , OPT( j -1) )

Equivalent algorithm: Bottom-Up

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 ))

Weighted Interval Scheduling: Finding a Solution

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

Segmented Least Squares

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 = ( yiaxib ) 2 i = 1 n ∑ € a = n xi yi − ( xi ) ∑ i ( yi ) ∑ ii n xi 2 − ( xi ) 2 ∑ ii , b = yia xiii n x y O ( n ) time

8

Segmented Least Squares

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

Dynamic Programming: Multiway Choice

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 ≤ ij

{^ e ( i ,^ j )^ +^ c^ +^ OPT ( i^ −^1 )} otherwise

11

Segmented Least Squares: Algorithm

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