Question: Given a sequence of integers X = x1, . . . , xn and a number k, find the longest k-zigzag subse- quence of X.

Given a sequence of integers X = x1, . . . , xn and a number k, find the longest k-zigzag subse- quence of X. The time of your DP algorithm should be O(kn2). A k-zigzag subsequence is one which alternates between being strictly increasing and being strictly decreasing at most k times. A 0-zigzag subsequence is just an increasing subsequence. A 1- zigzag subsequence is a subsequence which is increasing at first but then may change direction and become decreasing. A 2-zigzag subsequence is a sequence which is increasing at first and then may change direction at most twice. Similarly, a k-zigzag subsequence is a subsequence which starts as increasing but then it may change direction at most k times. For example, the subsequence 1,5,7,9,8,4 is a 1-zigzag as it is strictly increasing at first, up to 9, and then changes direction once and becomes strictly decreasing. For full credit, you should use the SRBTOT framework

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!