LIS:wikipedia
There is one thing that I can\'t understand:
why is X[M[i]] a non-decreasing sequence?
The base idea behind algorithm is to keep list of LIS of a given length ending with smallest possible element. Constructing such sequence
k
)k+1
lengthBecause in first step you search for smaller value then X[i] the new solution (for k+1
) will have last element greater then shorter sequence.
I hope it will help.
There is a proof here https://strncat.github.io/jekyll/update/2019/06/25/longest-increasing-subsequence.html
basically it is impossible to not be a strictly increasing subsequence. The proof is by contradiction: Suppose it is not then we have two cases: Case 1) There is some element M[j] that ends two subsequences of length j and j+some number. This is impossible (proof in link)
Case 2) Slightly different that Case 1 but pretty the same reasoning. How can you have a smallest number end two subsequences of two different lengths? it can't be.