Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:boyese:chapter6 [2018/03/27 21:16] – [Section 6.1: Weighted Interval Scheduling: A Recursive Procedure] boyese | courses:cs211:winter2018:journals:boyese:chapter6 [2018/03/27 23:00] (current) – [Section 6.3: Segmented Least Squares: Multi-way Choices] boyese | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====Section 6.1: Weighted Interval Scheduling: A Recursive Procedure==== | ====Section 6.1: Weighted Interval Scheduling: A Recursive Procedure==== | ||
| + | Weighted Interval Scheduling | ||
| + | * Job j starts at s< | ||
| + | * Two jobs are compatible if they don't overlap | ||
| + | * Goal: find maximum weight subset of mutually compatible jobs | ||
| + | * Notation: Label jobs by finishing time: f< | ||
| + | * Definition: p(j) = largest index i < j such that job i is compatible with j | ||
| + | |||
| + | The recursive algorithm that computes the optimal schedule, now with weights for importance of each request/ | ||
| < | < | ||
| Compute-Opt(j) | Compute-Opt(j) | ||
| Line 10: | Line 18: | ||
| </ | </ | ||
| + | The correctness of the algorithm follows directly by induction on j: | ||
| + | Compute-0pt(j) correctly computes OPT(j) for each j = 1, 2, ..., n. | ||
| + | But, unfortunately, | ||
| < | < | ||
| Line 23: | Line 34: | ||
| </ | </ | ||
| + | So far we have simply computed the value of an optimal solution; but presumably we want a full optimal set of intervals as well. It would be easy to extend M-Compute-0pt so as to keep track of an optimal solution in addition to its value. This extension of the algorithm is shown below. | ||
| < | < | ||
| Line 37: | Line 49: | ||
| </ | </ | ||
| + | Since Find-Solution calls itself recursively only on strictly smaller values, it makes a total of O(n) recursive calls; and since it spends constant time per call, we have Find-Solution returns an optimal solution in O(n) time. | ||
| ====Section 6.2: Principles of Dynamic Programming: | ====Section 6.2: Principles of Dynamic Programming: | ||
| + | Once we have the array M, the problem is solved: M[n] contains the value of the optimal solution on the full instance, and Find-Solution can be used to trace back through M efficiently and return an optimal solution itself. We can directly compute the entries in M by an iterative algorithm, rather than using memoized recursion. This algorithm is below: | ||
| + | |||
| + | < | ||
| + | Iterative-Compute-Opt | ||
| + | M[O] = 0 | ||
| + | For j = l, 2 .....n | ||
| + | M[j] = max(v< | ||
| + | Endfor | ||
| + | </ | ||
| + | |||
| + | The running time of Iterative-Compute-0pt is clearly O(n), since it explicitly runs for n iterations and spends constant time in each. | ||
| + | |||
| + | To set about developing an algorithm based on dynamic programming, | ||
| + | * There are only a polynomial number of subproblems | ||
| + | * The solution to the original problem can be easily computed from the solutions to the subproblems | ||
| + | * There is a natural ordering on subproblems from " | ||
| ====Section 6.3: Segmented Least Squares: Multi-way Choices==== | ====Section 6.3: Segmented Least Squares: Multi-way Choices==== | ||
| + | |||
| + | In the problem we consider here, the recurrence will involve what might be called " | ||
| + | |||
| + | Suppose we let OPT(i) denote the optimum solution for the points p< | ||
| + | |||
| + | < | ||
| + | Segmented-Least-Squares(n) | ||
| + | Array M[0... n] | ||
| + | Set M[0] = 0 | ||
| + | For all pairs i < j | ||
| + | Compute the least squares error e< | ||
| + | Endfor | ||
| + | For j = 1, 2, ..., n | ||
| + | Use the recurrence (6.7) to compute M[j] | ||
| + | Endfor | ||
| + | Return M[n] | ||
| + | </ | ||
| + | |||
| + | The algorithm to compute an optimum partition is as follows: | ||
| + | < | ||
| + | Find-Segments(j) | ||
| + | If j = 0 then | ||
| + | Output nothing | ||
| + | Else | ||
| + | Find an i that minimizes e< | ||
| + | Output the segment {p< | ||
| + | Find-Segments (i - 1) | ||
| + | Endif | ||
| + | </ | ||
| + | |||
| + | **Analyzing The Run Time** | ||
| + | |||
| + | There are O(n< | ||
