Longest Increasing Subsequence (LIS)
This is a classic problem that we studied in CS341.
Problem Formulation
- Input: An array of integers
- Output: A longest increasing subsequence of (or just its length) (does not need to be contiguous)
- Example: has answer
- Remark: there are subsequences (including an empty one, which doesn’t count)
My own proof: We define the following subproblem: Find the length of longest increasing subsequence of that includes . We store the value in .
We have a base case initializing .
Let be the second last element part of the LIS. For this to hold, with , then en the LIS is given by + the LIS of that includes
Since we don’t know , we can iterate over all possibilities.
We then come up with the algorithm:
This runs in .