Given a sequence of numbers — say 3, 1, 4, 1, 5, 9, 2, 6 — the longest increasing subsequence (LIS) is the longest chain you can pick from them (in order, without rearranging) so each picked number is strictly larger than the previous. For that example the answer is 1, 4, 5, 9 or 1, 2, 6, both of length 4.
The problem sounds like a puzzle. You could try every subset: possibilities for n numbers. For 50 numbers that's already more combinations than there are atoms in a grain of sand — obviously impractical.
A smarter approach uses dynamic programming: work left to right, keeping for each position the length of the longest increasing subsequence ending there. That costs time and solves the problem. But there is something even cleverer hiding behind the scenes — a connection to a card game called patience sorting that slashes the cost to .
Comments
Loading comments...