Richard Anderson Lecture 16a Dynamic Programming

Slides:



Advertisements
Similar presentations
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
Advertisements

Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Lecture 37 CSE 331 Nov 4, Homework stuff (Last!) HW 10 at the end of the lecture Solutions to HW 9 on Monday Graded HW 9 on.
CSE 421 Algorithms Richard Anderson Lecture 15 Fast Fourier Transform.
Lecture 38 CSE 331 Dec 3, A new grading proposal Towards your final score in the course MAX ( mid-term as 25%+ finals as 40%, finals as 65%) .
CSE 421 Algorithms Richard Anderson Lecture 16 Dynamic Programming.
Lecture 36 CSE 331 Dec 2, Graded HW 8 END of the lecture.
Lecture 37 CSE 331 Dec 1, A new grading proposal Towards your final score in the course MAX ( mid-term as 25%+ finals as 40%, finals as 65%) .
Dynamic Programming Adapted from Introduction and Algorithms by Kleinberg and Tardos.
Dynamic Programming.
CSCI 256 Data Structures and Algorithm Analysis Lecture 14 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 17.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 14.
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 18.
Lecture 33 CSE 331 Nov 20, HW 8 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm Submit your HWs to the side of.
CSE 421 Algorithms Richard Anderson Lecture 18 Dynamic Programming.
Algorithm Design and Analysis
Lecture 32 CSE 331 Nov 16, 2016.
Lecture 31 CSE 331 Nov 14, 2016.
Weighted Interval Scheduling
Analysis of Algorithms CS 477/677
Introduction to the Design and Analysis of Algorithms
Richard Anderson Lecture 17 Dynamic Programming
Richard Anderson Lecture 18 Dynamic Programming
Lecture 31 CSE 331 Nov 13, 2017.
Lecture 34 CSE 331 Nov 26, 2012.
CS38 Introduction to Algorithms
Lecture 34 CSE 331 Nov 26, 2012.
Prepared by Chen & Po-Chuan 2016/03/29
Richard Anderson Lecture 18 Dynamic Programming
Lecture 36 CSE 331 Nov 29, 2017.
Lecture 36 CSE 331 Nov 30, 2016.
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
Lecture 35 CSE 331 Nov 27, 2017.
Lecture 34 CSE 331 Nov 20, 2017.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Lecture 33 CSE 331 Nov 18, 2016.
Lecture 33 CSE 331 Nov 17, 2017.
Chapter 6 Dynamic Programming
Richard Anderson Lecture 17 Dynamic Programming
Lecture 35 CSE 331 Nov 28, 2016.
Richard Anderson Lecture 16 Dynamic Programming
Chapter 6 Dynamic Programming
Richard Anderson Lecture 18 Dynamic Programming
Medians and Order Statistics
CSEP 521 Applied Algorithms
Lecture 11 Overview Self-Reducibility.
Lecture 11 Overview Self-Reducibility.
Richard Anderson Lecture 16 Dynamic Programming
CSE 373 Data Structures and Algorithms
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Lecture 32 CSE 331 Nov 15, 2017.
Lecture 33 CSE 331 Nov 14, 2014.
Lecture 33 CSE 331 Nov 15, 2013.
Lecture 34 CSE 331 Nov 21, 2016.
2019/4/10 chapter25.
Lecture 36 CSE 331 Nov 28, 2011.
Lecture 36 CSE 331 Nov 30, 2012.
Dynamic Programming II DP over Intervals
Richard Anderson Lecture 16, Winter 2019 Dynamic Programming
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Analysis of Algorithms CS 477/677
Lecture 32 CSE 331 Nov 12, 2014.
Richard Anderson Lecture 18 Dynamic Programming
Richard Anderson Lecture 17, Winter 2019 Dynamic Programming
Dynamic Programming.
Week 8 - Friday CS322.
Presentation transcript:

Richard Anderson Lecture 16a Dynamic Programming CSE 421 Algorithms Richard Anderson Lecture 16a Dynamic Programming

Dynamic Programming Weighted Interval Scheduling Given a collection of intervals I1,…,In with weights w1,…,wn, choose a maximum weight set of non-overlapping intervals 4 Sorted by finish times 6 3 5 7 6

Recursive Algorithm Intervals sorted by finish time p[i] is the index of the last interval which finishes before i starts 1 2 3 4 5 6 7 8

Optimality Condition Opt[j] is the maximum weight independent set of intervals I1, I2, . . ., Ij Opt[ j ] = max( Opt[ j – 1], wj + Opt[ p [ j ] ])

Algorithm MaxValue(j) = if j = 0 return 0 else return max( MaxValue(j-1), wj + MaxValue(p[ j ]))

Run time What is the worst case run time of MaxValue Design a worst case input

A better algorithm M[ j ] initialized to -1 before the first recursive call for all j MaxValue(j) = if j = 0 return 0; else if M[ j ] != -1 return M[ j ]; else M[ j ] = max(MaxValue(j-1),wj + MaxValue(p[ j ])); return M[ j ];

Iterative Algorithm Express the MaxValue algorithm as an }

Fill in the array with the Opt values Opt[ j ] = max (Opt[ j – 1], wj + Opt[ p[ j ] ]) 2 4 7 4 6 7 6

Computing the solution Opt[ j ] = max (Opt[ j – 1], wj + Opt[ p[ j ] ]) Record which case is used in Opt computation 2 4 7 4 6 7 6

Dynamic Programming The most important algorithmic technique covered in CSE 421 Key ideas Express solution in terms of a polynomial number of sub problems Order sub problems to avoid recomputation

Optimal linear interpolation Error = S(yi –axi – b)2

What is the optimal linear interpolation with three line segments

What is the optimal linear interpolation with two line segments

What is the optimal linear interpolation with n line segments

Notation Points p1, p2, . . ., pn ordered by x-coordinate (pi = (xi, yi)) Ei,j is the least squares error for the optimal line interpolating pi, . . . pj Comment: Ei,j can be computed in O(n2) time

Optimal interpolation with two segments Give an equation for the optimal interpolation of p1,…,pn with two line segments Ei,j is the least squares error for the optimal line interpolating pi, . . . pj

Optimal interpolation with k segments Optimal segmentation with three segments Mini,j{E1,i + Ei,j + Ej,n} O(n2) combinations considered Generalization to k segments leads to considering O(nk-1) combinations

Optk[ j ] : Minimum error approximating p1…pj with k segments How do you express Optk[ j ] in terms of Optk-1[1],…,Optk-1[ j ]?

Optimal sub-solution property Optimal solution with k segments extends an optimal solution of k-1 segments on a smaller problem

Optimal multi-segment interpolation Compute Opt[ k, j ] for 0 < k < j < n for j := 1 to n Opt[ 1, j] = E1,j; for k := 2 to n-1 for j := 2 to n t := E1,j for i := 1 to j -1 t = min (t, Opt[k-1, i ] + Ei,j) Opt[k, j] = t