Dynamic Programming21 sections · 916 units
Open in Course

Challenge: LIS in O(n log n) Space O(n)

Understanding space usage

The binary search LIS uses O(n)O(n) space for the tails array. Can we do better? Not. We need to store the tails array to enable binary search.

The array size is at most nn (the LIS length). For reconstruction with O(nlogn)O(n \log n) time, we need additional O(n)O(n) space to track predecessors. space reduction is more relevant for the O(n2)O(n^2) approach: we can avoid storing the full DP array if we only need the length, but reconstruction requires O(n)O(n) space regardless.