I am having trouble understanding the nlogn algorithm for solving the LIS problem. I have implemented the algorithm given here on page number 6. Link to CPP implementation. I think it's only checking the subsequence starting at index 0
so how is this algorithm correct? Or is my implementation wrong? Someone please help prove the correctness of this algorithm. Thanks.
http://ideone.com/Vzvbyu
OK thanks a lot for your help. I understood your solution and its really O(nlogn), but what about the one posted earlier? What's wrong with the implementation I provided?
I think it should be
st.erase(it)
instead ofst.erase(a[i])
That was a really stupid mistake by me. Again thanks for your help.
Also, if we are searching for non-decreasing longest sequence then your algorithm will not work correctly.
The problem of this solutions is tracing. How can we get the result array?
this post explains it very well.
I think this will be helpful.
It's non-decreasing subsequence, right? Not increasing one.
yeah ur right, this is non-decreasing subsequence.
but changing
upper_bound
tolower_bound
fixes that! :)For Longest decreasing sub sequence, what changes needed in the code ?
Reverse the list i.e. Input array!
I think this is for longest non-decreasing subsequence right? And for LIS, we should use std::lower_bound and replace that element? isn't it? Just for confirmation? Thanks.
Yeah, this is non-decreasing subsequence. And yes, using lower_bound instead of upper_bound would make it increasing.
This also works
I have a very short implementation:
If you want to print the LIS:
is it nlogn solution???
lower_bound/upper_bound works O(log(N))
What does this mean? maximize(answer,f[i]);
Why does he code in such a cryptic way...
answer = max(answer, f[i])
I've learned it from this video https://www.youtube.com/watch?v=S9oUiVYEq7E
It's very well explained. My code: