1 / 8

Dynamic Programming (16.0)

Dynamic Programming (16.0). The 3-d Paradigm 1st = Divide and Conquer 2nd = Greedy Algorithm Dynamic Programming = metatechnique (not a particular algorithm) Programming = ``tableau method’’, not writing a code. Longest Common Subsequence (16.3).

iniko
Download Presentation

Dynamic Programming (16.0)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dynamic Programming (16.0) • The 3-d Paradigm • 1st = Divide and Conquer • 2nd = Greedy Algorithm • Dynamic Programming = metatechnique (not a particular algorithm) • Programming = ``tableau method’’, not writing a code

  2. Longest Common Subsequence (16.3) • Problem: Given x[1..m] and y[1..n], find LCS x: A B C B D A B  B C B A y: B D C A B A • Brute-force algorithm: • for every subsequence of x check if it is in y • O(n2m ) time • 2m subsequences of x (each element either in or out • O(n) for scanning y with x-subsequence (m  n)

  3. Recurrent Formula for LCS (16.3) • Let c[i,j] = length of LCS of X[i]=x[1..i],Y[j]= y[1..j] • Then c[m,n] = length of LCS of x and y • Theorem: if x[i] = y[j] otherwise • Proof. x[i] = y[j]  LCS([X[i],Y[j]) = LCS(X[i-1],Y[j-1]) + x[i]

  4. DP properties(16.2) • 1st Observation: any part of the optimal answer is also optimal • The subsequence of LCS(X,Y) is LCS for some subsequences of X and Y. • 2nd Observation: subproblems overlap • LCS(X[m],Y[n-1]) and LCS(X[m-1],Y[n]) has common subproblem LCS(X[m-1],Y[n-1]) • There are few problems in total = mn for LCS • Unlike divide and conquer

  5. DP (16.2) • After computing solution of a subproblem, store in table • Time = O(mn) • When computing c[i,j] we need O(1) time if we have: • x[i], y[j] • c[i,j-1] • c[i-1,j] • c[i-1,j-1]

  6. DP Table for LCS y B D C A B A x A B C B D A B

  7. Optimal Polygon Triangulation (16.4) • Polygon has sides and vertices • Polygon is simple = not self-intersecting. • Polygon P is convex if any segment with ends in P belong to P • Triangulation of P is partition of P with chords into triangles. • Problem: Given a convexpolygon and weight function defined on triangles (e.g. the perimeter). Find triangulation of minimum weight (of minimum total length). • # of triangles = n - 2 triangles with n-3 chords

  8. Optimal Polygon Triangulation (16.4) • Optimal sub-triangulation of optimal triangulation • Recurrent formula: t[i,j] = the weight of the optimal triangulation of the polygon <v[i-1],v[i],...,v[j]>; If i=j, then t[i,j]=0; else • Runtime O(n3) and space is O(n2) v[i] v[i] v[i-1] v[i-1] v[j] v[j] v[k] v[k]

More Related