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!
so helpful code
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 is these ?
would u plz tell me from where i can understand your code more descriptively..
What does this mean? maximize(answer,f[i]);
Why does he code in such a cryptic way...
Same question here :/
answer = max(answer, f[i])
can you check for 2 5 3 1 6 2 7 it gives 3 and 1 2 7 as output 2 5 6 7 is the right answer
it gives right answer lenght 4 and " 2 3 6 7 " is the answer
Thanks man ! . This is much better solution than scrambling the google for "_Nlog(N)_ time LIS with result printing" Anyone having problem reading cryptic code ? HERE is the same code in c++ -
thank you,,,
This can also be achieved with segment trees, though the code will be slightly longer because of the update and query functions.
I've learned it from this video https://www.youtube.com/watch?v=S9oUiVYEq7E
It's very well explained. My code: