Assignment 07 - Dynamic Programming (Solution)

Assignment 07 - Dynamic Programming (Solution) - The Hong...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Hong Kong University of Science & Technology COMP 271: Design and Analysis of Algorithms Fall 2007 Solution to Assignment 7 Question 1 : Give an O ( n 2 ) time dynamic programming algorithm to find the longest monotonically decreasing subsequence of n numbers. For example, if the input sequence is < 5 , 23 , 4 , 17 , 12 , 45 > , then the output should be < 23 , 17 , 12 > . Solution: Input: A sequence of n numbers X = < x 1 , · · · , x n > . Output: The longest decreasing subsequence in X . Idea: We first give an algorithm which finds the length of longest decreasing subsequence; later we will modify it to report a subsequence with this length. Step 1: Space of Subproblems For 1 ≤ i ≤ n , define c [ i ] = The length of the longest decreasing subsequence that ends with x i . Note that the length of the longest decreasing subsequence in X is given by max 1 ≤ i ≤ n c [ i ]. Step 2: Recursive Formulation The longest decreasing subsequence that ends with x i has the form < Z, x...
View Full Document

Page1 / 3

Assignment 07 - Dynamic Programming (Solution) - The Hong...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online