Richard Anderson Lecture 18 Dynamic Programming

Slides:



Advertisements
Similar presentations
CSEP 521 Applied Algorithms Richard Anderson Lecture 7 Dynamic Programming.
Advertisements

Lecture 38 CSE 331 Dec 7, The last few days Today: Solutions to HW 9 (end of lecture) Wednesday: Graded HW 9 (?), Sample final, Blog post on the.
CSE 421 Algorithms Richard Anderson Lecture 19 Longest Common Subsequence.
CSE 421 Algorithms Richard Anderson Lecture 16 Dynamic Programming.
Lecture 34 CSE 331 Nov 30, Graded HW 8 On Wednesday.
TODAY IN ALGEBRA…  Warm up: Find products of special polynomials  Learning Target: 9.4 You will solve polynomial equations in factored form  Independent.
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.
Advanced Algorithms Analysis and Design
Dynamic Programming Sequence of decisions. Problem state.
Lecture 32 CSE 331 Nov 16, 2016.
Lecture 5 Dynamic Programming
Advanced Design and Analysis Techniques
Richard Anderson Lecture 17 Dynamic Programming
String Processing.
Lecture 5 Dynamic Programming
Lecture 34 CSE 331 Nov 26, 2012.
Richard Anderson Lecture 18 Dynamic Programming
Lecture 36 CSE 331 Nov 29, 2017.
Lecture 36 CSE 331 Nov 30, 2016.
Lecture 35 CSE 331 Nov 27, 2017.
Lecture 34 CSE 331 Nov 20, 2017.
Lecture 33 CSE 331 Nov 18, 2016.
Lecture 33 CSE 331 Nov 17, 2017.
Richard Anderson Lecture 17 Dynamic Programming
Lecture 35 CSE 331 Nov 28, 2016.
Richard Anderson Lecture 16 Dynamic Programming
Lecture 37 CSE 331 Dec 1, 2017.
ICS 353: Design and Analysis of Algorithms
Richard Anderson Lecture 18 Dynamic Programming
EE5780 Advanced VLSI Computer-Aided Design
Memory Efficient Longest Common Subsequence
Richard Anderson Lecture 20 LCS / Shortest Paths
Richard Anderson Autumn 2006 Lecture 1
Richard Anderson Lecture 19 Longest Common Subsequence
ICS 353: Design and Analysis of Algorithms
Unit-4: Dynamic Programming
CSEP 521 Applied Algorithms
Richard Anderson Lecture 16a Dynamic Programming
Richard Anderson Lecture 16 Dynamic Programming
Richard Anderson Lecture 6 Greedy Algorithms
Lecture 37 CSE 331 Nov 30, 2011.
3. Brute Force Selection sort Brute-Force string matching
Richard Anderson Autumn 2015 Lecture 1
Lecture 32 CSE 331 Nov 15, 2017.
Lecture 33 CSE 331 Nov 14, 2014.
Richard Anderson Autumn 2016 Lecture 7
Lecture 33 CSE 331 Nov 15, 2013.
Lecture 34 CSE 331 Nov 18, 2011.
Lecture 34 CSE 331 Nov 21, 2016.
Lecture 31 CSE 331 Nov 14, 2012.
Richard Anderson Lecture 7 Greedy Algorithms
3. Brute Force Selection sort Brute-Force string matching
Lecture 36 CSE 331 Nov 28, 2011.
Lecture 36 CSE 331 Nov 30, 2012.
Lecture 37 CSE 331 Dec 2, 2016.
String Processing.
Richard Anderson Winter 2009 Lecture 2
Richard Anderson Lecture 27 Survey of NP Complete Problems
Richard Anderson Lecture 19 Longest Common Subsequence
Richard Anderson Lecture 16, Winter 2019 Dynamic Programming
Lecture 5 Dynamic Programming
Lecture 30 CSE 331 Nov 9, 2011.
Richard Anderson Lecture 18 Dynamic Programming
Richard Anderson Lecture 17, Winter 2019 Dynamic Programming
Richard Anderson Lecture 20 Space Efficient LCS
Memory Efficient Dynamic Programming / Shortest Paths
3. Brute Force Selection sort Brute-Force string matching
Lecture 36 CSE 331 Nov 22, 2013.
Lecture 37 CSE 331 Dec 3, 2018.
Presentation transcript:

