StudyHub

Algorithms · Hub

Algorithm paradigms

Five ways of thinking about a problem rather than five algorithms: split it (divide and conquer), grab the best option (greedy), remember sub-answers (dynamic programming), try and undo (backtracking), and recognise when no fast method is known (NP-completeness).

Why it matters: most new problems are solved by recognising which paradigm fits. The paradigm tells you the shape of the algorithm and roughly what it will cost.

5 random questions mixed from all five paradigms.

Quick comparison

ParadigmCore ideaTypical costClassic example
Divide and conquerSplit into independent smaller copies, combine$O(n \log n)$ oftenMerge sort
GreedyTake the best choice now, never undo$O(n \log n)$ (sort + pass)Activity selection
Dynamic programmingSolve overlapping subproblems once, store themsubproblems × work eachFibonacci, coin change
BacktrackingChoose, explore, undo; prune bad branchesExponential worst caseN-queens
NP-completenessEasy to check, no known fast way to solve$O(2^n)$ known exact methods3-SAT

The five paradigms

Divide and conquer

Split, solve the parts, combine.

Merge sort O(n log n) · binary search O(log n)

Study

Greedy

Always take the best-looking option.

Fast · optimal only with a proof

Study

Dynamic programming

Store each sub-answer, reuse it.

Fibonacci O(1.618ⁿ) → O(n)

Study

Backtracking

Try a choice, undo it at a dead end.

Exponential worst case · pruning helps

Study

NP-completeness

Quick to check, no known quick solve.

P ⊆ NP · reductions show hardness

Study

Which one to pick?

flowchart TD
  A{"Does the problem split into smaller copies?"} -->|"yes, independent parts"| DC["Divide and conquer"]
  A -->|"yes, but parts repeat"| DP["Dynamic programming"]
  A -->|no| B{"Is there a provably safe 'best next choice'?"}
  B -->|yes| G["Greedy"]
  B -->|no| C{"Is it a known NP-complete problem?"}
  C -->|yes| NP["Use approximation, heuristics, or exact search on small inputs"]
  C -->|no| BT["Backtracking with pruning"]
      

Key points

External resources

Videos

Review schedule

Come back after 3, 7, 14, then 30 days. Spacing beats cramming.

Feynman prompt

Explain this topic in your own words, as if teaching a beginner.

Explain it in your own words first, then record a 2–3 minute video on your phone.

25:00

Ready to record? Open your phone camera now and record a 2–3 minute explanation.

My notes

Saved only in this browser (localStorage). Nothing is uploaded.