Lecture 9: Dynamic Programming
Continuing the theme from last lecture, let M1, … , Mn be a series of matrices, and r0, … , rn be a series of dimensions such that Mi is an ri-1 * ri matrix.
Our goal is to compute the multiplication of all M:
best(i, j) = mink bestk(i, j)
bestk(i, j) = best(i, k) + best(k, j) + ri-1 * rk * rj
Using these rules, we can carefully fill a lower triangular table (being careful of the order of filling):
Matrix Cost/Order Algorithm:
For i = 1 to n
B[i, i] = 0
EndFor
For gap = 1 to (n-1)
for i = 1 to n - gap
j = i + gap
cost = mink {B[i, k] + B[k+1, j] + ri-1 * rk * rj}
B[i, j] = cost
EndFor
End For
return B[1,n]
- Need to remember choices!
- Whenever we assign B[i, j] we know the best k
- Use another array Mem[i, j] = best k found when doing B[i, j]
- Mem(1, n) tells where to split M1, … , Mn
Dividing a polygon into triangles:
This was once a very popular optimization technique for 3d rendering (and especially games) before graphics hardware supported complex shapes–triangles were fast to draw:

- Find the minimum weight of triangulation
- weight = sum of the lengths of new edges
- Polygon w/ vertices v1, … , vn– assume counterclockwise.
- D[i, j] = distance from vi to vj, unless outside the polygon, in which case the distance is infinite
- C(i, j) = minimum cost for triangulating polygon v1, … , vn
- Ck(1, n) = best answer using vertex k for triangle with v1 and vn
- C(1, n) = min Ck(1, n)
- Ck(1, n) = C(k, n) + C(1, k) + D[k, n] + D[1, k]
Polygon Triangulating Algorithm:
For i = 1 to n
C[i, i+1] = -D[i, i+1]
EndFor
For gap = 2 to n -1
for i = 1 to n - gap
j = i + gap
C[i, j] = mink {C[i, k] + C[k, j] + D[i, k] + D[k, j]}
EndFor
EndFor
return C[1, n]
This entry was posted on Friday, February 11th, 2005 at 1:23 pm and is tagged with nbsp nbsp nbsp nbsp nbsp, optimization technique, triangular table, dynamic programming, polygon, vertices, mink, vertex, graphics hardware, rk, matrices, triangles, multiplication, ck, gap, algorithm, shapes, triangle, array, matrix. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback.
Leave a Reply
Please take time to enjoy the archives: May 2005 (1) April 2005 (11) March 2005 (11) February 2005 (15) January 2005 (7)
Fresh, related resources:
- MIT?s Introduction to Algorithms, Lectures 13 and 14: Amortized b.../b
Have fun with amortized and competitive analysis! The next post will be about bdynamic programming/b! PS. This course is taught from the CLRS book (also called ?Introduction to Algorithms?): b.../b - Events Calendar - PHYSICS DEPARTMENT COLLOQUIUM
Our method of de novo structure prediction combines the strengths of bdynamic programming/b algorithms for secondary structure prediction, a novel BUILDER algorithm, and modified classical molecular dynamics simulations. b.../b - The ?Digg? of iPhone Apps - Checkout My New Site | iCodeBlog
It has been a while since my last tutorial. For that I am sorry. My wife is b9/b months pregnant and about ready to pop. This being the case, she takes. - Hosoo#39;s Lake @tistory :: Decision Making in Large Scale Systems
This course is an introduction to the theory and application of large-scale bdynamic programming/b. Topics include Markov decision processes, bdynamic programming/b algorithms, simulation-based algorithms, theory and algorithms for value b.../b - Terminally Incoherent » Blog Archive » First bProgramming/b Language b.../b
Introduce students to bprogramming/b with a bdynamic/b, interactive and easy to read language such as Python or Ruby. Then, once they get the basics toss them onto the deeper waters of statically typed, compiled, overly verbose ?enterprise? b.../b
