3.7.9 · D1Algorithm Paradigms

Foundations — DP problems — Fibonacci, coin change (count + min), 0 - 1 knapsack

2,045 words9 min readBack to topic

Before you can read the parent note, you need to own every symbol it throws at you. Below, each tool is built from nothing: plain words first, then a picture, then the reason the topic can't live without it. Read top to bottom — each item leans on the one above it.


0. What is a "function" like even saying?

Figure — DP problems — Fibonacci, coin change (count + min), 0 - 1 knapsack

WHY the topic needs this: every DP object — , , — is one of these machines. If "" already looks like a labelled box that swallows an input and returns an answer, none of the later notation can surprise you.


1. Sequences, indices, and the little integer

Figure — DP problems — Fibonacci, coin change (count + min), 0 - 1 knapsack
  • reads "n is at least 2" — the symbol means greater than or equal to.
  • reads "c is at most a" — means less than or equal to.

WHY the topic needs this: the whole game is "answer at position is built from answers at smaller positions." You cannot talk about "smaller positions" without an index to count them.


2. Arrays and the dp[...] table

Figure — DP problems — Fibonacci, coin change (count + min), 0 - 1 knapsack

WHY the topic needs this: "store the answer and reuse it" is meaningless without a place to store it. The array is the memory in "recursion + memory."


3. Recursion — a machine that calls itself

Figure — DP problems — Fibonacci, coin change (count + min), 0 - 1 knapsack

WHY the topic needs this: "break a problem into smaller versions of itself" is recursion. DP is recursion that remembers.


4. Memoization — recursion that writes things down

WHY the topic needs this: "solve each small version once, store, reuse" is the definition of memoization — the second half of "DP = recursion + memory."


5. The Greek letters and the growth symbols

WHY the topic needs this: these symbols are how the parent measures whether DP paid off. is the entire selling point of memoization, stated in one line.


6. , , , , and

WHY the topic needs this: every recurrence in the parent is a , a , or a over smaller table entries, with a base value that must be chosen to mean the right thing.


7. Subsets and the "0/1" idea

WHY the topic needs this: "pick a subset maximizing value" is the knapsack statement, and the 0/1 constraint is the single detail that makes it not the same as coin change.


8. Optimal substructure & overlapping subproblems


Prerequisite map

functions F of n

indices and sequences

arrays the dp table

recursion self call

base case

memoization notepad

growth theta and phi

min max sum plus-equals

subset and zero-one

DP problems topic

optimal substructure

overlapping subproblems


Equipment checklist

What does mean in plain words?
Feed input into machine ; catch the single number it returns.
Where does array counting start?
At index , so dp[0] is the first box.
What are the two brackets in dp[i][w]?
A grid: row = items allowed, column = capacity left.
What is recursion in one sentence?
A machine whose instructions tell it to run itself on a smaller input.
What is a base case and why must it exist?
The smallest input answered directly; without it recursion never stops.
What does memoization add to recursion?
A notepad — compute each distinct answer once, store it, reuse it.
Why does memoized Fibonacci run in not ?
Each of the distinct values is computed exactly once instead of exponentially many times.
What does vs mean?
is "at least" (greater-or-equal); is "at most" (less-or-equal).
Why seed unreachable amounts with ?
So any real answer is automatically smaller and wins the .
Why is dp[0]=1 for coin-count but dp[0]=0 for min-coins?
One way to make 0 (pick nothing) vs zero coins needed to make 0.
What does "0/1" mean in 0/1 knapsack?
Each item is taken zero or one time — never reused.
What two conditions must hold for DP to apply?
Optimal substructure AND overlapping subproblems.