The problem is as follows:
Given a sequence L of n integers not necessarily distinct , write an algorithm that computes the increasing subsequence of maximum length :
The recurrence equation that I developed is this:
I start the index from 0:
If j = n opt(j) = 0 (base case)
otherwise opt(j) = max j <i <= n such that Lj <Li = {opt(i) +1}
do you think is right to do so? the standard solution used for this typical problem is to first calculate the maximum increasing subsequence ending in Li for all elements of the sequence and then the maximum on these values, that is:
if i = 1 opt (i) = 1
otherwise opt (i) = max 1 <= j <= i-1 and Lj <Li = {opt (i)} +1
and then the max on these elements.
so I wanted to know if you think my solution was right anyway.
Here’s a hint: The loop invariant that will be trying to preserve in the algorithm is that a variable, k = index of the beginning of the longest increasing subsequence. So as you iterate through the sequence of integers [0…n] you increment the k value accordingly.