AlgoScope

Longest Increasing Subsequence

AlgorithmintermediateAdvanced Dynamic Programmingalso called LIS

O(n^2) DP over predecessors, or O(n log n) with patience sorting and binary search.

Decision · step 3 of 10DP in One Row: Longest increasing subsequence
10✓091225334751016187i

9: nothing before it is smaller, so no chain can take it. len[1] = 1.

Open in the player →or start at step 3

What you will see

Arrows from every smaller earlier element; or a tails array that binary search updates.

How dp in one row works →

Cost

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)

Quadratic variant is O(n^2).

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Table cells announce their state and value; each step announces which cells were read and the value written.

Reduced motion: Dependency arrows appear statically and the cell value crossfades.

Variants

  • O(n^2) DP Best ending at each index.
  • Patience Sorting Binary search into the tails array.

Taught by the same lesson

DP in One Row covers these too, in the same run.