Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:donohuem:chapter6 [2018/03/26 23:49] – donohuem | courses:cs211:winter2018:journals:donohuem:chapter6 [2018/03/27 01:05] (current) – donohuem | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ===== 6.1 Weighted Interval Scheduling ===== | ===== 6.1 Weighted Interval Scheduling ===== | ||
| + | The problem is similar to our previous Interval Scheduling problem with the added case that jobs now have different weights; thus, no greedy algorithm can be used to solve this problem, so we must switch to dynamic programming. More specifically, | ||
| + | |||
| + | | ||
| + | if j = 0 | ||
| + | return 0 | ||
| + | elif M[j] is not empty | ||
| + | return M[j] | ||
| + | else | ||
| + | M[j] = max(vj + Compute-Opt(p(j)), | ||
| + | |||
| + | In the recursive case, we take the maximum of the solution containing j and the solution not containing j (picking job j or not picking job j). The runtime of this algorithm is O(n) since it makes use of memoization. Computed values are stored in array M and recalled when needed, eliminating redundant computations. Lastly, we construct a second algorithm that returns the actual set of jobs that Compute-Opt would choose since Compute-Opt only returns the value of the optimal solution. This algorithm also runs in O(n) time. The readability of this section is 8/10. | ||
| + | |||
| + | |||
| ===== 6.2 Memoization and Iteration ===== | ===== 6.2 Memoization and Iteration ===== | ||
| + | The Weighted Interval Scheduling problem can also be solved using an iterative algorithm as opposed to a recursive one. Both algorithms are dynamic and use memoization. | ||
| + | |||
| + | | ||
| + | M[0] = 0 | ||
| + | for j-1 to n | ||
| + | M[j] = max(vj + M[p(j)], M[j-1]) | ||
| + | |||
| + | The iterative algorithm also has a runtime of O(n). Both algorithms are dynamic because the divide the main problem into subproblems and then combine computed subproblems to solve the overall problem. The readability of this sections is 8/10. | ||
| + | |||
| + | |||
| ===== 6.3 Segmented Least Squares ===== | ===== 6.3 Segmented Least Squares ===== | ||
| + | The problem arises out of best fit lines. Given a set of points, draw lines that best fit the points, or more formally with minimum error. When the points are not neatly arranged. Obviously, if we wanted the best accuracy, we could draw a line for each point. This, however, is not a helpful solution. | ||
