Longest Increasing Subsequence
Explore how to implement the longest increasing subsequence algorithm in C++ using dynamic programming. Understand two recursive approaches, optimize them with memoization, and achieve efficient solutions with O(n^2) time complexity to solve this classic problem.
We'll cover the following...
Longest increasing subsequence problem
Another problem we considered in the previous chapter was computing the length of the longest increasing subsequence of a given array of numbers. We developed two different recursive backtracking algorithms for this problem. Both algorithms run in time in the worst case; both algorithms can be sped up significantly via dynamic programming.
First recurrence: is this next?
Our first backtracking algorithm evaluated the function , which we defined as the length of the longest increasing subsequence of in which every element is larger than . We derived the following recurrence for this function:
To solve the original problem, we can add a sentinel value ...