Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Longest Increasing Subsequence (LIS) with two numbers

Tags:

algorithm

How to find the length of LIS using two numbers. For example, [(1,2) (7,8) (3,4) (5,6)] In the above array sequence, the length of LIS would be 3. i.e, [(1,2) (3,4) (5,6)] Any idea?

like image 715
devsathish Avatar asked Jan 03 '12 18:01

devsathish


People also ask

How do you find the number of longest increasing subsequence?

Initialize a variable 'cnt' with 0 to store the number of the longest increasing subsequence. Traverse the array 'LENGTH' and if at any index 'idx', LENGTH[idx] is the same as 'maxLength' then increment the 'cnt' by COUNT[idx]. After the above steps, print the value of 'cnt'.

What is the meaning of longest increasing subsequence?

In computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as possible. This subsequence is not necessarily contiguous, or unique.

What is maximum sum increasing subsequence?

The maximum sum increasing subsequence is a subsequence of a list of integers where the sum is maximum and, in a subsequence, all the elements are sorted in increasing order.


2 Answers

I'm not sure what you are asking but I will assume what you mean is that a pair (a,b) is less than another pair (c,d) if and only if a < c and b < d.

This can be easily solved in O(N^2) time by adapting the standard dynamic programming technique, which is described in another SO thread.

The classic O(N log N) solution to the standard LIS problem can be extended to give a subquadratic solution to the LIS problem with pairs, with some difficulty. We cannot simply remember one minimum value for every possible length; we have to maintain "staircase-like" structures containing all minimal pairs for each length, that is, up to N copies of the data structure described here, implemented using an ordered dynamic set of pairs keyed on the first member. We can then query one copy of this structure in O(log N) time (to check whether it contains any pair less than the current pair), giving O(log^2 N) time for the binary search step, and O(N log^2 N) time in all. This is the fastest solution I know to the problem.

like image 186
Brian Bi Avatar answered Nov 06 '22 08:11

Brian Bi


You could use any algorithm for the standard LIS problem, with two modifications:

  1. Discard any pairs where the second number isn't strictly greater than the first number.
  2. The comparison operator for pairs A and B (i.e. A < B) needs to compare the second number of A to the first number of B.
like image 45
NPE Avatar answered Nov 06 '22 08:11

NPE