Design Paradigm Clinic
Retrieval Prompts
- Name the five paradigms covered in this module and give a one-line identifier for each.
- State the exchange argument template for a greedy correctness proof.
- State the two properties required for DP to apply.
- Explain the difference between backtracking and brute force.
- Give the recurrence for mergesort and quicksort (expected) and their solutions.
Compare and Distinguish
Separate these pairs:
- brute force versus backtracking
- divide-and-conquer versus dynamic programming (when both split the input)
- greedy versus DP (same optimization goal, different structure)
- memoization versus tabulation
Common Mistake Check
Identify the error:
- "My greedy works on all the sample inputs, so it is correct."
- "I memoized the recursion, so the runtime is polynomial."
- "Divide-and-conquer is always faster than iteration."
- "Backtracking is the same as brute force, just recursive."
- "Since I have optimal substructure, greedy will work."
Mini Application
Paradigm triage
For each problem: (a) restate in one sentence; (b) estimate the brute-force runtime; (c) identify the paradigm you would use; (d) justify the choice in 2-3 sentences.
- Count inversions in an array of
n = 10^6integers. - Given
n = 20items with weight and value, maximize total value subject to a weight cap. - Schedule
n = 10^5unweighted activities to maximize count. - Same as 3 but each activity has a value; maximize total value.
- Minimum number of coins from
{1, 3, 4}to make amountT = 10^5. - Given a boolean formula over
n = 15variables, decide satisfiability. - Find the length of the longest increasing subsequence of
A. - Given
n = 10^4points in the plane, find the closest pair.
Exchange arguments
For each, prove optimality of the greedy rule or give a counterexample:
- Activity selection: pick earliest finish time.
- Fractional knapsack: sort by
value/weightdescending. - Huffman coding: merge the two lowest-frequency nodes at every step.
- Minimum-sum interval cover: sort intervals by left endpoint and take any greedy cover.
DP state design
For each, state the state, recurrence, base cases, and runtime:
- Edit distance between strings
XandY. - Longest common subsequence of
XandY. 0/1knapsack with capacityW.- Matrix chain multiplication of
nmatrices. - Weighted interval scheduling.
Recurrence sketch
Write the recurrence for each and solve with the master theorem or recursion tree:
- Mergesort on
nelements. - Quicksort expected running time with random pivot.
- Karatsuba multiplication:
T(n) = 3 T(n/2) + n. - Strassen matrix multiplication:
T(n) = 7 T(n/2) + n^2.
Evidence Check
This page is complete only if you can:
- triage an unfamiliar problem into a paradigm in under 5 minutes
- write a correct exchange argument or counterexample for a proposed greedy
- write a DP state and recurrence before touching the code
- pick up a familiar recurrence and solve it from memory
Integrated Paradigm Classification Drill
Classify each problem as brute force, greedy, divide and conquer, dynamic programming, or "needs more information." Then write one sentence naming the evidence.
- Try every possible subset to find the cheapest valid server placement.
- Sort intervals by finish time and choose the next compatible interval.
- Split an array in half, solve each half, and combine crossing information.
- Choose a local cheapest edge repeatedly in a graph without checking cycles.
- Optimize a sequence where each decision depends on the previous two positions.
- Count ways to form a target amount using unlimited coins.
- Find whether a target exists in a sorted array.
- Pick the first design pattern you remember for every object-modeling problem.
For each greedy or DP classification, add either an exchange-argument sketch, a counterexample, or a recurrence-to-state sketch. The classification alone is not accepted.