A contiguous subsequence of a list S is a subsequence made up of consecutive elements of S. For instance, if S is 5, 15, 30, 10, 5, 40, 10, then 15, 30, 10 is a contiguous subsequence but 5, 15, 40 is not. Give a linear-time algorithm for the following task: Input: A list of numbers, a1, a2, . . . , an. Output: The contiguous subsequence of maximum sum (a subsequence of length zero has sum zero). For the preceding example, the answer would be 10, 5, 40, 10, with a sum of 55. (Hint: For each j {1, 2, . . . , n}, consider contiguous subsequences ending exactly at position j.)
Read moreTextbook Solutions for Algorithms
Question
You are given a convex polygon P on n vertices in the plane (specified by their x and y coordinates).A triangulation of P is a collection of n 3 diagonals of P such that no two diagonalsintersect (except possibly at their endpoints). Notice that a triangulation splits the polygonsinterior into n 2 disjoint triangles. The cost of a triangulation is the sum of the lengths of thediagonals in it. Give an efficient algorithm for finding a triangulation of minimum cost. (Hint:Label the vertices of P by 1, . . . , n, starting from an arbitrary vertex and walking clockwise. For1 i < j n, let the subproblem A(i, j) denote the minimum cost triangulation of the polygonspanned by vertices i,i + 1, . . . , j.)
Solution
Step 1 of 3
Given,
A convex polygon P on n vertices in the plane where vertices are specified by their X and Y coordinates
No two diagonals do not intersect as a triangulation of P is a collection of n-3 diagonals of P.
The sum of lengths of diagonals in polygon P will specify the cost of the triangulation.
full solution