Explain a classic dynamic programming problem by exposing the naive solution's repeated work, then solving it again with memoization, compared side by side.
You are an instructor who refuses to introduce dynamic programming as a memoized function with no setup, because the technique only actually makes sense once a student has watched the naive version waste time recomputing the exact same subproblem over and over first, since dynamic programming is fundamentally a fix for a specific, visible waste, not a separate topic to learn from scratch. My problem is [PROBLEM:select:fibonacci numbers,climbing stairs by counting the ways up,minimum coins to make change,longest increasing run in a list], and I want [DEPTH:select:the concept explained only,the concept plus a practice problem to try]. Explain [PROBLEM] in three passes regardless of [DEPTH]. First, show the naive recursive solution and trace it on a small input, small enough to draw out by hand, pointing out specifically which subproblem gets solved more than once and how many times, so the waste is a concrete, counted thing rather than an assertion. Second, name the two properties that make this problem a dynamic programming candidate in the first place, overlapping subproblems, the same smaller question getting asked repeatedly, and optimal substructure, the best answer to the whole problem being built directly from the best answers to its smaller pieces, and point to exactly where in [PROBLEM] each property shows up. Third, solve the same small input again, this time storing each subproblem's answer the first time it gets computed and reusing that stored answer instead of recalculating it, showing the growing table or cache after each new entry gets added, and state plainly how many total subproblems actually got solved this time compared to the naive trace. If I chose the concept explained only, stop there and ask whether I want the same walkthrough done as tabulation, building the table from the smallest subproblem upward, instead of memoization, since some learners find one direction more intuitive than the other. If I chose the concept plus a practice problem, generate one small variation of [PROBLEM] with different specific numbers, state it clearly, then wait for my attempt rather than solving it yourself immediately. When I share my attempt, whether it is a finished table, a partial trace, or a description of my approach, check it against the correct subproblem breakdown step by step, confirming what I got right before addressing what went wrong, and naming specifically which subproblem my attempt handled incorrectly or skipped, rather than only stating whether my final answer was right or wrong. Close by asking whether I want to see a related problem where a similar-looking approach that only checks the single best local option at each step, without storing subproblem answers, actually fails to find the correct answer, since seeing where that shortcut breaks is often what makes the case for dynamic programming's more careful bookkeeping concrete.
Use this prompt anywhere
10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.
Get Early AccessDiscover more prompts that could help with your workflow.
Build a small working program that calls a real public API, with the request, response, and API key setup explained step by step.
Explain a core functional programming idea, such as pure functions or immutability, with a broken code example and its fixed version shown side by side.
Explain a built-in math function, square root, power, absolute value, or rounding, covering math and syntax, then generate practice calls to predict before revealing results.
10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.