Longest Increasing Subsequence (LIS) in $O(N \log N)$
Longest Increasing Subsequence (LIS) in $O(N \log N)$
Introduction
In the quadratic LIS solution, every position checks every earlier position. The dynamic programming idea is clear, but the nested loops become too slow when reaches .
To improve the algorithm, we need to stop remembering every possible ending position. The crucial observation is that, among increasing subsequences of the same length, only the one with the smallest final value is useful for the future.
Why a smaller ending is better
Suppose we have already found two increasing subsequences of length :
- ;
- .