My questions is for the nlogn algorithm, NOT the DP algorithm.
(1)
the book says “it is a greedy algorithm and uses binary search”, but I didn’t find the explanation for what part it is greedy. Where do you prove that it has one of the important greedy property : optimal substructure.?
(2)
In the description it says “If no length j+1 nondecreasing subsequence exists in A[0], A[1], … A[i], then Mi+1,j+1 must be A[i+1]”.
How come there would be a chance that there is a length j+1 nondecreasing subsequence exist in A[0], A[1], … A[i] in the first place? You already said that “look for the largest j such that Mi,j<=A[i+1]”, it means j is already largest, why you are assuming there could be a j+1 nondecreasing subsequence inside A[0],A[1]…A[i]?
(3) You use vector tail_values to represent Mi,j, why the answer finally returns size of the vector? I am kind of completely lost on the how you map your description to the data structure and the meaning of the data structure that you are using.
In fact, I have too many questions on this solution mainly because I don’t understand this nlogn algorithm at all. Would you please elaborate it more?