Uploaded by mydrivevna

DP Worksheet

advertisement
CSC 301
Worksheet
Spring 2023
In class: Thursday, April 6th
1. Triangulation
You are given a convex polygon P with n vertices in a plane (specified by their xi
and yj coordinates, given as input arrays where the labeling is counter-clockwise). A
triangulation of P is a collection of n − 3 diagonals of P (lines connecting vertices of
the polygon) such that no two diagonals intersect (except possible at the vertices).
Notice that a triangulation splits the polygon’s interior into n − 2 disjoint triangles.
The cost of a triangulation is the sum of the lengths of the diagonals chosen.
Assume that you have a function dist(i,j) which will return the length of the diagonal connecting the vertex at (xi , yi ) with the vertex at (xj , yj ). Describe an efficient
algorithm for finding a triangulation of minimum cost.
(Hint 1: Consider the set of vertices between index i and j. These vertices form their
own convex polygon if i and j are connected by a diagonal.)
(Hint 2: Define a recursive function tri(i,j) which returns the cost of the minimum
triangulation for that convex polygon. Note that vertices 0 and n − 1 are already
connected, so the original polynomial is described by tri(0,n-1).)
(a) Consider this Triangulation problem. Can you design a recursive use-it or lose-it
approach to solve this problem?
(b) Next, describe how you would implement this algorithm using dynamic programming: how the table is set up and the order for filling its cells. A picture may
help (although the picture alone will not be graded).
(c) Now write the actual DP pseudo-code for creating and filling the table.
(d) Describe how you could construct the optimal set of diagonals for the given polygon given your DP table.
(e) What is the runtime of your Dynamic Programming algorithm?
1
Download