3.7.11 · D1Algorithm Paradigms

Foundations — DP problems — Longest Increasing Subsequence (LIS) — O(n²) and O(n log n)

2,198 words10 min readBack to topic

Before you can read the parent note fluently, you need a small toolbox of ideas. This page builds each one from zero, in the order they depend on each other. Nothing here is assumed — if the parent used a symbol, we define it here first.


0. The picture we keep coming back to

Everything in this topic lives on top of one array — a row of boxes, each holding a number, each with an index (its position number) underneath.

Figure — DP problems — Longest Increasing Subsequence (LIS) — O(n²) and O(n log n)

1. Subarray vs Subsequence — the crossing-out idea

This is THE distinction the whole topic rests on.

Figure — DP problems — Longest Increasing Subsequence (LIS) — O(n²) and O(n log n)

In the picture, [3, 4, 5] from [3,1,4,1,5] is a valid subsequence (we crossed out the two 1's) but not a subarray (the boxes aren't next to each other).

Recall How many subsequences does a length-

array have? — each of the boxes is independently "kept" or "crossed out". This is exactly why brute force is and we need something cleverer.


2. "Strictly increasing" — what climbing means

Figure — DP problems — Longest Increasing Subsequence (LIS) — O(n²) and O(n log n)

3. Indices and the subscript notation

The definition uses . Two different < signs are hiding here — don't confuse them!


4. The and symbols (used in the recurrence)

The parent's recurrence is Three pieces of notation to unpack.


5. What "dp" even means


6. Big-O: what and promise


7. lower_bound and the tails array — the fast method's tools

Figure — DP problems — Longest Increasing Subsequence (LIS) — O(n²) and O(n log n)

Prerequisite map

Array A and index counting from 0

Subsequence delete keep order

Index chain i1 lt i2 order

Strictly increasing lt

LIS length L to maximise

max union set-builder notation

O n squared recurrence

Dynamic Programming store subproblems

Big-O and log n halving

O n log n method

lower_bound and tails array

Parent LIS note

Feeds directly into the parent LIS note and connects onward to Patience Sorting and Greedy Algorithms.


Equipment checklist

What does the acronym LIS stand for?
Longest Increasing Subsequence.
Given a length-5 array, what is the index of its last element?
4 (indices run 0 to n-1)
What is the LIS of an empty array (n = 0)?
0 — there is no subsequence to climb.
Is [5, 3] a subsequence of [3,1,4,1,5]? Why or why not?
No — order is locked; you may delete but never reorder, and 5 comes after 3 in the original.
How many subsequences does a length-n array have?
2^n (each element kept or crossed out).
Is [2, 2, 3] strictly increasing?
No — strict forbids equal neighbours; it is only non-decreasing.
In , are we comparing positions or values?
Positions (indices) — this enforces original order, separate from the value comparison .
How do you get the overall LIS length from the dp table?
Take the max over all cells: LIS = max over 0 ≤ i < n of dp[i], because the LIS can end at any index.
Why is the O(n²) recurrence quadratic?
An inner loop scans all earlier j (up to n) for each of the n boxes → n × n = n² steps.
Why does the recurrence union in ?
So the max is defined even when no earlier smaller element exists, giving length 1 (element alone).
What does count?
How many times you can halve n before reaching 1.
What does tails[k] store in the fast method?
The smallest possible last value of any increasing subsequence of length k+1 seen so far.
What does lower_bound(x) return on a sorted array?
The position of the first element that is .