The Core Idea
Strategies, Not Just Solutions
When you face a new problem, the first useful question isn't 'what's the code' — it's 'which paradigm fits this shape of problem.' Most algorithms you'll encounter are an application of one of five broad strategies, and recognizing which one applies turns an intimidating new problem into a familiar pattern.
These paradigms aren't mutually exclusive — dynamic programming is really 'divide and conquer plus memory,' and many greedy solutions are proven correct by comparing them against a brute-force baseline. Understanding how they relate to each other is as valuable as understanding each one alone.
💡 Memory Trick
BRUTE FORCE tries everything, GREEDY grabs the best option right now and never looks back, DIVIDE AND CONQUER splits the problem into smaller identical problems, DYNAMIC PROGRAMMING remembers answers to sub-problems so it never solves the same one twice, and BACKTRACKING tries a path and undoes it the moment it hits a dead end.
The Five Paradigms
How Each Strategy Solves Problems
1
Brute Force
Try every possible solution and pick the best one. Guaranteed correct, but often unacceptably slow (frequently O(2ⁿ) or O(n!)). It's the baseline every smarter algorithm is trying to beat.
Example: checking every possible route to find the shortest one among n cities.
2
Greedy
At each step, pick the option that looks best right now, without reconsidering past choices. Fast and simple, but only produces the correct overall answer for problems where local best choices actually lead to a global best result.
Example: making change with the fewest coins by always picking the largest coin that fits — works for US currency, but not for all coin systems.
3
Divide and Conquer
Break the problem into smaller sub-problems of the same type, solve each recursively, then combine the results. This is the strategy behind merge sort and binary search, and it's why so many O(n log n) algorithms share the same recursive shape.
Example: merge sort splits the array in half repeatedly, sorts each half, then merges.
4
Dynamic Programming
Break the problem into overlapping sub-problems, but store (memoize) each sub-problem's answer so it's computed exactly once instead of repeatedly. This turns exponential brute-force solutions into polynomial-time ones by trading memory for speed.
Example: computing Fibonacci numbers by storing previously computed values instead of recalculating them from scratch every time.
5
Backtracking
Explore a path step by step, and the instant it becomes clear the current path can't lead to a valid solution, abandon it and step back to try a different option. Used for constraint-satisfaction problems where you're searching through many candidate solutions.
Example: solving a Sudoku puzzle by placing a number, and undoing it the moment it conflicts with an existing row, column, or box.
Choosing the Right One
Matching Paradigm to Problem Shape
A useful diagnostic: if the problem asks for an optimal value and has overlapping sub-problems (the same smaller calculation needed repeatedly), reach for dynamic programming. If a locally optimal choice provably leads to a globally optimal one, greedy will be simpler and faster. If the problem naturally splits into independent halves, divide and conquer fits. If you need to enumerate all valid arrangements under constraints, backtracking is the tool.
Interviewers frequently present a problem, then ask 'what if constraints double' or 'what if this greedy solution fails on this input' specifically to test whether you can identify when a paradigm applies and when it silently breaks down.
🖥️ Applied Scenario
You're asked to find the minimum number of coins needed to make a given amount of change, using coin denominations that are not the standard clean US system.
1
You first consider a greedy approach — always picking the largest denomination that fits — but recognize that with unusual denominations, greedy can produce a wrong (non-minimal) answer.
2
You test a brute-force approach conceptually, trying every combination — correct, but far too slow for large target amounts.
3
You recognize this problem has overlapping sub-problems (the best way to make change for amount 7 is reused when solving for amount 10, 12, etc.), which is the signature of dynamic programming.
4
Conclusion: you build a DP table storing the minimum coins needed for every amount from 0 up to the target, reusing each sub-answer instead of recomputing it — solving the problem correctly and efficiently.
📌 Exam Application
A classic exam question presents a scenario and asks 'which paradigm best fits, and why?' The strongest answers name the specific structural feature that signals the paradigm — overlapping sub-problems for DP, provable local optimality for greedy, independent sub-problems for divide and conquer, constraint enumeration for backtracking — rather than just naming the paradigm.
⚠️ Most Common Algorithm Paradigms Mistakes
The most common mistake is applying greedy where it doesn't actually guarantee optimality — greedy is fast and tempting, but it must be proven correct for the specific problem, not assumed. Another frequent error is confusing divide and conquer with dynamic programming: if sub-problems are truly independent (no repeated work), it's divide and conquer; if the same sub-problem gets solved multiple times, it's DP, and skipping the memoization step wastes the entire benefit.
✓ Quick Self-Test
Can you name the five paradigms and give one real algorithm example for each? Can you explain, using the coin change example, why greedy fails on some denomination systems but dynamic programming always succeeds?
Next Lesson
Two-Pointer Technique
→
← All Algorithms Lessons