Dynamic Programming (16.0/15) PowerPoint PPT Presentation

presentation player overlay
1 / 9
About This Presentation
Transcript and Presenter's Notes

Title: Dynamic Programming (16.0/15)


1
Dynamic Programming (16.0/15)
  • 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/15.4)
  • Problem Given x1..m and y1..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/15.4)
  • Let ci,j length of LCS of Xix1..i,Yj
    y1..j
  • Then cm,n length of LCS of x and y
  • Theorem

  • if xi yj

  • otherwise
  • Proof. xi yj ?
  • LCS(Xi,Yj) LCS(Xi-1,Yj-1) xi

4
DP properties(16.2/15.3)
  • 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(Xm,Yn-1) and LCS(Xm-1,Yn) has common
    subproblem LCS(Xm-1,Yn-1)
  • There are few problems in total mn for LCS
  • Unlike divide and conquer

5
DP (16.2/15.3)
  • After computing solution of a subproblem, store
    in table
  • Time O(mn)
  • When computing ci,j we need O(1) time if we
    have
  • xi, yj
  • ci,j-1
  • ci-1,j
  • ci-1,j-1

6
DP Table for LCS
y B D C A B A
x A B C B D A B
7
DP Table for LCS
y B D C A B A
x A B C B D A B
0 0 0 0 0 0 0 0 0
0 0 1 1 1 0 1 1 1
1 2 2 0 1 1 2 2 2
2 0 1 1 2 2 3 3 0
1 2 2 2 3 3 0 1 2
2 3 3 4 0 1 2 2 3
4 4
8
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 convex polygon 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

9
Optimal Polygon Triangulation (16.4/?)
  • Optimal sub-triangulation of optimal
    triangulation
  • Recurrent formula
  • ti,j the weight of the optimal triangulation
    of the polygon
  • ltvi-1,vi,...,vjgt If ij, then ti,j0
    else
  • Runtime O(n3) and space is O(n2)

vi
vi
vi-1
vi-1
vj
vj
vk
vk
Write a Comment
User Comments (0)
About PowerShow.com