Find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. For example, the length of LIS for 10, 22,9, 33, 21, 50, 41, 60, 80 is 6 and LIS is 10, 22, 33, 50, 60, 80.
We can go about this problem in multiple ways, but here I will use the LCS as a tool for solving this problem.
First, since we are given a list of numbers, we will create another list that is created by sorting the given list. This new list can be used in LCS together with the original list to find the length of the longest increasing subsequence.
From this code we can see the same process as in LCS, which is a great way to find longest common subsequence using dynamic programming.
Variations of this problem are:
- Extract the LIS as a list
- Length of a Longest Decreasing Sequence (LDS)
- Extract the LDS