Richard Anderson Lecture 18 Dynamic Programming CSE 421 Algorithms Richard Anderson Lecture 18 Dynamic Programming

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

Today - Examples Examples Optimal Billboard Placement Text, Solved Exercise, Pg 307 Linebreaking with hyphenation Compare with HW problem 6, Pg 317 String approximation Text, Solved Exercise, Page 309

Billboard Placement Maximize income in placing billboards Constraint: bi = (pi, vi), vi: value of placing billboard at position pi Constraint: At most one billboard every five miles Example {(6,5), (8,6), (12, 5), (14, 1)}

Design a Dynamic Programming Algorithm for Billboard Placement Compute Opt[1], Opt[2], . . ., Opt[n] What is Opt[k]? Input b1, …, bn, where bi = (pi, vi), position and value of billboard i

Opt[k] = fun(Opt[0],…,Opt[k-1]) How is the solution determined from sub problems? Input b1, …, bn, where bi = (pi, vi), position and value of billboard i

Solution j = 0; // j is five miles behind the current position // the last valid location for a billboard, if one placed at P[k] for k := 1 to n while (P[ j ] < P[ k ] – 5) j := j + 1; j := j – 1; Opt[ k] = Max(Opt[ k-1] , V[ k ] + Opt[ j ]);

Optimal line breaking and hyphen-ation Problem: break lines and insert hyphens to make lines as balanced as possible Typographical considerations: Avoid excessive white space Limit number of hyphens Avoid widows and orphans Etc.

Penalty Function Pen(i, j) – penalty of starting a line a position i, and ending at position j Key technical idea Number the breaks between words/syllables Opt-i-mal line break-ing and hyph-en-a-tion is com-put-ed with dy-nam-ic pro-gram-ming

Design a Dynamic Programming Algorithm for Optimal Line Breaking Compute Opt[1], Opt[2], . . ., Opt[n] What is Opt[k]?

Opt[k] = fun(Opt[0],…,Opt[k-1]) How is the solution determined from sub problems?

Solution for k := 1 to n Opt[ k ] := infinity; for j := 0 to k-1 Opt[ k ] := Min(Opt[k], Opt[ j ] + Pen(j, k));

But what if you want to layout the text? And not just know the minimum penalty?

Solution for k := 1 to n Opt[ k ] := infinity; for j := 0 to k-1 temp := Opt[ j ] + Pen(j, k); if (temp < Opt[ k ]) Opt[ k] = temp; Best[ k ] := j;

String approximation Given a string S, and a library of strings B = {b1, …bm}, construct an approximation of the string S by using copies of strings in B. B = {abab, bbbaaa, ccbb, ccaacc} S = abaccbbbaabbccbbccaabab

Formal Model Strings from B assigned to non-overlapping positions of S Strings from B may be used multiple times Cost of d for unmatched character in S Cost of g for mismatched character in S MisMatch(i, j) – number of mismatched characters of bj, when aligned starting with position i in s.

Design a Dynamic Programming Algorithm for String Approximation Compute Opt[1], Opt[2], . . ., Opt[n] What is Opt[k]? Target string S = s1s2…sn Library of strings B = {b1,…,bm} MisMatch(i,j) = number of mismatched characters with bj when aligned starting at position i of S.

Opt[k] = fun(Opt[0],…,Opt[k-1]) How is the solution determined from sub problems? Target string S = s1s2…sn Library of strings B = {b1,…,bm} MisMatch(i,j) = number of mismatched characters with bj when aligned starting at position i of S.

Solution for i := 1 to n Opt[k] = Opt[k-1] + d; for j := 1 to |B| p = i – len(bj); Opt[k] = min(Opt[k], Opt[p-1] + g MisMatch(p, j));