The longest increasing subsequence (LIS) problem aims to find the subsequence exhibiting an increasing trend in a numeric sequence with the maximum length. In this paper, we generalize the LIS problem to the longest wave subsequence (LWS) problem, which encompasses two versions: LWSt and LWSr. Given a numeric sequence [Formula: see text] of distinct values and a target trend sequence [Formula: see text], the LWSt problem aims to identify the longest subsequence of [Formula: see text] that preserves the trend of the prefix of [Formula: see text]. And, the LWSr problem aims to find the longest subsequence of [Formula: see text] within [Formula: see text] segments, alternating increasing and decreasing subsequences. We propose two efficient algorithms for solving the two versions of the LWS problem. For the LWSt problem, the time complexity of our algorithm is O[Formula: see text], where [Formula: see text] represents the length of the given numeric sequence [Formula: see text]. Additionally, we propose an O[Formula: see text]-time algorithm for solving the LWSr problem. In both algorithms, we utilize the priority queues for the insertion, deletion, and successor operations.
Read full abstract