Anda di halaman 1dari 3

CSC 373 - Algorithm Design, Analysis, and Complexity

Lalla Mouatadid

Summer 2014

Dynamic Programming: Minimum Weight Triangulation

A polygon P is a 2-dimensional closed shape in the plane, made of a set of straight-line segments where
consecutive segments intersect at a vertex (point). P is convex if for any two points a, b inside P, the line
segment ab lies entirely inside P. Here are some examples of polygons and a more detailed definition.
So let P be a polygon on v1 , ..., vn vertices and let e1 , e2 , ..., en denote the edges (segments) of P, where ei
connects vi vi+1 and en connects vn v1 . A chord vi vj is a segment joining two nonadjacent vertices of P.
A triangulation is a set of chords that divides P into nonoverlapping triangles. It is easy (?) to see that
every polygon on n vertices (called an n-gon) has n 2 triangles and n 3 chords.
We call the weight of a triangulation the sum of the lengths of its chords, where the length of a chord vi vj
is the Euclidean distance between the two points vi (xi , yi ) and
pvj (xj , yj ) in the plane. Recall the Euclidean
distance between two points vi (xi , yi ), vj (xj , yj ) is d(vi , vj ) = (xj xi )2 + (yj yi )2 (i.e. just the distance
of the straight line connecting vi and vj ).
Triangulations of a polygons are not unique, and some weight more than others! Consider the example below
with the following coordinates:
v1 (0, 0), v2 (50, 25), v3 (80, 30), v4 (125, 25), v5 (160, 0)
And convince yourself why the greedy approach of selecting the cheapest chords at every step fails.







The algorithmic problem we are interested in is the following:

Given a convex polygon P = (v1 , v2 , ..., vn ), determine a triangulation T of P that minimizes:

w(T ) =
d(vi , vj )
e=(vi ,vj )T

More formally: Minimum Weight Triangulation:

Input: A convex polygon P defined by a set of n points in the plane (v1 , v2 , ..., vn ) and a set of n straight
lines (e1 , e2 , ..., en ) where ei connects vi , vj and en connects vn , v1 .
Output: A minimum weight triangulation T of P.

We once again follow our DP steps to try to break the problem into subproblems.
Step 1: Clearly our final goal is a triangulation for the entire polygon, so an optimal solution for the entire
problem is a minimum weight triangulation of P = (v1 , v2 , ..., vn ). Let T denote this optimal triangulation.
Step 2: In this step we are trying to somehow reduce our polygon on n points into smaller polygons, but
how do we come up with these smaller polygons? Well one thing we know for sure is that every two adjacent
vertices vi , vi+1 in P must end up in a triangle! Why is this guaranteed in a triangulation?
So this is a good starting point, yeah? Pick two consecutive vertices and find the triangle you can add them
to. But how is this helpful in terms of defining subproblems? Consider the polygon below, and suppose we
started with the pair (v3 , v4 ):





We raise two questions at this point: 1. Now what? And 2. Why choose v7 and not another vertex. Well,
now we have created two polygons smaller than P, namely (v1 , v2 , v3 , v7 ) and (v4 , v5 , v6 , v7 ). So now we can
just recurse on these smaller inputs. And 2. How do we choose v7 (and more generally, how do we choose
the third point of the triangle)? We ask another question, how many possible choices do we have? For the
first iteration on P we have at most n 1 vertices to choose from. It suffices to try all of them and pick
the vertex that minimizes the sum of distances of the new chords! And if we have a polygon on the vertices
(vi , vi+1 , ..., vj ), we have at most j i < n vertices to choose from.
So this is nice :) Start with a pair of adjacent vertices. Try all possible choices for a third point of the
triangle, and select the one that minimizes the total cost of the new chord(s). Then recurse on the new
smaller polygons.
Step 3: Lets formalize step 2 and create our array: For 1 i j, let T [i, j] be The minimum weight
triangulation of the polygon consisting of vertices (vi , vi+1 , ..., vj ). That is, T [i, j] is the sum of the weights
of the triangulations of the newly created (sub)polygons, plus the sum of any chords added:
T [i, j] = T [i, k] + T [k, j] + d(vi , vk ) + d(vk , vj )
And since we dont know which vertex vk will be the third point of the triangle, we need to try all j i
possible choices. So:
T [i, j] = min (T [i, k] + T [k, j] + d(vi , vk ) + d(vk , vj ))

Why isnt d(vi , vj ) included in the formula? Well, because we assume that vi , vj are adjacent from a previous
triangulation! Therefore we dont need to count d(vi , vj ) twice. Whats a base case for our recurrence?
T [i, i + 1] = 0 and T [n, 1] = 0.
Notice how this is very similar to what we did in Matrix Chain Multiplication! Weve split the problem into
two subproblems, recursed on both and then combined the solutions together! Now, lets prove that T [i, j]

is indeed a minimum weight triangulation of the polygon consisting of vertices (vi , vi+1 , ..., vj ). The proof is
again by induction on j i.
Proof of optimality:
Proof. If j i = 1 then j = i + 1 and T [i, i + 1] = 0, thus the claim holds for the base case. Suppose T [i, j]
is optimal for all j i < t, and consider j i = t.
Let Pij denote the polygon on (vi , vi+1 , ..., vj ) and let T [i, j] be an optimal triangulation for Pij . Since vi , vj
are adjacent in Pij , they must belong to a triangle in Tij . So let vk be the third vertex of this triangle in
Tij . Therefore Tij has two chords (vi , vk ) and (vk , vj ) but also two smaller polygons Pik and Pkj .
Notice that in Pij , the triangulations Tik , Tkj of Pik and Pkj respectively must be optimal, otherwise we can
replace them by cheaper triangulations and contradict the optimality of Tij . And by induction hypothesis,
Tik = T [i, k] and Tkj = T [k, j].
Since our recursive definition of T [i, j] checks all possible vertices vk and picks the minimum out of all
possible choices, it thus must have encounted Tij as a possible solution and by the optimality of Tij , T [i, j]
is therefore also optimal.
Below is the final algorithm. Whats x keeping track of? Play with an example and see how the solutions of
the small polygons are being used to compute solutions to larger ones.
Algorithm 1 Minimum Weight Triangulation
Input: A convex polygon P defined by a set of n points in the plane (v1 , v2 , ..., vn ) and a set of n straight
lines (e1 , e2 , ..., en ) where ei connects vi , vj and en connects vn , v1 .
Output: A minimum weight triangulation T of P.
1: for i=1 ... n-1 do
T [i, i + 1] = 0
3: end for
4: for x = 1 ... n-1 do
for i = 1 ... n-x do
j i+x
T [i, j] = min{T [i, k] + T [k, j] + d(vi , vk ) + d(vk , vj )}
end for
9: end for
10: return T [1, n]