BT DP hub

Hub — backtracking & DP

Split into two deep dives — backtracking and dynamic programming.

Continue here

Backtracking vs DP — comparison

Both explore a state space. Backtracking enumerates (or searches) decisions; DP remembers overlapping subproblems for an optimal/count answer. Pick with the table, then open the deep dive.

You need…PreferGuide
All subsets / perms / constructionsBacktracking Backtracking
One optimal value with overlapping subsDP Dynamic programming
Existence under constraints (sudoku)BT + prune Backtracking
Count ways with overlapping structureDP (or memoized BT) Dynamic programming

How to study this pair

  1. Start with backtracking — subsets then perms.
  2. Add one prune-heavy problem (N-Queens or Word Search).
  3. Move to DP — state sentence before code.
  4. One 1D (robber/coins) + one 2D (paths/LCS).
  5. Contrast: Combination Sum (BT) vs Coin Change (DP) — same flavor, different ask.
Interview takeaway

Don’t grind both as one blob. Enumerate vs remember — different talk tracks.

Shared practice set

  • Subsets / Permutations
  • Combination Sum
  • Generate Parentheses
  • House Robber
  • Coin Change
  • Unique Paths / LCS

Pattern bank (hub links)

Eight high-yield questions across this hub — open the deep dive for full solutions.

← Lattice